bytebuilder

package module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2022 License: MIT Imports: 4 Imported by: 2

README

bytebuilder

Golang API to manipulate byte slices.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadBytes

func ReadBytes(b *[]byte, n int) []byte

ReadBytes removes the first n bytes from b and returns it. If the read failed, returns nil.

func ReadInt added in v0.4.0

func ReadInt(b *[]byte, bitSize int) (int, bool)

ReadInt removes the first bytes (depends on bitSize) from b and returns it as an int.

func ReadReaderBytes

func ReadReaderBytes(in io.Reader, n int) ([]byte, error)

ReadReaderBytes reads n byte from in. At the end of the file, io.EOF is returned.

func ReadReaderUint16

func ReadReaderUint16(in io.Reader) (uint16, error)

ReadReaderUint16 reads bytes from in and returns it as an uint16. At the end of the file io.EOF returned.

func ReadReaderUint24

func ReadReaderUint24(in io.Reader) (uint32, error)

ReadReaderUint24 reads bytes from in and returns it as an uint32. At the end of the file, io.EOF is returned.

func ReadReaderUint32

func ReadReaderUint32(in io.Reader) (uint32, error)

ReadReaderUint32 reads bytes from in and returns it as an uint32. At the end of the file io.EOF returned.

func ReadReaderUint8

func ReadReaderUint8(in io.Reader) (uint8, error)

ReadReaderUint8 reads a byte from in and returns is as an uint8. At the end of the file, io.EOF is returned.

func ReadUint16

func ReadUint16(b *[]byte) (uint16, bool)

ReadUint16 removes the first bytes from b and returns it as an uint16. The bool indicates whether the read was successful.

func ReadUint24

func ReadUint24(b *[]byte) (uint32, bool)

ReadUint24 removes the first bytes from b and returns it as a uint32. The bool indicates whether the read was successful.

func ReadUint32

func ReadUint32(b *[]byte) (uint32, bool)

ReadUint32 removes the first bytes from b and returns it as an uint32. The bool indicates whether the read was successful.

func ReadUint8

func ReadUint8(b *[]byte) (uint8, bool)

ReadUint8 removes the first byte from b and returns it as an uint8. The bool indicates whether the read was successful.

func Skip

func Skip(b *[]byte, n int) bool

Skip removes the first n bytes from b. Returns whether it was successful.

func SkipReader

func SkipReader(in io.Reader, n int) error

ReadReaderSkip skips n bytes in in. At the end of the file, io.EOF is returned.

func WriteBytes

func WriteBytes(b *[]byte, bytes ...byte)

WriteBytes appends bytes at the end of b.

func WriteInt added in v0.4.0

func WriteInt(b *[]byte, v int, bitSize int)

WriteInt append v at the end of b with size bitSize.

func WriteUint16

func WriteUint16(b *[]byte, v uint16)

WriteUint16 appends v at the end of b.

func WriteUint24

func WriteUint24(b *[]byte, v uint32)

WriteUint24 appends v at the end of b.

func WriteUint32

func WriteUint32(b *[]byte, v uint32)

WriteUint32 appends v at the end of b.

func WriteUint8

func WriteUint8(b *[]byte, v uint8)

WriteUint8 appends v at the end of b.

func WriteWriterBytes

func WriteWriterBytes(in io.Writer, bytes ...byte) error

WriteWriterBytes appends v at the end of in.

func WriteWriterUint16

func WriteWriterUint16(in io.Writer, v uint16) error

WriteWriterUint16 appends v at the end of in.

func WriteWriterUint24

func WriteWriterUint24(in io.Writer, v uint32) error

WriteWriterUint24 appends v at the end of in.

func WriteWriterUint32

func WriteWriterUint32(in io.Writer, v uint32) error

WriteWriterUint32 appends v at the end of in.

func WriteWriterUint8

func WriteWriterUint8(in io.Writer, v uint8) error

WriteWriterUint8 appends v at the end of in.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer(bytes []byte) Buffer

func NewEmpty

func NewEmpty() Buffer

NewEmpty creates a Buffer with a zero length byte slice.

func ReadAll

