# proto: 必填字段 "name" 未设置

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

## 根因

proto2 消息中的必填字段在序列化前未完全填充。在 proto3 中不支持必填字段，但如果使用 proto2，则会出现此错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   msg := &YourMessage{
    Name: proto.String("value"), // Required field
}
if err := proto.Marshal(msg); err != nil {
    log.Fatalf("marshal failed: %v", err)
}
   ```
2. **** (90% 成功率)
   ```
   // Update .proto file to syntax = "proto3";
// Remove required keyword; regenerate code
   ```

## 无效尝试

- **** — Serialization will still fail or produce invalid data that cannot be parsed later. (100% 失败率)
- **** — An empty string is still a value, but if the field is required, it must be explicitly set; an empty string may be considered unset in some implementations. (70% 失败率)
