fix nil buf check

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-04-12 19:14:45 +03:00
parent 524145944a
commit e4bf8ea189

View File

@ -24,7 +24,7 @@ func (c *protoCodec) Marshal(v interface{}) ([]byte, error) {
} }
func (c *protoCodec) Unmarshal(d []byte, v interface{}) error { func (c *protoCodec) Unmarshal(d []byte, v interface{}) error {
if d == nil { if len(d) == 0 {
return nil return nil
} }
switch m := v.(type) { switch m := v.(type) {
@ -50,6 +50,8 @@ func (c *protoCodec) ReadBody(conn io.Reader, b interface{}) error {
buf, err := ioutil.ReadAll(conn) buf, err := ioutil.ReadAll(conn)
if err != nil { if err != nil {
return err return err
} else if len(buf) == 0 {
return nil
} }
m.Data = buf m.Data = buf
return nil return nil
@ -57,7 +59,7 @@ func (c *protoCodec) ReadBody(conn io.Reader, b interface{}) error {
buf, err := ioutil.ReadAll(conn) buf, err := ioutil.ReadAll(conn)
if err != nil { if err != nil {
return err return err
} else if buf == nil { } else if len(buf) == 0 {
return nil return nil
} }
return proto.Unmarshal(buf, m) return proto.Unmarshal(buf, m)