retrieval: Make types more spec complaiant

This commit is contained in:
Łukasz Magiera
2019-08-29 17:54:35 +02:00
parent fe6d5ff3a8
commit f79b755c58
5 changed files with 59 additions and 29 deletions
+16 -1
View File
@@ -1,16 +1,27 @@
package cborrpc
import (
"encoding/hex"
"io"
cbor "github.com/ipfs/go-ipld-cbor"
logging "github.com/ipfs/go-log"
cbg "github.com/whyrusleeping/cbor-gen"
)
const MessageSizeLimit = 1 << 20
var log = logging.Logger("cborrrpc")
const Debug = false
func init() {
if Debug {
log.Warn("CBOR-RPC Debugging enabled")
}
}
func WriteCborRPC(w io.Writer, obj interface{}) error {
if m, ok := obj.(cbg.CBORMarshaler); ok {
// TODO: impl debug
return m.MarshalCBOR(w)
}
data, err := cbor.DumpObject(obj)
@@ -18,6 +29,10 @@ func WriteCborRPC(w io.Writer, obj interface{}) error {
return err
}
if Debug {
log.Infof("> %s", hex.EncodeToString(data))
}
_, err = w.Write(data)
return err
}