Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
e4bf8ea189 | |||
524145944a |
19
codec_test.go
Normal file
19
codec_test.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package proto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReadBody(t *testing.T) {
|
||||||
|
t.Skip("skip as no proto")
|
||||||
|
s := &struct {
|
||||||
|
Name string
|
||||||
|
}{}
|
||||||
|
c := NewCodec()
|
||||||
|
b := bytes.NewReader(nil)
|
||||||
|
err := c.ReadBody(b, s)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
6
proto.go
6
proto.go
@@ -24,7 +24,7 @@ func (c *protoCodec) Marshal(v interface{}) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *protoCodec) Unmarshal(d []byte, v interface{}) error {
|
func (c *protoCodec) Unmarshal(d []byte, v interface{}) error {
|
||||||
if d == nil {
|
if len(d) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
switch m := v.(type) {
|
switch m := v.(type) {
|
||||||
@@ -50,6 +50,8 @@ func (c *protoCodec) ReadBody(conn io.Reader, b interface{}) error {
|
|||||||
buf, err := ioutil.ReadAll(conn)
|
buf, err := ioutil.ReadAll(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if len(buf) == 0 {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
m.Data = buf
|
m.Data = buf
|
||||||
return nil
|
return nil
|
||||||
@@ -57,7 +59,7 @@ func (c *protoCodec) ReadBody(conn io.Reader, b interface{}) error {
|
|||||||
buf, err := ioutil.ReadAll(conn)
|
buf, err := ioutil.ReadAll(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if buf == nil {
|
} else if len(buf) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return proto.Unmarshal(buf, m)
|
return proto.Unmarshal(buf, m)
|
||||||
|
Reference in New Issue
Block a user