use package level func for unmarshal
This commit is contained in:
		| @@ -11,10 +11,9 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| type Codec struct { | type Codec struct { | ||||||
| 	Conn        io.ReadWriteCloser | 	Conn    io.ReadWriteCloser | ||||||
| 	Encoder     *json.Encoder | 	Encoder *json.Encoder | ||||||
| 	Decoder     *json.Decoder | 	Decoder *json.Decoder | ||||||
| 	Unmarshaler *jsonpb.Unmarshaler |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func (c *Codec) ReadHeader(m *codec.Message, t codec.MessageType) error { | func (c *Codec) ReadHeader(m *codec.Message, t codec.MessageType) error { | ||||||
| @@ -26,7 +25,7 @@ func (c *Codec) ReadBody(b interface{}) error { | |||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 	if pb, ok := b.(proto.Message); ok { | 	if pb, ok := b.(proto.Message); ok { | ||||||
| 		return c.Unmarshaler.UnmarshalNext(c.Decoder, pb) | 		return jsonpb.UnmarshalNext(c.Decoder, pb) | ||||||
| 	} | 	} | ||||||
| 	return c.Decoder.Decode(b) | 	return c.Decoder.Decode(b) | ||||||
| } | } | ||||||
| @@ -48,9 +47,8 @@ func (c *Codec) String() string { | |||||||
|  |  | ||||||
| func NewCodec(c io.ReadWriteCloser) codec.Codec { | func NewCodec(c io.ReadWriteCloser) codec.Codec { | ||||||
| 	return &Codec{ | 	return &Codec{ | ||||||
| 		Conn:        c, | 		Conn:    c, | ||||||
| 		Decoder:     json.NewDecoder(c), | 		Decoder: json.NewDecoder(c), | ||||||
| 		Encoder:     json.NewEncoder(c), | 		Encoder: json.NewEncoder(c), | ||||||
| 		Unmarshaler: &jsonpb.Unmarshaler{}, |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user