2

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..?

Nikhil K
  • 31
  • 3

1 Answers1

1
  • In protobuf repeated = array. I don't see why you cannot use repeated 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 the uint32 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