在学习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
在进行编译就可