Author [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] Topic: bitshares toolkit serialization  (Read 274 times)

Offline crazybit

  • Sr. Member
  • ****
  • Posts: 402
    • View Profile
bitshares toolkit serialization
« 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
Delegate IDs: dpos.crazybit | titan.crazybit | anchor.crazybit |crazybit

Offline bytemaster

Re: bitshares toolkit serialization
« Reply #1 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.

 
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

  • Sr. Member
  • ****
  • Posts: 402
    • View Profile
Re: bitshares toolkit serialization
« Reply #2 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?
Delegate IDs: dpos.crazybit | titan.crazybit | anchor.crazybit |crazybit

Offline bytemaster

Re: bitshares toolkit serialization
« Reply #3 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
}


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

  • Sr. Member
  • ****
  • Posts: 402
    • View Profile
Re: bitshares toolkit serialization
« Reply #4 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.
Delegate IDs: dpos.crazybit | titan.crazybit | anchor.crazybit |crazybit

 

Google+