Skip to content

Commit

Permalink
add an EncodeWriter method, using the pooled marshallers
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Sep 18, 2024
1 parent 7fcd408 commit 74fa05e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func DecodeInto(b []byte, v interface{}) error {
return unmarshaller.Unmarshal(b, v)
}

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

// EncodeWriter marshals into the writer any object as its CBOR serialized byte representation.
func EncodeWriter(obj interface{}, w io.Writer) error {
return marshaller.Encode(obj, w)

Check warning on line 406 in node.go

View check run for this annotation

Codecov / codecov/patch

node.go#L405-L406

Added lines #L405 - L406 were not covered by tests
}

func toSaneMap(n map[interface{}]interface{}) (interface{}, error) {
if lnk, ok := n["/"]; ok && len(n) == 1 {
lnkb, ok := lnk.([]byte)
Expand Down

0 comments on commit 74fa05e

Please sign in to comment.