# panic: proto: 消息 pb.User 未实现 protoreflect.ProtoMessage

- **ID:** `go/protobuf-reflection-nil-descriptor`
- **领域:** go
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

传给 proto.Marshal 的结构体不是由 protoc-gen-go 生成的（或由旧版 github.com/golang/protobuf 插件生成）。它缺少新 API 所需的 ProtoReflect() 方法。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
protoc --go_out=. --go_opt=paths=source_relative user.proto
   ```
2. **** (90% 成功率)
   ```
   // Remove github.com/golang/protobuf imports; use google.golang.org/protobuf/proto
import "google.golang.org/protobuf/proto"
b, err := proto.Marshal(&pb.User{...})
   ```

## 无效尝试

- **** — Returns a nil descriptor; reflection and marshaling still fail at runtime. (85% 失败率)
- **** — Produces JSON, not protobuf wire format; peers expecting protobuf cannot decode. (70% 失败率)
