chrisrhyno2003
chrisrhyno2003

Reputation: 4197

Equivalent of ByteSize() in protobuf

Is there an equivalent of ByteSize() for protobuf in Java? I'm trying to get the size of a protobuf before serializing it.

Something like:

Protobuf.Builder buffer = Protobuf.newBuilder(); 

I need the size of the buffer now. Any idea how to obtain it?

Upvotes: 3

Views: 4511

Answers (2)

chrisrhyno2003
chrisrhyno2003

Reputation: 4197

Answer:

Protobuf.Builder buffer = Protobuf.newBuilder(); 
int size = buffer.build().getSerializedSize();

Upvotes: 3

Andy Turner
Andy Turner

Reputation: 140514

Build the protocol buffer, and call getSerializedSize().

Upvotes: 6

Related Questions