Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print out the values in a protobuf message

I know there is a way to serialize a message in protobuf. But is there a easy way to print out the values in a protobuf message? Something like a toString() method in Java?

Thanks.

like image 327
RNK Avatar asked Mar 05 '15 22:03

RNK


People also ask

How do you read Protobuf?

The Protobuf is a binary transfer format, meaning the data is transmitted as a binary. This improves the speed of transmission more than the raw string because it takes less space and bandwidth. Since the data is compressed, the CPU usage will also be less.

What are the numbers in Protobuf?

In the binary format, the field number is combined with a type identifier. Field numbers from 1 to 15 can be encoded with their type as a single byte. Numbers from 16 to 2,047 take 2 bytes. You can go higher if you need more than 2,047 fields on a message for any reason.

What is a message in Protobuf?

namespace google::protobuf. Defines Message, the abstract interface implemented by non-lite protocol message objects. Although it's possible to implement this interface manually, most users will use the protocol compiler to generate implementations.


1 Answers

protocol buffer basics -- Java

quoted from the link, check the standard message methods:

Standard Message Methods

Each message and builder class also contains a number of other methods that let you check or manipulate the entire message, including:

isInitialized(): checks if all the required fields have been set.

toString(): returns a human-readable representation of the message, particularly useful for debugging.

mergeFrom(Message other): (builder only) merges the contents of other into this message, overwriting singular fields and concatenating repeated ones.

clear(): (builder only) clears all the fields back to the empty state.
like image 125
Haifeng Zhang Avatar answered Nov 05 '22 02:11

Haifeng Zhang