Skip to content

add an EncodeWriter method, using the pooled marshallers #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
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 @@
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