github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/rpc/message/message.go (about) 1 package message 2 3 import ( 4 "fmt" 5 6 "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" 7 ) 8 9 // Message represents raw Protobuf message 10 // that can be transmitted via several 11 // transport protocols. 12 type Message interface { 13 // Must return gRPC message that can 14 // be used for gRPC protocol transmission. 15 ToGRPCMessage() grpc.Message 16 17 // Must restore the message from related 18 // gRPC message. 19 // 20 // If gRPC message is not a related one, 21 // ErrUnexpectedMessageType can be returned 22 // to indicate this. 23 FromGRPCMessage(grpc.Message) error 24 } 25 26 // ErrUnexpectedMessageType is an error that 27 // is used to indicate message mismatch. 28 type ErrUnexpectedMessageType struct { 29 exp, act interface{} 30 } 31 32 // NewUnexpectedMessageType initializes an error about message mismatch 33 // between act and exp. 34 func NewUnexpectedMessageType(act, exp interface{}) ErrUnexpectedMessageType { 35 return ErrUnexpectedMessageType{ 36 exp: exp, 37 act: act, 38 } 39 } 40 41 func (e ErrUnexpectedMessageType) Error() string { 42 return fmt.Sprintf("unexpected message type %T: expected %T", e.act, e.exp) 43 }