2019-07-03 17:39:07 +00:00
|
|
|
package cborrpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
)
|
2019-07-03 17:41:54 +00:00
|
|
|
|
2019-07-03 17:39:07 +00:00
|
|
|
const MessageSizeLimit = 1 << 20
|
|
|
|
|
|
|
|
func WriteCborRPC(w io.Writer, obj interface{}) error {
|
|
|
|
data, err := cbor.DumpObject(obj)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = w.Write(data)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-04 14:47:46 +00:00
|
|
|
func ReadCborRPC(r io.Reader, out interface{}) error {
|
2019-07-03 17:39:07 +00:00
|
|
|
b, err := ioutil.ReadAll(r)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cbor.DecodeInto(b, out)
|
2019-07-03 17:41:54 +00:00
|
|
|
}
|