From 8cccdfba536be9f68004bb53c2ceb06f7510bd58 Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Tue, 23 Feb 2021 11:30:07 -0800 Subject: [PATCH] Revert "[C#] Fix truncated ArraySegment if elementSize != 1 (#6462)" (#6488) This reverts commit cbbbaa61b34c31f17773c2fef354c31664e9562e. --- net/FlatBuffers/Table.cs | 4 ++-- src/idl_gen_csharp.cpp | 2 -- tests/FlatBuffers.Test/FlatBuffersExampleTests.cs | 3 --- tests/MyGame/Example/Monster.cs | 24 +++++++++++------------ tests/MyGame/Example/Stat.cs | 2 +- tests/MyGame/Example/TypeAliases.cs | 4 ++-- tests/MyGame/MonsterExtra.cs | 4 ++-- 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/net/FlatBuffers/Table.cs b/net/FlatBuffers/Table.cs index fb3b1ad..d888de5 100644 --- a/net/FlatBuffers/Table.cs +++ b/net/FlatBuffers/Table.cs @@ -112,7 +112,7 @@ namespace FlatBuffers // Get the data of a vector whoses offset is stored at "offset" in this object as an // ArraySegment<byte>. If the vector is not present in the ByteBuffer, // then a null value will be returned. - public ArraySegment? __vector_as_arraysegment(int offset, int elementSize) + public ArraySegment? __vector_as_arraysegment(int offset) { var o = this.__offset(offset); if (0 == o) @@ -122,7 +122,7 @@ namespace FlatBuffers var pos = this.__vector(o); var len = this.__vector_len(o); - return bb.ToArraySegment(pos, len * elementSize); + return bb.ToArraySegment(pos, len); } #endif diff --git a/src/idl_gen_csharp.cpp b/src/idl_gen_csharp.cpp index fed1169..a5423a2 100644 --- a/src/idl_gen_csharp.cpp +++ b/src/idl_gen_csharp.cpp @@ -845,8 +845,6 @@ class CSharpGenerator : public BaseGenerator { code += "Bytes() { return "; code += "__p.__vector_as_arraysegment("; code += NumToString(field.value.offset); - code += - ", " + NumToString(SizeOf(field.value.type.VectorType().base_type)); code += "); }\n"; code += "#endif\n"; diff --git a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs index 8e71747..b4093d4 100644 --- a/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs +++ b/tests/FlatBuffers.Test/FlatBuffersExampleTests.cs @@ -277,9 +277,6 @@ namespace FlatBuffers.Test { Assert.IsTrue(monster.GetTestarrayofboolsBytes().HasValue); } - - Assert.AreEqual(monster.VectorOfDoublesLength * 8, monster.GetVectorOfDoublesBytes().Value.Count); - #endif } diff --git a/tests/MyGame/Example/Monster.cs b/tests/MyGame/Example/Monster.cs index e89a658..12a4357 100644 --- a/tests/MyGame/Example/Monster.cs +++ b/tests/MyGame/Example/Monster.cs @@ -30,7 +30,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetNameBytes() { return __p.__vector_as_span(10, 1); } #else - public ArraySegment? GetNameBytes() { return __p.__vector_as_arraysegment(10, 1); } + public ArraySegment? GetNameBytes() { return __p.__vector_as_arraysegment(10); } #endif public byte[] GetNameArray() { return __p.__vector_as_array(10); } public byte Inventory(int j) { int o = __p.__offset(14); return o != 0 ? __p.bb.Get(__p.__vector(o) + j * 1) : (byte)0; } @@ -38,7 +38,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetInventoryBytes() { return __p.__vector_as_span(14, 1); } #else - public ArraySegment? GetInventoryBytes() { return __p.__vector_as_arraysegment(14, 1); } + public ArraySegment? GetInventoryBytes() { return __p.__vector_as_arraysegment(14); } #endif public byte[] GetInventoryArray() { return __p.__vector_as_array(14); } public bool MutateInventory(int j, byte inventory) { int o = __p.__offset(14); if (o != 0) { __p.bb.Put(__p.__vector(o) + j * 1, inventory); return true; } else { return false; } } @@ -64,7 +64,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetTestnestedflatbufferBytes() { return __p.__vector_as_span(30, 1); } #else - public ArraySegment? GetTestnestedflatbufferBytes() { return __p.__vector_as_arraysegment(30, 1); } + public ArraySegment? GetTestnestedflatbufferBytes() { return __p.__vector_as_arraysegment(30); } #endif public byte[] GetTestnestedflatbufferArray() { return __p.__vector_as_array(30); } public MyGame.Example.Monster? GetTestnestedflatbufferAsMonster() { int o = __p.__offset(30); return o != 0 ? (MyGame.Example.Monster?)(new MyGame.Example.Monster()).__assign(__p.__indirect(__p.__vector(o)), __p.bb) : null; } @@ -93,7 +93,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetTestarrayofboolsBytes() { return __p.__vector_as_span(52, 1); } #else - public ArraySegment? GetTestarrayofboolsBytes() { return __p.__vector_as_arraysegment(52, 1); } + public ArraySegment? GetTestarrayofboolsBytes() { return __p.__vector_as_arraysegment(52); } #endif public bool[] GetTestarrayofboolsArray() { return __p.__vector_as_array(52); } public bool MutateTestarrayofbools(int j, bool testarrayofbools) { int o = __p.__offset(52); if (o != 0) { __p.bb.Put(__p.__vector(o) + j * 1, (byte)(testarrayofbools ? 1 : 0)); return true; } else { return false; } } @@ -112,7 +112,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetFlexBytes() { return __p.__vector_as_span(64, 1); } #else - public ArraySegment? GetFlexBytes() { return __p.__vector_as_arraysegment(64, 1); } + public ArraySegment? GetFlexBytes() { return __p.__vector_as_arraysegment(64); } #endif public byte[] GetFlexArray() { return __p.__vector_as_array(64); } public bool MutateFlex(int j, byte flex) { int o = __p.__offset(64); if (o != 0) { __p.bb.Put(__p.__vector(o) + j * 1, flex); return true; } else { return false; } } @@ -123,7 +123,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetVectorOfLongsBytes() { return __p.__vector_as_span(68, 8); } #else - public ArraySegment? GetVectorOfLongsBytes() { return __p.__vector_as_arraysegment(68, 8); } + public ArraySegment? GetVectorOfLongsBytes() { return __p.__vector_as_arraysegment(68); } #endif public long[] GetVectorOfLongsArray() { return __p.__vector_as_array(68); } public bool MutateVectorOfLongs(int j, long vector_of_longs) { int o = __p.__offset(68); if (o != 0) { __p.bb.PutLong(__p.__vector(o) + j * 8, vector_of_longs); return true; } else { return false; } } @@ -132,7 +132,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetVectorOfDoublesBytes() { return __p.__vector_as_span(70, 8); } #else - public ArraySegment? GetVectorOfDoublesBytes() { return __p.__vector_as_arraysegment(70, 8); } + public ArraySegment? GetVectorOfDoublesBytes() { return __p.__vector_as_arraysegment(70); } #endif public double[] GetVectorOfDoublesArray() { return __p.__vector_as_array(70); } public bool MutateVectorOfDoubles(int j, double vector_of_doubles) { int o = __p.__offset(70); if (o != 0) { __p.bb.PutDouble(__p.__vector(o) + j * 8, vector_of_doubles); return true; } else { return false; } } @@ -147,7 +147,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetVectorOfWeakReferencesBytes() { return __p.__vector_as_span(78, 8); } #else - public ArraySegment? GetVectorOfWeakReferencesBytes() { return __p.__vector_as_arraysegment(78, 8); } + public ArraySegment? GetVectorOfWeakReferencesBytes() { return __p.__vector_as_arraysegment(78); } #endif public ulong[] GetVectorOfWeakReferencesArray() { return __p.__vector_as_array(78); } public bool MutateVectorOfWeakReferences(int j, ulong vector_of_weak_references) { int o = __p.__offset(78); if (o != 0) { __p.bb.PutUlong(__p.__vector(o) + j * 8, vector_of_weak_references); return true; } else { return false; } } @@ -161,7 +161,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetVectorOfCoOwningReferencesBytes() { return __p.__vector_as_span(84, 8); } #else - public ArraySegment? GetVectorOfCoOwningReferencesBytes() { return __p.__vector_as_arraysegment(84, 8); } + public ArraySegment? GetVectorOfCoOwningReferencesBytes() { return __p.__vector_as_arraysegment(84); } #endif public ulong[] GetVectorOfCoOwningReferencesArray() { return __p.__vector_as_array(84); } public bool MutateVectorOfCoOwningReferences(int j, ulong vector_of_co_owning_references) { int o = __p.__offset(84); if (o != 0) { __p.bb.PutUlong(__p.__vector(o) + j * 8, vector_of_co_owning_references); return true; } else { return false; } } @@ -172,7 +172,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetVectorOfNonOwningReferencesBytes() { return __p.__vector_as_span(88, 8); } #else - public ArraySegment? GetVectorOfNonOwningReferencesBytes() { return __p.__vector_as_arraysegment(88, 8); } + public ArraySegment? GetVectorOfNonOwningReferencesBytes() { return __p.__vector_as_arraysegment(88); } #endif public ulong[] GetVectorOfNonOwningReferencesArray() { return __p.__vector_as_array(88); } public bool MutateVectorOfNonOwningReferences(int j, ulong vector_of_non_owning_references) { int o = __p.__offset(88); if (o != 0) { __p.bb.PutUlong(__p.__vector(o) + j * 8, vector_of_non_owning_references); return true; } else { return false; } } @@ -191,7 +191,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetVectorOfEnumsBytes() { return __p.__vector_as_span(98, 1); } #else - public ArraySegment? GetVectorOfEnumsBytes() { return __p.__vector_as_arraysegment(98, 1); } + public ArraySegment? GetVectorOfEnumsBytes() { return __p.__vector_as_arraysegment(98); } #endif public MyGame.Example.Color[] GetVectorOfEnumsArray() { int o = __p.__offset(98); if (o == 0) return null; int p = __p.__vector(o); int l = __p.__vector_len(o); MyGame.Example.Color[] a = new MyGame.Example.Color[l]; for (int i = 0; i < l; i++) { a[i] = (MyGame.Example.Color)__p.bb.Get(p + i * 1); } return a; } public bool MutateVectorOfEnums(int j, MyGame.Example.Color vector_of_enums) { int o = __p.__offset(98); if (o != 0) { __p.bb.Put(__p.__vector(o) + j * 1, (byte)vector_of_enums); return true; } else { return false; } } @@ -202,7 +202,7 @@ public struct Monster : IFlatbufferObject #if ENABLE_SPAN_T public Span GetTestrequirednestedflatbufferBytes() { return __p.__vector_as_span(102, 1); } #else - public ArraySegment? GetTestrequirednestedflatbufferBytes() { return __p.__vector_as_arraysegment(102, 1); } + public ArraySegment? GetTestrequirednestedflatbufferBytes() { return __p.__vector_as_arraysegment(102); } #endif public byte[] GetTestrequirednestedflatbufferArray() { return __p.__vector_as_array(102); } public MyGame.Example.Monster? GetTestrequirednestedflatbufferAsMonster() { int o = __p.__offset(102); return o != 0 ? (MyGame.Example.Monster?)(new MyGame.Example.Monster()).__assign(__p.__indirect(__p.__vector(o)), __p.bb) : null; } diff --git a/tests/MyGame/Example/Stat.cs b/tests/MyGame/Example/Stat.cs index 9469acb..07c22da 100644 --- a/tests/MyGame/Example/Stat.cs +++ b/tests/MyGame/Example/Stat.cs @@ -23,7 +23,7 @@ public struct Stat : IFlatbufferObject #if ENABLE_SPAN_T public Span GetIdBytes() { return __p.__vector_as_span(4, 1); } #else - public ArraySegment? GetIdBytes() { return __p.__vector_as_arraysegment(4, 1); } + public ArraySegment? GetIdBytes() { return __p.__vector_as_arraysegment(4); } #endif public byte[] GetIdArray() { return __p.__vector_as_array(4); } public long Val { get { int o = __p.__offset(6); return o != 0 ? __p.bb.GetLong(o + __p.bb_pos) : (long)0; } } diff --git a/tests/MyGame/Example/TypeAliases.cs b/tests/MyGame/Example/TypeAliases.cs index f6a303d..79ffb07 100644 --- a/tests/MyGame/Example/TypeAliases.cs +++ b/tests/MyGame/Example/TypeAliases.cs @@ -44,7 +44,7 @@ public struct TypeAliases : IFlatbufferObject #if ENABLE_SPAN_T public Span GetV8Bytes() { return __p.__vector_as_span(24, 1); } #else - public ArraySegment? GetV8Bytes() { return __p.__vector_as_arraysegment(24, 1); } + public ArraySegment? GetV8Bytes() { return __p.__vector_as_arraysegment(24); } #endif public sbyte[] GetV8Array() { return __p.__vector_as_array(24); } public bool MutateV8(int j, sbyte v8) { int o = __p.__offset(24); if (o != 0) { __p.bb.PutSbyte(__p.__vector(o) + j * 1, v8); return true; } else { return false; } } @@ -53,7 +53,7 @@ public struct TypeAliases : IFlatbufferObject #if ENABLE_SPAN_T public Span GetVf64Bytes() { return __p.__vector_as_span(26, 8); } #else - public ArraySegment? GetVf64Bytes() { return __p.__vector_as_arraysegment(26, 8); } + public ArraySegment? GetVf64Bytes() { return __p.__vector_as_arraysegment(26); } #endif public double[] GetVf64Array() { return __p.__vector_as_array(26); } public bool MutateVf64(int j, double vf64) { int o = __p.__offset(26); if (o != 0) { __p.bb.PutDouble(__p.__vector(o) + j * 8, vf64); return true; } else { return false; } } diff --git a/tests/MyGame/MonsterExtra.cs b/tests/MyGame/MonsterExtra.cs index 4ab1ae2..d74ae8b 100644 --- a/tests/MyGame/MonsterExtra.cs +++ b/tests/MyGame/MonsterExtra.cs @@ -41,7 +41,7 @@ public struct MonsterExtra : IFlatbufferObject #if ENABLE_SPAN_T public Span GetDvecBytes() { return __p.__vector_as_span(20, 8); } #else - public ArraySegment? GetDvecBytes() { return __p.__vector_as_arraysegment(20, 8); } + public ArraySegment? GetDvecBytes() { return __p.__vector_as_arraysegment(20); } #endif public double[] GetDvecArray() { return __p.__vector_as_array(20); } public bool MutateDvec(int j, double dvec) { int o = __p.__offset(20); if (o != 0) { __p.bb.PutDouble(__p.__vector(o) + j * 8, dvec); return true; } else { return false; } } @@ -50,7 +50,7 @@ public struct MonsterExtra : IFlatbufferObject #if ENABLE_SPAN_T public Span GetFvecBytes() { return __p.__vector_as_span(22, 4); } #else - public ArraySegment? GetFvecBytes() { return __p.__vector_as_arraysegment(22, 4); } + public ArraySegment? GetFvecBytes() { return __p.__vector_as_arraysegment(22); } #endif public float[] GetFvecArray() { return __p.__vector_as_array(22); } public bool MutateFvec(int j, float fvec) { int o = __p.__offset(22); if (o != 0) { __p.bb.PutFloat(__p.__vector(o) + j * 4, fvec); return true; } else { return false; } } -- 2.7.4