diff --git a/proto.go b/proto.go index e3721e4..86b0031 100644 --- a/proto.go +++ b/proto.go @@ -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) { @@ -50,6 +50,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 @@ -57,7 +59,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)