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 <v.tolstov@unistack.org>
  • Loading branch information
vtolstov committed Apr 12, 2021
1 parent 5241459 commit e4bf8ea
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *protoCodec) Marshal(v interface{}) ([]byte, error) {
}

func (c *protoCodec) Unmarshal(d []byte, v interface{}) error {
if d == nil {
if len(d) == 0 {
return nil
}
switch m := v.(type) {
Expand All @@ -50,14 +50,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 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 e4bf8ea

Please sign in to comment.