# proto: 无法解析无效的 wire-format 数据

- **ID:** `go/protobuf-unknown-field-error`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

收到的字节不是有效的 protobuf wire format，通常因为客户端与服务端消息类型不一致，或向期待二进制 protobuf 的 gRPC 端点发送了 HTTP/JSON 数据。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| google.golang.org/protobuf 1.30+ | active | — | — |

## 解决方案

1. **** (80% 成功率)
   ```
   md, _ := metadata.FromIncomingContext(ctx)
log.Printf("content-type=%v len=%d", md.Get("content-type"), len(raw))
if err := proto.Unmarshal(raw, msg); err != nil {
    return status.Errorf(codes.InvalidArgument, "unmarshal: %v", err)
}
   ```
2. **** (90% 成功率)
   ```
   // pin proto version in go.mod and CI check
// go.mod: require github.com/acme/protos v1.4.2
// CI: diff generated files against committed ones
   ```

## 无效尝试

- **** — The bytes are malformed, not truncated; increasing the size limit does not make invalid wire format valid. (90% 失败率)
- **** — The bytes are binary protobuf, not JSON; protojson will fail with a different parse error. (85% 失败率)
