summaryrefslogtreecommitdiff
path: root/plugins/grpc/codec.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/grpc/codec.go')
-rw-r--r--plugins/grpc/codec.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/plugins/grpc/codec.go b/plugins/grpc/codec.go
new file mode 100644
index 00000000..5938e238
--- /dev/null
+++ b/plugins/grpc/codec.go
@@ -0,0 +1,35 @@
+package grpc
+
+import "google.golang.org/grpc/encoding"
+
+type rawMessage []byte
+
+func (r rawMessage) Reset() {}
+func (rawMessage) ProtoMessage() {}
+func (rawMessage) String() string { return "rawMessage" }
+
+type codec struct{ base encoding.Codec }
+
+// Marshal returns the wire format of v. rawMessages would be returned without encoding.
+func (c *codec) Marshal(v interface{}) ([]byte, error) {
+ if raw, ok := v.(rawMessage); ok {
+ return raw, nil
+ }
+
+ return c.base.Marshal(v)
+}
+
+// Unmarshal parses the wire format into v. rawMessages would not be unmarshalled.
+func (c *codec) Unmarshal(data []byte, v interface{}) error {
+ if raw, ok := v.(*rawMessage); ok {
+ *raw = data
+ return nil
+ }
+
+ return c.base.Unmarshal(data, v)
+}
+
+// String return codec name.
+func (c *codec) String() string {
+ return "raw:" + c.base.Name()
+}