forked from BigfootDev/flatbuffers
native_type and native_inline on fields
This commit is contained in:
@@ -987,7 +987,13 @@ class CppGenerator : public BaseGenerator {
|
||||
case BASE_TYPE_STRUCT: {
|
||||
auto type_name = WrapInNameSpace(*type.struct_def);
|
||||
if (IsStruct(type)) {
|
||||
auto native_type = type.struct_def->attributes.Lookup("native_type");
|
||||
// Field-level native_type takes priority over struct-level
|
||||
// native_type
|
||||
auto field_native_type = field.attributes.Lookup("native_type");
|
||||
auto native_type =
|
||||
field_native_type
|
||||
? field_native_type
|
||||
: type.struct_def->attributes.Lookup("native_type");
|
||||
if (native_type) {
|
||||
type_name = native_type->constant;
|
||||
}
|
||||
@@ -3516,10 +3522,21 @@ class CppGenerator : public BaseGenerator {
|
||||
case BASE_TYPE_STRUCT: {
|
||||
if (IsStruct(type)) {
|
||||
const auto& struct_attrs = type.struct_def->attributes;
|
||||
const auto native_type = struct_attrs.Lookup("native_type");
|
||||
// Field-level native_type takes priority over struct-level
|
||||
// native_type
|
||||
auto field_native_type = afield.attributes.Lookup("native_type");
|
||||
const auto native_type = field_native_type
|
||||
? field_native_type
|
||||
: struct_attrs.Lookup("native_type");
|
||||
if (native_type) {
|
||||
std::string unpack_call = "::flatbuffers::UnPack";
|
||||
const auto pack_name = struct_attrs.Lookup("native_type_pack_name");
|
||||
// Field-level native_type_pack_name takes priority over
|
||||
// struct-level
|
||||
auto field_pack_name =
|
||||
afield.attributes.Lookup("native_type_pack_name");
|
||||
const auto pack_name =
|
||||
field_pack_name ? field_pack_name
|
||||
: struct_attrs.Lookup("native_type_pack_name");
|
||||
if (pack_name) {
|
||||
unpack_call += pack_name->constant;
|
||||
}
|
||||
@@ -3918,11 +3935,22 @@ class CppGenerator : public BaseGenerator {
|
||||
case BASE_TYPE_STRUCT: {
|
||||
if (IsStruct(field.value.type)) {
|
||||
const auto& struct_attribs = field.value.type.struct_def->attributes;
|
||||
const auto native_type = struct_attribs.Lookup("native_type");
|
||||
// Field-level native_type takes priority over struct-level
|
||||
// native_type
|
||||
auto field_native_type = field.attributes.Lookup("native_type");
|
||||
const auto native_type = field_native_type
|
||||
? field_native_type
|
||||
: struct_attribs.Lookup("native_type");
|
||||
if (native_type && field.native_inline) {
|
||||
code += "::flatbuffers::Pack";
|
||||
// Field-level native_type_pack_name takes priority over
|
||||
// struct-level
|
||||
auto field_pack_name =
|
||||
field.attributes.Lookup("native_type_pack_name");
|
||||
const auto pack_name =
|
||||
struct_attribs.Lookup("native_type_pack_name");
|
||||
field_pack_name
|
||||
? field_pack_name
|
||||
: struct_attribs.Lookup("native_type_pack_name");
|
||||
if (pack_name) {
|
||||
code += pack_name->constant;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user