Documentation ¶
Overview ¶
Package bites implements a way to easily pack and unpack any primitive type into a byte slice.
Index ¶
- type ErrorInvalidRune
- type Get
- func (b Get) Clone() Get
- func (b Get) Error() bool
- func (b Get) ExpectBool(bools ...bool) Get
- func (b Get) ExpectByte(byt byte) Get
- func (b Get) ExpectComplex128(expect complex128) Get
- func (b Get) ExpectComplex64(expect complex64) Get
- func (b Get) ExpectFloat32(expect float32) Get
- func (b Get) ExpectFloat64(expect float64) Get
- func (b Get) ExpectInt16(expect int16) Get
- func (b Get) ExpectInt16LE(expect int16) Get
- func (b Get) ExpectInt32(expect int32) Get
- func (b Get) ExpectInt32LE(expect int32) Get
- func (b Get) ExpectInt64(expect int64) Get
- func (b Get) ExpectInt64LE(expect int64) Get
- func (b Get) ExpectInt8(expect int8) Get
- func (b Get) ExpectRune(r rune) Get
- func (b Get) ExpectSlice(byt []byte) Get
- func (b Get) ExpectString(s string) Get
- func (b Get) ExpectUint16(expect uint16) Get
- func (b Get) ExpectUint16LE(expect uint16) Get
- func (b Get) ExpectUint32(expect uint32) Get
- func (b Get) ExpectUint32LE(expect uint32) Get
- func (b Get) ExpectUint64(expect uint64) Get
- func (b Get) ExpectUint64LE(expect uint64) Get
- func (b Get) ExpectUint8(expect uint8) Get
- func (b Get) ExpectVarInt(expect int64, size *int) Get
- func (b Get) ExpectVarUint(expect uint64, size *int) Get
- func (b Get) GetBool(bools ...*bool) Get
- func (b Get) GetByte(byt *byte) Get
- func (b Get) GetComplex128(f *complex128) Get
- func (b Get) GetComplex64(f *complex64) Get
- func (b Get) GetFloat32(f *float32) Get
- func (b Get) GetFloat64(f *float64) Get
- func (b Get) GetInt16(ip *int16) Get
- func (b Get) GetInt16LE(ip *int16) Get
- func (b Get) GetInt32(ip *int32) Get
- func (b Get) GetInt32LE(ip *int32) Get
- func (b Get) GetInt64(ip *int64) Get
- func (b Get) GetInt64LE(ip *int64) Get
- func (b Get) GetInt8(i *int8) Get
- func (b Get) GetRune(r *rune, s *int) Get
- func (b Get) GetSlice(slice *[]byte, size int) Get
- func (b Get) GetSliceCopy(slice []byte) Get
- func (b Get) GetString(str *string, size int) Get
- func (b Get) GetUint16(ip *uint16) Get
- func (b Get) GetUint16LE(ip *uint16) Get
- func (b Get) GetUint32(ip *uint32) Get
- func (b Get) GetUint32LE(ip *uint32) Get
- func (b Get) GetUint64(ip *uint64) Get
- func (b Get) GetUint64LE(ip *uint64) Get
- func (b Get) GetUint8(i *uint8) Get
- func (b Get) GetVar(i *int) Get
- func (b Get) GetVarInt(i *int64, size *int) Get
- func (b Get) GetVarUint(i *uint64, size *int) Get
- func (b Get) Last(s int) Get
- func (b Get) Len() int
- func (b Get) More() bool
- func (b Get) NewReader() *Reader
- func (b Get) Put() Put
- func (b Get) Skip(s int) Get
- func (b Get) Snip(s int) Get
- func (b Get) Space(expect int) bool
- func (b Get) Split(s int) (Get, Get)
- func (b Get) String() string
- type Put
- func (b Put) Capacity(s int) Put
- func (b Put) Clone() Put
- func (b Put) Extend(s int) Put
- func (b Put) Get() Get
- func (b Put) Last(s int) Put
- func (b Put) NewWriter() *Writer
- func (b Put) PutBool(bools ...bool) Put
- func (b Put) PutByte(byt byte) Put
- func (b Put) PutComplex128(f complex128) Put
- func (b Put) PutComplex64(f complex64) Put
- func (b Put) PutFloat32(f float32) Put
- func (b Put) PutFloat64(f float64) Put
- func (b Put) PutInt16(i int16) Put
- func (b Put) PutInt16LE(i int16) Put
- func (b Put) PutInt32(i int32) Put
- func (b Put) PutInt32LE(i int32) Put
- func (b Put) PutInt64(i int64) Put
- func (b Put) PutInt64LE(i int64) Put
- func (b Put) PutInt8(i int8) Put
- func (b Put) PutRune(r rune, s *int) Put
- func (b Put) PutSlice(slice []byte) Put
- func (b Put) PutString(str string) Put
- func (b Put) PutUint16(i uint16) Put
- func (b Put) PutUint16LE(i uint16) Put
- func (b Put) PutUint32(i uint32) Put
- func (b Put) PutUint32LE(i uint32) Put
- func (b Put) PutUint64(i uint64) Put
- func (b Put) PutUint64LE(i uint64) Put
- func (b Put) PutUint8(i uint8) Put
- func (b Put) PutVar(ii int) Put
- func (b Put) PutVarInt(i int64, size *int) Put
- func (b Put) PutVarUint(i uint64, size *int) Put
- func (b Put) Reuse() Put
- func (b Put) Set(s byte) Put
- func (b Put) Snip(s int) Put
- func (b Put) String() string
- func (b Put) Zero() Put
- type Reader
- type Writer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorInvalidRune ¶
type ErrorInvalidRune rune
func (ErrorInvalidRune) Error ¶
func (err ErrorInvalidRune) Error() string
type Get ¶
type Get []byte
Bites' purpose is to give byte slices some useful methods. The Get methods snip things off the front, and return the remainder of the slice. The Expect methods do a Get, and then compare it to the provided value. If there is not enough space for a Get, or if the Expect does not match, the method will return nil. The int methods are big-endian by default, but they have Little-Endian versions too. The float and complex methods put them in the form of IEE754 binary representation.
func (Get) ExpectBool ¶
Try to read a set of bools, and see if it matches. See GetBool.
func (Get) ExpectByte ¶
Read one byte, compare it to byt. If it does not match, panic with ErrorExpectByte.
func (Get) ExpectComplex128 ¶
func (b Get) ExpectComplex128(expect complex128) Get
func (Get) ExpectComplex64 ¶
func (Get) ExpectFloat32 ¶
func (Get) ExpectFloat64 ¶
func (Get) ExpectInt16 ¶
func (Get) ExpectInt16LE ¶
func (Get) ExpectInt32 ¶
func (Get) ExpectInt32LE ¶
func (Get) ExpectInt64 ¶
func (Get) ExpectInt64LE ¶
func (Get) ExpectInt8 ¶
func (Get) ExpectRune ¶
Read one rune, compare it to byt. If it does not match, panic with ErrorExpectRune.
func (Get) ExpectSlice ¶
Try to read a slice as long as byt, and see if it matches. If it does not, panic with ErrorExpectSlice. If there is not enough to read the whole slice, panic with ErrSliceEOF.
func (Get) ExpectString ¶
Try to read a string as long as s, and see if it matches. If it does not, panic with ErrorExpectString. If it panics with this, it also allocates, but otherwise it does not. If there is not enough to read the whole slice, panic with ErrSliceEOF.
func (Get) ExpectUint16 ¶
func (Get) ExpectUint16LE ¶
func (Get) ExpectUint32 ¶
func (Get) ExpectUint32LE ¶
func (Get) ExpectUint64 ¶
func (Get) ExpectUint64LE ¶
func (Get) ExpectUint8 ¶
func (Get) GetBool ¶
Get a list of bools. The bools are interpreted as though they were written by PutBool. If a bool is nil, that bit is skipped.
func (Get) GetComplex128 ¶
func (b Get) GetComplex128(f *complex128) Get
func (Get) GetComplex64 ¶
func (Get) GetFloat32 ¶
func (Get) GetFloat64 ¶
func (Get) GetInt16LE ¶
func (Get) GetInt32LE ¶
func (Get) GetInt64LE ¶
func (Get) GetRune ¶
Get the first UTF8 rune in b. If the rune is not valid UTF8 or b is empty, it returns nil.
func (Get) GetSliceCopy ¶
Copy b to slice, and return what's left of b. If there's not enough in b to fill the slice, return nil.
func (Get) GetString ¶
Get a string of the given size. This allocates. If there's not enough in b to read the full string, return nil.
func (Get) GetUint16LE ¶
func (Get) GetUint32LE ¶
func (Get) GetUint64LE ¶
func (Get) NewReader ¶
A Reader returned by this will allow you to Read everything in the given byte slice.
type Put ¶
type Put []byte
func (Put) Extend ¶
Extend b by s, return the complete, extended, slice. The extension may contain garbage. An allocation (new backing array) will occur if s is larger than cap-len.
func (Put) NewWriter ¶
The byte slice provided here is merely as an option to re-use an existing slice. When you're done writing to the Writer, call Bites to return an updated slice.
func (Put) PutBool ¶
Append a list of bools. The bools are set as bits consolidated into bytes, and are stored in the same order as they are given. This means that if there is a single true given, the byte appended will have the value 128.
func (Put) PutComplex128 ¶
func (b Put) PutComplex128(f complex128) Put
func (Put) PutComplex64 ¶
func (Put) PutFloat32 ¶
func (Put) PutFloat64 ¶
func (Put) PutInt16LE ¶
func (Put) PutInt32LE ¶
func (Put) PutInt64LE ¶
func (Put) PutRune ¶
Append the given rune as UTF8. If the rune is not valid, it panics with an error of type ErrorInvalidRune.
func (Put) PutUint16LE ¶
func (Put) PutUint32LE ¶
func (Put) PutUint64LE ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A (Byte)Reader that reads everything contained in the given byte slice.
func (*Reader) Read ¶
Read from the slice. When there is nothing left to read, this returns 0, io.EOF.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A (Byte)Writer that appends everything written to the given byte slice.
Example ¶
package main import ( "fmt" "github.com/PieterD/bites" ) func main() { b := bites.New().PutString("Hello") w := b.NewWriter() fmt.Fprintf(w, ", world!") fmt.Println(w.Bites().String()) }
Output: Hello, world!
func (*Writer) Bites ¶
Return the updated (possibly reallocated) byte slice, containing everything written to the Writer.