diff options
author | David Reiss <davidn@gmail.com> | 2019-03-05 21:16:26 -0800 |
---|---|---|
committer | Robert <rw@users.noreply.github.com> | 2019-03-05 21:16:26 -0800 |
commit | bfa430309af520a8978331754d7fa24ae79e5b44 (patch) | |
tree | 8f0255ca785c49b7d740bb4ebea300a495119027 /src/idl_gen_go.cpp | |
parent | 1c7d91cc55a9deb05e7ea93ba10b5ab511d29238 (diff) | |
download | flatbuffers-bfa430309af520a8978331754d7fa24ae79e5b44.tar.gz flatbuffers-bfa430309af520a8978331754d7fa24ae79e5b44.tar.bz2 flatbuffers-bfa430309af520a8978331754d7fa24ae79e5b44.zip |
[Go] Add mutation functions for vector elements (#5221)
Fixes #5206
Diffstat (limited to 'src/idl_gen_go.cpp')
-rw-r--r-- | src/idl_gen_go.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/idl_gen_go.cpp b/src/idl_gen_go.cpp index 4a402936..7a68e8aa 100644 --- a/src/idl_gen_go.cpp +++ b/src/idl_gen_go.cpp @@ -620,6 +620,27 @@ class GoGenerator : public BaseGenerator { code += "}\n\n"; } + // Mutate an element of a vector of scalars. + void MutateElementOfVectorOfNonStruct(const StructDef &struct_def, + const FieldDef &field, + std::string *code_ptr) { + std::string &code = *code_ptr; + auto vectortype = field.value.type.VectorType(); + std::string type = MakeCamel(GenTypeBasic(vectortype)); + std::string setter = "rcv._tab.Mutate" + type; + GenReceiver(struct_def, code_ptr); + code += " Mutate" + MakeCamel(field.name); + code += "(j int, n " + TypeName(field) + ") bool "; + code += OffsetPrefix(field); + code += "\t\ta := rcv._tab.Vector(o)\n"; + code += "\t\treturn " + setter + "("; + code += "a+flatbuffers.UOffsetT(j*"; + code += NumToString(InlineSize(vectortype)) + "), n)\n"; + code += "\t}\n"; + code += "\treturn false\n"; + code += "}\n\n"; + } + // Generate a struct field setter, conditioned on its child type(s). void GenStructMutator(const StructDef &struct_def, const FieldDef &field, std::string *code_ptr) { @@ -630,6 +651,10 @@ class GoGenerator : public BaseGenerator { } else { MutateScalarFieldOfTable(struct_def, field, code_ptr); } + } else if (field.value.type.base_type == BASE_TYPE_VECTOR) { + if (IsScalar(field.value.type.element)) { + MutateElementOfVectorOfNonStruct(struct_def, field, code_ptr); + } } } |