Skip to content

Commit

Permalink
fix nil buf check
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Tolstov <[email protected]>
  • Loading branch information
vtolstov committed Apr 12, 2021
1 parent adbd069 commit 8ecea82
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ 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
case newproto.Message, proto.Message:
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)
Expand Down

0 comments on commit 8ecea82

Please sign in to comment.