fxamacker / cbor

CBOR codec (RFC 8949) with CBOR tags, Go struct tags (toarray, keyasint, omitempty), float64/32/16, big.Int, and fuzz tested billions of execs.
MIT License
748 stars 61 forks source link

Allow user to specify buffer by adding `cbor.MarshalToBuffer()`, `UserBufferEncMode` interface, etc. #553

Closed fxamacker closed 5 months ago

fxamacker commented 5 months ago

Currently, the encoder uses a built-in buffer pool. This PR allows encoding to a user specified buffer rather than using the built-in buffer pool.

This PR wraps and uses a function implemented in PR #521 by @benluddy. Thanks Ben! :+1:

This PR adds:

This PR added a check to return error if user provided buffer *bytes.Buffer is nil.

fxamacker commented 5 months ago

@benluddy @x448 PTAL 🙏