开发者

Storing 4 int32 values inside each PB message as 4 different variables 'instead of using repeated' to avoid parsing back as ''List of Integers''

For my usecase of Protocol Buffers, I need to seria开发者_如何学Clize 4 integers(at max.) inside each protocol buffer message. I want that when I retrieve those 4 integers from message, I get them as intand not as Integer. (The reason for this being I need some really fast calculations and equality checking(with some other int) on those retrieved integers)

If I use the repeated type in the PB message, then on parsing from the bytes, I get the list of Integer. Thus I planning to use 4 different variable(each int32 with optional tag) inside each PB message instead of using repeated. Thus I expect to get the integers as int and not as Integers

Is this a good idea & Will this help me ?


It will certainly avoid the "list" issue. In regular .proto the size will be the same as long as the field numbers are small - the only difference on the wire will be different field numbers instead of the same number 4 times. However, if your list is currently using the "packed" option it will be marginally larger as 4 fields.

Personally, since the size is capped at 4, I think the 4 field approach represents your scenario more closely, as otherwise there is nothing to stop you adding 20 values. I'm all for the 4 field approach here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