Documentation
¶
Overview ¶
Package bytes provides byte-oriented helpers used across go-service.
Most identifiers in this package are thin wrappers or aliases around the standard library `bytes` package. They exist to:
- provide a consistent import path within go-service, and
- centralize a small set of byte/string conversion utilities.
Aliases and wrappers ¶
`Buffer` is an alias for `bytes.Buffer`, and constructors like `NewBuffer`, `NewBufferString`, and `NewReader` delegate directly to the standard library.
Zero-copy conversions ¶
This package also exposes `String`, which converts a `[]byte` to a `string` without allocating. This is an advanced, performance-oriented helper with important safety constraints; see `String` for details.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clone ¶ added in v2.240.0
Clone returns a copy of b.
This is a thin wrapper around bytes.Clone. Unlike helpers that may return subslices, Clone always allocates a new slice (unless b is nil, in which case it returns nil).
func NewBuffer ¶
NewBuffer returns a new Buffer initialized with buf's contents.
This is a thin wrapper around bytes.NewBuffer. The returned buffer uses buf as its initial contents; subsequent writes may grow the buffer.
func NewBufferString ¶
NewBufferString returns a new Buffer initialized with the contents of s.
This is a thin wrapper around bytes.NewBufferString.
func NewReader ¶
NewReader returns a new bytes.Reader reading from b.
This is a thin wrapper around bytes.NewReader. The returned reader reads from b without copying.
func String ¶
String converts b to a string without copying.
Safety and lifetime ¶
The returned string aliases the memory backing b. That means:
- You MUST NOT modify the contents of b after calling String(b).
- The returned string is only valid while b remains alive (reachable) and its backing array is not reused.
Violating these constraints can lead to surprising behavior, data races, or memory safety issues. Use this helper only when you control the lifecycle of b and need to avoid an allocation. If you need an owning copy, use `string(b)` instead.