diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp index 5fa9b1848..c47ccffa4 100644 --- a/src/idl_gen_general.cpp +++ b/src/idl_gen_general.cpp @@ -1044,7 +1044,7 @@ class GeneralGenerator : public BaseGenerator { : lang_.accessor_prefix + "__indirect(" + index + ")"; code += ", " + lang_.accessor_prefix + "bb"; } else if (vectortype.base_type == BASE_TYPE_UNION) { - code += index + " - bb_pos"; + code += index + " - " + lang_.accessor_prefix + "bb_pos"; } else { code += index; } diff --git a/tests/generate_code.sh b/tests/generate_code.sh index 5d6b7ce42..40373a34e 100755 --- a/tests/generate_code.sh +++ b/tests/generate_code.sh @@ -17,7 +17,7 @@ set -e ../flatc --cpp --java --csharp --dart --go --binary --lobster --lua --python --js --ts --php --rust --grpc --gen-mutable --reflect-names --gen-object-api --gen-compare --no-includes --cpp-ptr-type flatbuffers::unique_ptr --no-fb-import -I include_test monster_test.fbs monsterdata_test.json ../flatc --cpp --java --csharp --dart --go --binary --lobster --lua --python --js --ts --php --rust --gen-mutable --reflect-names --no-fb-import --cpp-ptr-type flatbuffers::unique_ptr -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs -../flatc --cpp --java --js --ts --php --gen-mutable --reflect-names --gen-object-api --gen-compare --cpp-ptr-type flatbuffers::unique_ptr -o union_vector ./union_vector/union_vector.fbs +../flatc --cpp --java --csharp --js --ts --php --gen-mutable --reflect-names --gen-object-api --gen-compare --cpp-ptr-type flatbuffers::unique_ptr -o union_vector ./union_vector/union_vector.fbs ../flatc -b --schema --bfbs-comments --bfbs-builtins -I include_test monster_test.fbs ../flatc --jsonschema --schema -I include_test monster_test.fbs ../flatc --cpp --java --csharp --python --gen-mutable --reflect-names --gen-object-api --gen-compare --no-includes monster_extra.fbs || goto FAIL diff --git a/tests/union_vector/Attacker.cs b/tests/union_vector/Attacker.cs index c81e8d596..7f20fff87 100644 --- a/tests/union_vector/Attacker.cs +++ b/tests/union_vector/Attacker.cs @@ -15,6 +15,7 @@ public struct Attacker : IFlatbufferObject public Attacker __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } public int SwordAttackDamage { get { int o = __p.__offset(4); return o != 0 ? __p.bb.GetInt(o + __p.bb_pos) : (int)0; } } + public bool MutateSwordAttackDamage(int sword_attack_damage) { int o = __p.__offset(4); if (o != 0) { __p.bb.PutInt(o + __p.bb_pos, sword_attack_damage); return true; } else { return false; } } public static Offset CreateAttacker(FlatBufferBuilder builder, int sword_attack_damage = 0) { diff --git a/tests/union_vector/BookReader.cs b/tests/union_vector/BookReader.cs index 1642b81ff..2cd33bfc5 100644 --- a/tests/union_vector/BookReader.cs +++ b/tests/union_vector/BookReader.cs @@ -13,6 +13,7 @@ public struct BookReader : IFlatbufferObject public BookReader __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } public int BooksRead { get { return __p.bb.GetInt(__p.bb_pos + 0); } } + public void MutateBooksRead(int books_read) { __p.bb.PutInt(__p.bb_pos + 0, books_read); } public static Offset CreateBookReader(FlatBufferBuilder builder, int BooksRead) { builder.Prep(4, 4); diff --git a/tests/union_vector/Movie.cs b/tests/union_vector/Movie.cs index b229b4fee..6a9130a7c 100644 --- a/tests/union_vector/Movie.cs +++ b/tests/union_vector/Movie.cs @@ -16,6 +16,7 @@ public struct Movie : IFlatbufferObject public Movie __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } public Character MainCharacterType { get { int o = __p.__offset(4); return o != 0 ? (Character)__p.bb.Get(o + __p.bb_pos) : Character.NONE; } } + public bool MutateMainCharacterType(Character main_character_type) { int o = __p.__offset(4); if (o != 0) { __p.bb.Put(o + __p.bb_pos, (byte)main_character_type); return true; } else { return false; } } public TTable? MainCharacter() where TTable : struct, IFlatbufferObject { int o = __p.__offset(6); return o != 0 ? (TTable?)__p.__union(o) : null; } public Character CharactersType(int j) { int o = __p.__offset(8); return o != 0 ? (Character)__p.bb.Get(__p.__vector(o) + j * 1) : (Character)0; } public int CharactersTypeLength { get { int o = __p.__offset(8); return o != 0 ? __p.__vector_len(o) : 0; } } @@ -25,7 +26,8 @@ public struct Movie : IFlatbufferObject public ArraySegment? GetCharactersTypeBytes() { return __p.__vector_as_arraysegment(8); } #endif public Character[] GetCharactersTypeArray() { return __p.__vector_as_array(8); } - public TTable? Characters(int j) where TTable : struct, IFlatbufferObject { int o = __p.__offset(10); return o != 0 ? (TTable?)__p.__union(__p.__vector(o) + j * 4) : null; } + public bool MutateCharactersType(int j, Character characters_type) { int o = __p.__offset(8); if (o != 0) { __p.bb.Put(__p.__vector(o) + j * 1, (byte)characters_type); return true; } else { return false; } } + public TTable? Characters(int j) where TTable : struct, IFlatbufferObject { int o = __p.__offset(10); return o != 0 ? (TTable?)__p.__union(__p.__vector(o) + j * 4 - __p.bb_pos) : null; } public int CharactersLength { get { int o = __p.__offset(10); return o != 0 ? __p.__vector_len(o) : 0; } } public static Offset CreateMovie(FlatBufferBuilder builder, diff --git a/tests/union_vector/Rapunzel.cs b/tests/union_vector/Rapunzel.cs index 4928f5d43..f95f10045 100644 --- a/tests/union_vector/Rapunzel.cs +++ b/tests/union_vector/Rapunzel.cs @@ -13,6 +13,7 @@ public struct Rapunzel : IFlatbufferObject public Rapunzel __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } public int HairLength { get { return __p.bb.GetInt(__p.bb_pos + 0); } } + public void MutateHairLength(int hair_length) { __p.bb.PutInt(__p.bb_pos + 0, hair_length); } public static Offset CreateRapunzel(FlatBufferBuilder builder, int HairLength) { builder.Prep(4, 4);