// written in new data nor accessed in new code.
bool required; // Field must always be present.
bool key; // Field functions as a key for creating sorted vectors.
+ bool native_inline; // Field will be defined inline (instead of as a pointer)
+ // for native tables if field is a struct.
size_t padding; // Bytes to always pad after this field.
};
known_attributes_["idempotent"] = true;
known_attributes_["cpp_type"] = true;
known_attributes_["cpp_ptr_type"] = true;
+ known_attributes_["native_inline"] = true;
}
~Parser() {
">";
case BASE_TYPE_STRUCT:
if (IsStruct(type)) {
- if (invector) {
+ if (invector || field.native_inline) {
return WrapInNameSpace(*type.struct_def);
} else {
return GenTypeNativePtr(WrapInNameSpace(*type.struct_def), &field,
return val + "->str()";
case BASE_TYPE_STRUCT:
if (IsStruct(type)) {
- if (invector) {
+ if (invector || afield.native_inline) {
return "*" + val;
} else {
return GenTypeNativePtr(WrapInNameSpace(*type.struct_def),
code += "{ for (flatbuffers::uoffset_t _i = 0;";
code += " _i < _e->size(); _i++) { ";
code += dest + ".push_back(";
- std::string indexing = "_e->Get(_i)";
+ std::string indexing;
+ if (field.value.type.enum_def) {
+ indexing += "(" + field.value.type.enum_def->name + ")";
+ }
+ indexing += "_e->Get(_i)";
if (field.value.type.element == BASE_TYPE_BOOL)
indexing += "!=0";
code += GenUnpackVal(field.value.type.VectorType(),
code += "_fbb.CreateVectorOfStructs(" + accessor + ")";
} else {
code += "_fbb.CreateVector<flatbuffers::Offset<";
- code += vector_type.struct_def->name + ">>(" + accessor;
+ code += WrapInNameSpace(*vector_type.struct_def) + ">>(" +
+ accessor;
code += ".size(), [&](size_t i) { return Create";
code += vector_type.struct_def->name + "(_fbb, " + accessor;
code += "[i]" + GenPtrGet(field) + ", rehasher); })";
}
break;
- default:
+ case BASE_TYPE_BOOL:
code += "_fbb.CreateVector(" + accessor + ")";
break;
+ default: {
+ std::string args = accessor;
+ if (field.value.type.enum_def) {
+ const std::string basetype = GenTypeBasic(
+ field.value.type.enum_def->underlying_type, false);
+ args = "(const " + basetype + "*)" + accessor +
+ ".data(), " + accessor + ".size()";
+ }
+ code += "_fbb.CreateVector(" + args + ")";
+ break;
+ }
}
code += postfix;
break;
break;
case BASE_TYPE_STRUCT:
if (IsStruct(field.value.type)) {
- code += ptrprefix + accessor + GenPtrGet(field) + postfix;
+ if (field.native_inline) {
+ code += "&" + accessor;
+ } else {
+ code += ptrprefix + accessor + GenPtrGet(field) + postfix;
+ }
} else {
code += ptrprefix + "Create";
code += field.value.type.struct_def->name;
return Error("'key' field must be string or scalar type");
}
}
+
+ field->native_inline = field->attributes.Lookup("native_inline") != nullptr;
+ if (field->native_inline && !IsStruct(field->value.type))
+ return Error("native_inline can only be defined on structs'");
+
auto nested = field->attributes.Lookup("nested_flatbuffer");
if (nested) {
if (nested->type.base_type != BASE_TYPE_STRING)
case kTokenFloatConstant:
EXPECT(kTokenFloatConstant);
break;
- case kTokenNull:
- EXPECT(kTokenNull);
- break;
default:
return Error(std::string("Unexpected token:") + std::string(1, static_cast<char>(token_)));
}