Protobuf: ... is not proto.Message: missing method ProtoMessage

Created on 17 Dec 2018  路  2Comments  路  Source: golang/protobuf

When I use proto.Marshal, like this:
payload, err := proto.Marshal(arg.(proto.Message))

a panic occured:

panic: interface conversion: proto.CopyrightTxRequest is not proto.Message: missing method ProtoMessage

But my message has implemented the Message interface after using protoc-gen-go plugin:

type CopyrightTxRequest struct {
SessionID string protobuf:"bytes,1,opt,name=SessionID" json:"SessionID,omitempty"
WorkID string protobuf:"bytes,2,opt,name=WorkID" json:"WorkID,omitempty"
From string protobuf:"bytes,3,opt,name=From" json:"From,omitempty"
To string protobuf:"bytes,4,opt,name=To" json:"To,omitempty"
}
func (m *CopyrightTxRequest) Reset() { *m = CopyrightTxRequest{} }
func (m *CopyrightTxRequest) String() string { return proto1.CompactTextString(m) }
func (m *CopyrightTxRequest) ProtoMessage() {}
func (*CopyrightTxRequest) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{0} }
So I don't know how should I do?

question

Most helpful comment

Is arg a CopyrightTxRequest or *CopyrightTxRequest? The ProtoMessage method is declared on the pointer receiver.

All 2 comments

Is arg a CopyrightTxRequest or *CopyrightTxRequest? The ProtoMessage method is declared on the pointer receiver.

Thank you very much! That's what you said.It has been solved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seungryulchoisc picture seungryulchoisc  路  3Comments

jonomacd picture jonomacd  路  3Comments

leduy99 picture leduy99  路  4Comments

parkr picture parkr  路  5Comments

zamberform picture zamberform  路  5Comments