mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-27 17:38:06 +00:00
Correct span and non-span versions of ToArray() and ToArrayPadded() methods (#8734)
* Correction of bug inside ToArray<T> methods Avoid allocating too large buffers (len is expressed in bytes, not in Ts). Added validation to ensure len is a multiple of SizeOf<T>() before converting to array. * Update ByteBuffer.cs * Refactor ToArray and ToArrayPadded methods I understand from failed test that pos, len, padLeft and padRight are expressed in Ts * Refactor ToArray and ToArrayPadded methods * Final correction All functions parameters expressed in bytes for homogeneity Tests run: - UNSAFE_BYTEBUFFER=true/ENABLE_SPAN_T=true: passed - UNSAFE_BYTEBUFFER=true/ENABLE_SPAN_T=false: passed - UNSAFE_BYTEBUFFER=false/ENABLE_SPAN_T=false: passed - UNSAFE_BYTEBUFFER=false/ENABLE_SPAN_T=true: configuration forbidden by compilation Correction of FlatBuffers.Test.csproj to allow UNSAFE_BYTEBUFFER/ENABLE_SPAN_T tests Correction of FlatBuffersExampleTests.cs: I think the test was not run because it could not pass (to be reviewed carefully)
This commit is contained in:
@@ -268,10 +268,10 @@ namespace Google.FlatBuffers.Test
|
||||
}
|
||||
|
||||
var longArrayBytes = monster.GetVectorOfLongsBytes();
|
||||
Assert.IsTrue(monster.VectorOfLongsLength * 8 == longArrayBytes.Length);
|
||||
Assert.IsTrue(monster.VectorOfLongsLength == longArrayBytes.Length);
|
||||
|
||||
var doubleArrayBytes = monster.GetVectorOfDoublesBytes();
|
||||
Assert.IsTrue(monster.VectorOfDoublesLength * 8 == doubleArrayBytes.Length);
|
||||
Assert.IsTrue(monster.VectorOfDoublesLength == doubleArrayBytes.Length);
|
||||
#else
|
||||
var nameBytes = monster.GetNameBytes().Value;
|
||||
Assert.AreEqual("MyMonster", Encoding.UTF8.GetString(nameBytes.Array, nameBytes.Offset, nameBytes.Count));
|
||||
|
||||
Reference in New Issue
Block a user