Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrWriterBufferFull = errors.New("exbytes.Writer: buffer full")
Functions ¶
This section is empty.
Types ¶
type Writer ¶
type Writer []byte
Writer is a simple byte writer that does not allow extending the buffer.
Writes always go after the current len() and will fail if the slice capacity is too low.
The correct way to use this is to create a slice with sufficient capacity and zero length:
x := make([]byte, 0, 11) w := (*Writer)(&x) w.Write([]byte("hello")) w.WriteByte(' ') w.WriteString("world") fmt.Println(string(x)) // "hello world"
Example ¶
package main import ( "fmt" "go.mau.fi/util/exbytes" ) func main() { x := make([]byte, 0, 11) w := (*exbytes.Writer)(&x) w.Write([]byte("hello")) w.WriteByte(' ') w.WriteString("world") fmt.Println(string(x)) }
Output: hello world
Click to show internal directories.
Click to hide internal directories.