二进制协议序列化框架
Binary Protocol Serialization Frameworks
有一些很棒的库可以反序列化二进制格式。我真的很喜欢 kaitai and nom's approach 使用 Rust 的声明式方法。
但是,我不知道有什么好的方法可以序列化二进制格式。
例如,您经常遇到这样的情况,您必须将消息长度直接写入消息 header,但实际上此时您并不知道确切的消息长度,因为它取决于许多字段位于 header 的下游。有时您还必须处理可能很麻烦的填充对齐。
你知道解决这些问题的方法吗?
请查看 ITU-T ASN.1 项目的 ASN.1 which has solved this problem many years ago, and is still continuing to be widely used in critical infrastructure in many different industries. It is independent of programming language and machine architecture so you can set up communication whether one peer is using C on a little-endian machine and the other is using Java or C# on a big-endian machine. Structure padding issues are easily handed by good quality tools for ASN.1. A good list of tools (both free and commercial) is available at the ASN.1 Tools 页面。
有一些很棒的库可以反序列化二进制格式。我真的很喜欢 kaitai and nom's approach 使用 Rust 的声明式方法。
但是,我不知道有什么好的方法可以序列化二进制格式。
例如,您经常遇到这样的情况,您必须将消息长度直接写入消息 header,但实际上此时您并不知道确切的消息长度,因为它取决于许多字段位于 header 的下游。有时您还必须处理可能很麻烦的填充对齐。
你知道解决这些问题的方法吗?
请查看 ITU-T ASN.1 项目的 ASN.1 which has solved this problem many years ago, and is still continuing to be widely used in critical infrastructure in many different industries. It is independent of programming language and machine architecture so you can set up communication whether one peer is using C on a little-endian machine and the other is using Java or C# on a big-endian machine. Structure padding issues are easily handed by good quality tools for ASN.1. A good list of tools (both free and commercial) is available at the ASN.1 Tools 页面。