github.com/songzhibin97/gkit@v1.2.13/coding/proto/proto.go (about) 1 package proto 2 3 import ( 4 "github.com/songzhibin97/gkit/coding" 5 "google.golang.org/protobuf/proto" 6 ) 7 8 const Name = "proto" 9 10 func init() { 11 _ = coding.RegisterCode(code{}) 12 } 13 14 type code struct{} 15 16 func (c code) Marshal(v interface{}) ([]byte, error) { 17 return proto.Marshal(v.(proto.Message)) 18 } 19 20 func (c code) Unmarshal(data []byte, v interface{}) error { 21 return proto.Unmarshal(data, v.(proto.Message)) 22 } 23 24 func (c code) Name() string { 25 return Name 26 }