diff options
Diffstat (limited to 'internal/grpc/encoding/raw.go')
-rw-r--r-- | internal/grpc/encoding/raw.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/grpc/encoding/raw.go b/internal/grpc/encoding/raw.go new file mode 100644 index 000000000..5aed6b87d --- /dev/null +++ b/internal/grpc/encoding/raw.go @@ -0,0 +1,36 @@ +package encoding + +import ( + "google.golang.org/grpc/encoding" +) + +const Name = "raw" + +func init() { + // TODO: This should be called explicitly + encoding.RegisterCodec(codec{}) +} + +// codec is a Codec implementation with raw encoding. Clients and Servers +// exchange raw bytes without serializing/deserializing. It means they can +// send/receive any message without being restricted to Protobuf. Both sides +// are responsible for performing serialization and deserialization in the +// handler. +// The usage of this encoder is restricted: +// - The call must be bi-directional streaming +// - Both sides must use SendMsg and RecvMsg. Code-generated Send and Recv are +// not usable. +type codec struct{} + +func (codec) Marshal(v interface{}) ([]byte, error) { + return v.([]byte), nil +} + +func (codec) Unmarshal(data []byte, v interface{}) error { + *v.(*[]byte) = data + return nil +} + +func (codec) Name() string { + return Name +} |