func ParseHexUint64(data []byte) (uint64, bool)
ParseHexUint64 is equivalent to using strconv.ParseUint with base 16, except that it operates directly on a byte slice without having to allocate a string. (A version of strconv.ParseUint that operates on a byte slice has been a frequently requested Go feature for years, but as of the time this comment was written, those requests have not been acted on.)
LocalBuffer is a simplified equivalent to bytes.Buffer that allows usage of a preallocated local byte slice.
The bytes.Buffer type is very efficient except in one regard: it must always allocate the byte slice on the heap, since its internal "buf" field starts out as nil and cannot be directly modified. LocalBuffer exports this field so it can be initialized to a slice which, if allowed by Go's escape analysis, can remain on the stack as long as its capacity is not exceeded. For example:
buf := LocalBuffer{Data: make([]byte, 0, 100)} buf.AppendString("some data") // etc. result := buf.Data
In the example, as long as no more than 100 bytes are written to the buffer, there are no heap allocations. As soon as the capacity is exceeded, the byte slice is moved to the heap and its capacity expands exponentially, similar to bytes.Buffer.
To simplify the API, the LocalBuffer methods return nothing; that's why they're named Append rather than Write, because Write has a connotation of imitating the io.Writer API.
type LocalBuffer struct { // Data is the current content of the buffer. Data []byte }
func (b *LocalBuffer) Append(data []byte)
Append appends a byte slice to the buffer.
func (b *LocalBuffer) AppendByte(ch byte)
AppendByte appends a single byte to the buffer.
func (b *LocalBuffer) AppendInt(n int)
AppendInt appends the base-10 string representation of an integer to the buffer.
func (b *LocalBuffer) AppendString(s string)
AppendString appends the bytes of a string to the buffer.