在 Rust 中序列化 rust-protobuf 消息的方法
Ways to serialize rust-protobuf messages in Rust
我是 Rust 的新手,我想知道我应该如何序列化从 rust-protobuf
库派生的 protobuf 消息。我有哪些选择?如我所见,有 protobuf
库,但我没有找到序列化选项(我只找到反序列化)。如我所见,其他选项是 serde
和 bytes
。我应该看哪一个?我正在寻找序列化以尽可能快地在两台计算机之间发送数据,所以我正在研究二进制,而不是 json。
文档 (https://github.com/stepancheg/rust-protobuf/blob/master/FAQ.md) 说:
The easiest way to do it is to invoke write_to_bytes
function:
message.write_to_bytes()
但我猜他们的意思是消息是一种类型,因为我没有在消息实例上获得此选项。
改为:
protobuf::Message::write_to_bytes(message)
我是 Rust 的新手,我想知道我应该如何序列化从 rust-protobuf
库派生的 protobuf 消息。我有哪些选择?如我所见,有 protobuf
库,但我没有找到序列化选项(我只找到反序列化)。如我所见,其他选项是 serde
和 bytes
。我应该看哪一个?我正在寻找序列化以尽可能快地在两台计算机之间发送数据,所以我正在研究二进制,而不是 json。
文档 (https://github.com/stepancheg/rust-protobuf/blob/master/FAQ.md) 说:
The easiest way to do it is to invoke
write_to_bytes
function:message.write_to_bytes()
但我猜他们的意思是消息是一种类型,因为我没有在消息实例上获得此选项。
改为:
protobuf::Message::write_to_bytes(message)