Author Topic: bitshares toolkit serialization  (Read 2218 times)

0 Members and 1 Guest are viewing this topic.

Offline crazybit

Code: [Select]
struct test
{
     int a;
     string b;
     vector<string> c;
}

FC_REFLECT( test, (a)(b)(c) )

In binary converts to:

4 bytes for a
VARINT  storing b.size()
b.size bytes string content of b
VARINT  storing c.size()
for( c.size() )
{
       VARINT  storing c.size()
       c.size bytes string content of c
}

wow, the sample is quite easy to understand,thank you very much.

Offline bytemaster

Code: [Select]
struct test
{
     int a;
     string b;
     vector<string> c;
}

FC_REFLECT( test, (a)(b)(c) )

In binary converts to:

4 bytes for a
VARINT  storing b.size()
b.size bytes string content of b
VARINT  storing c.size()
for( c.size() )
{
       VARINT  storing c.size()
       c.size bytes string content of c
}


For the latest updates checkout my blog: http://bytemaster.bitshares.org
Anything said on these forums does not constitute an intent to create a legal obligation or contract between myself and anyone else.   These are merely my opinions and I reserve the right to change them at any time.

Offline crazybit

it is difficult for me to understand the bitshares tookit serialization mechanism and technology, would be appreciated if anyone can provide some guidence /documentation

Sure...  100% of all serialization is managed by fc via the reflection system.
Looking at the structure definition is enough to infer the serialization.
Data is serialized in the order listed in the FC_REFLECT macro
Strings & Arrays are prefixed with a variable length int that uses the same encoding as google protocol buffers.

In binary terms the data is simply copied with the same byte order as the host.. ie: it will not work on big endian systems.

Check out FC_REFLECT and fc/io/raw.hpp which defines the "raw binary" serialization based upon reflection.

thanks for your reply.

yes, i know the serialization in bitshares is managed by fc via the reflection system. i am also checking macro FC_REFLECT and fc/io/raw.hpp, but it is difficult for me to understand the c++ generic  programming and the macro(i am a java programmer :(  , is the reflection in FC same with boost reflection? is there any documentation i can refer to?

Offline bytemaster

it is difficult for me to understand the bitshares tookit serialization mechanism and technology, would be appreciated if anyone can provide some guidence /documentation

Sure...  100% of all serialization is managed by fc via the reflection system.
Looking at the structure definition is enough to infer the serialization.
Data is serialized in the order listed in the FC_REFLECT macro
Strings & Arrays are prefixed with a variable length int that uses the same encoding as google protocol buffers.

In binary terms the data is simply copied with the same byte order as the host.. ie: it will not work on big endian systems.

Check out FC_REFLECT and fc/io/raw.hpp which defines the "raw binary" serialization based upon reflection.

 
For the latest updates checkout my blog: http://bytemaster.bitshares.org
Anything said on these forums does not constitute an intent to create a legal obligation or contract between myself and anyone else.   These are merely my opinions and I reserve the right to change them at any time.

Offline crazybit

it is difficult for me to understand the bitshares tookit serialization mechanism and technology, would be appreciated if anyone can provide some guidence /documentation