Skip to content

Commit

Permalink
Release version 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkelfj committed Jan 5, 2018
1 parent b2bed16 commit 59bacd8
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 88 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
42 changes: 18 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions include/flatcc/flatcc_version.h
Original file line number Diff line number Diff line change
@@ -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
148 changes: 133 additions & 15 deletions include/flatcc/reflection/flatbuffers_common_builder.h
Original file line number Diff line number Diff line change
@@ -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. */

Expand All @@ -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;
Expand Down Expand Up @@ -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)\
Expand Down Expand Up @@ -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); }\
Expand Down Expand Up @@ -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)\
Expand All @@ -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)

Expand All @@ -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. */
Expand All @@ -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);\
Expand Down Expand Up @@ -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)\
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 59bacd8

Please sign in to comment.