Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-11-29 21:08:49 +03:00
parent 03740d5647
commit c2fe5b084e
2 changed files with 19 additions and 20 deletions

View File

@@ -39,10 +39,9 @@ type jsonCodec struct {
}
func (c *jsonCodec) Marshal(b interface{}) ([]byte, error) {
if b == nil {
return nil, nil
}
switch m := b.(type) {
case nil:
return nil, nil
case *codec.Frame:
return m.Data, nil
}
@@ -54,10 +53,12 @@ func (c *jsonCodec) Marshal(b interface{}) ([]byte, error) {
}
func (c *jsonCodec) Unmarshal(b []byte, v interface{}) error {
if b == nil || v == nil {
if b == nil {
return nil
}
switch m := v.(type) {
case nil:
return nil
case *codec.Frame:
m.Data = b
return nil
@@ -72,10 +73,9 @@ func (c *jsonCodec) ReadHeader(conn io.ReadWriter, m *codec.Message, t codec.Mes
}
func (c *jsonCodec) ReadBody(conn io.ReadWriter, b interface{}) error {
if b == nil {
return nil
}
switch m := b.(type) {
case nil:
return nil
case *codec.Frame:
buf, err := ioutil.ReadAll(conn)
if err != nil {
@@ -89,10 +89,9 @@ func (c *jsonCodec) ReadBody(conn io.ReadWriter, b interface{}) error {
}
func (c *jsonCodec) Write(conn io.ReadWriter, m *codec.Message, b interface{}) error {
if b == nil {
return nil
}
switch m := b.(type) {
case nil:
return nil
case *codec.Frame:
_, err := conn.Write(m.Data)
return err