Released bytes in protocol buffer arrays?

I have a protocol buffer setting as follows:

[ProtoContract]
Foo
{
    [ProtoMember(1)]
    Bar[] Bars;
}

One byte receives the encoding in a byte buffer of 67 bytes. That sounds right, because I know that there is only a 64-byte array in the bar, and then there are 3 bytes for the length prefix.

However, when I encode Foo with an array of 20 bars, it takes 1362 bytes. 20 * 67 - 1340, so there are 22 bytes of service data for encrypting the array!

Why does it take up so much space? And is there anything I can do to reduce it?

+3
source share
2 answers

- , , 20 . , (.. - ).

gory:

( "", ) -. - ; . :

[header][length][data]

header - ( 08 1), length - data, -. (data 128 ) 2 , : ( 15 ) b: .

, :

[header][data][footer]

header - (hex 0B 1), data - -, footer - varint mash ( 0C 1).

, , , data . ( 16) 2 . , double .

+5

Source: https://habr.com/ru/post/1796658/


All Articles