forked from BigfootDev/flatbuffers
[c#] Fix Table __vector_as_array correct len calc (#8911)
* fix for https://github.com/google/flatbuffers/issues/8759 __vector_as_array<T> calling ByteBuffer.ToArray<T> with the length in bytes by multiplying len with ByteBuffer.Sizeof<T> and FlatBuffersExampleTests extended to call GetVectorOfLongsArray/GetVectorOfDoublesArray which failed without the fix * first try to repair build-dotnet-windows * syntax error fixed * Update solution creation command in build workflow add --format sln to the dotnet new command, maybe it is currently creating a .slnx instead?
This commit is contained in:
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@@ -197,8 +197,7 @@ jobs:
|
|||||||
configuration: [
|
configuration: [
|
||||||
'',
|
'',
|
||||||
'-p:UnsafeByteBuffer=true',
|
'-p:UnsafeByteBuffer=true',
|
||||||
# Fails two tests currently.
|
'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
||||||
#'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
|
||||||
]
|
]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
@@ -209,7 +208,7 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
cd tests\FlatBuffers.Test
|
cd tests\FlatBuffers.Test
|
||||||
dotnet new sln --force --name FlatBuffers.Test
|
dotnet new sln --force --name FlatBuffers.Test --format sln
|
||||||
dotnet sln FlatBuffers.Test.sln add FlatBuffers.Test.csproj
|
dotnet sln FlatBuffers.Test.sln add FlatBuffers.Test.csproj
|
||||||
dotnet build -c Release ${{matrix.configuration}} FlatBuffers.Test.sln
|
dotnet build -c Release ${{matrix.configuration}} FlatBuffers.Test.sln
|
||||||
- name: Run net6.0
|
- name: Run net6.0
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ namespace Google.FlatBuffers
|
|||||||
|
|
||||||
var pos = this.__vector(o);
|
var pos = this.__vector(o);
|
||||||
var len = this.__vector_len(o);
|
var len = this.__vector_len(o);
|
||||||
return bb.ToArray<T>(pos, len);
|
return bb.ToArray<T>(pos, len * ByteBuffer.SizeOf<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize any Table-derived type to point to the union at the given offset.
|
// Initialize any Table-derived type to point to the union at the given offset.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 Google Inc. All rights reserved.
|
* Copyright 2014 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -90,6 +90,9 @@ namespace Google.FlatBuffers.Test
|
|||||||
fbb.AddOffset(test1.Value);
|
fbb.AddOffset(test1.Value);
|
||||||
var testArrayOfString = fbb.EndVector();
|
var testArrayOfString = fbb.EndVector();
|
||||||
|
|
||||||
|
var longsVector = Monster.CreateVectorOfLongsVector(fbb, new long[] { 1, 100, 10000, 1000000, 100000000 });
|
||||||
|
var doublesVector = Monster.CreateVectorOfDoublesVector(fbb, new double[] { -1.7976931348623157e+308, 0, 1.7976931348623157e+308 });
|
||||||
|
|
||||||
Monster.StartMonster(fbb);
|
Monster.StartMonster(fbb);
|
||||||
Monster.AddPos(fbb, Vec3.CreateVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0,
|
Monster.AddPos(fbb, Vec3.CreateVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0,
|
||||||
Color.Green, (short)5, (sbyte)6));
|
Color.Green, (short)5, (sbyte)6));
|
||||||
@@ -102,6 +105,8 @@ namespace Google.FlatBuffers.Test
|
|||||||
Monster.AddTestarrayofstring(fbb, testArrayOfString);
|
Monster.AddTestarrayofstring(fbb, testArrayOfString);
|
||||||
Monster.AddTestbool(fbb, true);
|
Monster.AddTestbool(fbb, true);
|
||||||
Monster.AddTestarrayoftables(fbb, sortMons);
|
Monster.AddTestarrayoftables(fbb, sortMons);
|
||||||
|
Monster.AddVectorOfLongs(fbb, longsVector);
|
||||||
|
Monster.AddVectorOfDoubles(fbb, doublesVector);
|
||||||
var mon = Monster.EndMonster(fbb);
|
var mon = Monster.EndMonster(fbb);
|
||||||
|
|
||||||
if (sizePrefix)
|
if (sizePrefix)
|
||||||
@@ -285,6 +290,13 @@ namespace Google.FlatBuffers.Test
|
|||||||
Assert.IsTrue(monster.GetTestarrayofboolsBytes().HasValue);
|
Assert.IsTrue(monster.GetTestarrayofboolsBytes().HasValue);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
var longArray = monster.GetVectorOfLongsArray();
|
||||||
|
Assert.AreEqual(5, longArray.Length);
|
||||||
|
Assert.AreEqual(100, longArray[1]);
|
||||||
|
|
||||||
|
var doublesArray = monster.GetVectorOfDoublesArray();
|
||||||
|
Assert.AreEqual(3, doublesArray.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
[FlatBuffersTestMethod]
|
[FlatBuffersTestMethod]
|
||||||
|
|||||||
Reference in New Issue
Block a user