protoc: does not implement protoreflect.ProtoMessage (missing ProtoReflect method)

本文介绍了在使用Go语言实现Protobuf的过程中遇到的一个常见错误:*Student类型不满足protoreflect.ProtoMessage接口的问题及解决方案。文章指出正确的导入方式对于实现序列化和反序列化的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在学习protobuf做第一个小例子时出现如下错误:

# command-line-arguments
./test_proto.go:23:29: cannot use test (type *Student) as type protoreflect.ProtoMessage in argument to marshaler.Marshal:
        *Student does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
./test_proto.go:29:21: cannot use newTest (type *Student) as type protoreflect.ProtoMessage in argument to "google.golang.org/protobuf/proto".Unmarshal:
        *Student does not implement protoreflect.ProtoMessage (missing ProtoReflect method)

解决方法:
在这里插入图片描述
一开始将这边使用成

"google.golang.org/protobuf/proto"

后改称上述形式就可以了,要使用go mod tidy在进行编译就可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值