m3v3rik
m3v3rik

Reputation: 345

Do protocol buffers support byte[] fields?

I am trying to update the Android BluetoothChat example's code to use Protobuf for more structured data exchange. I also need byte[] array fields to send arbitrary data like an image byte array but on trying to compile the .proto file, I get the below error.

protofiles/bluetoothmessage.proto:8:18: Expected field name.

Below is my .proto file.

package bluetoothmessage;

option java_package = "com.example.bluetoothexample";
option java_outer_classname = "ProtocolBuffers";

message BTMessage {
    required int32 cmd = 1;
    optional byte[] appData = 2;
}

A couple of other posts on stackoverflow mentioned that byte[] can be used as a filed and the below page also says the same thing.

https://developers.google.com/protocol-buffers/docs/proto#scalar

Any help is much appreciated! Thanks!!

Upvotes: 2

Views: 1613

Answers (1)

Maxim
Maxim

Reputation: 339

From manual: bytes May contain any arbitrary sequence of bytes.

The line:

optional byte[] appData = 2;

Must be changed to:

optional bytes appData = 2;

Upvotes: 2

Related Questions