1 /*
2 The MIT License (MIT)
3 
4 Copyright (c) 2017 Charles Gunyon
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 
25 #ifndef CMP_H__
26 #define CMP_H__
27 
28 struct cmp_ctx_s;
29 
30 typedef bool   (*cmp_reader)(struct cmp_ctx_s *ctx, void *data, size_t limit);
31 typedef bool   (*cmp_skipper)(struct cmp_ctx_s *ctx, size_t count);
32 typedef size_t (*cmp_writer)(struct cmp_ctx_s *ctx, const void *data,
33                                                     size_t count);
34 
35 enum {
36   CMP_TYPE_POSITIVE_FIXNUM, /*  0 */
37   CMP_TYPE_FIXMAP,          /*  1 */
38   CMP_TYPE_FIXARRAY,        /*  2 */
39   CMP_TYPE_FIXSTR,          /*  3 */
40   CMP_TYPE_NIL,             /*  4 */
41   CMP_TYPE_BOOLEAN,         /*  5 */
42   CMP_TYPE_BIN8,            /*  6 */
43   CMP_TYPE_BIN16,           /*  7 */
44   CMP_TYPE_BIN32,           /*  8 */
45   CMP_TYPE_EXT8,            /*  9 */
46   CMP_TYPE_EXT16,           /* 10 */
47   CMP_TYPE_EXT32,           /* 11 */
48   CMP_TYPE_FLOAT,           /* 12 */
49   CMP_TYPE_DOUBLE,          /* 13 */
50   CMP_TYPE_UINT8,           /* 14 */
51   CMP_TYPE_UINT16,          /* 15 */
52   CMP_TYPE_UINT32,          /* 16 */
53   CMP_TYPE_UINT64,          /* 17 */
54   CMP_TYPE_SINT8,           /* 18 */
55   CMP_TYPE_SINT16,          /* 19 */
56   CMP_TYPE_SINT32,          /* 20 */
57   CMP_TYPE_SINT64,          /* 21 */
58   CMP_TYPE_FIXEXT1,         /* 22 */
59   CMP_TYPE_FIXEXT2,         /* 23 */
60   CMP_TYPE_FIXEXT4,         /* 24 */
61   CMP_TYPE_FIXEXT8,         /* 25 */
62   CMP_TYPE_FIXEXT16,        /* 26 */
63   CMP_TYPE_STR8,            /* 27 */
64   CMP_TYPE_STR16,           /* 28 */
65   CMP_TYPE_STR32,           /* 29 */
66   CMP_TYPE_ARRAY16,         /* 30 */
67   CMP_TYPE_ARRAY32,         /* 31 */
68   CMP_TYPE_MAP16,           /* 32 */
69   CMP_TYPE_MAP32,           /* 33 */
70   CMP_TYPE_NEGATIVE_FIXNUM  /* 34 */
71 };
72 
73 typedef struct cmp_ext_s {
74   int8_t type;
75   uint32_t size;
76 } cmp_ext_t;
77 
78 union cmp_object_data_u {
79   bool      boolean;
80   uint8_t   u8;
81   uint16_t  u16;
82   uint32_t  u32;
83   uint64_t  u64;
84   int8_t    s8;
85   int16_t   s16;
86   int32_t   s32;
87   int64_t   s64;
88   float     flt;
89   double    dbl;
90   uint32_t  array_size;
91   uint32_t  map_size;
92   uint32_t  str_size;
93   uint32_t  bin_size;
94   cmp_ext_t ext;
95 };
96 
97 typedef struct cmp_ctx_s {
98   uint8_t      error;
99   void        *buf;
100   cmp_reader   read;
101   cmp_skipper  skip;
102   cmp_writer   write;
103 } cmp_ctx_t;
104 
105 typedef struct cmp_object_s {
106   uint8_t type;
107   union cmp_object_data_u as;
108 } cmp_object_t;
109 
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113 
114 /*
115  * ============================================================================
116  * === Main API
117  * ============================================================================
118  */
119 
120 /*
121  * Initializes a CMP context
122  *
123  * If you don't intend to read, `read` may be NULL, but calling `*read*`
124  * functions will crash; there is no check.
125  *
126  * `skip` may be NULL, in which case skipping functions will use `read`.
127  *
128  * If you don't intend to write, `write` may be NULL, but calling `*write*`
129  * functions will crash; there is no check.
130  */
131 void cmp_init(cmp_ctx_t *ctx, void *buf, cmp_reader read,
132                                          cmp_skipper skip,
133                                          cmp_writer write);
134 
135 /* Returns CMP's version */
136 uint32_t cmp_version(void);
137 
138 /* Returns the MessagePack version employed by CMP */
139 uint32_t cmp_mp_version(void);
140 
141 /* Returns a string description of a CMP context's error */
142 const char* cmp_strerror(cmp_ctx_t *ctx);
143 
144 /* Writes a signed integer to the backend */
145 bool cmp_write_integer(cmp_ctx_t *ctx, int64_t d);
146 
147 /* Writes an unsigned integer to the backend */
148 bool cmp_write_uinteger(cmp_ctx_t *ctx, uint64_t u);
149 
150 /*
151  * Writes a floating-point value (either single or double-precision) to the
152  * backend
153  */
154 bool cmp_write_decimal(cmp_ctx_t *ctx, double d);
155 
156 /* Writes NULL to the backend */
157 bool cmp_write_nil(cmp_ctx_t *ctx);
158 
159 /* Writes true to the backend */
160 bool cmp_write_true(cmp_ctx_t *ctx);
161 
162 /* Writes false to the backend */
163 bool cmp_write_false(cmp_ctx_t *ctx);
164 
165 /* Writes a boolean value to the backend */
166 bool cmp_write_bool(cmp_ctx_t *ctx, bool b);
167 
168 /*
169  * Writes an unsigned char's value to the backend as a boolean.  This is useful
170  * if you are using a different boolean type in your application.
171  */
172 bool cmp_write_u8_as_bool(cmp_ctx_t *ctx, uint8_t b);
173 
174 /*
175  * Writes a string to the backend; according to the MessagePack spec, this must
176  * be encoded using UTF-8, but CMP leaves that job up to the programmer.
177  */
178 bool cmp_write_str(cmp_ctx_t *ctx, const char *data, uint32_t size);
179 
180 /*
181  * Writes a string to the backend.  This avoids using the STR8 marker, which
182  * is unsupported by MessagePack v4, the version implemented by many other
183  * MessagePack libraries.  No encoding is assumed in this case, not that it
184  * matters.
185  */
186 bool cmp_write_str_v4(cmp_ctx_t *ctx, const char *data, uint32_t size);
187 
188 /*
189  * Writes the string marker to the backend.  This is useful if you are writing
190  * data in chunks instead of a single shot.
191  */
192 bool cmp_write_str_marker(cmp_ctx_t *ctx, uint32_t size);
193 
194 /*
195  * Writes the string marker to the backend.  This is useful if you are writing
196  * data in chunks instead of a single shot.  This avoids using the STR8
197  * marker, which is unsupported by MessagePack v4, the version implemented by
198  * many other MessagePack libraries.  No encoding is assumed in this case, not
199  * that it matters.
200  */
201 bool cmp_write_str_marker_v4(cmp_ctx_t *ctx, uint32_t size);
202 
203 /* Writes binary data to the backend */
204 bool cmp_write_bin(cmp_ctx_t *ctx, const void *data, uint32_t size);
205 
206 /*
207  * Writes the binary data marker to the backend.  This is useful if you are
208  * writing data in chunks instead of a single shot.
209  */
210 bool cmp_write_bin_marker(cmp_ctx_t *ctx, uint32_t size);
211 
212 /* Writes an array to the backend. */
213 bool cmp_write_array(cmp_ctx_t *ctx, uint32_t size);
214 
215 /* Writes a map to the backend. */
216 bool cmp_write_map(cmp_ctx_t *ctx, uint32_t size);
217 
218 /* Writes an extended type to the backend */
219 bool cmp_write_ext(cmp_ctx_t *ctx, int8_t type, uint32_t size,
220                                    const void *data);
221 
222 /*
223  * Writes the extended type marker to the backend.  This is useful if you want
224  * to write the type's data in chunks instead of a single shot.
225  */
226 bool cmp_write_ext_marker(cmp_ctx_t *ctx, int8_t type, uint32_t size);
227 
228 /* Writes an object to the backend */
229 bool cmp_write_object(cmp_ctx_t *ctx, cmp_object_t *obj);
230 
231 /*
232  * Writes an object to the backend. This avoids using the STR8 marker, which
233  * is unsupported by MessagePack v4, the version implemented by many other
234  * MessagePack libraries.
235  */
236 bool cmp_write_object_v4(cmp_ctx_t *ctx, cmp_object_t *obj);
237 
238 /* Reads a signed integer that fits inside a signed char */
239 bool cmp_read_char(cmp_ctx_t *ctx, int8_t *c);
240 
241 /* Reads a signed integer that fits inside a signed short */
242 bool cmp_read_short(cmp_ctx_t *ctx, int16_t *s);
243 
244 /* Reads a signed integer that fits inside a signed int */
245 bool cmp_read_int(cmp_ctx_t *ctx, int32_t *i);
246 
247 /* Reads a signed integer that fits inside a signed long */
248 bool cmp_read_long(cmp_ctx_t *ctx, int64_t *d);
249 
250 /* Reads a signed integer */
251 bool cmp_read_integer(cmp_ctx_t *ctx, int64_t *d);
252 
253 /* Reads an unsigned integer that fits inside an unsigned char */
254 bool cmp_read_uchar(cmp_ctx_t *ctx, uint8_t *c);
255 
256 /* Reads an unsigned integer that fits inside an unsigned short */
257 bool cmp_read_ushort(cmp_ctx_t *ctx, uint16_t *s);
258 
259 /* Reads an unsigned integer that fits inside an unsigned int */
260 bool cmp_read_uint(cmp_ctx_t *ctx, uint32_t *i);
261 
262 /* Reads an unsigned integer that fits inside an unsigned long */
263 bool cmp_read_ulong(cmp_ctx_t *ctx, uint64_t *u);
264 
265 /* Reads an unsigned integer */
266 bool cmp_read_uinteger(cmp_ctx_t *ctx, uint64_t *u);
267 
268 /*
269  * Reads a floating point value (either single or double-precision) from the
270  * backend
271  */
272 bool cmp_read_decimal(cmp_ctx_t *ctx, double *d);
273 
274 /* "Reads" (more like "skips") a NULL value from the backend */
275 bool cmp_read_nil(cmp_ctx_t *ctx);
276 
277 /* Reads a boolean from the backend */
278 bool cmp_read_bool(cmp_ctx_t *ctx, bool *b);
279 
280 /*
281  * Reads a boolean as an unsigned char from the backend; this is useful if your
282  * application uses a different boolean type.
283  */
284 bool cmp_read_bool_as_u8(cmp_ctx_t *ctx, uint8_t *b);
285 
286 /* Reads a string's size from the backend */
287 bool cmp_read_str_size(cmp_ctx_t *ctx, uint32_t *size);
288 
289 /*
290  * Reads a string from the backend; according to the spec, the string's data
291  * ought to be encoded using UTF-8,
292  */
293 bool cmp_read_str(cmp_ctx_t *ctx, char *data, uint32_t *size);
294 
295 /* Reads the size of packed binary data from the backend */
296 bool cmp_read_bin_size(cmp_ctx_t *ctx, uint32_t *size);
297 
298 /* Reads packed binary data from the backend */
299 bool cmp_read_bin(cmp_ctx_t *ctx, void *data, uint32_t *size);
300 
301 /* Reads an array from the backend */
302 bool cmp_read_array(cmp_ctx_t *ctx, uint32_t *size);
303 
304 /* Reads a map from the backend */
305 bool cmp_read_map(cmp_ctx_t *ctx, uint32_t *size);
306 
307 /* Reads the extended type's marker from the backend */
308 bool cmp_read_ext_marker(cmp_ctx_t *ctx, int8_t *type, uint32_t *size);
309 
310 /* Reads an extended type from the backend */
311 bool cmp_read_ext(cmp_ctx_t *ctx, int8_t *type, uint32_t *size, void *data);
312 
313 /* Reads an object from the backend */
314 bool cmp_read_object(cmp_ctx_t *ctx, cmp_object_t *obj);
315 
316 /*
317  * Skips the next object from the backend.  If that object is an array or map,
318  * this function will:
319  *   - If `obj` is not `NULL`, fill in `obj` with that object
320  *   - Set `ctx->error` to `SKIP_DEPTH_LIMIT_EXCEEDED_ERROR`
321  *   - Return `false`
322  * Otherwise:
323  *   - (Don't touch `obj`)
324  *   - Return `true`
325  */
326 bool cmp_skip_object(cmp_ctx_t *ctx, cmp_object_t *obj);
327 
328 /*
329  * This is similar to `cmp_skip_object`, except it tolerates up to `limit`
330  * levels of nesting.  For example, in order to skip an array that contains a
331  * map, call `cmp_skip_object_limit(ctx, &obj, 2)`.  Or in other words,
332  * `cmp_skip_object(ctx, &obj)` acts similarly to `cmp_skip_object_limit(ctx,
333  * &obj, 0)`
334  *
335  * Specifically, `limit` refers to depth, not breadth.  So in order to skip an
336  * array that contains two arrays that each contain 3 strings, you would call
337  * `cmp_skip_object_limit(ctx, &obj, 2).  In order to skip an array that
338  * contains 4 arrays that each contain 1 string, you would still call
339  * `cmp_skip_object_limit(ctx, &obj, 2).
340  */
341 bool cmp_skip_object_limit(cmp_ctx_t *ctx, cmp_object_t *obj, uint32_t limit);
342 
343 /*
344  * This is similar to `cmp_skip_object`, except it will continually skip
345  * nested data structures.
346  *
347  * WARNING: This can cause your application to spend an unbounded amount of
348  *          time reading nested data structures.  Unless you completely trust
349  *          the data source, you should strongly consider `cmp_skip_object` or
350  *          `cmp_skip_object_limit`.
351  */
352 bool cmp_skip_object_no_limit(cmp_ctx_t *ctx);
353 
354 /*
355  * ============================================================================
356  * === Specific API
357  * ============================================================================
358  */
359 
360 bool cmp_write_pfix(cmp_ctx_t *ctx, uint8_t c);
361 bool cmp_write_nfix(cmp_ctx_t *ctx, int8_t c);
362 
363 bool cmp_write_sfix(cmp_ctx_t *ctx, int8_t c);
364 bool cmp_write_s8(cmp_ctx_t *ctx, int8_t c);
365 bool cmp_write_s16(cmp_ctx_t *ctx, int16_t s);
366 bool cmp_write_s32(cmp_ctx_t *ctx, int32_t i);
367 bool cmp_write_s64(cmp_ctx_t *ctx, int64_t l);
368 
369 bool cmp_write_ufix(cmp_ctx_t *ctx, uint8_t c);
370 bool cmp_write_u8(cmp_ctx_t *ctx, uint8_t c);
371 bool cmp_write_u16(cmp_ctx_t *ctx, uint16_t s);
372 bool cmp_write_u32(cmp_ctx_t *ctx, uint32_t i);
373 bool cmp_write_u64(cmp_ctx_t *ctx, uint64_t l);
374 
375 bool cmp_write_float(cmp_ctx_t *ctx, float f);
376 bool cmp_write_double(cmp_ctx_t *ctx, double d);
377 
378 bool cmp_write_fixstr_marker(cmp_ctx_t *ctx, uint8_t size);
379 bool cmp_write_fixstr(cmp_ctx_t *ctx, const char *data, uint8_t size);
380 bool cmp_write_str8_marker(cmp_ctx_t *ctx, uint8_t size);
381 bool cmp_write_str8(cmp_ctx_t *ctx, const char *data, uint8_t size);
382 bool cmp_write_str16_marker(cmp_ctx_t *ctx, uint16_t size);
383 bool cmp_write_str16(cmp_ctx_t *ctx, const char *data, uint16_t size);
384 bool cmp_write_str32_marker(cmp_ctx_t *ctx, uint32_t size);
385 bool cmp_write_str32(cmp_ctx_t *ctx, const char *data, uint32_t size);
386 
387 bool cmp_write_bin8_marker(cmp_ctx_t *ctx, uint8_t size);
388 bool cmp_write_bin8(cmp_ctx_t *ctx, const void *data, uint8_t size);
389 bool cmp_write_bin16_marker(cmp_ctx_t *ctx, uint16_t size);
390 bool cmp_write_bin16(cmp_ctx_t *ctx, const void *data, uint16_t size);
391 bool cmp_write_bin32_marker(cmp_ctx_t *ctx, uint32_t size);
392 bool cmp_write_bin32(cmp_ctx_t *ctx, const void *data, uint32_t size);
393 
394 bool cmp_write_fixarray(cmp_ctx_t *ctx, uint8_t size);
395 bool cmp_write_array16(cmp_ctx_t *ctx, uint16_t size);
396 bool cmp_write_array32(cmp_ctx_t *ctx, uint32_t size);
397 
398 bool cmp_write_fixmap(cmp_ctx_t *ctx, uint8_t size);
399 bool cmp_write_map16(cmp_ctx_t *ctx, uint16_t size);
400 bool cmp_write_map32(cmp_ctx_t *ctx, uint32_t size);
401 
402 bool cmp_write_fixext1_marker(cmp_ctx_t *ctx, int8_t type);
403 bool cmp_write_fixext1(cmp_ctx_t *ctx, int8_t type, const void *data);
404 bool cmp_write_fixext2_marker(cmp_ctx_t *ctx, int8_t type);
405 bool cmp_write_fixext2(cmp_ctx_t *ctx, int8_t type, const void *data);
406 bool cmp_write_fixext4_marker(cmp_ctx_t *ctx, int8_t type);
407 bool cmp_write_fixext4(cmp_ctx_t *ctx, int8_t type, const void *data);
408 bool cmp_write_fixext8_marker(cmp_ctx_t *ctx, int8_t type);
409 bool cmp_write_fixext8(cmp_ctx_t *ctx, int8_t type, const void *data);
410 bool cmp_write_fixext16_marker(cmp_ctx_t *ctx, int8_t type);
411 bool cmp_write_fixext16(cmp_ctx_t *ctx, int8_t type, const void *data);
412 
413 bool cmp_write_ext8_marker(cmp_ctx_t *ctx, int8_t type, uint8_t size);
414 bool cmp_write_ext8(cmp_ctx_t *ctx, int8_t type, uint8_t size,
415                                     const void *data);
416 bool cmp_write_ext16_marker(cmp_ctx_t *ctx, int8_t type, uint16_t size);
417 bool cmp_write_ext16(cmp_ctx_t *ctx, int8_t type, uint16_t size,
418                                      const void *data);
419 bool cmp_write_ext32_marker(cmp_ctx_t *ctx, int8_t type, uint32_t size);
420 bool cmp_write_ext32(cmp_ctx_t *ctx, int8_t type, uint32_t size,
421                                      const void *data);
422 
423 bool cmp_read_pfix(cmp_ctx_t *ctx, uint8_t *c);
424 bool cmp_read_nfix(cmp_ctx_t *ctx, int8_t *c);
425 
426 bool cmp_read_sfix(cmp_ctx_t *ctx, int8_t *c);
427 bool cmp_read_s8(cmp_ctx_t *ctx, int8_t *c);
428 bool cmp_read_s16(cmp_ctx_t *ctx, int16_t *s);
429 bool cmp_read_s32(cmp_ctx_t *ctx, int32_t *i);
430 bool cmp_read_s64(cmp_ctx_t *ctx, int64_t *l);
431 
432 bool cmp_read_ufix(cmp_ctx_t *ctx, uint8_t *c);
433 bool cmp_read_u8(cmp_ctx_t *ctx, uint8_t *c);
434 bool cmp_read_u16(cmp_ctx_t *ctx, uint16_t *s);
435 bool cmp_read_u32(cmp_ctx_t *ctx, uint32_t *i);
436 bool cmp_read_u64(cmp_ctx_t *ctx, uint64_t *l);
437 
438 bool cmp_read_float(cmp_ctx_t *ctx, float *f);
439 bool cmp_read_double(cmp_ctx_t *ctx, double *d);
440 
441 bool cmp_read_fixext1_marker(cmp_ctx_t *ctx, int8_t *type);
442 bool cmp_read_fixext1(cmp_ctx_t *ctx, int8_t *type, void *data);
443 bool cmp_read_fixext2_marker(cmp_ctx_t *ctx, int8_t *type);
444 bool cmp_read_fixext2(cmp_ctx_t *ctx, int8_t *type, void *data);
445 bool cmp_read_fixext4_marker(cmp_ctx_t *ctx, int8_t *type);
446 bool cmp_read_fixext4(cmp_ctx_t *ctx, int8_t *type, void *data);
447 bool cmp_read_fixext8_marker(cmp_ctx_t *ctx, int8_t *type);
448 bool cmp_read_fixext8(cmp_ctx_t *ctx, int8_t *type, void *data);
449 bool cmp_read_fixext16_marker(cmp_ctx_t *ctx, int8_t *type);
450 bool cmp_read_fixext16(cmp_ctx_t *ctx, int8_t *type, void *data);
451 
452 bool cmp_read_ext8_marker(cmp_ctx_t *ctx, int8_t *type, uint8_t *size);
453 bool cmp_read_ext8(cmp_ctx_t *ctx, int8_t *type, uint8_t *size, void *data);
454 bool cmp_read_ext16_marker(cmp_ctx_t *ctx, int8_t *type, uint16_t *size);
455 bool cmp_read_ext16(cmp_ctx_t *ctx, int8_t *type, uint16_t *size, void *data);
456 bool cmp_read_ext32_marker(cmp_ctx_t *ctx, int8_t *type, uint32_t *size);
457 bool cmp_read_ext32(cmp_ctx_t *ctx, int8_t *type, uint32_t *size, void *data);
458 
459 /*
460  * ============================================================================
461  * === Object API
462  * ============================================================================
463  */
464 
465 bool cmp_object_is_char(cmp_object_t *obj);
466 bool cmp_object_is_short(cmp_object_t *obj);
467 bool cmp_object_is_int(cmp_object_t *obj);
468 bool cmp_object_is_long(cmp_object_t *obj);
469 bool cmp_object_is_sinteger(cmp_object_t *obj);
470 bool cmp_object_is_uchar(cmp_object_t *obj);
471 bool cmp_object_is_ushort(cmp_object_t *obj);
472 bool cmp_object_is_uint(cmp_object_t *obj);
473 bool cmp_object_is_ulong(cmp_object_t *obj);
474 bool cmp_object_is_uinteger(cmp_object_t *obj);
475 bool cmp_object_is_float(cmp_object_t *obj);
476 bool cmp_object_is_double(cmp_object_t *obj);
477 bool cmp_object_is_nil(cmp_object_t *obj);
478 bool cmp_object_is_bool(cmp_object_t *obj);
479 bool cmp_object_is_str(cmp_object_t *obj);
480 bool cmp_object_is_bin(cmp_object_t *obj);
481 bool cmp_object_is_array(cmp_object_t *obj);
482 bool cmp_object_is_map(cmp_object_t *obj);
483 bool cmp_object_is_ext(cmp_object_t *obj);
484 
485 bool cmp_object_as_char(cmp_object_t *obj, int8_t *c);
486 bool cmp_object_as_short(cmp_object_t *obj, int16_t *s);
487 bool cmp_object_as_int(cmp_object_t *obj, int32_t *i);
488 bool cmp_object_as_long(cmp_object_t *obj, int64_t *d);
489 bool cmp_object_as_sinteger(cmp_object_t *obj, int64_t *d);
490 bool cmp_object_as_uchar(cmp_object_t *obj, uint8_t *c);
491 bool cmp_object_as_ushort(cmp_object_t *obj, uint16_t *s);
492 bool cmp_object_as_uint(cmp_object_t *obj, uint32_t *i);
493 bool cmp_object_as_ulong(cmp_object_t *obj, uint64_t *u);
494 bool cmp_object_as_uinteger(cmp_object_t *obj, uint64_t *u);
495 bool cmp_object_as_float(cmp_object_t *obj, float *f);
496 bool cmp_object_as_double(cmp_object_t *obj, double *d);
497 bool cmp_object_as_bool(cmp_object_t *obj, bool *b);
498 bool cmp_object_as_str(cmp_object_t *obj, uint32_t *size);
499 bool cmp_object_as_bin(cmp_object_t *obj, uint32_t *size);
500 bool cmp_object_as_array(cmp_object_t *obj, uint32_t *size);
501 bool cmp_object_as_map(cmp_object_t *obj, uint32_t *size);
502 bool cmp_object_as_ext(cmp_object_t *obj, int8_t *type, uint32_t *size);
503 
504 bool cmp_object_to_str(cmp_ctx_t *ctx, cmp_object_t *obj, char *data, uint32_t buf_size);
505 bool cmp_object_to_bin(cmp_ctx_t *ctx, cmp_object_t *obj, void *data, uint32_t buf_size);
506 
507 #ifdef __cplusplus
508 } /* extern "C" */
509 #endif
510 
511 /*
512  * ============================================================================
513  * === Backwards compatibility defines
514  * ============================================================================
515  */
516 
517 #define cmp_write_int      cmp_write_integer
518 #define cmp_write_sint     cmp_write_integer
519 #define cmp_write_sinteger cmp_write_integer
520 #define cmp_write_uint     cmp_write_uinteger
521 #define cmp_read_sinteger  cmp_read_integer
522 
523 #endif /* CMP_H__ */
524 
525 /* vi: set et ts=2 sw=2: */
526 
527