Text encoding of Protocol Buffers string fields

风格不统一 提交于 2020-12-26 06:43:11

问题


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:


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.



来源:https://stackoverflow.com/questions/52384082/text-encoding-of-protocol-buffers-string-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!