Gangmax Blog

Decode "Escaped Octal Value" in Proto Text

In protobuf text, a string can be shown in the following “escaped octal value” format:

1
some_string: "\350\277\231\346\230\257\344\270\200\344\270\252\346\265\213\350\257\225"

Here is how to make the content readable.

From here and here.

1
2
3
4
5
6
# Convert an "escaped octal value" string to a text string:
b'\345\255\246\346\240\241'.decode('utf-8')

# Reversely, here is how to convert a text string to an
# "escaped octal value" string:
''.join([ '\\' + oct(x)[2:] for x in '学校'.encode('utf-8')])

Comments