fix nil buf check

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-04-12 19:17:01 +03:00
parent adbd069875
commit 8ecea8221f
2 changed files with 6 additions and 2 deletions

View File

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

View File

@ -54,6 +54,8 @@ func (c *protoCodec) ReadBody(conn io.Reader, b interface{}) error {
buf, err := ioutil.ReadAll(conn)
if err != nil {
return err
} else if len(buf) == 0 {
return nil
}
m.Data = buf
return nil
@ -61,7 +63,7 @@ func (c *protoCodec) ReadBody(conn io.Reader, b interface{}) error {
buf, err := ioutil.ReadAll(conn)
if err != nil {
return err
} else if buf == nil {
} else if len(buf) == 0 {
return nil
}
return proto.Unmarshal(buf, m)