Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting Protobuf messages including non-ASCII strings

When a protobuf message contains a string with non-ASCII characters, message.toString() returns something like

alarm {
  message: "\320\227\320\260\320\262\320\265\321\200\321\210\320\265\320\275\320\270\320\265 \321\201\320\262\321\217\320\267\320\270 \321\201 mzta1."
}

I'd prefer to see the string including Cyrillic characters in logs. Is there a simple way to do this?

like image 338
Alexey Romanov Avatar asked Sep 11 '12 06:09

Alexey Romanov


People also ask

Is Protobuf text or binary?

Protobuf is a binary format, so working with it becomes tedious. Without an easy way to see what the message contained, I struggled to quickly implement the library and work with it.

How do I set default value in Protobuf?

For bool s, the default value is false. For numeric types, the default value is zero. For enums , the default value is the first value listed in the enum's type definition. This means care must be taken when adding a value to the beginning of an enum value list.

What is the difference between proto2 and Proto3?

Proto3 is the latest version of Protocol Buffers and includes the following changes from proto2: Field presence, also known as hasField , is removed by default for primitive fields. An unset primitive field has a language-defined default value.

What is Protobuf format?

Protocol buffers, or Protobuf, is a binary format created by Google to serialize data between different services. Google made this protocol open source and now it provides support, out of the box, to the most common languages, like JavaScript, Java, C#, Ruby and others.


1 Answers

Since 2.5.0, there is TextFormat.printToUnicodeString.

like image 191
Alexey Romanov Avatar answered Oct 02 '22 06:10

Alexey Romanov