Skip to content

Commit 2e94acd

Browse files
MichaelMurervagg
authored andcommitted
add an EncodeWriter method, using the pooled marshallers
1 parent 7fcd408 commit 2e94acd

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

node.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func DecodeInto(b []byte, v interface{}) error {
108108
return unmarshaller.Unmarshal(b, v)
109109
}
110110

111+
// DecodeReader reads from the given reader and decodes a serialized IPLD cbor object into the given object.
111112
func DecodeReader(r io.Reader, v interface{}) error {
112113
return unmarshaller.Decode(r, v)
113114
}
@@ -400,6 +401,11 @@ func DumpObject(obj interface{}) (out []byte, err error) {
400401
return marshaller.Marshal(obj)
401402
}
402403

404+
// EncodeWriter marshals into the writer any object as its CBOR serialized byte representation.
405+
func EncodeWriter(obj interface{}, w io.Writer) error {
406+
return marshaller.Encode(obj, w)
407+
}
408+
403409
func toSaneMap(n map[interface{}]interface{}) (interface{}, error) {
404410
if lnk, ok := n["/"]; ok && len(n) == 1 {
405411
lnkb, ok := lnk.([]byte)

0 commit comments

Comments
 (0)