Reputation: 4197
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
Reputation: 4197
Answer:
Protobuf.Builder buffer = Protobuf.newBuilder();
int size = buffer.build().getSerializedSize();
Upvotes: 3