# rpc错误：代码=内部错误 描述=grpc：解组时出错：proto：无法解析无效的线格式数据

- **ID:** `go/grpc-internal-error-codec-mismatch`
- **领域:** go
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

服务器接收到无效的protobuf数据，通常是由于编解码器不匹配或数据损坏。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.0 | active | — | — |
| 1.1 | active | — | — |

## 解决方案

1. **Ensure both client and server use the same protobuf version and schema.** (90% 成功率)
   ```
   Run 'protoc --go_out=. --go-grpc_out=. *.proto' on both sides and rebuild.
   ```
2. **Add logging to inspect the raw bytes received.** (70% 成功率)
   ```
   Use a server interceptor to log incoming data for debugging:
func loggingInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
    log.Printf("request: %v", req)
    return handler(ctx, req)
}
   ```

## 无效尝试

- **Assume the data is fine and retry.** — If the data is malformed, retrying will produce the same error. (100% 失败率)
- **Change the protobuf schema without regenerating code.** — The server and client must use the same schema; manual changes cause incompatibility. (95% 失败率)
