Skip to content

Commit

Permalink
codec: return error directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jazg committed Nov 29, 2019
1 parent eb65fff commit 7f0345b
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ func (binaryCodec) Encode(obj interface{}) ([]byte, error) {
return obj.(encoding.BinaryMarshaler).MarshalBinary()
default:
buf := new(bytes.Buffer)
if err := binary.Write(buf, binary.LittleEndian, obj); err != nil {
return buf.Bytes(), err
}
return buf.Bytes(), nil
err := binary.Write(buf, binary.LittleEndian, obj)
return buf.Bytes(), err
}
}

Expand Down Expand Up @@ -79,11 +77,8 @@ type gobCodec struct{}
// Encode implements the `db.Codec`
func (gobCodec) Encode(obj interface{}) ([]byte, error) {
buf := new(bytes.Buffer)
if err := gob.NewEncoder(buf).Encode(obj); err != nil {
return nil, err
}

return buf.Bytes(), nil
err := gob.NewEncoder(buf).Encode(obj)
return buf.Bytes(), err
}

// Decode implements the `db.Codec`
Expand Down

0 comments on commit 7f0345b

Please sign in to comment.