google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library

Home Page:https://flatbuffers.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to convert buffer to field value

romanholidaypancakes opened this issue · comments

table tb1{
value:unint;
}
table tb2{
value:tb1;
}

# Get the object of tab1 through bytes data
objTab1 = tb1.GetTb1(tb1Bytearray)

# Now, I want to put this piece of data into tab2, but failed, is there any api to do it, I checked the official example, there is no any explanation about this
tb2.AddValue(builder,objTab1)

You have to rebuild tb1 in the new builder. I don't think we have a way for tb1 to directly write itself into the builder, but contributions are welcome.

Alternatively you could make tb2.value be a bytes field and copy it in yourself, then remember that the bytes are actually a flatbuffer with type tb1. There is a "nested flatbuffers" feature that makes handling this a little more ergonomic but its not in all languages.

You have to rebuild tb1 in the new builder. I don't think we have a way for tb1 to directly write itself into the builder, but contributions are welcome.

Alternatively you could make tb2.value be a bytes field and copy it in yourself, then remember that the bytes are actually a flatbuffer with type tb1. There is a "nested flatbuffers" feature that makes handling this a little more ergonomic but its not in all languages.

thanks for your help, it seems I need to rebuild the builder, for contributing. unfortunately I don't have strong coding skills.