Replace most marshaling with codegen

This commit is contained in:
whyrusleeping
2019-08-22 12:53:32 -07:00
parent 53be71fb73
commit 7eb89f90d1
17 changed files with 819 additions and 151 deletions
+7
View File
@@ -4,11 +4,15 @@ import (
"io"
cbor "github.com/ipfs/go-ipld-cbor"
cbg "github.com/whyrusleeping/cbor-gen"
)
const MessageSizeLimit = 1 << 20
func WriteCborRPC(w io.Writer, obj interface{}) error {
if m, ok := obj.(cbg.CBORMarshaler); ok {
return m.MarshalCBOR(w)
}
data, err := cbor.DumpObject(obj)
if err != nil {
return err
@@ -19,5 +23,8 @@ func WriteCborRPC(w io.Writer, obj interface{}) error {
}
func ReadCborRPC(r io.Reader, out interface{}) error {
if um, ok := out.(cbg.CBORUnmarshaler); ok {
return um.UnmarshalCBOR(r)
}
return cbor.DecodeReader(r, out)
}