Is there any way to store array using google protocol buffer in cpp without using repeated. I need to store and send buffer (of size 640x480x2) consisting image data. Also how to store uint16_t array data using protocol buffer..?
Asked
Active
Viewed 1,620 times
2
-
Why don't you send your image as it is, without additional packing it to varint (protocol buffer) ? – Victor Gubin Nov 01 '18 at 11:20
-
Actually I need to use protocol buffer to store image data and to send it over network. – Nikhil K Nov 02 '18 at 13:00
1 Answers
1
- In protobuf
repeated
=array
. I don't see why you cannot userepeated uint32 img = field_num
If you really want to store into a byte array, you can try
pb.set_mybytearray( std::string( data, data_length ) );
Protobuf does not support
uint16
: https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#fields. I'd recommend to use theuint32
type. Given that protobuf encodes values into varint the message will not contain 2 bytes of zeros.

Tezirg
- 1,629
- 1
- 10
- 20
-
I was trying to store int array containing image data using bytes.As bytes is arbitrary sequence of bytes. Could I use bytes to store int array data..? – Nikhil K Nov 02 '18 at 12:58
-
Yes, you will have to convert each int to byte[4], and then create a string to set the byte array, as updated in the answer. – Tezirg Nov 02 '18 at 13:26