protobuf JsonStringToMessage 遇到bytes字段报错

在用proto协议的系统中,写自测用具用到json转pb的函数,但是如果proto协议中有bytes字段,纯json转pb就会报错,以下函数返回false

JsonStringToMessage(test_msg, &message).ok()

查资料发现bytes 字段要先进行base64编码,再放到json里,这样就能成功解析成pb对象了。

参考:https://github.com/protocolbuffers/protobuf/issues/5719icon-default.png?t=L892https://github.com/protocolbuffers/protobuf/issues/5719

你可能感兴趣的:(protobuf,protobuf)