diff --git a/CHANGELOG.md b/CHANGELOG.md index 170472c0..8813f116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [0.5.0-pre] +## [0.5.0] - New schema type aliases: int8, uint8, int16, uint16, int32, uint32, int64, uint64, float32, float64. - Low-level: access multiple user frames in builder via handles. diff --git a/README.md b/README.md index a0390bbe..ec28cb07 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,6 @@ Windows: [![Windows Build Status](https://ci.appveyor.com/api/projects/status/gi # FlatCC FlatBuffers in C for C -_NOTE: ongoing work towards version 0.5.0 features might cause minor -breakage. For full backwards compatibility use the v0.4.3 tag. -If you work with JSON parsing, you may want to patch v0.4.3 with commit -[1cb266](https://github.com/dvidelabs/flatcc/commit/1cb2664dcd104b2051d410955018cb255370302e) -which only affects code generation, not the runtime library._ - `flatcc` has no external dependencies except for build and compiler tools, and the C runtime library. With concurrent Ninja builds, a small client project can build flatcc with libraries, generate schema code, @@ -234,21 +228,21 @@ fi ## Status -v0.5.0 is in development on master branch primarily to reach feature -parity with Googles flatc schema parser as of end 2017. These new -features are union vectors and mixed type unions that can include -tables, structs and strings, and type aliases for int8, uint8, int16, -uint16, int32, uint32, int64, uint64, float32, float64 types in the -schema. Support for base64(url) JSON encoded [ubyte] vectors has been -added which will also be added to Googles flatc tool in a future -release. In addition the following changes have been added: Runtime -builder library support for `aligned_alloc/free`. Handling of unions is -slightly incompatible with previous releases as covered in the -documentation. v0.5.0 fixes a bug that could cause a JSON parser to -reject some valid symbols for some schemas and also fixes a non-critical -JSON scoping issue with symbolic union names and a bug verifying buffers -with a struct as root. Low-level custom frame support has been improved -in the builder library which is useful for complex parsing scenarios. +Release 0.5.0 aims to reach feature parity with C++ FlatBuffers as of +end 2017. These new features are union vectors and mixed type unions +that can include tables, structs and strings, and type aliases for int8, +uint8, int16, uint16, int32, uint32, int64, uint64, float32, float64 +types in the schema. Support for base64(url) JSON encoded [ubyte] +vectors has been added which will also be added to Googles flatc tool in +a future release. In addition the following changes have been added: +Runtime builder library support for `aligned_alloc/free`. Handling of +unions is slightly incompatible with previous releases as covered in the +documentation and the changelog. v0.5.0 fixes a bug that could cause a +JSON parser to reject some valid symbols for some schemas and also fixes +a non-critical JSON scoping issue with symbolic union names and a bug +verifying buffers with a struct as root. Low-level custom frame support +has been improved in the builder library which is useful for complex +parsing scenarios. Main features supported as of 0.5.0 @@ -271,9 +265,9 @@ Main features supported as of 0.5.0 - flexible configuration of malloc alternatives and runtime aligned_alloc/free support in builder library. - feature parity with C++ FlatBuffers schema features added in 2017 - union vectors and mixed type unions of strings, structs, and tables. -- base64(url) encoded binary data in JSON, soon to also be supported by - Googles flatc JSON parser. + adding support for union vectors and mixed type unions of strings, + structs, and tables, and type aliases for uint8, ..., float64. +- base64(url) encoded binary data in JSON. Supported platforms (as covered by CI release tests on ci-more branch): diff --git a/include/flatcc/flatcc_version.h b/include/flatcc/flatcc_version.h index 25ae3634..cd644a72 100644 --- a/include/flatcc/flatcc_version.h +++ b/include/flatcc/flatcc_version.h @@ -1,6 +1,6 @@ -#define FLATCC_VERSION_TEXT "0.5.0-pre" +#define FLATCC_VERSION_TEXT "0.5.0" #define FLATCC_VERSION_MAJOR 0 #define FLATCC_VERSION_MINOR 5 #define FLATCC_VERSION_PATCH 0 /* 1 or 0 */ -#define FLATCC_VERSION_RELEASED 0 +#define FLATCC_VERSION_RELEASED 1 diff --git a/include/flatcc/reflection/flatbuffers_common_builder.h b/include/flatcc/reflection/flatbuffers_common_builder.h index 08cd4185..d8c94afa 100644 --- a/include/flatcc/reflection/flatbuffers_common_builder.h +++ b/include/flatcc/reflection/flatbuffers_common_builder.h @@ -1,7 +1,7 @@ #ifndef FLATBUFFERS_COMMON_BUILDER_H #define FLATBUFFERS_COMMON_BUILDER_H -/* Generated by flatcc 0.4.3 FlatBuffers schema compiler for C by dvide.com */ +/* Generated by flatcc 0.5.0 FlatBuffers schema compiler for C by dvide.com */ /* Common FlatBuffers build functionality for C. */ @@ -13,6 +13,8 @@ typedef flatcc_builder_t flatbuffers_builder_t; typedef flatcc_builder_ref_t flatbuffers_ref_t; typedef flatcc_builder_ref_t flatbuffers_vec_ref_t; +typedef flatcc_builder_union_ref_t flatbuffers_union_ref_t; +typedef flatcc_builder_union_vec_ref_t flatbuffers_union_vec_ref_t; /* integer return code (ref and ptr always fail on 0) */ #define flatbuffers_failed(x) ((x) < 0) typedef flatbuffers_ref_t flatbuffers_root_t; @@ -85,7 +87,15 @@ static inline NS ## buffer_ref_t N ## _create_as_typed_root(NS ## builder_t *B _ N ## _create(B __ ## N ## _call_args), A, 0); }\ static inline NS ## buffer_ref_t N ## _create_as_typed_root_with_size(NS ## builder_t *B __ ## N ## _formal_args)\ { return flatcc_builder_create_buffer(B, TFID, 0,\ - N ## _create(B __ ## N ## _call_args), A, flatcc_builder_with_size); } + N ## _create(B __ ## N ## _call_args), A, flatcc_builder_with_size); }\ +static inline NS ## buffer_ref_t N ## _clone_as_root(NS ## builder_t *B, N ## _struct_t p)\ +{ return flatcc_builder_create_buffer(B, FID, 0, N ## _clone(B, p), A, 0); }\ +static inline NS ## buffer_ref_t N ## _clone_as_root_with_size(NS ## builder_t *B, N ## _struct_t p)\ +{ return flatcc_builder_create_buffer(B, FID, 0, N ## _clone(B, p), A, flatcc_builder_with_size); }\ +static inline NS ## buffer_ref_t N ## _clone_as_typed_root(NS ## builder_t *B, N ## _struct_t p)\ +{ return flatcc_builder_create_buffer(B, TFID, 0, N ## _clone(B, p), A, 0); }\ +static inline NS ## buffer_ref_t N ## _clone_as_typed_root_with_size(NS ## builder_t *B, N ## _struct_t p)\ +{ return flatcc_builder_create_buffer(B, TFID, 0, N ## _clone(B, p), A, flatcc_builder_with_size); } #define __flatbuffers_build_nested_table_root(NS, N, TN, FID, TFID)\ static inline int N ## _start_as_root(NS ## builder_t *B)\ @@ -169,6 +179,29 @@ static inline N ## _vec_ref_t N ## _vec_slice(NS ## builder_t *B, N ##_vec_t vec return flatcc_builder_create_vector(B, N ## __const_ptr_add(vec, index), len, S, A, FLATBUFFERS_COUNT_MAX(S)); }\ __flatbuffers_build_vector_ops(NS, N ## _vec, N, N, T) +#define __flatbuffers_build_union_vector_ops(NS, V, N, TN)\ +static inline TN ## _union_ref_t *V ## _extend(NS ## builder_t *B, size_t len)\ +{ return flatcc_builder_extend_union_vector(B, len); }\ +static inline TN ## _union_ref_t *V ## _append(NS ## builder_t *B, const TN ## _union_ref_t *data, size_t len)\ +{ return flatcc_builder_append_union_vector(B, data, len); }\ +static inline int V ## _truncate(NS ## builder_t *B, size_t len)\ +{ return flatcc_builder_truncate_union_vector(B, len); }\ +static inline TN ## _union_ref_t *V ## _edit(NS ## builder_t *B)\ +{ return flatcc_builder_union_vector_edit(B); }\ +static inline size_t V ## _reserved_len(NS ## builder_t *B)\ +{ return flatcc_builder_union_vector_count(B); }\ +static inline TN ## _union_ref_t *V ## _push(NS ## builder_t *B, const TN ## _union_ref_t ref)\ +{ return flatcc_builder_union_vector_push(B, ref); } + +#define __flatbuffers_build_union_vector(NS, N)\ +static inline int N ## _vec_start(NS ## builder_t *B)\ +{ return flatcc_builder_start_union_vector(B); }\ +static inline N ## _union_vec_ref_t N ## _vec_end(NS ## builder_t *B)\ +{ return flatcc_builder_end_union_vector(B); }\ +static inline N ## _union_vec_ref_t N ## _vec_create(NS ## builder_t *B, const N ## _union_ref_t *data, size_t len)\ +{ return flatcc_builder_create_union_vector(B, data, len); }\ +__flatbuffers_build_union_vector_ops(NS, N ## _vec, N, N) + #define __flatbuffers_build_string_vector_ops(NS, N)\ static inline int N ## _push_start(NS ## builder_t *B)\ { return NS ## string_start(B); }\ @@ -279,7 +312,7 @@ static inline N ## _t *N ##_to_pe(N ## _t *p)\ { if (!NS ## is_native_pe()) { N ## _copy_to_pe(p, p); }; return p; }\ static inline N ## _t *N ##_from_pe(N ## _t *p)\ { if (!NS ## is_native_pe()) { N ## _copy_from_pe(p, p); }; return p; }\ -static inline N ## _t *N ## _clear(N ## _t *p) { return memset(p, 0, N ## __size()); } +static inline N ## _t *N ## _clear(N ## _t *p) { return (N ## _t *)memset(p, 0, N ## __size()); } /* Depends on generated copy/assign_to/from_pe functions, and the type. */ #define __flatbuffers_build_struct(NS, N, S, A, FID, TFID)\ @@ -288,13 +321,16 @@ typedef NS ## ref_t N ## _ref_t;\ static inline N ## _t *N ## _start(NS ## builder_t *B)\ { return (N ## _t *)flatcc_builder_start_struct(B, S, A); }\ static inline N ## _ref_t N ## _end(NS ## builder_t *B)\ -{ if (!NS ## is_native_pe()) { N ## _to_pe(flatcc_builder_struct_edit(B)); }\ +{ if (!NS ## is_native_pe()) { N ## _to_pe((N ## _t *)flatcc_builder_struct_edit(B)); }\ return flatcc_builder_end_struct(B); }\ static inline N ## _ref_t N ## _end_pe(NS ## builder_t *B)\ { return flatcc_builder_end_struct(B); }\ static inline N ## _ref_t N ## _create(NS ## builder_t *B __ ## N ## _formal_args)\ { N ## _t *_p = N ## _start(B); if (!_p) return 0; N ##_assign_to_pe(_p __ ## N ## _call_args);\ return N ## _end_pe(B); }\ +static inline N ## _ref_t N ## _clone(NS ## builder_t *B, N ## _struct_t p)\ +{ N ## _t *_p = N ## _start(B); if (!_p) return 0;\ + N ## _copy(_p, p); return N ##_end_pe(B); }\ __flatbuffers_build_vector(NS, N, N ## _t, S, A)\ __flatbuffers_build_struct_root(NS, N, A, FID, TFID) @@ -321,24 +357,52 @@ static inline TN ## _ref_t N ## _create(NS ## builder_t *B __ ## TN ##_formal_ar #define __flatbuffers_build_union_field(ID, NS, N, TN)\ static inline int N ## _add(NS ## builder_t *B, TN ## _union_ref_t uref)\ -{ NS ## ref_t *_p; TN ## _union_type_t *_pt; if (uref.type == TN ## _NONE) return 0; if (uref._member == 0) return -1;\ - if (!(_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1, sizeof(*_pt), sizeof(_pt))) ||\ - !(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_pt = uref.type; *_p = uref._member; return 0; }\ +{ NS ## ref_t *_p; TN ## _union_type_t *_pt; if (uref.type == TN ## _NONE) return 0; if (uref.member == 0) return -1;\ + if (!(_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1, sizeof(*_pt), sizeof(*_pt))) ||\ + !(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_pt = uref.type; *_p = uref.member; return 0; }\ static inline int N ## _add_type(NS ## builder_t *B, TN ## _union_type_t type)\ { TN ## _union_type_t *_pt; if (type == TN ## _NONE) return 0; return (_pt = (TN ## _union_type_t *)flatcc_builder_table_add(B, ID - 1,\ sizeof(*_pt), sizeof(*_pt))) ? ((*_pt = type), 0) : -1; }\ static inline int N ## _add_member(NS ## builder_t *B, TN ## _union_ref_t uref)\ { NS ## ref_t *p; if (uref.type == TN ## _NONE) return 0; return (p = flatcc_builder_table_add_offset(B, ID)) ?\ - ((*p = uref._member), 0) : -1; } + ((*p = uref.member), 0) : -1; } /* M is the union member name and T is its type, i.e. the qualified name. */ -#define __flatbuffers_build_union_member_field(NS, N, NU, M, T)\ +#define __flatbuffers_build_union_table_member_field(NS, N, NU, M, T)\ static inline int N ## _ ## M ## _add(NS ## builder_t *B, T ## _ref_t ref)\ { return N ## _add(B, NU ## _as_ ## M (ref)); }\ static inline int N ## _ ## M ## _start(NS ## builder_t *B)\ { return T ## _start(B); }\ static inline int N ## _ ## M ## _end(NS ## builder_t *B)\ -{ return N ## _ ## M ## _add(B, T ## _end(B)); } +{ T ## _ref_t ref = T ## _end(B);\ + return ref ? N ## _ ## M ## _add(B, ref) : -1; }\ +static inline int N ## _ ## M ## _create(NS ## builder_t *B __ ## T ##_formal_args)\ +{ T ## _ref_t ref = T ## _create(B __ ## T ## _call_args);\ + return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; } + +/* M is the union member name and T is its type, i.e. the qualified name. */ +#define __flatbuffers_build_union_struct_member_field(NS, N, NU, M, T)\ +static inline int N ## _ ## M ## _add(NS ## builder_t *B, T ## _ref_t ref)\ +{ return N ## _add(B, NU ## _as_ ## M (ref)); }\ +static inline T ## _t *N ## _ ## M ## _start(NS ## builder_t *B)\ +{ return T ## _start(B); }\ +static inline int N ## _ ## M ## _end(NS ## builder_t *B)\ +{ T ## _ref_t ref = T ## _end(B);\ + return ref ? N ## _ ## M ## _add(B, ref) : -1; }\ +static inline int N ## _ ## M ## _create(NS ## builder_t *B __ ## T ##_formal_args)\ +{ T ## _ref_t ref = T ## _create(B __ ## T ## _call_args);\ + return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\ +static inline int N ## _ ## M ## _end_pe(NS ## builder_t *B)\ +{ T ## _ref_t ref = T ## _end_pe(B);\ + return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; }\ +static inline int N ## _ ## M ## _clone(NS ## builder_t *B, T ## _struct_t p)\ +{ T ## _ref_t ref = T ## _clone(B, p);\ + return ref ? N ## _add(B, NU ## _as_ ## M(ref)) : -1; } + +#define __flatbuffers_build_union_string_member_field(NS, N, NU, M)\ +static inline int N ## _ ## M ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\ +{ return N ## _add(B, NU ## _as_ ## M (ref)); }\ +__flatbuffers_build_string_field_ops(NS, N ## _ ## M) /* NS: common namespace, ID: table field id (not offset), TN: name of type T, * S: sizeof of scalar type, A: alignment of type T, default value V of type T. */ @@ -348,13 +412,13 @@ static inline int N ## _add(NS ## builder_t *B, const T v)\ TN ## _assign_to_pe(_p, v); return 0; }\ static inline int N ## _force_add(NS ## builder_t *B, const T v)\ { T *_p; if (!(_p = (T *)flatcc_builder_table_add(B, ID, S, A))) return -1;\ - TN ## _assign_to_pe(_p, v); return 0; }\ + TN ## _assign_to_pe(_p, v); return 0; } #define __flatbuffers_build_struct_field(ID, NS, N, TN, S, A)\ static inline TN ## _t *N ## _start(NS ## builder_t *B)\ { return (TN ## _t *)flatcc_builder_table_add(B, ID, S, A); }\ static inline int N ## _end(NS ## builder_t *B)\ -{ if (!NS ## is_native_pe()) { TN ## _to_pe(flatcc_builder_table_edit(B, S)); } return 0; }\ +{ if (!NS ## is_native_pe()) { TN ## _to_pe((TN ## _t *)flatcc_builder_table_edit(B, S)); } return 0; }\ static inline int N ## _end_pe(NS ## builder_t *B) { return 0; }\ static inline int N ## _create(NS ## builder_t *B __ ## TN ## _formal_args)\ { TN ## _t *_p = N ## _start(B); if (!_p) return 0; TN ##_assign_to_pe(_p __ ## TN ## _call_args);\ @@ -394,9 +458,7 @@ static inline int N ## _create(NS ## builder_t *B, const TN ## _ref_t *data, siz { return N ## _add(B, flatcc_builder_create_offset_vector(B, data, len)); }\ __flatbuffers_build_offset_vector_ops(NS, N, N, TN) -#define __flatbuffers_build_string_field(ID, NS, N)\ -static inline int N ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\ -{ NS ## string_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\ +#define __flatbuffers_build_string_field_ops(NS, N)\ static inline int N ## _start(NS ## builder_t *B)\ { return flatcc_builder_start_string(B); }\ static inline int N ## _end(NS ## builder_t *B)\ @@ -413,10 +475,66 @@ static inline int N ## _slice(NS ## builder_t *B, NS ## string_t string, size_t { return N ## _add(B, NS ## string_slice(B, string, index, len)); }\ __flatbuffers_build_string_ops(NS, N) +#define __flatbuffers_build_string_field(ID, NS, N)\ +static inline int N ## _add(NS ## builder_t *B, NS ## string_ref_t ref)\ +{ NS ## string_ref_t *_p; return (ref && (_p = flatcc_builder_table_add_offset(B, ID))) ? ((*_p = ref), 0) : -1; }\ +__flatbuffers_build_string_field_ops(NS, N) + #define __flatbuffers_build_table_vector_field(ID, NS, N, TN)\ __flatbuffers_build_offset_vector_field(ID, NS, N, TN)\ __flatbuffers_build_table_vector_ops(NS, N, TN) +#define __flatbuffers_build_union_vector_field(ID, NS, N, TN)\ +static inline int N ## _add(NS ## builder_t *B, TN ## _union_vec_ref_t uvref)\ +{ NS ## vec_ref_t *_p; if (!uvref.types || !uvref.members) return uvref.types == uvref.members ? 0 : -1;\ + if (!(_p = flatcc_builder_table_add_offset(B, ID - 1))) return -1; *_p = uvref.types;\ + if (!(_p = flatcc_builder_table_add_offset(B, ID))) return -1; *_p = uvref.members; return 0; }\ +static inline int N ## _start(NS ## builder_t *B)\ +{ return flatcc_builder_start_union_vector(B); }\ +static inline int N ## _end(NS ## builder_t *B)\ +{ return N ## _add(B, flatcc_builder_end_union_vector(B)); }\ +static inline int N ## _create(NS ## builder_t *B, const TN ## _union_ref_t *data, size_t len)\ +{ return N ## _add(B, flatcc_builder_create_union_vector(B, data, len)); }\ +__flatbuffers_build_union_vector_ops(NS, N, N, TN) + +#define __flatbuffers_build_union_table_vector_member_field(NS, N, NU, M, T)\ +static inline int N ## _ ## M ## _push_start(NS ## builder_t *B)\ +{ return T ## _start(B); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M (T ## _end(B))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, T ## _ref_t ref)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B __ ## T ##_formal_args)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(T ## _create(B __ ## T ## _call_args))); } + +#define __flatbuffers_build_union_struct_vector_member_field(NS, N, NU, M, T)\ +static inline T ## _t *N ## _ ## M ## _push_start(NS ## builder_t *B)\ +{ return T ## _start(B); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M (T ## _end(B))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, T ## _ref_t ref)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B __ ## T ##_formal_args)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(T ## _create(B __ ## T ## _call_args))); } + +#define __flatbuffers_build_union_string_vector_member_field(NS, N, NU, M)\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push(NS ## builder_t *B, NS ## string_ref_t ref)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M (ref)); }\ +static inline int N ## _ ## M ## _push_start(NS ## builder_t *B)\ +{ return NS ## string_start(B); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_end(NS ## builder_t *B)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_end(B))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_create(NS ## builder_t *B, const char *s, size_t len)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create(B, s, len))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_create_str(NS ## builder_t *B, const char *s)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create_str(B, s))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_create_strn(NS ## builder_t *B, const char *s, size_t max_len)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_create_strn(B, s, max_len))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_clone(NS ## builder_t *B, NS ## string_t string)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_clone(B, string))); }\ +static inline NU ## _union_ref_t *N ## _ ## M ## _push_slice(NS ## builder_t *B, NS ## string_t string, size_t index, size_t len)\ +{ return NU ## _vec_push(B, NU ## _as_ ## M(NS ## string_slice(B, string, index, len))); } + #define __flatbuffers_build_string_vector_field(ID, NS, N)\ __flatbuffers_build_offset_vector_field(ID, NS, N, NS ## string)\ __flatbuffers_build_string_vector_ops(NS, N) diff --git a/include/flatcc/reflection/flatbuffers_common_reader.h b/include/flatcc/reflection/flatbuffers_common_reader.h index 54e23ee2..96d3b626 100644 --- a/include/flatcc/reflection/flatbuffers_common_reader.h +++ b/include/flatcc/reflection/flatbuffers_common_reader.h @@ -1,7 +1,7 @@ #ifndef FLATBUFFERS_COMMON_READER_H #define FLATBUFFERS_COMMON_READER_H -/* Generated by flatcc 0.4.3 FlatBuffers schema compiler for C by dvide.com */ +/* Generated by flatcc 0.5.0 FlatBuffers schema compiler for C by dvide.com */ /* Common FlatBuffers read functionality for C. */ @@ -24,18 +24,6 @@ flatbuffers_voffset_t offset = 0;\ }\ } #define __flatbuffers_field_present(ID, t) { __flatbuffers_read_vt(ID, offset, t) return offset != 0; } -#define __flatbuffers_union_type_field(ID, t)\ -{\ - __flatbuffers_read_vt(ID, offset, t)\ - return offset ? __flatbuffers_read_scalar_at_byteoffset(__flatbuffers_utype, t, offset) : 0;\ -} -#define __flatbuffers_define_union_field(ID, N, NK, r)\ -static inline flatbuffers_utype_t N ## _ ## NK ## _type(N ## _table_t t)\ -__flatbuffers_union_type_field(((ID) - 1), t)\ -static inline flatbuffers_generic_t N ## _ ## NK(N ## _table_t t)\ -__flatbuffers_table_field(flatbuffers_generic_t, ID, t, r)\ -static inline int N ## _ ## NK ## _is_present(N ## _table_t t)\ -__flatbuffers_field_present(ID, t) #define __flatbuffers_define_scalar_field(ID, N, NK, TK, T, V)\ static inline T N ## _ ## NK (N ## _table_t t)\ { __flatbuffers_read_vt(ID, offset, t)\ @@ -120,6 +108,69 @@ __flatbuffers_vec_len(vec) static inline flatbuffers_string_t flatbuffers_string_vec_at(flatbuffers_string_vec_t vec, size_t i) __flatbuffers_offset_vec_at(flatbuffers_string_t, vec, i, sizeof(vec[0])) typedef const void *flatbuffers_generic_t; +static inline flatbuffers_string_t flatbuffers_string_cast_from_generic(const flatbuffers_generic_t p)\ +{ return p ? ((const char *)p) + __flatbuffers_uoffset__size() : 0; } +typedef const flatbuffers_uoffset_t *flatbuffers_generic_vec_t; +typedef flatbuffers_uoffset_t *flatbuffers_generic_table_mutable_vec_t; +static inline size_t flatbuffers_generic_vec_len(flatbuffers_generic_vec_t vec) +__flatbuffers_vec_len(vec) +static inline flatbuffers_generic_t flatbuffers_generic_vec_at(flatbuffers_generic_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(flatbuffers_generic_t, vec, i, 0)\ +static inline flatbuffers_generic_t flatbuffers_generic_vec_at_as_string(flatbuffers_generic_vec_t vec, size_t i) +__flatbuffers_offset_vec_at(flatbuffers_generic_t, vec, i, sizeof(vec[0]))\ +typedef struct flatbuffers_union { + flatbuffers_union_type_t type; + flatbuffers_generic_t member; +} flatbuffers_union_t; +typedef struct flatbuffers_union_vec { + const flatbuffers_union_type_t *type; + const flatbuffers_uoffset_t *member; +} flatbuffers_union_vec_t; +#define __flatbuffers_union_type_field(ID, t)\ +{\ + __flatbuffers_read_vt(ID, offset, t)\ + return offset ? __flatbuffers_read_scalar_at_byteoffset(__flatbuffers_utype, t, offset) : 0;\ +} +static inline flatbuffers_string_t flatbuffers_string_cast_from_union(const flatbuffers_union_t u)\ +{ return flatbuffers_string_cast_from_generic(u.member); } +#define __flatbuffers_define_union_field(NS, ID, N, NK, T, r)\ +static inline T ## _union_type_t N ## _ ## NK ## _type(N ## _table_t t)\ +__## NS ## union_type_field(((ID) - 1), t)\ +static inline NS ## generic_t N ## _ ## NK(N ## _table_t t)\ +__## NS ## table_field(NS ## generic_t, ID, t, r)\ +static inline int N ## _ ## NK ## _is_present(N ## _table_t t)\ +__## NS ## field_present(ID, t)\ +static inline T ## _union_t N ## _ ## NK ## _union(N ## _table_t t)\ +{ T ## _union_t u = { 0, 0 }; u.type = N ## _ ## NK ## _type(t);\ + if (u.type == 0) return u; u.member = N ## _ ## NK (t); return u; }\ +static inline NS ## string_t N ## _ ## NK ## _as_string(N ## _table_t t)\ +{ return NS ## string_cast_from_generic(N ## _ ## NK(t)); }\ + +#define __flatbuffers_define_union_vector_ops(NS, T)\ +static inline size_t T ## _union_vec_len(T ## _union_vec_t uv)\ +{ return NS ## vec_len(uv.type); }\ +static inline T ## _union_t T ## _union_vec_at(T ## _union_vec_t uv, size_t i)\ +{ T ## _union_t u = { 0, 0 }; size_t n = NS ## vec_len(uv.type);\ + assert(n > (i) && "index out of range"); u.type = uv.type[i];\ + /* Unknown type is treated as NONE for schema evolution. */\ + if (u.type == 0) return u;\ + u.member = NS ## generic_vec_at(uv.member, i); return u; }\ +static inline NS ## string_t T ## _union_vec_at_as_string(T ## _union_vec_t uv, size_t i)\ +{ return NS ## generic_vec_at_as_string(uv.member, i); }\ + +#define __flatbuffers_define_union_vector(NS, T)\ +typedef NS ## union_vec_t T ## _union_vec_t;\ +__## NS ## define_union_vector_ops(NS, T) +#define __flatbuffers_define_union(NS, T)\ +typedef NS ## union_t T ## _union_t;\ +__## NS ## define_union_vector(NS, T) +#define __flatbuffers_define_union_vector_field(NS, ID, N, NK, T, r)\ +__## NS ## define_vector_field(ID - 1, N, NK ## _type, T ## _vec_t, r)\ +__## NS ## define_vector_field(ID, N, NK, flatbuffers_generic_vec_t, r)\ +static inline T ## _union_vec_t N ## _ ## NK ## _union(N ## _table_t t)\ +{ T ## _union_vec_t uv; uv.type = N ## _ ## NK ## _type(t); uv.member = N ## _ ## NK(t);\ + assert(NS ## vec_len(uv.type) == NS ## vec_len(uv.member)\ + && "union vector type length mismatch"); return uv; } #include static size_t flatbuffers_not_found = (size_t)-1; static size_t flatbuffers_end = (size_t)-1; @@ -352,6 +403,7 @@ __flatbuffers_define_scalar_vector(flatbuffers_uint64, uint64_t) __flatbuffers_define_scalar_vector(flatbuffers_int64, int64_t) __flatbuffers_define_scalar_vector(flatbuffers_float, float) __flatbuffers_define_scalar_vector(flatbuffers_double, double) +__flatbuffers_define_scalar_vector(flatbuffers_union_type, flatbuffers_union_type_t) static inline size_t flatbuffers_string_vec_find(flatbuffers_string_vec_t vec, const char *s) __flatbuffers_find_by_string_field(__flatbuffers_identity, vec, flatbuffers_string_vec_at, flatbuffers_string_vec_len, s) static inline size_t flatbuffers_string_vec_find_n(flatbuffers_string_vec_t vec, const char *s, size_t n) diff --git a/include/flatcc/reflection/reflection_builder.h b/include/flatcc/reflection/reflection_builder.h index 33642733..531561ef 100644 --- a/include/flatcc/reflection/reflection_builder.h +++ b/include/flatcc/reflection/reflection_builder.h @@ -1,7 +1,7 @@ #ifndef REFLECTION_BUILDER_H #define REFLECTION_BUILDER_H -/* Generated by flatcc 0.4.3 FlatBuffers schema compiler for C by dvide.com */ +/* Generated by flatcc 0.5.0 FlatBuffers schema compiler for C by dvide.com */ #ifndef REFLECTION_READER_H #include "reflection_reader.h" diff --git a/include/flatcc/reflection/reflection_reader.h b/include/flatcc/reflection/reflection_reader.h index 616480cd..c726a502 100644 --- a/include/flatcc/reflection/reflection_reader.h +++ b/include/flatcc/reflection/reflection_reader.h @@ -1,7 +1,7 @@ #ifndef REFLECTION_READER_H #define REFLECTION_READER_H -/* Generated by flatcc 0.4.3 FlatBuffers schema compiler for C by dvide.com */ +/* Generated by flatcc 0.5.0 FlatBuffers schema compiler for C by dvide.com */ #ifndef FLATBUFFERS_COMMON_READER_H #include "flatbuffers_common_reader.h" @@ -36,6 +36,36 @@ typedef flatbuffers_uoffset_t *reflection_Object_mutable_vec_t; typedef const struct reflection_Schema_table *reflection_Schema_table_t; typedef const flatbuffers_uoffset_t *reflection_Schema_vec_t; typedef flatbuffers_uoffset_t *reflection_Schema_mutable_vec_t; +#ifndef reflection_Type_identifier +#define reflection_Type_identifier flatbuffers_identifier +#endif +#define reflection_Type_type_hash ((flatbuffers_thash_t)0x44c8fe5e) +#define reflection_Type_type_identifier "\x5e\xfe\xc8\x44" +#ifndef reflection_EnumVal_identifier +#define reflection_EnumVal_identifier flatbuffers_identifier +#endif +#define reflection_EnumVal_type_hash ((flatbuffers_thash_t)0x9531c946) +#define reflection_EnumVal_type_identifier "\x46\xc9\x31\x95" +#ifndef reflection_Enum_identifier +#define reflection_Enum_identifier flatbuffers_identifier +#endif +#define reflection_Enum_type_hash ((flatbuffers_thash_t)0xacffa90f) +#define reflection_Enum_type_identifier "\x0f\xa9\xff\xac" +#ifndef reflection_Field_identifier +#define reflection_Field_identifier flatbuffers_identifier +#endif +#define reflection_Field_type_hash ((flatbuffers_thash_t)0x9f7e408a) +#define reflection_Field_type_identifier "\x8a\x40\x7e\x9f" +#ifndef reflection_Object_identifier +#define reflection_Object_identifier flatbuffers_identifier +#endif +#define reflection_Object_type_hash ((flatbuffers_thash_t)0xb09729bd) +#define reflection_Object_type_identifier "\xbd\x29\x97\xb0" +#ifndef reflection_Schema_identifier +#define reflection_Schema_identifier flatbuffers_identifier +#endif +#define reflection_Schema_type_hash ((flatbuffers_thash_t)0xfaf93779) +#define reflection_Schema_type_identifier "\x79\x37\xf9\xfa" typedef int8_t reflection_BaseType_enum_t; __flatbuffers_define_integer_type(reflection_BaseType, reflection_BaseType_enum_t, 8) @@ -81,15 +111,34 @@ static inline const char *reflection_BaseType_name(reflection_BaseType_enum_t va } } +static inline int reflection_BaseType_is_known_value(reflection_BaseType_enum_t value) +{ + switch (value) { + case reflection_BaseType_None: return 1; + case reflection_BaseType_UType: return 1; + case reflection_BaseType_Bool: return 1; + case reflection_BaseType_Byte: return 1; + case reflection_BaseType_UByte: return 1; + case reflection_BaseType_Short: return 1; + case reflection_BaseType_UShort: return 1; + case reflection_BaseType_Int: return 1; + case reflection_BaseType_UInt: return 1; + case reflection_BaseType_Long: return 1; + case reflection_BaseType_ULong: return 1; + case reflection_BaseType_Float: return 1; + case reflection_BaseType_Double: return 1; + case reflection_BaseType_String: return 1; + case reflection_BaseType_Vector: return 1; + case reflection_BaseType_Obj: return 1; + case reflection_BaseType_Union: return 1; + default: return 0; + } +} + struct reflection_Type_table { uint8_t unused__; }; -#ifndef reflection_Type_identifier -#define reflection_Type_identifier flatbuffers_identifier -#endif -#define reflection_Type_type_hash ((flatbuffers_thash_t)0x44c8fe5e) -#define reflection_Type_type_identifier "\x5e\xfe\xc8\x44" static inline size_t reflection_Type_vec_len(reflection_Type_vec_t vec) __flatbuffers_vec_len(vec) static inline reflection_Type_table_t reflection_Type_vec_at(reflection_Type_vec_t vec, size_t i) @@ -102,11 +151,6 @@ __flatbuffers_define_scalar_field(2, reflection_Type, index, flatbuffers_int32, struct reflection_EnumVal_table { uint8_t unused__; }; -#ifndef reflection_EnumVal_identifier -#define reflection_EnumVal_identifier flatbuffers_identifier -#endif -#define reflection_EnumVal_type_hash ((flatbuffers_thash_t)0x9531c946) -#define reflection_EnumVal_type_identifier "\x46\xc9\x31\x95" static inline size_t reflection_EnumVal_vec_len(reflection_EnumVal_vec_t vec) __flatbuffers_vec_len(vec) static inline reflection_EnumVal_table_t reflection_EnumVal_vec_at(reflection_EnumVal_vec_t vec, size_t i) @@ -125,11 +169,6 @@ __flatbuffers_define_table_field(2, reflection_EnumVal, object, reflection_Objec struct reflection_Enum_table { uint8_t unused__; }; -#ifndef reflection_Enum_identifier -#define reflection_Enum_identifier flatbuffers_identifier -#endif -#define reflection_Enum_type_hash ((flatbuffers_thash_t)0xacffa90f) -#define reflection_Enum_type_identifier "\x0f\xa9\xff\xac" static inline size_t reflection_Enum_vec_len(reflection_Enum_vec_t vec) __flatbuffers_vec_len(vec) static inline reflection_Enum_table_t reflection_Enum_vec_at(reflection_Enum_vec_t vec, size_t i) @@ -148,11 +187,6 @@ __flatbuffers_define_table_field(3, reflection_Enum, underlying_type, reflection struct reflection_Field_table { uint8_t unused__; }; -#ifndef reflection_Field_identifier -#define reflection_Field_identifier flatbuffers_identifier -#endif -#define reflection_Field_type_hash ((flatbuffers_thash_t)0x9f7e408a) -#define reflection_Field_type_identifier "\x8a\x40\x7e\x9f" static inline size_t reflection_Field_vec_len(reflection_Field_vec_t vec) __flatbuffers_vec_len(vec) static inline reflection_Field_table_t reflection_Field_vec_at(reflection_Field_vec_t vec, size_t i) @@ -176,11 +210,6 @@ __flatbuffers_define_scalar_field(8, reflection_Field, key, flatbuffers_bool, fl struct reflection_Object_table { uint8_t unused__; }; -#ifndef reflection_Object_identifier -#define reflection_Object_identifier flatbuffers_identifier -#endif -#define reflection_Object_type_hash ((flatbuffers_thash_t)0xb09729bd) -#define reflection_Object_type_identifier "\xbd\x29\x97\xb0" static inline size_t reflection_Object_vec_len(reflection_Object_vec_t vec) __flatbuffers_vec_len(vec) static inline reflection_Object_table_t reflection_Object_vec_at(reflection_Object_vec_t vec, size_t i) @@ -200,11 +229,6 @@ __flatbuffers_define_scalar_field(4, reflection_Object, bytesize, flatbuffers_in struct reflection_Schema_table { uint8_t unused__; }; -#ifndef reflection_Schema_identifier -#define reflection_Schema_identifier flatbuffers_identifier -#endif -#define reflection_Schema_type_hash ((flatbuffers_thash_t)0xfaf93779) -#define reflection_Schema_type_identifier "\x79\x37\xf9\xfa" static inline size_t reflection_Schema_vec_len(reflection_Schema_vec_t vec) __flatbuffers_vec_len(vec) static inline reflection_Schema_table_t reflection_Schema_vec_at(reflection_Schema_vec_t vec, size_t i) diff --git a/include/flatcc/reflection/reflection_verifier.h b/include/flatcc/reflection/reflection_verifier.h index 649b82e2..8ee35867 100644 --- a/include/flatcc/reflection/reflection_verifier.h +++ b/include/flatcc/reflection/reflection_verifier.h @@ -1,7 +1,7 @@ #ifndef REFLECTION_VERIFIER_H #define REFLECTION_VERIFIER_H -/* Generated by flatcc 0.4.3 FlatBuffers schema compiler for C by dvide.com */ +/* Generated by flatcc 0.5.0 FlatBuffers schema compiler for C by dvide.com */ #ifndef REFLECTION_READER_H #include "reflection_reader.h"