feat(protobuf): 添加 Protobuf 格式检测与解码支持 #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
概述
本 PR 为 Zedis 添加了 Protobuf 数据格式的检测和解码支持,使用户能够直观地查看存储在 Redis 中的 Protobuf 编码数据。
新增功能
1. 原始 Protobuf 格式自动检测
2. Schema-based Protobuf 解码
.proto文件(通过 protoc 编译)prost-reflect进行运行时反射解码3. 状态栏集成
protobuf标签.proto文件技术实现
核心模块
src/helpers/protobuf.rssrc/states/server/protobuf.rssrc/states/server/value.rsDataFormat::ProtobufRaw和DataFormat::Protobuf类型src/views/status_bar.rs安全边界
启发式检测策略
为减少误报,实现了以下检测规则:
依赖变更
测试
新增 50 个单元测试,覆盖:
decode_varint_safe()边界测试(6 个)try_parse_raw_protobuf()解析测试(12 个)is_likely_protobuf()启发式检测测试(7 个)decode_raw_to_json()JSON 输出测试(11 个)ProtobufSchema状态管理测试(14 个)使用示例
无 Schema 模式(自动)
当 Redis 值被检测为 Protobuf 格式时,自动以 JSON 形式展示:
{ "1": 42, "2": "hello", "3": { "1": 100 } }有 Schema 模式
.proto文件截图
(如需要可补充 UI 截图)
Checklist
make lint检查