diff options
| author | Mateusz Poliwczak <mpoliwczak34@gmail.com> | 2024-07-29 18:39:02 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-07-30 14:22:50 +0000 |
| commit | d0a468e52c6f7bc7e3cb4731f03e1693eb535a38 (patch) | |
| tree | 0c9c3e1619d492195537a204c33b5a87e069004c /src/encoding | |
| parent | a55f9d93e31c885f104896dc7c03fa14ec1a1b29 (diff) | |
| download | go-d0a468e52c6f7bc7e3cb4731f03e1693eb535a38.tar.xz | |
encoding: add TextAppender and BinaryAppender
For #62384
Change-Id: I54707a29653df72ad9cd5633f434b87e0f630b94
GitHub-Last-Rev: 4f78947ac563d78f862c5c8de1c2e1578a8d6e08
GitHub-Pull-Request: golang/go#68620
Reviewed-on: https://go-review.googlesource.com/c/go/+/601595
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/encoding')
| -rw-r--r-- | src/encoding/encoding.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/encoding/encoding.go b/src/encoding/encoding.go index 50acf3c23a..4d288b6d3b 100644 --- a/src/encoding/encoding.go +++ b/src/encoding/encoding.go @@ -35,6 +35,18 @@ type BinaryUnmarshaler interface { UnmarshalBinary(data []byte) error } +// BinaryAppender is the interface implemented by an object +// that can append the binary representation of itself. +// If a type implements both [BinaryAppender] and [BinaryMarshaler], +// then v.MarshalBinary() must be semantically identical to v.AppendBinary(nil). +type BinaryAppender interface { + // AppendBinary appends the binary representation of itself to the end of b + // (allocating a larger slice if necessary) and returns the updated slice. + // + // Implementations must not retain b, nor mutate any bytes within b[:len(b)]. + AppendBinary(b []byte) ([]byte, error) +} + // TextMarshaler is the interface implemented by an object that can // marshal itself into a textual form. // @@ -52,3 +64,15 @@ type TextMarshaler interface { type TextUnmarshaler interface { UnmarshalText(text []byte) error } + +// TextAppender is the interface implemented by an object +// that can append the textual representation of itself. +// If a type implements both [TextAppender] and [TextMarshaler], +// then v.MarshalText() must be semantically identical to v.AppendText(nil). +type TextAppender interface { + // AppendText appends the textual representation of itself to the end of b + // (allocating a larger slice if necessary) and returns the updated slice. + // + // Implementations must not retain b, nor mutate any bytes within b[:len(b)]. + AppendText(b []byte) ([]byte, error) +} |
