• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #pragma once
3 /*
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *   you may not use this file except in compliance with the License.
6  *   You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *   See the License for the specific language governing permissions and
14  *   limitations under the License.
15  */
16 
17 // TO ENABLE INLINE FUNCTIONS:
18 //   ON MSVC: enable the 'Inline Function Expansion' (/Ob2) compiler option, and maybe the
19 //            'Whole Program Optimitazion' (/GL), that requires the
20 //            'Link Time Code Generation' (/LTCG) linker option to be enabled too
21 
22 #ifndef BINN_H
23 #define BINN_H
24 
25 #include <string.h>
26 #include "basedefs.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #ifndef NULL
33 #ifdef __cplusplus
34 #define NULL 0
35 #else
36 #define NULL ((void*) 0)
37 #endif
38 #endif
39 
40 #ifndef TRUE
41 #define TRUE 1
42 #endif
43 
44 #ifndef FALSE
45 #define FALSE 0
46 #endif
47 
48 #ifndef BOOL
49 typedef int BOOL;
50 #endif
51 
52 #ifndef BINN_PRIVATE
53 #ifdef DEBUG
54 #define BINN_PRIVATE
55 #else
56 #define BINN_PRIVATE static
57 #endif
58 #endif
59 
60 #ifndef int64
61 #if defined(_MSC_VER) || defined(__BORLANDC__)
62 typedef __int64 int64;
63 typedef unsigned __int64 uint64;
64 #else
65 typedef int64_t int64;
66 typedef uint64_t uint64;
67 #endif
68 #endif
69 
70 // BINN CONSTANTS  ----------------------------------------
71 
72 // magic number:  0x1F 0xb1 0x22 0x1F  =>  0x1FB1221F or 0x1F22B11F
73 // because the BINN_STORAGE_NOBYTES (binary 000) may not have so many sub-types (BINN_STORAGE_HAS_MORE = 0x10)
74 #define BINN_MAGIC      0x1F22B11F
75 #define MAX_BINN_HEADER 9        // [1:type][4:size][4:count]
76 #define MIN_BINN_SIZE   3        // [1:type][1:size][1:count]
77 #define MAX_BIN_KEY_LEN 255
78 
79 #define INVALID_BINN 0
80 
81 // Storage Data Types  ------------------------------------
82 
83 #define BINN_STORAGE_NOBYTES   0x00
84 #define BINN_STORAGE_BYTE      0x20  //  8 bits
85 #define BINN_STORAGE_WORD      0x40  // 16 bits -- the endianess (byte order) is automatically corrected
86 #define BINN_STORAGE_DWORD     0x60  // 32 bits -- the endianess (byte order) is automatically corrected
87 #define BINN_STORAGE_QWORD     0x80  // 64 bits -- the endianess (byte order) is automatically corrected
88 #define BINN_STORAGE_STRING    0xA0  // Are stored with null termination
89 #define BINN_STORAGE_BLOB      0xC0
90 #define BINN_STORAGE_CONTAINER 0xE0
91 #define BINN_STORAGE_VIRTUAL   0x80000
92 //--
93 #define BINN_STORAGE_MIN BINN_STORAGE_NOBYTES
94 #define BINN_STORAGE_MAX BINN_STORAGE_CONTAINER
95 
96 #define BINN_STORAGE_MASK     0xE0
97 #define BINN_STORAGE_MASK16   0xE000
98 #define BINN_STORAGE_HAS_MORE 0x10
99 #define BINN_TYPE_MASK        0x0F
100 #define BINN_TYPE_MASK16      0x0FFF
101 
102 #define BINN_MAX_VALUE_MASK 0xFFFFF
103 //++
104 
105 // Data Formats  ------------------------------------------
106 
107 #define BINN_LIST   0xE0
108 #define BINN_MAP    0xE1
109 #define BINN_OBJECT 0xE2
110 
111 #define BINN_NULL  0x00
112 #define BINN_TRUE  0x01
113 #define BINN_FALSE 0x02
114 
115 #define BINN_UINT8 0x20      // (BYTE) (unsigned byte) Is the default format for the BYTE type
116 #define BINN_INT8  0x21      // (BYTE) (signed byte, from -128 to +127. The 0x80 is the sign bit, so the range in hex is
117                              // from 0x80 [-128] to 0x7F [127], being 0x00 = 0 and 0xFF = -1)
118 #define BINN_UINT16 0x40     // (WORD) (unsigned integer) Is the default format for the WORD type
119 #define BINN_INT16  0x41     // (WORD) (signed integer)
120 #define BINN_UINT32 0x60     // (DWORD) (unsigned integer) Is the default format for the DWORD type
121 #define BINN_INT32  0x61     // (DWORD) (signed integer)
122 #define BINN_UINT64 0x80     // (QWORD) (unsigned integer) Is the default format for the QWORD type
123 #define BINN_INT64  0x81     // (QWORD) (signed integer)
124 
125 #define BINN_SCHAR BINN_INT8
126 #define BINN_UCHAR BINN_UINT8
127 
128 #define BINN_STRING   0xA0    // (STRING) Raw String
129 #define BINN_DATETIME 0xA1    // (STRING) iso8601 format -- YYYY-MM-DD HH:MM:SS
130 #define BINN_DATE     0xA2    // (STRING) iso8601 format -- YYYY-MM-DD
131 #define BINN_TIME     0xA3    // (STRING) iso8601 format -- HH:MM:SS
132 #define BINN_DECIMAL  0xA4    // (STRING) High precision number - used for generic decimal values and for those ones
133                               // that cannot be represented in the float64 format.
134 #define BINN_CURRENCYSTR 0xA5 // (STRING) With currency unit/symbol - check for some iso standard format
135 #define BINN_SINGLE_STR  0xA6 // (STRING) Can be restored to float32
136 #define BINN_DOUBLE_STR  0xA7 // (STRING) May be restored to float64
137 
138 #define BINN_FLOAT32 0x62    // (DWORD)
139 #define BINN_FLOAT64 0x82    // (QWORD)
140 #define BINN_FLOAT   BINN_FLOAT32
141 #define BINN_SINGLE  BINN_FLOAT32
142 #define BINN_DOUBLE  BINN_FLOAT64
143 
144 #define BINN_CURRENCY 0x83   // (QWORD)
145 
146 #define BINN_BLOB 0xC0       // (BLOB) Raw Blob
147 
148 
149 // virtual types:
150 
151 #define BINN_BOOL 0x80061       // (DWORD) The value may be 0 or 1
152 
153 #ifdef BINN_EXTENDED
154 //#define BINN_SINGLE    0x800A1  // (STRING) Can be restored to float32
155 //#define BINN_DOUBLE    0x800A2  // (STRING) May be restored to float64
156 #endif
157 
158 //#define BINN_BINN      0x800E1  // (CONTAINER)
159 //#define BINN_BINN_BUFFER  0x800C1  // (BLOB) user binn. it's not open by the parser
160 
161 // extended content types:
162 
163 // strings:
164 #define BINN_HTML       0xB001
165 #define BINN_XML        0xB002
166 #define BINN_JSON       0xB003
167 #define BINN_JAVASCRIPT 0xB004
168 #define BINN_CSS        0xB005
169 
170 // blobs:
171 #define BINN_JPEG 0xD001
172 #define BINN_GIF  0xD002
173 #define BINN_PNG  0xD003
174 #define BINN_BMP  0xD004
175 
176 // type families
177 #define BINN_FAMILY_NONE   0x00
178 #define BINN_FAMILY_NULL   0xf1
179 #define BINN_FAMILY_INT    0xf2
180 #define BINN_FAMILY_FLOAT  0xf3
181 #define BINN_FAMILY_STRING 0xf4
182 #define BINN_FAMILY_BLOB   0xf5
183 #define BINN_FAMILY_BOOL   0xf6
184 #define BINN_FAMILY_BINN   0xf7
185 
186 // integer types related to signal
187 #define BINN_SIGNED_INT   11
188 #define BINN_UNSIGNED_INT 22
189 
190 typedef void (*binn_mem_free)(void*);
191 
192 typedef void (*binn_user_data_free)(void*);
193 
194 #define BINN_STATIC    ((binn_mem_free) 0)
195 #define BINN_TRANSIENT ((binn_mem_free) - 1)
196 
197 
198 #define BINN_IS_CONTAINER_TYPE(type_) ((type_) >= BINN_LIST && (type_) <= BINN_OBJECT)
199 
200 #define BINN_IS_INT_TYPE(type_) ((type_) >= BINN_UINT8 && (type_) <= BINN_INT64)
201 
202 
203 // --- BINN STRUCTURE --------------------------------------------------------------
204 
205 struct binn_struct {
206   int header;        // this struct header holds the magic number (BINN_MAGIC) that identifies this memory block as a
207                      // binn structure
208   BOOL allocated;    // the struct can be allocated using malloc_fn() or can be on the stack
209   BOOL writable;     // did it was create for writing? it can use the pbuf if not unified with ptr
210   BOOL dirty;        // the container header is not written to the buffer
211   //
212   void *pbuf;        // use *ptr below?
213   BOOL  pre_allocated;
214   int   alloc_size;
215   int   used_size;
216   //
217   int   type;
218   void *ptr;
219   int   size;
220   int   count;
221   //
222   binn_mem_free freefn;  // used only when type == BINN_STRING or BINN_BLOB
223   //
224   void *user_data;
225   binn_user_data_free userdata_freefn;
226   //
227   union {
228     int8_t   vint8;
229     int16_t  vint16;
230     int32_t  vint32;
231     int64_t  vint64;
232     uint8_t  vuint8;
233     uint16_t vuint16;
234     uint32_t vuint32;
235     uint64_t vuint64;
236     //
237     signed char    vchar;
238     unsigned char  vuchar;
239     signed short   vshort;
240     unsigned short vushort;
241     signed int     vint;
242     unsigned int   vuint;
243     //
244     float  vfloat;
245     double vdouble;
246     //
247     BOOL vbool;
248   };
249 };
250 
251 typedef struct binn_struct binn;
252 
253 // --- GENERAL FUNCTIONS  ----------------------------------------------------------
254 
255 void binn_set_alloc_functions(
256   void*(*new_malloc)(size_t), void*(*new_realloc)(void*, size_t),
257   void (*new_free)(void*));
258 int binn_create_type(int storage_type, int data_type_index);
259 BOOL binn_get_type_info(int long_type, int *pstorage_type, int *pextra_type);
260 int binn_get_write_storage(int type);
261 int binn_get_read_storage(int type);
262 BOOL binn_is_container(binn *item);
263 
264 void binn_set_user_data(binn *item, void *user_data, binn_user_data_free freefn);
265 
266 // --- WRITE FUNCTIONS  ------------------------------------------------------------
267 
268 BOOL binn_save_header(binn *item);
269 
270 // create a new binn allocating memory for the structure
271 IW_ALLOC binn* binn_new(int type, int size, void *buffer);
272 IW_ALLOC binn* binn_list(void);
273 IW_ALLOC binn* binn_map(void);
274 IW_ALLOC binn* binn_object(void);
275 
276 // create a new binn storing the structure on the stack
277 BOOL binn_create(binn *item, int type, int size, void *buffer);
278 BOOL binn_create_list(binn *list);
279 BOOL binn_create_map(binn *map);
280 BOOL binn_create_object(binn *object);
281 
282 // create a new binn as a copy from another
283 IW_ALLOC binn* binn_copy(void *old);
284 
285 BOOL binn_list_add_new(binn *list, binn *value);
286 BOOL binn_map_set_new(binn *map, int id, binn *value);
287 BOOL binn_object_set_new(binn *obj, const char *key, binn *value);
288 BOOL binn_object_set_new2(binn *obj, const char *key, int keylen, binn *value);
289 
290 // extended interface
291 BOOL binn_list_add(binn *list, int type, void *pvalue, int size);
292 BOOL binn_map_set(binn *map, int id, int type, void *pvalue, int size);
293 BOOL binn_object_set(binn *obj, const char *key, int type, void *pvalue, int size);
294 BOOL binn_object_set2(binn *obj, const char *key, int keylen, int type, void *pvalue, int size);
295 
296 // release memory
297 void binn_free(binn *item);
298 
299 // free the binn structure but keeps the binn buffer allocated, returning a pointer to it.
300 // use the free function to release the buffer later
301 void* binn_release(binn *item);
302 
303 // --- CREATING VALUES ---------------------------------------------------
304 
305 IW_ALLOC binn* binn_value(int type, void *pvalue, int size, binn_mem_free freefn);
306 
binn_init_item(binn * item)307 IW_INLINE void binn_init_item(binn *item) {
308   memset(item, 0, sizeof(binn));
309   item->header = BINN_MAGIC;
310 }
311 
binn_int8(signed char value)312 IW_ALLOC IW_INLINE binn* binn_int8(signed char value) {
313   return binn_value(BINN_INT8, &value, 0, NULL);
314 }
315 
binn_int16(short value)316 IW_ALLOC IW_INLINE binn* binn_int16(short value) {
317   return binn_value(BINN_INT16, &value, 0, NULL);
318 }
319 
binn_int32(int value)320 IW_ALLOC IW_INLINE binn* binn_int32(int value) {
321   return binn_value(BINN_INT32, &value, 0, NULL);
322 }
323 
binn_int64(int64 value)324 IW_ALLOC IW_INLINE binn* binn_int64(int64 value) {
325   return binn_value(BINN_INT64, &value, 0, NULL);
326 }
327 
binn_uint8(unsigned char value)328 IW_ALLOC IW_INLINE binn* binn_uint8(unsigned char value) {
329   return binn_value(BINN_UINT8, &value, 0, NULL);
330 }
331 
binn_uint16(unsigned short value)332 IW_ALLOC IW_INLINE binn* binn_uint16(unsigned short value) {
333   return binn_value(BINN_UINT16, &value, 0, NULL);
334 }
335 
binn_uint32(unsigned int value)336 IW_ALLOC IW_INLINE binn* binn_uint32(unsigned int value) {
337   return binn_value(BINN_UINT32, &value, 0, NULL);
338 }
339 
binn_uint64(uint64 value)340 IW_ALLOC IW_INLINE binn* binn_uint64(uint64 value) {
341   return binn_value(BINN_UINT64, &value, 0, NULL);
342 }
343 
binn_float(float value)344 IW_ALLOC IW_INLINE binn* binn_float(float value) {
345   return binn_value(BINN_FLOAT, &value, 0, NULL);
346 }
347 
binn_double(double value)348 IW_ALLOC IW_INLINE binn* binn_double(double value) {
349   return binn_value(BINN_DOUBLE, &value, 0, NULL);
350 }
351 
binn_bool(BOOL value)352 IW_ALLOC IW_INLINE binn* binn_bool(BOOL value) {
353   return binn_value(BINN_BOOL, &value, 0, NULL);
354 }
355 
binn_null(void)356 IW_ALLOC IW_INLINE binn* binn_null(void) {
357   return binn_value(BINN_NULL, NULL, 0, NULL);
358 }
359 
binn_string(const char * str,binn_mem_free freefn)360 IW_ALLOC IW_INLINE binn* binn_string(const char *str, binn_mem_free freefn) {
361   return binn_value(BINN_STRING, (void*) str, 0, freefn);
362 }
363 
binn_blob(void * ptr,int size,binn_mem_free freefn)364 IW_ALLOC IW_INLINE binn* binn_blob(void *ptr, int size, binn_mem_free freefn) {
365   return binn_value(BINN_BLOB, ptr, size, freefn);
366 }
367 
368 // --- READ FUNCTIONS  -------------------------------------------------------------
369 
370 // these functions accept pointer to the binn structure and pointer to the binn buffer
371 void* binn_ptr(void *ptr);
372 int binn_size(void *ptr);
373 int binn_buf_size(const void *ptr);
374 int binn_type(void *ptr);
375 int binn_buf_type(const void *pbuf);
376 int binn_count(void *ptr);
377 int binn_buf_count(const void *pbuf);
378 BOOL binn_is_valid_header(const void *pbuf, int *ptype, int *pcount, int *psize, int *pheadersize);
379 
380 BOOL binn_is_valid(void *ptr, int *ptype, int *pcount, int *psize);
381 
382 /* the function returns the values (type, count and size) and they don't need to be
383    initialized. these values are read from the buffer. example:
384 
385    int type, count, size;
386    result = binn_is_valid(ptr, &type, &count, &size);
387  */
388 BOOL binn_is_valid_ex(void *ptr, int *ptype, int *pcount, int *psize);
389 
390 /* if some value is informed (type, count or size) then the function will check if
391    the value returned from the serialized data matches the informed value. otherwise
392    the values must be initialized to zero. example:
393 
394    int type=0, count=0, size = known_size;
395    result = binn_is_valid_ex(ptr, &type, &count, &size);
396  */
397 
398 BOOL binn_is_struct(void *ptr);
399 
400 // Loading a binn buffer into a binn value - this is optional
401 
402 BOOL binn_load(void *data, binn *item);      // on stack
403 binn* binn_open(void *data);                 // allocated
404 
405 // easiest interface to use, but don't check if the value is there
406 
407 signed char binn_list_int8(void *list, int pos);
408 short binn_list_int16(void *list, int pos);
409 int binn_list_int32(void *list, int pos);
410 int64 binn_list_int64(void *list, int pos);
411 unsigned char binn_list_uint8(void *list, int pos);
412 unsigned short binn_list_uint16(void *list, int pos);
413 unsigned int binn_list_uint32(void *list, int pos);
414 uint64 binn_list_uint64(void *list, int pos);
415 float binn_list_float(void *list, int pos);
416 double binn_list_double(void *list, int pos);
417 BOOL binn_list_bool(void *list, int pos);
418 BOOL binn_list_null(void *list, int pos);
419 char* binn_list_str(void *list, int pos);
420 void* binn_list_blob(void *list, int pos, int *psize);
421 void* binn_list_list(void *list, int pos);
422 void* binn_list_map(void *list, int pos);
423 void* binn_list_object(void *list, int pos);
424 
425 signed char binn_map_int8(void *map, int id);
426 short binn_map_int16(void *map, int id);
427 int binn_map_int32(void *map, int id);
428 int64 binn_map_int64(void *map, int id);
429 unsigned char binn_map_uint8(void *map, int id);
430 unsigned short binn_map_uint16(void *map, int id);
431 unsigned int binn_map_uint32(void *map, int id);
432 uint64 binn_map_uint64(void *map, int id);
433 float binn_map_float(void *map, int id);
434 double binn_map_double(void *map, int id);
435 BOOL binn_map_bool(void *map, int id);
436 BOOL binn_map_null(void *map, int id);
437 char* binn_map_str(void *map, int id);
438 void* binn_map_blob(void *map, int id, int *psize);
439 void* binn_map_list(void *map, int id);
440 void* binn_map_map(void *map, int id);
441 void* binn_map_object(void *map, int id);
442 
443 signed char binn_object_int8(void *obj, const char *key);
444 short binn_object_int16(void *obj, const char *key);
445 int binn_object_int32(void *obj, const char *key);
446 int64 binn_object_int64(void *obj, const char *key);
447 unsigned char binn_object_uint8(void *obj, const char *key);
448 unsigned short binn_object_uint16(void *obj, const char *key);
449 unsigned int binn_object_uint32(void *obj, const char *key);
450 uint64 binn_object_uint64(void *obj, const char *key);
451 float binn_object_float(void *obj, const char *key);
452 double binn_object_double(void *obj, const char *key);
453 BOOL binn_object_bool(void *obj, const char *key);
454 BOOL binn_object_null(void *obj, const char *key);
455 char* binn_object_str(void *obj, const char *key);
456 void* binn_object_blob(void *obj, const char *key, int *psize);
457 void* binn_object_list(void *obj, const char *key);
458 void* binn_object_map(void *obj, const char *key);
459 void* binn_object_object(void *obj, const char *key);
460 
461 
462 // return a pointer to an allocated binn structure - must be released with the free() function or equivalent set in
463 // binn_set_alloc_functions()
464 binn* binn_list_value(void *list, int pos);
465 binn* binn_map_value(void *map, int id);
466 binn* binn_object_value(void *obj, const char *key);
467 
468 // read the value to a binn structure on the stack
469 BOOL binn_list_get_value(void *list, int pos, binn *value);
470 BOOL binn_map_get_value(void *map, int id, binn *value);
471 BOOL binn_object_get_value(void *obj, const char *key, binn *value);
472 
473 // single interface - these functions check the data type
474 BOOL binn_list_get(void *list, int pos, int type, void *pvalue, int *psize);
475 BOOL binn_map_get(void *map, int id, int type, void *pvalue, int *psize);
476 BOOL binn_object_get(void *obj, const char *key, int type, void *pvalue, int *psize);
477 
478 // these 3 functions return a pointer to the value and the data type
479 // they are thread-safe on big-endian devices
480 // on little-endian devices they are thread-safe only to return pointers to list, map, object, blob and strings
481 // the returned pointer to 16, 32 and 64 bits values must be used only by single-threaded applications
482 void* binn_list_read(void *list, int pos, int *ptype, int *psize);
483 void* binn_map_read(void *map, int id, int *ptype, int *psize);
484 void* binn_object_read(void *obj, const char *key, int *ptype, int *psize);
485 
486 // READ PAIR FUNCTIONS
487 
488 // these functions use base 1 in the 'pos' argument
489 
490 // on stack
491 BOOL binn_map_get_pair(void *map, int pos, int *pid, binn *value);
492 BOOL binn_object_get_pair(
493   void *obj, int pos, char *pkey,
494   binn *value);                                   // must free the memory returned in the pkey
495 
496 // allocated
497 IW_ALLOC binn* binn_map_pair(void *map, int pos, int *pid);
498 IW_ALLOC binn* binn_object_pair(void *obj, int pos, char *pkey);     // must free the memory returned in the pkey
499 
500 // these 2 functions return a pointer to the value and the data type
501 // they are thread-safe on big-endian devices
502 // on little-endian devices they are thread-safe only to return pointers to list, map, object, blob and strings
503 // the returned pointer to 16, 32 and 64 bits values must be used only by single-threaded applications
504 void* binn_map_read_pair(void *ptr, int pos, int *pid, int *ptype, int *psize);
505 void* binn_object_read_pair(void *ptr, int pos, char *pkey, int *ptype, int *psize);
506 
507 // SEQUENTIAL READ FUNCTIONS
508 
509 typedef struct binn_iter_struct {
510   unsigned char *pnext;
511   unsigned char *plimit;
512   int type;
513   int count;
514   int current;
515 } binn_iter;
516 
517 BOOL binn_iter_init(binn_iter *iter, void *pbuf, int type);
518 
519 // allocated
520 IW_ALLOC binn* binn_list_next_value(binn_iter *iter);
521 IW_ALLOC binn* binn_map_next_value(binn_iter *iter, int *pid);
522 IW_ALLOC binn* binn_object_next_value(binn_iter *iter, char *pkey);     // the key must be declared as: char key[256];
523 
524 // on stack
525 BOOL binn_list_next(binn_iter *iter, binn *value);
526 BOOL binn_map_next(binn_iter *iter, int *pid, binn *value);
527 BOOL binn_object_next(
528   binn_iter *iter, char *pkey,
529   binn *value);                                 // the key must be declared as: char key[256];
530 BOOL binn_object_next2(binn_iter *iter, char **pkey, int *klen, binn *value);
531 
532 // these 3 functions return a pointer to the value and the data type
533 // they are thread-safe on big-endian devices
534 // on little-endian devices they are thread-safe only to return pointers to list, map, object, blob and strings
535 // the returned pointer to 16, 32 and 64 bits values must be used only by single-threaded applications
536 void* binn_list_read_next(binn_iter *iter, int *ptype, int *psize);
537 void* binn_map_read_next(binn_iter *iter, int *pid, int *ptype, int *psize);
538 void* binn_object_read_next(
539   binn_iter *iter, char *pkey, int *ptype,
540   int *psize);                                      // the key must be declared as: char key[256];
541 
542 // --- MACROS ------------------------------------------------------------
543 
544 #define binn_is_writable(item) (item)->writable;
545 
546 // set values on stack allocated binn structures
547 
548 #define binn_set_null(item) do { (item)->type = BINN_NULL; } while (0)
549 
550 #define binn_set_bool(item, value) do { (item)->type = BINN_BOOL; (item)->vbool = value; (item)->ptr = &((item)->vbool); \
551 } while (0)
552 
553 #define binn_set_int(item, value)   do { (item)->type = BINN_INT32; (item)->vint32 = value; \
554                                          (item)->ptr = &((item)->vint32); } while (0)
555 #define binn_set_int64(item, value) do { (item)->type = BINN_INT64; (item)->vint64 = value; \
556                                          (item)->ptr = &((item)->vint64); } while (0)
557 
558 #define binn_set_uint(item, value)   do { (item)->type = BINN_UINT32; (item)->vuint32 = value; \
559                                           (item)->ptr = &((item)->vuint32); } while (0)
560 #define binn_set_uint64(item, value) do { (item)->type = BINN_UINT64; (item)->vuint64 = value; \
561                                           (item)->ptr = &((item)->vuint64); } while (0)
562 
563 #define binn_set_float(item, value)  do { (item)->type = BINN_FLOAT;  (item)->vfloat = value; \
564                                           (item)->ptr = &((item)->vfloat); } while (0)
565 #define binn_set_double(item, value) do { (item)->type = BINN_DOUBLE; (item)->vdouble = value; \
566                                           (item)->ptr = &((item)->vdouble); } while (0)
567 
568 //#define binn_set_string(item,str,pfree)    do { (item)->type = BINN_STRING; (item)->ptr = str; (item)->freefn = pfree;
569 // } while (0)
570 //#define binn_set_blob(item,ptr,size,pfree) do { (item)->type = BINN_BLOB;   (item)->ptr = ptr; (item)->freefn = pfree;
571 // (item)->size = size; } while (0)
572 BOOL binn_set_string(binn *item, const char *str, size_t len);
573 BOOL binn_set_blob(binn *item, void *ptr, int size, binn_mem_free pfree);
574 
575 //#define binn_double(value) {       (item)->type = BINN_DOUBLE; (item)->vdouble = value; (item)->ptr =
576 // &((item)->vdouble) }
577 
578 // FOREACH MACROS
579 // must use these declarations in the function that will use them:
580 //  binn_iter iter;
581 //  char key[256];  // only for the object
582 //  int  id;        // only for the map
583 //  binn value;
584 
585 #define binn_object_foreach(object, key, value)   \
586   binn_iter_init(&iter, object, BINN_OBJECT);   \
587   while (binn_object_next(&iter, key, &value))
588 
589 #define binn_map_foreach(map, id, value)      \
590   binn_iter_init(&iter, map, BINN_MAP);     \
591   while (binn_map_next(&iter, &id, &value))
592 
593 #define binn_list_foreach(list, value)      \
594   binn_iter_init(&iter, list, BINN_LIST); \
595   while (binn_list_next(&iter, &value))
596 
597 /*************************************************************************************/
598 /*** SET FUNCTIONS *******************************************************************/
599 /*************************************************************************************/
600 
binn_list_add_int8(binn * list,signed char value)601 IW_INLINE BOOL binn_list_add_int8(binn *list, signed char value) {
602   return binn_list_add(list, BINN_INT8, &value, 0);
603 }
604 
binn_list_add_int16(binn * list,short value)605 IW_INLINE BOOL binn_list_add_int16(binn *list, short value) {
606   return binn_list_add(list, BINN_INT16, &value, 0);
607 }
608 
binn_list_add_int32(binn * list,int value)609 IW_INLINE BOOL binn_list_add_int32(binn *list, int value) {
610   return binn_list_add(list, BINN_INT32, &value, 0);
611 }
612 
binn_list_add_int64(binn * list,int64 value)613 IW_INLINE BOOL binn_list_add_int64(binn *list, int64 value) {
614   return binn_list_add(list, BINN_INT64, &value, 0);
615 }
616 
binn_list_add_uint8(binn * list,unsigned char value)617 IW_INLINE BOOL binn_list_add_uint8(binn *list, unsigned char value) {
618   return binn_list_add(list, BINN_UINT8, &value, 0);
619 }
620 
binn_list_add_uint16(binn * list,unsigned short value)621 IW_INLINE BOOL binn_list_add_uint16(binn *list, unsigned short value) {
622   return binn_list_add(list, BINN_UINT16, &value, 0);
623 }
624 
binn_list_add_uint32(binn * list,unsigned int value)625 IW_INLINE BOOL binn_list_add_uint32(binn *list, unsigned int value) {
626   return binn_list_add(list, BINN_UINT32, &value, 0);
627 }
628 
binn_list_add_uint64(binn * list,uint64 value)629 IW_INLINE BOOL binn_list_add_uint64(binn *list, uint64 value) {
630   return binn_list_add(list, BINN_UINT64, &value, 0);
631 }
632 
binn_list_add_float(binn * list,float value)633 IW_INLINE BOOL binn_list_add_float(binn *list, float value) {
634   return binn_list_add(list, BINN_FLOAT32, &value, 0);
635 }
636 
binn_list_add_double(binn * list,double value)637 IW_INLINE BOOL binn_list_add_double(binn *list, double value) {
638   return binn_list_add(list, BINN_FLOAT64, &value, 0);
639 }
640 
binn_list_add_bool(binn * list,BOOL value)641 IW_INLINE BOOL binn_list_add_bool(binn *list, BOOL value) {
642   return binn_list_add(list, BINN_BOOL, &value, 0);
643 }
644 
binn_list_add_null(binn * list)645 IW_INLINE BOOL binn_list_add_null(binn *list) {
646   return binn_list_add(list, BINN_NULL, NULL, 0);
647 }
648 
binn_list_add_str(binn * list,char * str)649 IW_INLINE BOOL binn_list_add_str(binn *list, char *str) {
650   return binn_list_add(list, BINN_STRING, str, 0);
651 }
652 
binn_list_add_const_str(binn * list,const char * str)653 IW_INLINE BOOL binn_list_add_const_str(binn *list, const char *str) {
654   return binn_list_add(list, BINN_STRING, (char*) str, 0);
655 }
656 
binn_list_add_blob(binn * list,void * ptr,int size)657 IW_INLINE BOOL binn_list_add_blob(binn *list, void *ptr, int size) {
658   return binn_list_add(list, BINN_BLOB, ptr, size);
659 }
660 
binn_list_add_list(binn * list,void * list2)661 IW_INLINE BOOL binn_list_add_list(binn *list, void *list2) {
662   return binn_list_add(list, BINN_LIST, binn_ptr(list2), binn_size(list2));
663 }
664 
binn_list_add_map(binn * list,void * map)665 IW_INLINE BOOL binn_list_add_map(binn *list, void *map) {
666   return binn_list_add(list, BINN_MAP, binn_ptr(map), binn_size(map));
667 }
668 
binn_list_add_object(binn * list,void * obj)669 IW_INLINE BOOL binn_list_add_object(binn *list, void *obj) {
670   return binn_list_add(list, BINN_OBJECT, binn_ptr(obj), binn_size(obj));
671 }
672 
binn_list_add_value(binn * list,binn * value)673 IW_INLINE BOOL binn_list_add_value(binn *list, binn *value) {
674   return binn_list_add(list, value->type, binn_ptr(value), binn_size(value));
675 }
676 
677 /*************************************************************************************/
678 
binn_map_set_int8(binn * map,int id,signed char value)679 IW_INLINE BOOL binn_map_set_int8(binn *map, int id, signed char value) {
680   return binn_map_set(map, id, BINN_INT8, &value, 0);
681 }
682 
binn_map_set_int16(binn * map,int id,short value)683 IW_INLINE BOOL binn_map_set_int16(binn *map, int id, short value) {
684   return binn_map_set(map, id, BINN_INT16, &value, 0);
685 }
686 
binn_map_set_int32(binn * map,int id,int value)687 IW_INLINE BOOL binn_map_set_int32(binn *map, int id, int value) {
688   return binn_map_set(map, id, BINN_INT32, &value, 0);
689 }
690 
binn_map_set_int64(binn * map,int id,int64 value)691 IW_INLINE BOOL binn_map_set_int64(binn *map, int id, int64 value) {
692   return binn_map_set(map, id, BINN_INT64, &value, 0);
693 }
694 
binn_map_set_uint8(binn * map,int id,unsigned char value)695 IW_INLINE BOOL binn_map_set_uint8(binn *map, int id, unsigned char value) {
696   return binn_map_set(map, id, BINN_UINT8, &value, 0);
697 }
698 
binn_map_set_uint16(binn * map,int id,unsigned short value)699 IW_INLINE BOOL binn_map_set_uint16(binn *map, int id, unsigned short value) {
700   return binn_map_set(map, id, BINN_UINT16, &value, 0);
701 }
702 
binn_map_set_uint32(binn * map,int id,unsigned int value)703 IW_INLINE BOOL binn_map_set_uint32(binn *map, int id, unsigned int value) {
704   return binn_map_set(map, id, BINN_UINT32, &value, 0);
705 }
706 
binn_map_set_uint64(binn * map,int id,uint64 value)707 IW_INLINE BOOL binn_map_set_uint64(binn *map, int id, uint64 value) {
708   return binn_map_set(map, id, BINN_UINT64, &value, 0);
709 }
710 
binn_map_set_float(binn * map,int id,float value)711 IW_INLINE BOOL binn_map_set_float(binn *map, int id, float value) {
712   return binn_map_set(map, id, BINN_FLOAT32, &value, 0);
713 }
714 
binn_map_set_double(binn * map,int id,double value)715 IW_INLINE BOOL binn_map_set_double(binn *map, int id, double value) {
716   return binn_map_set(map, id, BINN_FLOAT64, &value, 0);
717 }
718 
binn_map_set_bool(binn * map,int id,BOOL value)719 IW_INLINE BOOL binn_map_set_bool(binn *map, int id, BOOL value) {
720   return binn_map_set(map, id, BINN_BOOL, &value, 0);
721 }
722 
binn_map_set_null(binn * map,int id)723 IW_INLINE BOOL binn_map_set_null(binn *map, int id) {
724   return binn_map_set(map, id, BINN_NULL, NULL, 0);
725 }
726 
binn_map_set_str(binn * map,int id,char * str)727 IW_INLINE BOOL binn_map_set_str(binn *map, int id, char *str) {
728   return binn_map_set(map, id, BINN_STRING, str, 0);
729 }
730 
binn_map_set_blob(binn * map,int id,void * ptr,int size)731 IW_INLINE BOOL binn_map_set_blob(binn *map, int id, void *ptr, int size) {
732   return binn_map_set(map, id, BINN_BLOB, ptr, size);
733 }
734 
binn_map_set_list(binn * map,int id,void * list)735 IW_INLINE BOOL binn_map_set_list(binn *map, int id, void *list) {
736   return binn_map_set(map, id, BINN_LIST, binn_ptr(list), binn_size(list));
737 }
738 
binn_map_set_map(binn * map,int id,void * map2)739 IW_INLINE BOOL binn_map_set_map(binn *map, int id, void *map2) {
740   return binn_map_set(map, id, BINN_MAP, binn_ptr(map2), binn_size(map2));
741 }
742 
binn_map_set_object(binn * map,int id,void * obj)743 IW_INLINE BOOL binn_map_set_object(binn *map, int id, void *obj) {
744   return binn_map_set(map, id, BINN_OBJECT, binn_ptr(obj), binn_size(obj));
745 }
746 
binn_map_set_value(binn * map,int id,binn * value)747 IW_INLINE BOOL binn_map_set_value(binn *map, int id, binn *value) {
748   return binn_map_set(map, id, value->type, binn_ptr(value), binn_size(value));
749 }
750 
751 /*************************************************************************************/
752 
binn_object_set_int8(binn * obj,const char * key,signed char value)753 IW_INLINE BOOL binn_object_set_int8(binn *obj, const char *key, signed char value) {
754   return binn_object_set(obj, key, BINN_INT8, &value, 0);
755 }
756 
binn_object_set_int16(binn * obj,const char * key,short value)757 IW_INLINE BOOL binn_object_set_int16(binn *obj, const char *key, short value) {
758   return binn_object_set(obj, key, BINN_INT16, &value, 0);
759 }
760 
binn_object_set_int32(binn * obj,const char * key,int value)761 IW_INLINE BOOL binn_object_set_int32(binn *obj, const char *key, int value) {
762   return binn_object_set(obj, key, BINN_INT32, &value, 0);
763 }
764 
binn_object_set_int64(binn * obj,const char * key,int64 value)765 IW_INLINE BOOL binn_object_set_int64(binn *obj, const char *key, int64 value) {
766   return binn_object_set(obj, key, BINN_INT64, &value, 0);
767 }
768 
binn_object_set_uint8(binn * obj,const char * key,unsigned char value)769 IW_INLINE BOOL binn_object_set_uint8(binn *obj, const char *key, unsigned char value) {
770   return binn_object_set(obj, key, BINN_UINT8, &value, 0);
771 }
772 
binn_object_set_uint16(binn * obj,const char * key,unsigned short value)773 IW_INLINE BOOL binn_object_set_uint16(binn *obj, const char *key, unsigned short value) {
774   return binn_object_set(obj, key, BINN_UINT16, &value, 0);
775 }
776 
binn_object_set_uint32(binn * obj,const char * key,unsigned int value)777 IW_INLINE BOOL binn_object_set_uint32(binn *obj, const char *key, unsigned int value) {
778   return binn_object_set(obj, key, BINN_UINT32, &value, 0);
779 }
780 
binn_object_set_uint64(binn * obj,const char * key,uint64 value)781 IW_INLINE BOOL binn_object_set_uint64(binn *obj, const char *key, uint64 value) {
782   return binn_object_set(obj, key, BINN_UINT64, &value, 0);
783 }
784 
binn_object_set_float(binn * obj,const char * key,float value)785 IW_INLINE BOOL binn_object_set_float(binn *obj, const char *key, float value) {
786   return binn_object_set(obj, key, BINN_FLOAT32, &value, 0);
787 }
788 
binn_object_set_double(binn * obj,const char * key,double value)789 IW_INLINE BOOL binn_object_set_double(binn *obj, const char *key, double value) {
790   return binn_object_set(obj, key, BINN_FLOAT64, &value, 0);
791 }
792 
binn_object_set_bool(binn * obj,const char * key,BOOL value)793 IW_INLINE BOOL binn_object_set_bool(binn *obj, const char *key, BOOL value) {
794   return binn_object_set(obj, key, BINN_BOOL, &value, 0);
795 }
796 
binn_object_set_null(binn * obj,const char * key)797 IW_INLINE BOOL binn_object_set_null(binn *obj, const char *key) {
798   return binn_object_set(obj, key, BINN_NULL, NULL, 0);
799 }
800 
binn_object_set_str(binn * obj,const char * key,const char * str)801 IW_INLINE BOOL binn_object_set_str(binn *obj, const char *key, const char *str) {
802   return binn_object_set(obj, key, BINN_STRING, (char*) str, 0);  // todo
803 }
804 
binn_object_set_blob(binn * obj,const char * key,void * ptr,int size)805 IW_INLINE BOOL binn_object_set_blob(binn *obj, const char *key, void *ptr, int size) {
806   return binn_object_set(obj, key, BINN_BLOB, ptr, size);
807 }
808 
binn_object_set_list(binn * obj,const char * key,void * list)809 IW_INLINE BOOL binn_object_set_list(binn *obj, const char *key, void *list) {
810   return binn_object_set(obj, key, BINN_LIST, binn_ptr(list), binn_size(list));
811 }
812 
binn_object_set_map(binn * obj,const char * key,void * map)813 IW_INLINE BOOL binn_object_set_map(binn *obj, const char *key, void *map) {
814   return binn_object_set(obj, key, BINN_MAP, binn_ptr(map), binn_size(map));
815 }
816 
binn_object_set_object(binn * obj,const char * key,void * obj2)817 IW_INLINE BOOL binn_object_set_object(binn *obj, const char *key, void *obj2) {
818   return binn_object_set(obj, key, BINN_OBJECT, binn_ptr(obj2), binn_size(obj2));
819 }
820 
binn_object_set_value(binn * obj,const char * key,binn * value)821 IW_INLINE BOOL binn_object_set_value(binn *obj, const char *key, binn *value) {
822   return binn_object_set(obj, key, value->type, binn_ptr(value), binn_size(value));
823 }
824 
binn_object_set_value2(binn * obj,const char * key,int keylen,binn * value)825 IW_INLINE BOOL binn_object_set_value2(binn *obj, const char *key, int keylen, binn *value) {
826   return binn_object_set2(obj, key, keylen, value->type, binn_ptr(value), binn_size(value));
827 }
828 
829 /*************************************************************************************/
830 /*** GET FUNCTIONS *******************************************************************/
831 /*************************************************************************************/
832 
binn_list_get_int8(void * list,int pos,signed char * pvalue)833 IW_INLINE BOOL binn_list_get_int8(void *list, int pos, signed char *pvalue) {
834   return binn_list_get(list, pos, BINN_INT8, pvalue, NULL);
835 }
836 
binn_list_get_int16(void * list,int pos,short * pvalue)837 IW_INLINE BOOL binn_list_get_int16(void *list, int pos, short *pvalue) {
838   return binn_list_get(list, pos, BINN_INT16, pvalue, NULL);
839 }
840 
binn_list_get_int32(void * list,int pos,int * pvalue)841 IW_INLINE BOOL binn_list_get_int32(void *list, int pos, int *pvalue) {
842   return binn_list_get(list, pos, BINN_INT32, pvalue, NULL);
843 }
844 
binn_list_get_int64(void * list,int pos,int64 * pvalue)845 IW_INLINE BOOL binn_list_get_int64(void *list, int pos, int64 *pvalue) {
846   return binn_list_get(list, pos, BINN_INT64, pvalue, NULL);
847 }
848 
binn_list_get_uint8(void * list,int pos,unsigned char * pvalue)849 IW_INLINE BOOL binn_list_get_uint8(void *list, int pos, unsigned char *pvalue) {
850   return binn_list_get(list, pos, BINN_UINT8, pvalue, NULL);
851 }
852 
binn_list_get_uint16(void * list,int pos,unsigned short * pvalue)853 IW_INLINE BOOL binn_list_get_uint16(void *list, int pos, unsigned short *pvalue) {
854   return binn_list_get(list, pos, BINN_UINT16, pvalue, NULL);
855 }
856 
binn_list_get_uint32(void * list,int pos,unsigned int * pvalue)857 IW_INLINE BOOL binn_list_get_uint32(void *list, int pos, unsigned int *pvalue) {
858   return binn_list_get(list, pos, BINN_UINT32, pvalue, NULL);
859 }
860 
binn_list_get_uint64(void * list,int pos,uint64 * pvalue)861 IW_INLINE BOOL binn_list_get_uint64(void *list, int pos, uint64 *pvalue) {
862   return binn_list_get(list, pos, BINN_UINT64, pvalue, NULL);
863 }
864 
binn_list_get_float(void * list,int pos,float * pvalue)865 IW_INLINE BOOL binn_list_get_float(void *list, int pos, float *pvalue) {
866   return binn_list_get(list, pos, BINN_FLOAT32, pvalue, NULL);
867 }
868 
binn_list_get_double(void * list,int pos,double * pvalue)869 IW_INLINE BOOL binn_list_get_double(void *list, int pos, double *pvalue) {
870   return binn_list_get(list, pos, BINN_FLOAT64, pvalue, NULL);
871 }
872 
binn_list_get_bool(void * list,int pos,BOOL * pvalue)873 IW_INLINE BOOL binn_list_get_bool(void *list, int pos, BOOL *pvalue) {
874   return binn_list_get(list, pos, BINN_BOOL, pvalue, NULL);
875 }
876 
binn_list_get_str(void * list,int pos,char ** pvalue)877 IW_INLINE BOOL binn_list_get_str(void *list, int pos, char **pvalue) {
878   return binn_list_get(list, pos, BINN_STRING, pvalue, NULL);
879 }
880 
binn_list_get_blob(void * list,int pos,void ** pvalue,int * psize)881 IW_INLINE BOOL binn_list_get_blob(void *list, int pos, void **pvalue, int *psize) {
882   return binn_list_get(list, pos, BINN_BLOB, pvalue, psize);
883 }
884 
binn_list_get_list(void * list,int pos,void ** pvalue)885 IW_INLINE BOOL binn_list_get_list(void *list, int pos, void **pvalue) {
886   return binn_list_get(list, pos, BINN_LIST, pvalue, NULL);
887 }
888 
binn_list_get_map(void * list,int pos,void ** pvalue)889 IW_INLINE BOOL binn_list_get_map(void *list, int pos, void **pvalue) {
890   return binn_list_get(list, pos, BINN_MAP, pvalue, NULL);
891 }
892 
binn_list_get_object(void * list,int pos,void ** pvalue)893 IW_INLINE BOOL binn_list_get_object(void *list, int pos, void **pvalue) {
894   return binn_list_get(list, pos, BINN_OBJECT, pvalue, NULL);
895 }
896 
897 /***************************************************************************/
898 
binn_map_get_int8(void * map,int id,signed char * pvalue)899 IW_INLINE BOOL binn_map_get_int8(void *map, int id, signed char *pvalue) {
900   return binn_map_get(map, id, BINN_INT8, pvalue, NULL);
901 }
902 
binn_map_get_int16(void * map,int id,short * pvalue)903 IW_INLINE BOOL binn_map_get_int16(void *map, int id, short *pvalue) {
904   return binn_map_get(map, id, BINN_INT16, pvalue, NULL);
905 }
906 
binn_map_get_int32(void * map,int id,int * pvalue)907 IW_INLINE BOOL binn_map_get_int32(void *map, int id, int *pvalue) {
908   return binn_map_get(map, id, BINN_INT32, pvalue, NULL);
909 }
910 
binn_map_get_int64(void * map,int id,int64 * pvalue)911 IW_INLINE BOOL binn_map_get_int64(void *map, int id, int64 *pvalue) {
912   return binn_map_get(map, id, BINN_INT64, pvalue, NULL);
913 }
914 
binn_map_get_uint8(void * map,int id,unsigned char * pvalue)915 IW_INLINE BOOL binn_map_get_uint8(void *map, int id, unsigned char *pvalue) {
916   return binn_map_get(map, id, BINN_UINT8, pvalue, NULL);
917 }
918 
binn_map_get_uint16(void * map,int id,unsigned short * pvalue)919 IW_INLINE BOOL binn_map_get_uint16(void *map, int id, unsigned short *pvalue) {
920   return binn_map_get(map, id, BINN_UINT16, pvalue, NULL);
921 }
922 
binn_map_get_uint32(void * map,int id,unsigned int * pvalue)923 IW_INLINE BOOL binn_map_get_uint32(void *map, int id, unsigned int *pvalue) {
924   return binn_map_get(map, id, BINN_UINT32, pvalue, NULL);
925 }
926 
binn_map_get_uint64(void * map,int id,uint64 * pvalue)927 IW_INLINE BOOL binn_map_get_uint64(void *map, int id, uint64 *pvalue) {
928   return binn_map_get(map, id, BINN_UINT64, pvalue, NULL);
929 }
930 
binn_map_get_float(void * map,int id,float * pvalue)931 IW_INLINE BOOL binn_map_get_float(void *map, int id, float *pvalue) {
932   return binn_map_get(map, id, BINN_FLOAT32, pvalue, NULL);
933 }
934 
binn_map_get_double(void * map,int id,double * pvalue)935 IW_INLINE BOOL binn_map_get_double(void *map, int id, double *pvalue) {
936   return binn_map_get(map, id, BINN_FLOAT64, pvalue, NULL);
937 }
938 
binn_map_get_bool(void * map,int id,BOOL * pvalue)939 IW_INLINE BOOL binn_map_get_bool(void *map, int id, BOOL *pvalue) {
940   return binn_map_get(map, id, BINN_BOOL, pvalue, NULL);
941 }
942 
binn_map_get_str(void * map,int id,char ** pvalue)943 IW_INLINE BOOL binn_map_get_str(void *map, int id, char **pvalue) {
944   return binn_map_get(map, id, BINN_STRING, pvalue, NULL);
945 }
946 
binn_map_get_blob(void * map,int id,void ** pvalue,int * psize)947 IW_INLINE BOOL binn_map_get_blob(void *map, int id, void **pvalue, int *psize) {
948   return binn_map_get(map, id, BINN_BLOB, pvalue, psize);
949 }
950 
binn_map_get_list(void * map,int id,void ** pvalue)951 IW_INLINE BOOL binn_map_get_list(void *map, int id, void **pvalue) {
952   return binn_map_get(map, id, BINN_LIST, pvalue, NULL);
953 }
954 
binn_map_get_map(void * map,int id,void ** pvalue)955 IW_INLINE BOOL binn_map_get_map(void *map, int id, void **pvalue) {
956   return binn_map_get(map, id, BINN_MAP, pvalue, NULL);
957 }
958 
binn_map_get_object(void * map,int id,void ** pvalue)959 IW_INLINE BOOL binn_map_get_object(void *map, int id, void **pvalue) {
960   return binn_map_get(map, id, BINN_OBJECT, pvalue, NULL);
961 }
962 
963 /***************************************************************************/
964 
965 // usage:
966 //   if (binn_object_get_int32(obj, "key", &value) == FALSE) xxx;
967 
binn_object_get_int8(void * obj,const char * key,signed char * pvalue)968 IW_INLINE BOOL binn_object_get_int8(void *obj, const char *key, signed char *pvalue) {
969   return binn_object_get(obj, key, BINN_INT8, pvalue, NULL);
970 }
971 
binn_object_get_int16(void * obj,const char * key,short * pvalue)972 IW_INLINE BOOL binn_object_get_int16(void *obj, const char *key, short *pvalue) {
973   return binn_object_get(obj, key, BINN_INT16, pvalue, NULL);
974 }
975 
binn_object_get_int32(void * obj,const char * key,int * pvalue)976 IW_INLINE BOOL binn_object_get_int32(void *obj, const char *key, int *pvalue) {
977   return binn_object_get(obj, key, BINN_INT32, pvalue, NULL);
978 }
979 
binn_object_get_int64(void * obj,const char * key,int64 * pvalue)980 IW_INLINE BOOL binn_object_get_int64(void *obj, const char *key, int64 *pvalue) {
981   return binn_object_get(obj, key, BINN_INT64, pvalue, NULL);
982 }
983 
binn_object_get_uint8(void * obj,const char * key,unsigned char * pvalue)984 IW_INLINE BOOL binn_object_get_uint8(void *obj, const char *key, unsigned char *pvalue) {
985   return binn_object_get(obj, key, BINN_UINT8, pvalue, NULL);
986 }
987 
binn_object_get_uint16(void * obj,const char * key,unsigned short * pvalue)988 IW_INLINE BOOL binn_object_get_uint16(void *obj, const char *key, unsigned short *pvalue) {
989   return binn_object_get(obj, key, BINN_UINT16, pvalue, NULL);
990 }
991 
binn_object_get_uint32(void * obj,const char * key,unsigned int * pvalue)992 IW_INLINE BOOL binn_object_get_uint32(void *obj, const char *key, unsigned int *pvalue) {
993   return binn_object_get(obj, key, BINN_UINT32, pvalue, NULL);
994 }
995 
binn_object_get_uint64(void * obj,const char * key,uint64 * pvalue)996 IW_INLINE BOOL binn_object_get_uint64(void *obj, const char *key, uint64 *pvalue) {
997   return binn_object_get(obj, key, BINN_UINT64, pvalue, NULL);
998 }
999 
binn_object_get_float(void * obj,const char * key,float * pvalue)1000 IW_INLINE BOOL binn_object_get_float(void *obj, const char *key, float *pvalue) {
1001   return binn_object_get(obj, key, BINN_FLOAT32, pvalue, NULL);
1002 }
1003 
binn_object_get_double(void * obj,const char * key,double * pvalue)1004 IW_INLINE BOOL binn_object_get_double(void *obj, const char *key, double *pvalue) {
1005   return binn_object_get(obj, key, BINN_FLOAT64, pvalue, NULL);
1006 }
1007 
binn_object_get_bool(void * obj,const char * key,BOOL * pvalue)1008 IW_INLINE BOOL binn_object_get_bool(void *obj, const char *key, BOOL *pvalue) {
1009   return binn_object_get(obj, key, BINN_BOOL, pvalue, NULL);
1010 }
1011 
binn_object_get_str(void * obj,const char * key,char ** pvalue)1012 IW_INLINE BOOL binn_object_get_str(void *obj, const char *key, char **pvalue) {
1013   return binn_object_get(obj, key, BINN_STRING, pvalue, NULL);
1014 }
1015 
binn_object_get_blob(void * obj,const char * key,void ** pvalue,int * psize)1016 IW_INLINE BOOL binn_object_get_blob(void *obj, const char *key, void **pvalue, int *psize) {
1017   return binn_object_get(obj, key, BINN_BLOB, pvalue, psize);
1018 }
1019 
binn_object_get_list(void * obj,const char * key,void ** pvalue)1020 IW_INLINE BOOL binn_object_get_list(void *obj, const char *key, void **pvalue) {
1021   return binn_object_get(obj, key, BINN_LIST, pvalue, NULL);
1022 }
1023 
binn_object_get_map(void * obj,const char * key,void ** pvalue)1024 IW_INLINE BOOL binn_object_get_map(void *obj, const char *key, void **pvalue) {
1025   return binn_object_get(obj, key, BINN_MAP, pvalue, NULL);
1026 }
1027 
binn_object_get_object(void * obj,const char * key,void ** pvalue)1028 IW_INLINE BOOL binn_object_get_object(void *obj, const char *key, void **pvalue) {
1029   return binn_object_get(obj, key, BINN_OBJECT, pvalue, NULL);
1030 }
1031 
1032 /***************************************************************************/
1033 
1034 BOOL binn_get_int32(binn *value, int *pint);
1035 BOOL binn_get_int64(binn *value, int64 *pint);
1036 BOOL binn_get_double(binn *value, double *pfloat);
1037 BOOL binn_get_bool(binn *value, BOOL *pbool);
1038 char* binn_get_str(binn *value);
1039 
1040 // boolean string values:
1041 // 1, true, yes, on
1042 // 0, false, no, off
1043 
1044 // boolean number values:
1045 // !=0 [true]
1046 // ==0 [false]
1047 
1048 
1049 #ifdef __cplusplus
1050 }
1051 #endif
1052 
1053 #endif //BINN_H
1054