Text encoding of Protocol Buffers string fields

Viewed 6135

If a C++ program receives a Protocol Buffers message that has a Protocol Buffers string field, which is represented by a std::string, what is the encoding of text in that field? Is it UTF-8?

1 Answers

Protobuf strings are always valid UTF-8 strings.

See the Language Guide:

A string must always contain UTF-8 encoded or 7-bit ASCII text.

(And ASCII is always also valid UTF-8.)

Not all protobuf implementations enforce this, but if I recall correctly, at least the Python library refuses to decode non-unicode strings.

Related