damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

flatbuffers_common_builder.h (44062B)


      1 #ifndef FLATBUFFERS_COMMON_BUILDER_H
      2 #define FLATBUFFERS_COMMON_BUILDER_H
      3 
      4 /* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */
      5 
      6 /* Common FlatBuffers build functionality for C. */
      7 
      8 #include "flatcc/flatcc_prologue.h"
      9 #ifndef FLATBUILDER_H
     10 #include "flatcc/flatcc_builder.h"
     11 #endif
     12 typedef flatcc_builder_t flatbuffers_builder_t;
     13 typedef flatcc_builder_ref_t flatbuffers_ref_t;
     14 typedef flatcc_builder_ref_t flatbuffers_vec_ref_t;
     15 typedef flatcc_builder_union_ref_t flatbuffers_union_ref_t;
     16 typedef flatcc_builder_union_vec_ref_t flatbuffers_union_vec_ref_t;
     17 /* integer return code (ref and ptr always fail on 0) */
     18 #define flatbuffers_failed(x) ((x) < 0)
     19 typedef flatbuffers_ref_t flatbuffers_root_t;
     20 #define flatbuffers_root(ref) ((flatbuffers_root_t)(ref))
     21 
     22 #define __flatbuffers_memoize_begin(B, src)\
     23 do { flatcc_builder_ref_t _ref; if ((_ref = flatcc_builder_refmap_find((B), (src)))) return _ref; } while (0)
     24 #define __flatbuffers_memoize_end(B, src, op) do { return flatcc_builder_refmap_insert((B), (src), (op)); } while (0)
     25 #define __flatbuffers_memoize(B, src, op) do { __flatbuffers_memoize_begin(B, src); __flatbuffers_memoize_end(B, src, op); } while (0)
     26 
     27 #define __flatbuffers_build_buffer(NS)\
     28 typedef NS ## ref_t NS ## buffer_ref_t;\
     29 static inline int NS ## buffer_start(NS ## builder_t *B, const NS ##fid_t fid)\
     30 { return flatcc_builder_start_buffer(B, fid, 0, 0); }\
     31 static inline int NS ## buffer_start_with_size(NS ## builder_t *B, const NS ##fid_t fid)\
     32 { return flatcc_builder_start_buffer(B, fid, 0, flatcc_builder_with_size); }\
     33 static inline int NS ## buffer_start_aligned(NS ## builder_t *B, NS ##fid_t fid, uint16_t block_align)\
     34 { return flatcc_builder_start_buffer(B, fid, block_align, 0); }\
     35 static inline int NS ## buffer_start_aligned_with_size(NS ## builder_t *B, NS ##fid_t fid, uint16_t block_align)\
     36 { return flatcc_builder_start_buffer(B, fid, block_align, flatcc_builder_with_size); }\
     37 static inline NS ## buffer_ref_t NS ## buffer_end(NS ## builder_t *B, NS ## ref_t root)\
     38 { return flatcc_builder_end_buffer(B, root); }
     39 
     40 #define __flatbuffers_build_table_root(NS, N, FID, TFID)\
     41 static inline int N ## _start_as_root(NS ## builder_t *B)\
     42 { return NS ## buffer_start(B, FID) ? -1 : N ## _start(B); }\
     43 static inline int N ## _start_as_root_with_size(NS ## builder_t *B)\
     44 { return NS ## buffer_start_with_size(B, FID) ? -1 : N ## _start(B); }\
     45 static inline int N ## _start_as_typed_root(NS ## builder_t *B)\
     46 { return NS ## buffer_start(B, TFID) ? -1 : N ## _start(B); }\
     47 static inline int N ## _start_as_typed_root_with_size(NS ## builder_t *B)\
     48 { return NS ## buffer_start_with_size(B, TFID) ? -1 : N ## _start(B); }\
     49 static inline NS ## buffer_ref_t N ## _end_as_root(NS ## builder_t *B)\
     50 { return NS ## buffer_end(B, N ## _end(B)); }\
     51 static inline NS ## buffer_ref_t N ## _end_as_typed_root(NS ## builder_t *B)\
     52 { return NS ## buffer_end(B, N ## _end(B)); }\
     53 static inline NS ## buffer_ref_t N ## _create_as_root(NS ## builder_t *B __ ## N ## _formal_args)\
     54 { if (NS ## buffer_start(B, FID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\
     55 static inline NS ## buffer_ref_t N ## _create_as_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\
     56 { if (NS ## buffer_start_with_size(B, FID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\
     57 static inline NS ## buffer_ref_t N ## _create_as_typed_root(NS ## builder_t *B __ ## N ## _formal_args)\
     58 { if (NS ## buffer_start(B, TFID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\
     59 static inline NS ## buffer_ref_t N ## _create_as_typed_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\
     60 { if (NS ## buffer_start_with_size(B, TFID)) return 0; return NS ## buffer_end(B, N ## _create(B __ ## N ## _call_args)); }\
     61 static inline NS ## buffer_ref_t N ## _clone_as_root(NS ## builder_t *B, N ## _table_t t)\
     62 { if (NS ## buffer_start(B, FID)) return 0; return NS ## buffer_end(B, N ## _clone(B, t)); }\
     63 static inline NS ## buffer_ref_t N ## _clone_as_root_with_size(NS ## builder_t *B, N ## _table_t t)\
     64 { if (NS ## buffer_start_with_size(B, FID)) return 0; return NS ## buffer_end(B, N ## _clone(B, t)); }\
     65 static inline NS ## buffer_ref_t N ## _clone_as_typed_root(NS ## builder_t *B, N ## _table_t t)\
     66 { if (NS ## buffer_start(B, TFID)) return 0;return NS ## buffer_end(B, N ## _clone(B, t)); }\
     67 static inline NS ## buffer_ref_t N ## _clone_as_typed_root_with_size(NS ## builder_t *B, N ## _table_t t)\
     68 { if (NS ## buffer_start_with_size(B, TFID)) return 0; return NS ## buffer_end(B, N ## _clone(B, t)); }
     69 
     70 #define __flatbuffers_build_table_prolog(NS, N, FID, TFID)\
     71 __flatbuffers_build_table_vector_ops(NS, N ## _vec, N)\
     72 __flatbuffers_build_table_root(NS, N, FID, TFID)
     73 
     74 #define __flatbuffers_build_struct_root(NS, N, A, FID, TFID)\
     75 static inline N ## _t *N ## _start_as_root(NS ## builder_t *B)\
     76 { return NS ## buffer_start(B, FID) ? 0 : N ## _start(B); }\
     77 static inline N ## _t *N ## _start_as_root_with_size(NS ## builder_t *B)\
     78 { return NS ## buffer_start_with_size(B, FID) ? 0 : N ## _start(B); }\
     79 static inline N ## _t *N ## _start_as_typed_root(NS ## builder_t *B)\
     80 { return NS ## buffer_start(B, TFID) ? 0 : N ## _start(B); }\
     81 static inline N ## _t *N ## _start_as_typed_root_with_size(NS ## builder_t *B)\
     82 { return NS ## buffer_start_with_size(B, TFID) ? 0 : N ## _start(B); }\
     83 static inline NS ## buffer_ref_t N ## _end_as_root(NS ## builder_t *B)\
     84 { return NS ## buffer_end(B, N ## _end(B)); }\
     85 static inline NS ## buffer_ref_t N ## _end_as_typed_root(NS ## builder_t *B)\
     86 { return NS ## buffer_end(B, N ## _end(B)); }\
     87 static inline NS ## buffer_ref_t N ## _end_pe_as_root(NS ## builder_t *B)\
     88 { return NS ## buffer_end(B, N ## _end_pe(B)); }\
     89 static inline NS ## buffer_ref_t N ## _end_pe_as_typed_root(NS ## builder_t *B)\
     90 { return NS ## buffer_end(B, N ## _end_pe(B)); }\
     91 static inline NS ## buffer_ref_t N ## _create_as_root(NS ## builder_t *B __ ## N ## _formal_args)\
     92 { return flatcc_builder_create_buffer(B, FID, 0,\
     93   N ## _create(B __ ## N ## _call_args), A, 0); }\
     94 static inline NS ## buffer_ref_t N ## _create_as_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\
     95 { return flatcc_builder_create_buffer(B, FID, 0,\
     96   N ## _create(B __ ## N ## _call_args), A, flatcc_builder_with_size); }\
     97 static inline NS ## buffer_ref_t N ## _create_as_typed_root(NS ## builder_t *B __ ## N ## _formal_args)\
     98 { return flatcc_builder_create_buffer(B, TFID, 0,\
     99   N ## _create(B __ ## N ## _call_args), A, 0); }\
    100 static inline NS ## buffer_ref_t N ## _create_as_typed_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\
    101 { return flatcc_builder_create_buffer(B, TFID, 0,\
    102   N ## _create(B __ ## N ## _call_args), A, flatcc_builder_with_size); }\
    103 static inline NS ## buffer_ref_t N ## _clone_as_root(NS ## builder_t *B, N ## _struct_t p)\
    104 { return flatcc_builder_create_buffer(B, FID, 0, N ## _clone(B, p), A, 0); }\
    105 static inline NS ## buffer_ref_t N ## _clone_as_root_with_size(NS ## builder_t *B, N ## _struct_t p)\
    106 { return flatcc_builder_create_buffer(B, FID, 0, N ## _clone(B, p), A, flatcc_builder_with_size); }\
    107 static inline NS ## buffer_ref_t N ## _clone_as_typed_root(NS ## builder_t *B, N ## _struct_t p)\
    108 { return flatcc_builder_create_buffer(B, TFID, 0, N ## _clone(B, p), A, 0); }\
    109 static inline NS ## buffer_ref_t N ## _clone_as_typed_root_with_size(NS ## builder_t *B, N ## _struct_t p)\
    110 { return flatcc_builder_create_buffer(B, TFID, 0, N ## _clone(B, p), A, flatcc_builder_with_size); }
    111 
    112 #define __flatbuffers_build_nested_table_root(NS, N, TN, FID, TFID)\
    113 static inline int N ## _start_as_root(NS ## builder_t *B)\
    114 { return NS ## buffer_start(B, FID) ? -1 : TN ## _start(B); }\
    115 static inline int N ## _start_as_typed_root(NS ## builder_t *B)\
    116 { return NS ## buffer_start(B, TFID) ? -1 : TN ## _start(B); }\
    117 static inline int N ## _end_as_root(NS ## builder_t *B)\
    118 { return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\
    119 static inline int N ## _end_as_typed_root(NS ## builder_t *B)\
    120 { return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\
    121 static inline int N ## _nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\
    122 { return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\
    123   align ? align : 8, FLATBUFFERS_COUNT_MAX(1))); }\
    124 static inline int N ## _typed_nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\
    125 { return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\
    126   align ? align : 8, FLATBUFFERS_COUNT_MAX(1))); }\
    127 static inline int N ## _clone_as_root(NS ## builder_t *B, TN ## _table_t t)\
    128 { return N ## _add(B, TN ## _clone_as_root(B, t)); }\
    129 static inline int N ## _clone_as_typed_root(NS ## builder_t *B, TN ## _table_t t)\
    130 { return N ## _add(B, TN ## _clone_as_typed_root(B, t)); }
    131 
    132 #define __flatbuffers_build_nested_struct_root(NS, N, TN, A, FID, TFID)\
    133 static inline TN ## _t *N ## _start_as_root(NS ## builder_t *B)\
    134 { return NS ## buffer_start(B, FID) ? 0 : TN ## _start(B); }\
    135 static inline TN ## _t *N ## _start_as_typed_root(NS ## builder_t *B)\
    136 { return NS ## buffer_start(B, FID) ? 0 : TN ## _start(B); }\
    137 static inline int N ## _end_as_root(NS ## builder_t *B)\
    138 { return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\
    139 static inline int N ## _end_as_typed_root(NS ## builder_t *B)\
    140 { return N ## _add(B, NS ## buffer_end(B, TN ## _end(B))); }\
    141 static inline int N ## _end_pe_as_root(NS ## builder_t *B)\
    142 { return N ## _add(B, NS ## buffer_end(B, TN ## _end_pe(B))); }\
    143 static inline int N ## _create_as_root(NS ## builder_t *B __ ## TN ## _formal_args)\
    144 { return N ## _add(B, flatcc_builder_create_buffer(B, FID, 0,\
    145   TN ## _create(B __ ## TN ## _call_args), A, flatcc_builder_is_nested)); }\
    146 static inline int N ## _create_as_typed_root(NS ## builder_t *B __ ## TN ## _formal_args)\
    147 { return N ## _add(B, flatcc_builder_create_buffer(B, TFID, 0,\
    148   TN ## _create(B __ ## TN ## _call_args), A, flatcc_builder_is_nested)); }\
    149 static inline int N ## _nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\
    150 { return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\
    151   align < A ? A : align, FLATBUFFERS_COUNT_MAX(1))); }\
    152 static inline int N ## _typed_nest(NS ## builder_t *B, void *data, size_t size, uint16_t align)\
    153 { return N ## _add(B, flatcc_builder_create_vector(B, data, size, 1,\
    154   align < A ? A : align, FLATBUFFERS_COUNT_MAX(1))); }\
    155 static inline int N ## _clone_as_root(NS ## builder_t *B, TN ## _struct_t p)\
    156 { return N ## _add(B, TN ## _clone_as_root(B, p)); }\
    157 static inline int N ## _clone_as_typed_root(NS ## builder_t *B, TN ## _struct_t p)\
    158 { return N ## _add(B, TN ## _clone_as_typed_root(B, p)); }
    159 
    160 #define __flatbuffers_build_vector_ops(NS, V, N, TN, T)\
    161 static inline T *V ## _extend(NS ## builder_t *B, size_t len)\
    162 { return (T *)flatcc_builder_extend_vector(B, len); }\
    163 static inline T *V ## _append(NS ## builder_t *B, const T *data, size_t len)\
    164 { return (T *)flatcc_builder_append_vector(B, data, len); }\
    165 static inline int V ## _truncate(NS ## builder_t *B, size_t len)\
    166 { return flatcc_builder_truncate_vector(B, len); }\
    167 static inline T *V ## _edit(NS ## builder_t *B)\
    168 { return (T *)flatcc_builder_vector_edit(B); }\
    169 static inline size_t V ## _reserved_len(NS ## builder_t *B)\
    170 { return flatcc_builder_vector_count(B); }\
    171 static inline T *V ## _push(NS ## builder_t *B, const T *p)\
    172 { T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? (memcpy(_p, p, TN ## __size()), _p) : 0; }\
    173 static inline T *V ## _push_copy(NS ## builder_t *B, const T *p)\
    174 { T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? TN ## _copy(_p, p) : 0; }\
    175 static inline T *V ## _push_clone(NS ## builder_t *B, const T *p)\
    176 { T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? TN ## _copy(_p, p) : 0; }\
    177 static inline T *V ## _push_create(NS ## builder_t *B __ ## TN ## _formal_args)\
    178 { T *_p; return (_p = (T *)flatcc_builder_extend_vector(B, 1)) ? TN ## _assign(_p __ ## TN ## _call_args) : 0; }
    179 
    180 #define __flatbuffers_build_vector(NS, N, T, S, A)\
    181 typedef NS ## ref_t N ## _vec_ref_t;\
    182 static inline int N ## _vec_start(NS ## builder_t *B)\
    183 { return flatcc_builder_start_vector(B, S, A, FLATBUFFERS_COUNT_MAX(S)); }\
    184 static inline N ## _vec_ref_t N ## _vec_end_pe(NS ## builder_t *B)\
    185 { return flatcc_builder_end_vector(B); }\
    186 static inline N ## _vec_ref_t N ## _vec_end(NS ## builder_t *B)\
    187 { if (!NS ## is_native_pe()) { size_t i, n; T *p = (T *)flatcc_builder_vector_edit(B);\
    188     for (i = 0, n = flatcc_builder_vector_count(B); i < n; ++i)\
    189     { N ## _to_pe(N ## __ptr_add(p, i)); }} return flatcc_builder_end_vector(B); }\
    190 static inline N ## _vec_ref_t N ## _vec_create_pe(NS ## builder_t *B, const T *data, size_t len)\
    191 { return flatcc_builder_create_vector(B, data, len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\
    192 static inline N ## _vec_ref_t N ## _vec_create(NS ## builder_t *B, const T *data, size_t len)\
    193 { if (!NS ## is_native_pe()) { size_t i; T *p; int ret = flatcc_builder_start_vector(B, S, A, FLATBUFFERS_COUNT_MAX(S)); if (ret) { return ret; }\
    194   p = (T *)flatcc_builder_extend_vector(B, len); if (!p) return 0;\
    195   for (i = 0; i < len; ++i) { N ## _copy_to_pe(N ## __ptr_add(p, i), N ## __const_ptr_add(data, i)); }\
    196   return flatcc_builder_end_vector(B); } else return flatcc_builder_create_vector(B, data, len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\
    197 static inline N ## _vec_ref_t N ## _vec_clone(NS ## builder_t *B, N ##_vec_t vec)\
    198 { __flatbuffers_memoize(B, vec, flatcc_builder_create_vector(B, vec, N ## _vec_len(vec), S, A, FLATBUFFERS_COUNT_MAX(S))); }\
    199 static inline N ## _vec_ref_t N ## _vec_slice(NS ## builder_t *B, N ##_vec_t vec, size_t index, size_t len)\
    200 { size_t n = N ## _vec_len(vec); if (index >= n) index = n; n -= index; if (len > n) len = n;\
    201   return flatcc_builder_create_vector(B, N ## __const_ptr_add(vec, index), len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\
    202 __flatbuffers_build_vector_ops(NS, N ## _vec, N, N, T)
    203 
    204 #define __flatbuffers_build_union_vector_ops(NS, V, N, TN)\
    205 static inline TN ## _union_ref_t *V ## _extend(NS ## builder_t *B, size_t len)\
    206 { return flatcc_builder_extend_union_vector(B, len); }\
    207 static inline TN ## _union_ref_t *V ## _append(NS ## builder_t *B, const TN ## _union_ref_t *data, size_t len)\
    208 { return flatcc_builder_append_union_vector(B, data, len); }\
    209 static inline int V ## _truncate(NS ## builder_t *B, size_t len)\
    210 { return flatcc_builder_truncate_union_vector(B, len); }\
    211 static inline TN ## _union_ref_t *V ## _edit(NS ## builder_t *B)\
    212 { return (TN ## _union_ref_t *) flatcc_builder_union_vector_edit(B); }\
    213 static inline size_t V ## _reserved_len(NS ## builder_t *B)\
    214 { return flatcc_builder_union_vector_count(B); }\
    215 static inline TN ## _union_ref_t *V ## _push(NS ## builder_t *B, const TN ## _union_ref_t ref)\
    216 { return flatcc_builder_union_vector_push(B, ref); }\
    217 static inline TN ## _union_ref_t *V ## _push_clone(NS ## builder_t *B, TN ## _union_t u)\
    218 { return TN ## _vec_push(B, TN ## _clone(B, u)); }
    219 
    220 #define __flatbuffers_build_union_vector(NS, N)\
    221 static inline int N ## _vec_start(NS ## builder_t *B)\
    222 { return flatcc_builder_start_union_vector(B); }\
    223 static inline N ## _union_vec_ref_t N ## _vec_end(NS ## builder_t *B)\
    224 { return flatcc_builder_end_union_vector(B); }\
    225 static inline N ## _union_vec_ref_t N ## _vec_create(NS ## builder_t *B, const N ## _union_ref_t *data, size_t len)\
    226 { return flatcc_builder_create_union_vector(B, data, len); }\
    227 __flatbuffers_build_union_vector_ops(NS, N ## _vec, N, N)\
    228 /* Preserves DAG structure separately for type and value vector, so a type vector could be shared for many value vectors. */\
    229 static inline N ## _union_vec_ref_t N ## _vec_clone(NS ## builder_t *B, N ##_union_vec_t vec)\
    230 { N ## _union_vec_ref_t _uvref, _ret = { 0, 0 }; NS ## union_ref_t _uref; size_t _i, _len;\
    231   if (vec.type == 0) return _ret;\
    232   _uvref.type = flatcc_builder_refmap_find(B, vec.type); _uvref.value = flatcc_builder_refmap_find(B, vec.value);\
    233   _len = N ## _union_vec_len(vec); if (_uvref.type == 0) {\
    234   _uvref.type = flatcc_builder_refmap_insert(B, vec.type, (flatcc_builder_create_type_vector(B, vec.type, _len))); }\
    235   if (_uvref.type == 0) return _ret; if (_uvref.value == 0) {\
    236   if (flatcc_builder_start_offset_vector(B)) return _ret;\
    237   for (_i = 0; _i < _len; ++_i) { _uref = N ## _clone(B, N ## _union_vec_at(vec, _i));\
    238     if (!_uref.value || !(flatcc_builder_offset_vector_push(B, _uref.value))) return _ret; }\
    239   _uvref.value = flatcc_builder_refmap_insert(B, vec.value, flatcc_builder_end_offset_vector(B));\
    240   if (_uvref.value == 0) return _ret; } return _uvref; }
    241 
    242 #define __flatbuffers_build_string_vector_ops(NS, N)\
    243 static inline int N ## _push_start(NS ## builder_t *B)\
    244 { return NS ## string_start(B); }\
    245 static inline NS ## string_ref_t *N ## _push_end(NS ## builder_t *B)\
    246 { return NS ## string_vec_push(B, NS ## string_end(B)); }\
    247 static inline NS ## string_ref_t *N ## _push_create(NS ## builder_t *B, const char *s, size_t len)\
    248 { return NS ## string_vec_push(B, NS ## string_create(B, s, len)); }\
    249 static inline NS ## string_ref_t *N ## _push_create_str(NS ## builder_t *B, const char *s)\
    250 { return NS ## string_vec_push(B, NS ## string_create_str(B, s)); }\
    251 static inline NS ## string_ref_t *N ## _push_create_strn(NS ## builder_t *B, const char *s, size_t max_len)\
    252 { return NS ## string_vec_push(B, NS ## string_create_strn(B, s, max_len)); }\
    253 static inline NS ## string_ref_t *N ## _push_clone(NS ## builder_t *B, NS ## string_t string)\
    254 { return NS ## string_vec_push(B, NS ## string_clone(B, string)); }\
    255 static inline NS ## string_ref_t *N ## _push_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\
    256 { return NS ## string_vec_push(B, NS ## string_slice(B, string, index, len)); }
    257 
    258 #define __flatbuffers_build_table_vector_ops(NS, N, TN)\
    259 static inline int N ## _push_start(NS ## builder_t *B)\
    260 { return TN ## _start(B); }\
    261 static inline TN ## _ref_t *N ## _push_end(NS ## builder_t *B)\
    262 { return N ## _push(B, TN ## _end(B)); }\
    263 static inline TN ## _ref_t *N ## _push_create(NS ## builder_t *B __ ## TN ##_formal_args)\
    264 { return N ## _push(B, TN ## _create(B __ ## TN ## _call_args)); }
    265 
    266 #define __flatbuffers_build_offset_vector_ops(NS, V, N, TN)\
    267 static inline TN ## _ref_t *V ## _extend(NS ## builder_t *B, size_t len)\
    268 { return flatcc_builder_extend_offset_vector(B, len); }\
    269 static inline TN ## _ref_t *V ## _append(NS ## builder_t *B, const TN ## _ref_t *data, size_t len)\
    270 { return flatcc_builder_append_offset_vector(B, data, len); }\
    271 static inline int V ## _truncate(NS ## builder_t *B, size_t len)\
    272 { return flatcc_builder_truncate_offset_vector(B, len); }\
    273 static inline TN ## _ref_t *V ## _edit(NS ## builder_t *B)\
    274 { return (TN ## _ref_t *)flatcc_builder_offset_vector_edit(B); }\
    275 static inline size_t V ## _reserved_len(NS ## builder_t *B)\
    276 { return flatcc_builder_offset_vector_count(B); }\
    277 static inline TN ## _ref_t *V ## _push(NS ## builder_t *B, const TN ## _ref_t ref)\
    278 { return ref ? flatcc_builder_offset_vector_push(B, ref) : 0; }
    279 
    280 #define __flatbuffers_build_offset_vector(NS, N)\
    281 typedef NS ## ref_t N ## _vec_ref_t;\
    282 static inline int N ## _vec_start(NS ## builder_t *B)\
    283 { return flatcc_builder_start_offset_vector(B); }\
    284 static inline N ## _vec_ref_t N ## _vec_end(NS ## builder_t *B)\
    285 { return flatcc_builder_end_offset_vector(B); }\
    286 static inline N ## _vec_ref_t N ## _vec_create(NS ## builder_t *B, const N ## _ref_t *data, size_t len)\
    287 { return flatcc_builder_create_offset_vector(B, data, len); }\
    288 __flatbuffers_build_offset_vector_ops(NS, N ## _vec, N, N)\
    289 static inline N ## _vec_ref_t N ## _vec_clone(NS ## builder_t *B, N ##_vec_t vec)\
    290 { int _ret; N ## _ref_t _e; size_t _i, _len; __flatbuffers_memoize_begin(B, vec);\
    291  _len = N ## _vec_len(vec); if (flatcc_builder_start_offset_vector(B)) return 0;\
    292   for (_i = 0; _i < _len; ++_i) { if (!(_e = N ## _clone(B, N ## _vec_at(vec, _i)))) return 0;\
    293     if (!flatcc_builder_offset_vector_push(B, _e)) return 0; }\
    294   __flatbuffers_memoize_end(B, vec, flatcc_builder_end_offset_vector(B)); }\
    295 
    296 #define __flatbuffers_build_string_ops(NS, N)\
    297 static inline char *N ## _append(NS ## builder_t *B, const char *s, size_t len)\
    298 { return flatcc_builder_append_string(B, s, len); }\
    299 static inline char *N ## _append_str(NS ## builder_t *B, const char *s)\
    300 { return flatcc_builder_append_string_str(B, s); }\
    301 static inline char *N ## _append_strn(NS ## builder_t *B, const char *s, size_t len)\
    302 { return flatcc_builder_append_string_strn(B, s, len); }\
    303 static inline size_t N ## _reserved_len(NS ## builder_t *B)\
    304 { return flatcc_builder_string_len(B); }\
    305 static inline char *N ## _extend(NS ## builder_t *B, size_t len)\
    306 { return flatcc_builder_extend_string(B, len); }\
    307 static inline char *N ## _edit(NS ## builder_t *B)\
    308 { return flatcc_builder_string_edit(B); }\
    309 static inline int N ## _truncate(NS ## builder_t *B, size_t len)\
    310 { return flatcc_builder_truncate_string(B, len); }
    311 
    312 #define __flatbuffers_build_string(NS)\
    313 typedef NS ## ref_t NS ## string_ref_t;\
    314 static inline int NS ## string_start(NS ## builder_t *B)\
    315 { return flatcc_builder_start_string(B); }\
    316 static inline NS ## string_ref_t NS ## string_end(NS ## builder_t *B)\
    317 { return flatcc_builder_end_string(B); }\
    318 static inline NS ## ref_t NS ## string_create(NS ## builder_t *B, const char *s, size_t len)\
    319 { return flatcc_builder_create_string(B, s, len); }\
    320 static inline NS ## ref_t NS ## string_create_str(NS ## builder_t *B, const char *s)\
    321 { return flatcc_builder_create_string_str(B, s); }\
    322 static inline NS ## ref_t NS ## string_create_strn(NS ## builder_t *B, const char *s, size_t len)\
    323 { return flatcc_builder_create_string_strn(B, s, len); }\
    324 static inline NS ## string_ref_t NS ## string_clone(NS ## builder_t *B, NS ## string_t string)\
    325 { __flatbuffers_memoize(B, string, flatcc_builder_create_string(B, string, NS ## string_len(string))); }\
    326 static inline NS ## string_ref_t NS ## string_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\
    327 { size_t n = NS ## string_len(string); if (index >= n) index = n; n -= index; if (len > n) len = n;\
    328   return flatcc_builder_create_string(B, string + index, len); }\
    329 __flatbuffers_build_string_ops(NS, NS ## string)\
    330 __flatbuffers_build_offset_vector(NS, NS ## string)
    331 
    332 #define __flatbuffers_copy_from_pe(P, P2, N) (*(P) = N ## _read_from_pe(P2), (P))
    333 #define __flatbuffers_from_pe(P, N) (*(P) = N ## _read_from_pe(P), (P))
    334 #define __flatbuffers_copy_to_pe(P, P2, N) (N ## _write_to_pe((P), *(P2)), (P))
    335 #define __flatbuffers_to_pe(P, N) (N ## _write_to_pe((P), *(P)), (P))
    336 #define __flatbuffers_define_fixed_array_primitives(NS, N, T)\
    337 static inline T *N ## _array_copy(T *p, const T *p2, size_t n)\
    338 { memcpy(p, p2, n * sizeof(T)); return p; }\
    339 static inline T *N ## _array_copy_from_pe(T *p, const T *p2, size_t n)\
    340 { size_t i; if (NS ## is_native_pe()) memcpy(p, p2, n * sizeof(T)); else\
    341   for (i = 0; i < n; ++i) N ## _copy_from_pe(&p[i], &p2[i]); return p; }\
    342 static inline T *N ## _array_copy_to_pe(T *p, const T *p2, size_t n)\
    343 { size_t i; if (NS ## is_native_pe()) memcpy(p, p2, n * sizeof(T)); else\
    344   for (i = 0; i < n; ++i) N ## _copy_to_pe(&p[i], &p2[i]); return p; }
    345 #define __flatbuffers_define_scalar_primitives(NS, N, T)\
    346 static inline T *N ## _from_pe(T *p) { return __ ## NS ## from_pe(p, N); }\
    347 static inline T *N ## _to_pe(T *p) { return __ ## NS ## to_pe(p, N); }\
    348 static inline T *N ## _copy(T *p, const T *p2) { *p = *p2; return p; }\
    349 static inline T *N ## _copy_from_pe(T *p, const T *p2)\
    350 { return __ ## NS ## copy_from_pe(p, p2, N); }\
    351 static inline T *N ## _copy_to_pe(T *p, const T *p2) \
    352 { return __ ## NS ## copy_to_pe(p, p2, N); }\
    353 static inline T *N ## _assign(T *p, const T v0) { *p = v0; return p; }\
    354 static inline T *N ## _assign_from_pe(T *p, T v0)\
    355 { *p = N ## _read_from_pe(&v0); return p; }\
    356 static inline T *N ## _assign_to_pe(T *p, T v0)\
    357 { N ## _write_to_pe(p, v0); return p; }
    358 #define __flatbuffers_build_scalar(NS, N, T)\
    359 __ ## NS ## define_scalar_primitives(NS, N, T)\
    360 __ ## NS ## define_fixed_array_primitives(NS, N, T)\
    361 __ ## NS ## build_vector(NS, N, T, sizeof(T), sizeof(T))
    362 /* Depends on generated copy_to/from_pe functions, and the type. */
    363 #define __flatbuffers_define_struct_primitives(NS, N)\
    364 static inline N ## _t *N ##_to_pe(N ## _t *p)\
    365 { if (!NS ## is_native_pe()) { N ## _copy_to_pe(p, p); }; return p; }\
    366 static inline N ## _t *N ##_from_pe(N ## _t *p)\
    367 { if (!NS ## is_native_pe()) { N ## _copy_from_pe(p, p); }; return p; }\
    368 static inline N ## _t *N ## _clear(N ## _t *p) { return (N ## _t *)memset(p, 0, N ## __size()); }
    369 
    370 /* Depends on generated copy/assign_to/from_pe functions, and the type. */
    371 #define __flatbuffers_build_struct(NS, N, S, A, FID, TFID)\
    372 __ ## NS ## define_struct_primitives(NS, N)\
    373 typedef NS ## ref_t N ## _ref_t;\
    374 static inline N ## _t *N ## _start(NS ## builder_t *B)\
    375 { return (N ## _t *)flatcc_builder_start_struct(B, S, A); }\
    376 static inline N ## _ref_t N ## _end(NS ## builder_t *B)\
    377 { if (!NS ## is_native_pe()) { N ## _to_pe((N ## _t *)flatcc_builder_struct_edit(B)); }\
    378   return flatcc_builder_end_struct(B); }\
    379 static inline N ## _ref_t N ## _end_pe(NS ## builder_t *B)\
    380 { return flatcc_builder_end_struct(B); }\
    381 static inline N ## _ref_t N ## _create(NS ## builder_t *B __ ## N ## _formal_args)\
    382 { N ## _t *_p = N ## _start(B); if (!_p) return 0; N ##_assign_to_pe(_p __ ## N ## _call_args);\
    383   return N ## _end_pe(B); }\
    384 static inline N ## _ref_t N ## _clone(NS ## builder_t *B, N ## _struct_t p)\
    385 { N ## _t *_p; __flatbuffers_memoize_begin(B, p); _p = N ## _start(B); if (!_p) return 0;\
    386   N ## _copy(_p, p); __flatbuffers_memoize_end(B, p, N ##_end_pe(B)); }\
    387 __flatbuffers_build_vector(NS, N, N ## _t, S, A)\
    388 __flatbuffers_build_struct_root(NS, N, A, FID, TFID)\
    389 
    390 #define __flatbuffers_struct_clear_field(p) memset((p), 0, sizeof(*(p)))
    391 #define __flatbuffers_build_table(NS, N, K)\
    392 static inline int N ## _start(NS ## builder_t *B)\
    393 { return flatcc_builder_start_table(B, K); }\
    394 static inline N ## _ref_t N ## _end(NS ## builder_t *B)\
    395 { FLATCC_ASSERT(flatcc_builder_check_required(B, __ ## N ## _required,\
    396   sizeof(__ ## N ## _required) / sizeof(__ ## N ## _required[0]) - 1));\
    397   return flatcc_builder_end_table(B); }\
    398 __flatbuffers_build_offset_vector(NS, N)
    399 
    400 #define __flatbuffers_build_table_field(ID, NS, N, TN, TT)\
    401 static inline int N ## _add(NS ## builder_t *B, TN ## _ref_t ref)\
    402 { TN ## _ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ?\
    403   ((*_p = ref), 0) : -1; }\
    404 static inline int N ## _start(NS ## builder_t *B)\
    405 { return TN ## _start(B); }\
    406 static inline int N ## _end(NS ## builder_t *B)\
    407 { return N ## _add(B, TN ## _end(B)); }\
    408 static inline TN ## _ref_t N ## _create(NS ## builder_t *B __ ## TN ##_formal_args)\
    409 { return N ## _add(B, TN ## _create(B __ ## TN ## _call_args)); }\
    410 static inline int N ## _clone(NS ## builder_t *B, TN ## _table_t p)\
    411 { return N ## _add(B, TN ## _clone(B, p)); }\
    412 static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
    413 { TN ## _table_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }
    414 
    415 #define __flatbuffers_build_union_field(ID, NS, N, TN, TT)\
    416 static inline int N ## _add(NS ## builder_t *B, TN ## _union_ref_t uref)\
    417 { NS ## ref_t *_p; TN ## _union_type_t *_pt; if (uref.type == TN ## _NONE) return 0; if (uref.value == 0) return -1;\
    418   if (!(_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1, sizeof(*_pt), sizeof(*_pt)))) return -1;\
    419   *_pt = uref.type; if (!(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_p = uref.value; return 0; }\
    420 static inline int N ## _add_type(NS ## builder_t *B, TN ## _union_type_t type)\
    421 { TN ## _union_type_t *_pt; if (type == TN ## _NONE) return 0; return (_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1,\
    422   sizeof(*_pt), sizeof(*_pt))) ? ((*_pt = type), 0) : -1; }\
    423 static inline int N ## _add_value(NS ## builder_t *B, TN ## _union_ref_t uref)\
    424 { NS ## ref_t *p; if (uref.type == TN ## _NONE) return 0; return (p = flatcc_builder_table_add_offset(B, ID)) ?\
    425   ((*p = uref.value), 0) : -1; }\
    426 static inline int N ## _clone(NS ## builder_t *B, TN ## _union_t p)\
    427 { return N ## _add(B, TN ## _clone(B, p)); }\
    428 static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
    429 { TN ## _union_t _p = N ## _union(t); return _p.type ? N ## _clone(B, _p) : 0; }
    430 
    431 /* M is the union value name and T is its type, i.e. the qualified name. */
    432 #define __flatbuffers_build_union_table_value_field(NS, N, NU, M, T)\
    433 static inline int N ## _ ## M ## _add(NS ## builder_t *B, T ## _ref_t ref)\
    434 { return N ## _add(B, NU ## _as_ ## M (ref)); }\
    435 static inline int N ## _ ## M ## _start(NS ## builder_t *B)\
    436 { return T ## _start(B); }\
    437 static inline int N ## _ ## M ## _end(NS ## builder_t *B)\
    438 { T ## _ref_t ref = T ## _end(B);\
    439   return ref ? N ## _ ## M ## _add(B, ref) : -1; }\
    440 static inline int N ## _ ## M ## _create(NS ## builder_t *B __ ## T ##_formal_args)\
    441 { T ## _ref_t ref = T ## _create(B __ ## T ## _call_args);\
    442   return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\
    443 static inline int N ## _ ## M ## _clone(NS ## builder_t *B, T ## _table_t t)\
    444 { T ## _ref_t ref = T ## _clone(B, t);\
    445   return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }
    446 
    447 /* M is the union value name and T is its type, i.e. the qualified name. */
    448 #define __flatbuffers_build_union_struct_value_field(NS, N, NU, M, T)\
    449 static inline int N ## _ ## M ## _add(NS ## builder_t *B, T ## _ref_t ref)\
    450 { return N ## _add(B, NU ## _as_ ## M (ref)); }\
    451 static inline T ## _t *N ## _ ## M ## _start(NS ## builder_t *B)\
    452 { return T ## _start(B); }\
    453 static inline int N ## _ ## M ## _end(NS ## builder_t *B)\
    454 { T ## _ref_t ref = T ## _end(B);\
    455   return ref ? N ## _ ## M ## _add(B, ref) : -1; }\
    456 static inline int N ## _ ## M ## _create(NS ## builder_t *B __ ## T ##_formal_args)\
    457 { T ## _ref_t ref = T ## _create(B __ ## T ## _call_args);\
    458   return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\
    459 static inline int N ## _ ## M ## _end_pe(NS ## builder_t *B)\
    460 { T ## _ref_t ref = T ## _end_pe(B);\
    461   return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\
    462 static inline int N ## _ ## M ## _clone(NS ## builder_t *B, T ## _struct_t p)\
    463 { T ## _ref_t ref = T ## _clone(B, p);\
    464   return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }
    465 #define __flatbuffers_build_union_string_value_field(NS, N, NU, M)\
    466 static inline int N ## _ ## M ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\
    467 { return N ## _add(B, NU ## _as_ ## M (ref)); }\
    468 __flatbuffers_build_string_field_ops(NS, N ## _ ## M)
    469 
    470 /* NS: common namespace, ID: table field id (not offset), TN: name of type T, TT: name of table type
    471  * S: sizeof of scalar type, A: alignment of type T, default value V of type T. */
    472 #define __flatbuffers_build_scalar_field(ID, NS, N, TN, T, S, A, V, TT)\
    473 static inline int N ## _add(NS ## builder_t *B, const T v)\
    474 { T *_p; if (v == V) return 0; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\
    475   TN ## _assign_to_pe(_p, v); return 0; }\
    476 static inline int N ## _force_add(NS ## builder_t *B, const T v)\
    477 { T *_p; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\
    478   TN ## _assign_to_pe(_p, v); return 0; }\
    479 /* Clone does not skip default values and expects pe endian content. */\
    480 static inline int N ## _clone(NS ## builder_t *B, const T *p)\
    481 { return 0 == flatcc_builder_table_add_copy(B, ID, p, S, A) ? -1 : 0; }\
    482 /* Transferring a missing field is a nop success with 0 as result. */\
    483 static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
    484 { const T *_p = N ## _get_ptr(t); return _p ? N ## _clone(B, _p) : 0; }
    485 
    486 /* NS: common namespace, ID: table field id (not offset), TN: name of type T, TT: name of table type
    487  * S: sizeof of scalar type, A: alignment of type T. */
    488 #define __flatbuffers_build_scalar_optional_field(ID, NS, N, TN, T, S, A, TT)\
    489 static inline int N ## _add(NS ## builder_t *B, const T v)\
    490 { T *_p; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\
    491   TN ## _assign_to_pe(_p, v); return 0; }\
    492 /* Clone does not skip default values and expects pe endian content. */\
    493 static inline int N ## _clone(NS ## builder_t *B, const T *p)\
    494 { return 0 == flatcc_builder_table_add_copy(B, ID, p, S, A) ? -1 : 0; }\
    495 /* Transferring a missing field is a nop success with 0 as result. */\
    496 static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
    497 { const T *_p = N ## _get_ptr(t); return _p ? N ## _clone(B, _p) : 0; }
    498 
    499 #define __flatbuffers_build_struct_field(ID, NS, N, TN, S, A, TT)\
    500 static inline TN ## _t *N ## _start(NS ## builder_t *B)\
    501 { return (TN ## _t *)flatcc_builder_table_add(B, ID, S, A); }\
    502 static inline int N ## _end(NS ## builder_t *B)\
    503 { if (!NS ## is_native_pe()) { TN ## _to_pe((TN ## _t *)flatcc_builder_table_edit(B, S)); } return 0; }\
    504 static inline int N ## _end_pe(NS ## builder_t *B) { return 0; }\
    505 static inline int N ## _create(NS ## builder_t *B __ ## TN ## _formal_args)\
    506 { TN ## _t *_p = N ## _start(B); if (!_p) return -1; TN ##_assign_to_pe(_p __ ## TN ## _call_args);\
    507   return 0; }\
    508 static inline int N ## _add(NS ## builder_t *B, const TN ## _t *p)\
    509 { TN ## _t *_p = N ## _start(B); if (!_p) return -1; TN ##_copy_to_pe(_p, p); return 0; }\
    510 static inline int N ## _clone(NS ## builder_t *B, TN ## _struct_t p)\
    511 { return 0 == flatcc_builder_table_add_copy(B, ID, p, S, A) ? -1 : 0; }\
    512 static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
    513 { TN ## _struct_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }
    514 
    515 #define __flatbuffers_build_vector_field(ID, NS, N, TN, T, TT)\
    516 static inline int N ## _add(NS ## builder_t *B, TN ## _vec_ref_t ref)\
    517 { TN ## _vec_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\
    518 static inline int N ## _start(NS ## builder_t *B)\
    519 { return TN ## _vec_start(B); }\
    520 static inline int N ## _end_pe(NS ## builder_t *B)\
    521 { return N ## _add(B, TN ## _vec_end_pe(B)); }\
    522 static inline int N ## _end(NS ## builder_t *B)\
    523 { return N ## _add(B, TN ## _vec_end(B)); }\
    524 static inline int N ## _create_pe(NS ## builder_t *B, const T *data, size_t len)\
    525 { return N ## _add(B, TN ## _vec_create_pe(B, data, len)); }\
    526 static inline int N ## _create(NS ## builder_t *B, const T *data, size_t len)\
    527 { return N ## _add(B, TN ## _vec_create(B, data, len)); }\
    528 static inline int N ## _slice(NS ## builder_t *B, TN ## _vec_t vec, size_t index, size_t len)\
    529 { return N ## _add(B, TN ## _vec_slice(B, vec, index, len)); }\
    530 static inline int N ## _clone(NS ## builder_t *B, TN ## _vec_t vec)\
    531 { return N ## _add(B, TN ## _vec_clone(B, vec)); }\
    532 static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
    533 { TN ## _vec_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }\
    534 __flatbuffers_build_vector_ops(NS, N, N, TN, T)\
    535 
    536 #define __flatbuffers_build_offset_vector_field(ID, NS, N, TN, TT)\
    537 static inline int N ## _add(NS ## builder_t *B, TN ## _vec_ref_t ref)\
    538 { TN ## _vec_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\
    539 static inline int N ## _start(NS ## builder_t *B)\
    540 { return flatcc_builder_start_offset_vector(B); }\
    541 static inline int N ## _end(NS ## builder_t *B)\
    542 { return N ## _add(B, flatcc_builder_end_offset_vector(B)); }\
    543 static inline int N ## _create(NS ## builder_t *B, const TN ## _ref_t *data, size_t len)\
    544 { return N ## _add(B, flatcc_builder_create_offset_vector(B, data, len)); }\
    545 __flatbuffers_build_offset_vector_ops(NS, N, N, TN)\
    546 static inline int N ## _clone(NS ## builder_t *B, TN ## _vec_t vec)\
    547 { return N ## _add(B, TN ## _vec_clone(B, vec)); }\
    548 static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
    549 { TN ## _vec_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }
    550 
    551 /* depends on N ## _add which differs for union member fields and ordinary fields */\
    552 #define __flatbuffers_build_string_field_ops(NS, N)\
    553 static inline int N ## _start(NS ## builder_t *B)\
    554 { return flatcc_builder_start_string(B); }\
    555 static inline int N ## _end(NS ## builder_t *B)\
    556 { return N ## _add(B, flatcc_builder_end_string(B)); }\
    557 static inline int N ## _create(NS ## builder_t *B, const char *s, size_t len)\
    558 { return N ## _add(B, flatcc_builder_create_string(B, s, len)); }\
    559 static inline int N ## _create_str(NS ## builder_t *B, const char *s)\
    560 { return N ## _add(B, flatcc_builder_create_string_str(B, s)); }\
    561 static inline int N ## _create_strn(NS ## builder_t *B, const char *s, size_t max_len)\
    562 { return N ## _add(B, flatcc_builder_create_string_strn(B, s, max_len)); }\
    563 static inline int N ## _clone(NS ## builder_t *B, NS ## string_t string)\
    564 { return N ## _add(B, NS ## string_clone(B, string)); }\
    565 static inline int N ## _slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\
    566 { return N ## _add(B, NS ## string_slice(B, string, index, len)); }\
    567 __flatbuffers_build_string_ops(NS, N)
    568 
    569 #define __flatbuffers_build_string_field(ID, NS, N, TT)\
    570 static inline int N ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\
    571 { NS ## string_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\
    572 __flatbuffers_build_string_field_ops(NS, N)\
    573 static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
    574 { NS ## string_t _p = N ## _get(t); return _p ? N ## _clone(B, _p) : 0; }
    575 
    576 #define __flatbuffers_build_table_vector_field(ID, NS, N, TN, TT)\
    577 __flatbuffers_build_offset_vector_field(ID, NS, N, TN, TT)\
    578 __flatbuffers_build_table_vector_ops(NS, N, TN)
    579 
    580 #define __flatbuffers_build_union_vector_field(ID, NS, N, TN, TT)\
    581 static inline int N ## _add(NS ## builder_t *B, TN ## _union_vec_ref_t uvref)\
    582 { NS ## vec_ref_t *_p; if (!uvref.type || !uvref.value) return uvref.type == uvref.value ? 0 : -1;\
    583   if (!(_p = flatcc_builder_table_add_offset(B, ID - 1))) return -1; *_p = uvref.type;\
    584   if (!(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_p = uvref.value; return 0; }\
    585 static inline int N ## _start(NS ## builder_t *B)\
    586 { return flatcc_builder_start_union_vector(B); }\
    587 static inline int N ## _end(NS ## builder_t *B)\
    588 { return N ## _add(B, flatcc_builder_end_union_vector(B)); }\
    589 static inline int N ## _create(NS ## builder_t *B, const TN ## _union_ref_t *data, size_t len)\
    590 { return N ## _add(B, flatcc_builder_create_union_vector(B, data, len)); }\
    591 __flatbuffers_build_union_vector_ops(NS, N, N, TN)\
    592 static inline int N ## _clone(NS ## builder_t *B, TN ## _union_vec_t vec)\
    593 { return N ## _add(B, TN ## _vec_clone(B, vec)); }\
    594 static inline int N ## _pick(NS ## builder_t *B, TT ## _table_t t)\
    595 { TN ## _union_vec_t _p = N ## _union(t); return _p.type ? N ## _clone(B, _p) : 0; }
    596 
    597 #define __flatbuffers_build_union_table_vector_value_field(NS, N, NU, M, T)\
    598 static inline int N ## _ ## M ## _push_start(NS ## builder_t *B)\
    599 { return T ## _start(B); }\
    600 static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\
    601 { return NU ## _vec_push(B, NU ## _as_ ## M (T ## _end(B))); }\
    602 static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, T ## _ref_t ref)\
    603 { return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\
    604 static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B __ ## T ##_formal_args)\
    605 { return NU ## _vec_push(B, NU ## _as_ ## M(T ## _create(B __ ## T ## _call_args))); }\
    606 static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, T ## _table_t t)\
    607 { return NU ## _vec_push(B, NU ## _as_ ## M(T ## _clone(B, t))); }
    608 
    609 #define __flatbuffers_build_union_struct_vector_value_field(NS, N, NU, M, T)\
    610 static inline T ## _t *N ## _ ## M ## _push_start(NS ## builder_t *B)\
    611 { return T ## _start(B); }\
    612 static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\
    613 { return NU ## _vec_push(B, NU ## _as_ ## M (T ## _end(B))); }\
    614 static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, T ## _ref_t ref)\
    615 { return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\
    616 static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B __ ## T ##_formal_args)\
    617 { return NU ## _vec_push(B, NU ## _as_ ## M(T ## _create(B __ ## T ## _call_args))); }\
    618 static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, T ## _struct_t p)\
    619 { return NU ## _vec_push(B, NU ## _as_ ## M(T ## _clone(B, p))); }
    620 
    621 #define __flatbuffers_build_union_string_vector_value_field(NS, N, NU, M)\
    622 static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, NS ## string_ref_t ref)\
    623 { return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\
    624 static inline int N ## _ ## M ## _push_start(NS ## builder_t *B)\
    625 { return NS ## string_start(B); }\
    626 static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\
    627 { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_end(B))); }\
    628 static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B, const char *s, size_t len)\
    629 { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create(B, s, len))); }\
    630 static inline NU ## _union_ref_t *N ## _ ## M ## _push_create_str(NS ## builder_t *B, const char *s)\
    631 { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create_str(B, s))); }\
    632 static inline NU ## _union_ref_t *N ## _ ## M ## _push_create_strn(NS ## builder_t *B, const char *s, size_t max_len)\
    633 { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create_strn(B, s, max_len))); }\
    634 static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, NS ## string_t string)\
    635 { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_clone(B, string))); }\
    636 static inline NU ## _union_ref_t *N ## _ ## M ## _push_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\
    637 { return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_slice(B, string, index, len))); }
    638 
    639 #define __flatbuffers_build_string_vector_field(ID, NS, N, TT)\
    640 __flatbuffers_build_offset_vector_field(ID, NS, N, NS ## string, TT)\
    641 __flatbuffers_build_string_vector_ops(NS, N)
    642 
    643 #define __flatbuffers_char_formal_args , char v0
    644 #define __flatbuffers_char_call_args , v0
    645 #define __flatbuffers_uint8_formal_args , uint8_t v0
    646 #define __flatbuffers_uint8_call_args , v0
    647 #define __flatbuffers_int8_formal_args , int8_t v0
    648 #define __flatbuffers_int8_call_args , v0
    649 #define __flatbuffers_bool_formal_args , flatbuffers_bool_t v0
    650 #define __flatbuffers_bool_call_args , v0
    651 #define __flatbuffers_uint16_formal_args , uint16_t v0
    652 #define __flatbuffers_uint16_call_args , v0
    653 #define __flatbuffers_uint32_formal_args , uint32_t v0
    654 #define __flatbuffers_uint32_call_args , v0
    655 #define __flatbuffers_uint64_formal_args , uint64_t v0
    656 #define __flatbuffers_uint64_call_args , v0
    657 #define __flatbuffers_int16_formal_args , int16_t v0
    658 #define __flatbuffers_int16_call_args , v0
    659 #define __flatbuffers_int32_formal_args , int32_t v0
    660 #define __flatbuffers_int32_call_args , v0
    661 #define __flatbuffers_int64_formal_args , int64_t v0
    662 #define __flatbuffers_int64_call_args , v0
    663 #define __flatbuffers_float_formal_args , float v0
    664 #define __flatbuffers_float_call_args , v0
    665 #define __flatbuffers_double_formal_args , double v0
    666 #define __flatbuffers_double_call_args , v0
    667 
    668 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_char, char)
    669 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint8, uint8_t)
    670 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_int8, int8_t)
    671 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_bool, flatbuffers_bool_t)
    672 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint16, uint16_t)
    673 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint32, uint32_t)
    674 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_uint64, uint64_t)
    675 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_int16, int16_t)
    676 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_int32, int32_t)
    677 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_int64, int64_t)
    678 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_float, float)
    679 __flatbuffers_build_scalar(flatbuffers_, flatbuffers_double, double)
    680 
    681 __flatbuffers_build_string(flatbuffers_)
    682 
    683 __flatbuffers_build_buffer(flatbuffers_)
    684 #include "flatcc/flatcc_epilogue.h"
    685 #endif /* FLATBUFFERS_COMMON_BUILDER_H */