func ReadAll(r io.Reader) (Buffer, error)

ReadAll reads from r until an error or EOF and returns a Buffer from the data it read. A successful call returns err == nil, not err == EOF. Because ReadAll is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns the underlying byte slice.

func (*Buffer) BytesPointer

func (b *Buffer) BytesPointer() *[]byte

BytesPointer returns a pointer to the underlying byte slice.

func (*Buffer) Empty

func (b *Buffer) Empty() bool

Empty returns whether b is empty.

func (*Buffer) ReadBytes

func (b *Buffer) ReadBytes(n int) []byte

ReadBytes removes the first n bytes from b and returns it. If the read failed, returns nil.

func (*Buffer) ReadGMTUnixTime32

func (b *Buffer) ReadGMTUnixTime32() (time.Time, bool)

ReadGMTUnixTime32 removes the first bytes from b and returns it as an unix time. The bool indicates whether the read was successful.

func (*Buffer) ReadInt added in v0.4.0

func (b *Buffer) ReadInt(bitSize int) (int, bool)

ReadInt removes the first bytes (depends on bitSize) from b and returns it as an int.

func (*Buffer) ReadUint16

func (b *Buffer) ReadUint16() (uint16, bool)

ReadUint16 removes the first bytes from b and returns it as an uint16. The bool indicates whether the read was successful.

func (*Buffer) ReadUint24

func (b *Buffer) ReadUint24() (uint32, bool)

ReadUint24 removes the first bytes from b and returns it as a uint32. The bool indicates whether the read was successful.

func (*Buffer) ReadUint32

func (b *Buffer) ReadUint32() (uint32, bool)

ReadUint32 removes the first bytes from b and returns it as an uint32. The bool indicates whether the read was successful.

func (*Buffer) ReadUint8

func (b *Buffer) ReadUint8() (uint8, bool)

ReadUint8 removes the first byte from b and returns it as an uint8. The bool indicates whether the read was successful.

func (*Buffer) ReadVector added in v0.4.0

func (b *Buffer) ReadVector(bitSize int) ([]byte, bool)

ReadVector reads the length of bytes then the bytes itself. The length type is depend on bitSize (eg.: uint8, uint16, uint24, uint32). Therefore, bitSize must be 8/16/24/32. If bitSize is an invalid number, this function panics.

func (*Buffer) Size

func (b *Buffer) Size() int

Size returns the size of the underlying byte slice

func (*Buffer) Skip

func (b *Buffer) Skip(n int) bool

Skip removes the first n bytes from b. Returns whether it was successful.

func (*Buffer) WriteBytes

func (b *Buffer) WriteBytes(bytes ...byte)

WriteBytes appends bytes at the end of b.

func (*Buffer) WriteGMTUnixTime32

func (b *Buffer) WriteGMTUnixTime32(time time.Time)

WriteGMTUnixTime32 appends time to b in 32 bit unix format.

func (*Buffer) WriteInt added in v0.4.0

func (b *Buffer) WriteInt(v int, bitSize int)

WriteInt append v at the end of b with size bitSize.

func (*Buffer) WriteRandom

func (b *Buffer) WriteRandom(n int)

WriteRandom appends n random bytes to b. If failed to read random, this function panics.

func (*Buffer) WriteUint16

func (b *Buffer) WriteUint16(v uint16)

WriteUint16 appends v at the end of b.

func (*Buffer) WriteUint24

func (b *Buffer) WriteUint24(v uint32)

WriteUint24 appends v at the end of b.

func (*Buffer) WriteUint32

func (b *Buffer) WriteUint32(v uint32)

WriteUint32 appends v at the end of b.

func (*Buffer) WriteUint8

func (b *Buffer) WriteUint8(v uint8)

WriteUint8 appends v at the end of b.

func (*Buffer) WriteVector added in v0.4.0

func (b *Buffer) WriteVector(v []byte, bitSize int)

WriteVector appends the length of bytes then the bytes itself. The length type is depend on bitSize (eg.: uint8, uint16, uint24, uint32). Therefore, bitSize must be 8/16/24/32. If bitSize is an invalid number, this function panics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL