BitShares Forum

Main => Technical Support => Topic started by: crazybit on August 28, 2014, 01:20:01 pm

Title: bitshares toolkit serialization
Post by: crazybit on August 28, 2014, 01:20:01 pm
it is difficult for me to understand the bitshares tookit serialization mechanism and technology, would be appreciated if anyone can provide some guidence /documentation
Title: Re: bitshares toolkit serialization
Post by: bytemaster on August 28, 2014, 01:36:43 pm
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.

 
Title: Re: bitshares toolkit serialization
Post by: crazybit on August 28, 2014, 02:07:02 pm
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?
Title: Re: bitshares toolkit serialization
Post by: bytemaster on August 28, 2014, 02:17:29 pm
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
}


Title: Re: bitshares toolkit serialization
Post by: crazybit on August 28, 2014, 02:25:41 pm
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.