# 内部错误：解析响应时出错：字段 5 类型为 int64 但消息期望为字符串

- **ID:** `grpc/protobuf-field-mismatch`
- **领域:** grpc
- **类别:** type_error
- **错误码:** `GRPC_PROTOBUF_FIELD_MISMATCH`
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

服务器和客户端对同一 RPC 的 Protobuf 定义不匹配，字段类型不同（例如服务器发送 int64 但客户端期望字符串）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| protobuf v3.21.x | active | — | — |
| protobuf v4.25.x | active | — | — |
| gRPC v1.62.x | active | — | — |

## 解决方案

1. ```
   同步服务器和客户端的 .proto 文件：使用 `diff server.proto client.proto` 找出字段类型差异，更新错误的一方。使用 `protoc` 重新编译两端。
   ```
2. ```
   使用版本化的模式注册表（如 Confluent Schema Registry），强制 RPC 两端使用相同的 Protobuf 模式版本。
   ```
3. ```
   临时将客户端字段改为 `google.protobuf.Any` 以接受任意类型，然后在应用代码中手动转换。
   ```

## 无效尝试

- **** — If the .proto file itself is outdated, regenerated stubs still have the wrong types; the root cause is the definition mismatch. (80% 失败率)
- **** — gRPC uses strict Protobuf parsing; custom deserializers are not supported and will cause further parsing errors. (90% 失败率)
- **** — Version mismatch is not the issue; the .proto file content is what defines the field types. (50% 失败率)
