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

- **ID:** `go/proto-unmarshal-invalid-wire-type`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

传给 proto.Unmarshal 的字节不符合 protobuf wire 格式。通常是因为把 JSON、纯文本或截断/拼接的缓冲区交给了二进制 proto 反序列化器。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   if err := proto.Unmarshal(data, msg); err != nil {
    // if data is JSON, use:
    err = protojson.Unmarshal(data, msg)
}
   ```
2. **** (85% 成功率)
   ```
   log.Printf("len=%d head=%x", len(data), data[:min(16,len(data))])
   ```

## 无效尝试

- **** — The buffer is deterministic; malformed bytes never become valid on retry. The error is not transient. (95% 失败率)
- **** — On wire-format errors the message is left in an undefined/partial state; downstream logic reads zero or garbage fields. (90% 失败率)
