名称: 序列化 描述: 二进制与文本序列化格式、模式设计及性能优化的专家技能 允许使用的工具:
- Bash
- Read
- Write
- Edit
- Glob
- Grep
序列化技能
二进制与文本序列化格式、模式设计及性能优化的专家技能。
能力
- Protocol Buffers: 为多种语言生成Protocol Buffer模式与代码
- FlatBuffers: 设计FlatBuffers模式以实现零拷贝反序列化
- MessagePack/CBOR: 实现MessagePack和CBOR二进制编码
- 性能分析: 分析与比较序列化性能
- 格式对比: 针对特定用例比较序列化格式
- 反序列化调试: 调试反序列化问题与版本不匹配
- 负载优化: 优化负载大小与编码效率
- 模式演进: 处理向后/向前兼容的模式变更
工具与依赖
protoc- Protocol Buffer编译器flatc- FlatBuffers编译器msgpack-tools- MessagePack工具集cbor-tools- CBOR工具集capnp- Cap’n Proto编译器avro-tools- Apache Avro工具集
目标流程
- binary-protocol-parser.js
- custom-protocol-design.js
- message-framing.js
- websocket-server.js
使用示例
Protocol Buffers模式
syntax = "proto3";
package network;
message Packet {
uint32 sequence = 1;
bytes payload = 2;
int64 timestamp = 3;
map<string, string> headers = 4;
}
FlatBuffers模式
namespace Network;
table Packet {
sequence: uint32;
payload: [ubyte];
timestamp: int64;
headers: [KeyValue];
}
table KeyValue {
key: string;
value: string;
}
root_type Packet;
代码生成
protoc --python_out=. --go_out=. packet.proto
flatc --python --go packet.fbs
性能基准测试
hyperfine 'protoc-bench encode message.proto' 'msgpack-bench encode message.json'
质量门限
- 模式验证通过
- 向后兼容性已验证
- 性能基准测试达标
- 跨语言互操作性已测试
- 负载大小符合要求