如何更改 protobuf 日志记录行为(分隔符)?

How can I change protobuf logging behavior (separator)?

我在 protobuf 消息上使用 ShortDebugString() 来获取字符串并将其记录到文件中。此函数returns 简明版本以':' 作为分隔符。从 protobuf 代码看来它发生在 TextFormat::Printer::PrintField.

generator.Print(": ");
// Write the field value.
PrintFieldValue(message, reflection, field, field_index, generator);

我想将 ShortDebugString 返回的字符串中的“:”更改为“=”。如何在不更改 protobuf 库代码本身的情况下完成此操作?从 ShortDebugString 取回字符串后,我可以用“=”替换“:”,但我也希望避免这种情况。谢谢

最好的办法是复制整个 TextFormat class 并进行修改。 TextFormat 代码不使用任何私有 protobuf API,因此将它移出核心库应该没有问题。事实上,TextFormat 的部分设计目的是作为一个示例,说明您如何为替代文本格式编写自己的编码器,这听起来正是您想要的。 :)