google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
22.52k stars 3.19k forks source link

newbie's question.. use in c# / vector struct / adding int64... #8280

Open foranie opened 2 months ago

foranie commented 2 months ago

It's been a year since I started using it... there's still a section where I get stuck once every time I insert and subtract data.

I came because I couldn't solve various problems.

The following declaration was made to FBS.

table resWorldUserListCR
{
    result:resultcode;
    userinfo:[cUserInfo];

    testint64:int64;//add for int64 maxvalue test
}
root_type resWorldUserListCR;

Returns the result code (success/failure...) of the request and the user's list.

cUserInfo is as follows.

struct cUserInfo
{
    uuid:int64;
    cpos:Vec3;
    tpos:Vec3;
}

It contains the user's unique ID and location values.

I started make a packet.

Offset<cUserInfo>[] userOffsetAry = new Offset<cUserInfo>[keys.Count];
for(;;)
    userOffsetAry[index] = cUserInfo.CreatecUserInfo(builder, (Int64.MaxValue),2,3,4,5,6,7);//Question 1!!!!

var usersOffset = builder.CreateVectorOfTables<cUserInfo>(userOffsetAry);//Question 2!!!!!

res = resWorldUserListCR.CreateresWorldUserListCR(builder, resultcode.success, usersOffset);
builder.Finish(res.Value);

var asd = resWorldUserListCR.GetRootAsresWorldUserListCR(builder.DataBuffer); //Question 3!!!!!!!!!
                            Int64 asdasdasd = asd.Userinfo(0).Value.Uuid;

I have two questions about the above.

Q1. If you look at Question 1 and Question 3, there is a part where cUserInfo's uuid : int64 is put in and left out.

When the client receives the value sent from the server, the input value does not come out, so I wrote such a code.

The result was int64.MaxValue = 9223372036854775807 but it came out asdasdasd= -4294967292. What did it go wrong?

Q2. To make the structure offset, put the offset into the offset Array, and put the offset into the packet CreateVectorOfTables() was used. In c++, CreateVectorOfStructure() is used in that case, but is it okay to use CreateVectorOfTables() in C#?

You will see that there is only API - C# item in the official document..

For the test, add the testint64:int64 value to the resWorldUserListCR and deliver the int64.MaxValue instead of the structure cUserInfo, the value is coming out properly.

Is it the simplest version of the problem? Or is there a constraint rule that the structure can't contain int64? It seems like it's supporting it on the interface, but it's confusing when I see it addLong in the internal implementation.

thanks.