# 错误：proto：无法使用键类型为字符串的映射字段"metadata"：不支持的键类型

- **ID:** `go/grpc-protobuf-map-key-type-error`
- **领域:** go
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

protobuf映射字段在Go生成的代码中使用了不支持的键类型（例如float或bytes）。

## 版本兼容性

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

## 解决方案

1. **Use string keys in proto definition.** (95% 成功率)
   ```
   map<string, string> metadata = 1;
   ```
2. **Encode unsupported keys as string with custom encoding.** (85% 成功率)
   ```
   map<string, string> metadata = 1; // encode float as string via strconv.FormatFloat
   ```

## 无效尝试

- **Change the key type in generated Go code manually.** — Regeneration will overwrite manual changes. (95% 失败率)
- **Use a repeated field instead of map.** — Requires changing the proto schema and all consumers. (80% 失败率)
