Skip to content
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

Allow representations of nillable primitive field values #758

Merged
merged 5 commits into from Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion buffer/buffer.go
Expand Up @@ -44,6 +44,11 @@ func (b *Buffer) AppendString(s string) {
b.bs = append(b.bs, s...)
}

// AppendBytes appends a byte slice to the Buffer.
func (b *Buffer) AppendBytes(bs []byte) {
b.bs = append(b.bs, bs...)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why create this method instead of just using Write?

Since this package and type is public, we'd prefer to not introduce new
methods if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just figured it helped avoid checking for errors via Write() which were known-impossible, but not worth disrupting the larger picture just for that (and in a previous, unsubmitted version, I was calling it from more than one site, so it was a mild ergonomic improvement).


// AppendInt appends an integer to the underlying buffer (assuming base 10).
func (b *Buffer) AppendInt(i int64) {
b.bs = strconv.AppendInt(b.bs, i, 10)
Expand Down Expand Up @@ -94,7 +99,7 @@ func (b *Buffer) Reset() {

// Write implements io.Writer.
func (b *Buffer) Write(bs []byte) (int, error) {
b.bs = append(b.bs, bs...)
b.AppendBytes(bs)
return len(bs), nil
}

Expand Down