go
data_error
ai_generated
true
proto:无法解析无效的 wire-format 数据
proto: cannot parse invalid wire-format data
ID: go/proto-marshal-invalid-wire-type
80%修复率
87%置信度
0证据数
2024-05-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| google.golang.org/protobuf v1.31+ | active | — | — | — |
根因分析
被反序列化的字节不是有效的 protobuf wire format —— 通常是因为发送了 JSON、gzip 压缩载荷或使用了不同 schema 的消息。
English
The bytes being unmarshaled are not valid protobuf wire format — typically caused by sending JSON, gzip-compressed payloads, or a message of a different schema over the wire.
解决方案
-
90% 成功率
if err := proto.Unmarshal(data, msg); err != nil { log.Printf("unmarshal failed: %v, first bytes: % x", err, data[:min(32, len(data))]) return err } -
86% 成功率
// client conn, _ := grpc.NewClient(addr, grpc.WithDefaultCallOptions(grpc.ForceCodec(proto.Marshaler{})), ) // server: verify incoming Content-Type header md, _ := metadata.FromIncomingContext(ctx) log.Printf("content-type: %v", md["content-type"])
无效尝试
常见但无效的做法:
-
99% 失败
Unmarshal is deterministic; invalid wire bytes always fail at the same offset.
-
85% 失败
Doesn't fix the underlying wire corruption; just moves the failure deeper.