diff --git a/json/json.go b/json/json.go index 2572491..e17938e 100644 --- a/json/json.go +++ b/json/json.go @@ -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 diff --git a/proto/proto.go b/proto/proto.go index bce50d7..35bcf86 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -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)