go
data_error
ai_generated
true
proto: cannot parse invalid wire-format data
ID: go/proto-marshal-invalid-wire-type
80%Fix Rate
87%Confidence
0Evidence
2024-05-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| google.golang.org/protobuf v1.31+ | active | — | — | — |
Root Cause
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.
generic中文
被反序列化的字节不是有效的 protobuf wire format —— 通常是因为发送了 JSON、gzip 压缩载荷或使用了不同 schema 的消息。
Workarounds
-
90% success
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% success
// 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"])
Dead Ends
Common approaches that don't work:
-
99% fail
Unmarshal is deterministic; invalid wire bytes always fail at the same offset.
-
85% fail
Doesn't fix the underlying wire corruption; just moves the failure deeper.