@@ -65,7 +65,8 @@ namespace flatbuffers {
6565 TD (VECTOR, " " , Offset<void >, int , int , VectorOffset, int , unused) \
6666 TD (STRUCT, " " , Offset<void >, int , int , int , int , unused) \
6767 TD (UNION, " " , Offset<void >, int , int , int , int , unused)
68-
68+ #define FLATBUFFERS_GEN_TYPE_ARRAY (TD ) \
69+ TD (ARRAY, " " , int , int , int , int , int , unused)
6970// The fields are:
7071// - enum
7172// - FlatBuffers schema type.
@@ -91,7 +92,8 @@ switch (type) {
9192
9293#define FLATBUFFERS_GEN_TYPES (TD ) \
9394 FLATBUFFERS_GEN_TYPES_SCALAR (TD) \
94- FLATBUFFERS_GEN_TYPES_POINTER (TD)
95+ FLATBUFFERS_GEN_TYPES_POINTER (TD) \
96+ FLATBUFFERS_GEN_TYPE_ARRAY (TD)
9597
9698// Create an enum for all the types above.
9799#ifdef __GNUC__
@@ -145,18 +147,21 @@ class Parser;
145147// and additional information for vectors/structs_.
146148struct Type {
147149 explicit Type (BaseType _base_type = BASE_TYPE_NONE, StructDef *_sd = nullptr ,
148- EnumDef *_ed = nullptr )
150+ EnumDef *_ed = nullptr , uint16_t _fixed_length = 0 )
149151 : base_type(_base_type),
150152 element(BASE_TYPE_NONE),
151153 struct_def(_sd),
152- enum_def(_ed) {}
154+ enum_def(_ed),
155+ fixed_length(_fixed_length) {}
153156
154157 bool operator ==(const Type &o) {
155158 return base_type == o.base_type && element == o.element &&
156159 struct_def == o.struct_def && enum_def == o.enum_def ;
157160 }
158161
159- Type VectorType () const { return Type (element, struct_def, enum_def); }
162+ Type VectorType () const {
163+ return Type (element, struct_def, enum_def, fixed_length);
164+ }
160165
161166 Offset<reflection::Type> Serialize (FlatBufferBuilder *builder) const ;
162167
@@ -167,6 +172,7 @@ struct Type {
167172 StructDef *struct_def; // only set if t or element == BASE_TYPE_STRUCT
168173 EnumDef *enum_def; // set if t == BASE_TYPE_UNION / BASE_TYPE_UTYPE,
169174 // or for an integral type derived from an enum.
175+ uint16_t fixed_length; // only set if t == BASE_TYPE_ARRAY
170176};
171177
172178// Represents a parsed scalar value, it's type, and field offset.
@@ -335,12 +341,34 @@ inline bool IsStruct(const Type &type) {
335341 return type.base_type == BASE_TYPE_STRUCT && type.struct_def ->fixed ;
336342}
337343
344+ inline bool IsVector (const Type &type) {
345+ return type.base_type == BASE_TYPE_VECTOR;
346+ }
347+
348+ inline bool IsArray (const Type &type) {
349+ return type.base_type == BASE_TYPE_ARRAY;
350+ }
351+
352+ inline bool IsSeries (const Type &type) {
353+ return IsVector (type) || IsArray (type);
354+ }
355+
356+ inline bool IsEnum (const Type &type) {
357+ return type.enum_def != nullptr && IsInteger (type.base_type );
358+ }
359+
338360inline size_t InlineSize (const Type &type) {
339- return IsStruct (type) ? type.struct_def ->bytesize : SizeOf (type.base_type );
361+ return IsStruct (type)
362+ ? type.struct_def ->bytesize
363+ : (IsArray (type)
364+ ? InlineSize (type.VectorType ()) * type.fixed_length
365+ : SizeOf (type.base_type ));
340366}
341367
342368inline size_t InlineAlignment (const Type &type) {
343- return IsStruct (type) ? type.struct_def ->minalign : SizeOf (type.base_type );
369+ return IsStruct (type)
370+ ? type.struct_def ->minalign
371+ : (SizeOf (IsArray (type) ? type.element : type.base_type ));
344372}
345373
346374struct EnumDef ;
@@ -799,10 +827,13 @@ class Parser : public ParserState {
799827 FLATBUFFERS_CHECKED_ERROR ParseTable (const StructDef &struct_def,
800828 std::string *value, uoffset_t *ovalue);
801829 void SerializeStruct (const StructDef &struct_def, const Value &val);
830+ void SerializeStruct (FlatBufferBuilder &builder, const StructDef &struct_def,
831+ const Value &val);
802832 template <typename F>
803833 FLATBUFFERS_CHECKED_ERROR ParseVectorDelimiters (uoffset_t &count, F body);
804834 FLATBUFFERS_CHECKED_ERROR ParseVector (const Type &type, uoffset_t *ovalue,
805835 FieldDef *field, size_t fieldn);
836+ FLATBUFFERS_CHECKED_ERROR ParseArray (Value &array);
806837 FLATBUFFERS_CHECKED_ERROR ParseNestedFlatbuffer (Value &val, FieldDef *field,
807838 size_t fieldn,
808839 const StructDef *parent_struct_def);
@@ -849,6 +880,7 @@ class Parser : public ParserState {
849880 BaseType baseType);
850881
851882 bool SupportsAdvancedUnionFeatures () const ;
883+ bool SupportsAdvancedArrayFeatures () const ;
852884 Namespace *UniqueNamespace (Namespace *ns);
853885
854886 FLATBUFFERS_CHECKED_ERROR RecurseError ();
0 commit comments