Skip to content

uuid: implement encoding.TextAppender and encoding.BinaryAppender#214

Open
alliasgher wants to merge 1 commit intogoogle:masterfrom
alliasgher:feat-append-text-binary
Open

uuid: implement encoding.TextAppender and encoding.BinaryAppender#214
alliasgher wants to merge 1 commit intogoogle:masterfrom
alliasgher:feat-append-text-binary

Conversation

@alliasgher
Copy link
Copy Markdown

Summary

Implements the encoding.TextAppender and encoding.BinaryAppender interfaces introduced in Go 1.24 for both UUID and NullUUID.

These interfaces (AppendText and AppendBinary) are the append-to-existing-slice equivalents of TextMarshaler / BinaryMarshaler. They avoid a heap allocation in hot paths because callers can reuse a buffer.

New methods

Type Method Notes
UUID AppendText(b []byte) ([]byte, error) Appends the 36-byte dash-separated hex string
UUID AppendBinary(b []byte) ([]byte, error) Appends the raw 16-byte form
NullUUID AppendText(b []byte) ([]byte, error) Appends text form or null
NullUUID AppendBinary(b []byte) ([]byte, error) Appends binary form or nothing

All new methods produce output identical to their Marshal* counterparts.

Fixes #193

Tests

  • TestAppendText and TestAppendBinary added to uuid_test.go
  • Full test suite passes

Go 1.24 introduced encoding.TextAppender and encoding.BinaryAppender
interfaces that allow appending encoded data to an existing byte slice
without allocating. Add AppendText and AppendBinary to both UUID and
NullUUID to implement these interfaces.

Compared to their Marshaler counterparts, AppendText/AppendBinary
append to the provided slice instead of allocating a new one each call,
which is more memory-efficient in hot paths.

Fixes google#193

Signed-off-by: alliasgher <[email protected]>
@alliasgher alliasgher requested a review from a team as a code owner April 13, 2026 23:17
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 13, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement AppendText and AppendBinary

1 participant