-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Go]streaming / verify flatbuffers in network transfer #5793
Comments
For FlatBuffers format information, please follow these documents rather than the notes you made above: If you're going to write a verifier, please follow the C++ code closely, it is the authorative source on how this should be done: flatbuffers/include/flatbuffers/flatbuffers.h Lines 2128 to 2526 in 5a98d65
|
thanks for comments. should be learning indeep and try again. |
This comment has been minimized.
This comment has been minimized.
Would be nice to start kicking off this feature for golang again :) |
0. movation
i trying implementing a instance message service via tcp client / server. The Message serialized by flatbuffers, so, read streaming flatbuffers Message is must.
learning from
#3898
#5775
#4604
#3905
i will implementing verify in Go, here is some knowdge:
1. struct of serialized flatbuffers
assume serialized flatbufers ( Message ) as two part: Header ( metadata ) / Payload ( data ....)
1.1 Message Header
4 byte of root header ( , get offset of payload start
zero or more then one byte of prefilled ZERO
vtable struct , as below reference from builder.go, the Payload size ( data size ) include in vtable
1.2 Message payload part struct
TBD....
2. read streaming serialized flatbuffers
read Message (flatbuf serialized data) from network, 4 byte by 4 byte
read and parse header. check is a valid flatbufers or not
get the data size of message from header, and get the rest data
un-serialize the Message when know the IDL
( option ) Experimental reflaction to guess ths struct of IDL
3. a bug in builder.go , in func (b *Builder) WriteVtable()
As my assume, serialized flatbufers ( Message ) as two part: Header ( metadata ) / Payload ( data ....) .
<VOffsetT: size of the vtable in bytes, including this value> -------------- call it as vTableSize
<VOffsetT: size of the object in bytes, including the vtable offset> -------- this " size of the object" should be size of Message Payload ( call it as payloadSize )
so,
whole size of serialized flatbuffers = HeaderSize ( include vTableSize ) + payloadSize
in builder.go
in builder.go , line 163:
testing IDL like this:
filled the Field with "1234567", serialized data should be
[1100 0 0 0 0 0 110 0 10100 0 100 0 110 0 0 0 100 0 0 0 111 0 0 0 110001 110010 110011 110100 110101 110110 110111 0]
--> Object size in 9th byte shuld be 20 --- [ 101000 ] -----> 4 byte SOffset / 4 byte vector construction / 4 byte is real size of string ( "1234567" is 7 ) / 7 byte "1234567" + 1 byte ended string with "zero" byte , no any pre-filled "zero" byte in end of string
total serialized data is 32 byte:
but , we got:
[1100 0 0 0 0 0 110 0 1000 0 100 0 110 0 0 0 100 0 0 0 111 0 0 0 110001 110010 110011 110100 110101 110110 110111 0]
--> Object size in 9th byte is 8 --- [ 1000]
in builder.go , line 163, change to :
will got correct
correct object size in vTable , will help to read streaming flatbuffers .
PR is #5794
any suggestion r welcome!
The text was updated successfully, but these errors were encountered: