Equivalent to ByteSize () in protobuff

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

Something like:

Protobuf.Builder buffer = Protobuf.newBuilder(); 

      

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

+3


source to share


2 answers


Create a protocol buffer and call getSerializedSize()

.



+5


source


Answer:



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

      

+2


source







All Articles