Documentation
¶
Index ¶
- func FromBigEndian(obj Unmarshaler, b []byte) error
- func FromBytes(obj Unmarshaler, b []byte, order binary.ByteOrder) error
- func FromLittleEndian(obj Unmarshaler, b []byte) error
- func NewLazyOpener(open func() (io.Reader, error)) io.ReadCloser
- func ReadAll(r io.ReaderAt) ([]byte, error)
- func Reader(r io.ReaderAt) io.Reader
- func ReaderAtEqual(r1, r2 io.ReaderAt) bool
- func ToBigEndian(m Marshaler) []byte
- func ToBytes(m Marshaler, order binary.ByteOrder) []byte
- func ToLittleEndian(m Marshaler) []byte
- type Buffer
- type CachingReader
- type LazyOpener
- type LazyOpenerAt
- type Lexer
- func (l *Lexer) Append(n int) []byte
- func (l *Lexer) Consume(n int) []byte
- func (l *Lexer) CopyN(n int) []byte
- func (l *Lexer) Error() error
- func (l *Lexer) FinError() error
- func (l *Lexer) Read(p []byte) (int, error)
- func (l *Lexer) Read16() uint16
- func (l *Lexer) Read32() uint32
- func (l *Lexer) Read64() uint64
- func (l *Lexer) Read8() uint8
- func (l *Lexer) ReadAll() []byte
- func (l *Lexer) ReadBytes(p []byte)
- func (l *Lexer) ReadData(data interface{})
- func (l *Lexer) Write(p []byte) (int, error)
- func (l *Lexer) Write16(v uint16)
- func (l *Lexer) Write32(v uint32)
- func (l *Lexer) Write64(v uint64)
- func (l *Lexer) Write8(v uint8)
- func (l *Lexer) WriteBytes(p []byte)
- func (l *Lexer) WriteData(data interface{})
- type Marshaler
- type ReadAtCloser
- type Unmarshaler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromBigEndian ¶ added in v0.4.0
func FromBigEndian(obj Unmarshaler, b []byte) error
FromBigEndian unmarshals b into obj in big endian byte order.
func FromBytes ¶ added in v0.4.0
func FromBytes(obj Unmarshaler, b []byte, order binary.ByteOrder) error
FromBytes unmarshals b into obj in the given byte order.
func FromLittleEndian ¶ added in v0.4.0
func FromLittleEndian(obj Unmarshaler, b []byte) error
FromLittleEndian unmarshals b into obj in little endian byte order.
func NewLazyOpener ¶
func NewLazyOpener(open func() (io.Reader, error)) io.ReadCloser
NewLazyOpener returns a lazy io.Reader based on `open`.
func ReadAll ¶
ReadAll reads everything that r contains.
Callers *must* not modify bytes in the returned byte slice.
If r is an in-memory representation, ReadAll will attempt to return a pointer to those bytes directly.
func ReaderAtEqual ¶ added in v0.4.0
ReaderAtEqual compares the contents of r1 and r2.
func ToBigEndian ¶ added in v0.4.0
ToBigEndian marshals m to big endian byte order.
func ToLittleEndian ¶ added in v0.4.0
ToLittleEndian marshals m to little endian byte order.
Types ¶
type Buffer ¶ added in v0.4.0
type Buffer struct {
// contains filtered or unexported fields
}
Buffer implements functions to manipulate byte slices in a zero-copy way.
func NewBuffer ¶ added in v0.4.0
NewBuffer Consumes b for marshaling or unmarshaling in the given byte order.
func (*Buffer) Preallocate ¶ added in v0.4.0
Preallocate increases the capacity of the buffer by n bytes.
type CachingReader ¶
type CachingReader struct {
// contains filtered or unexported fields
}
CachingReader is a lazily caching wrapper of an io.Reader.
The wrapped io.Reader is only read from on demand, not upfront.
func NewCachingReader ¶
func NewCachingReader(r io.Reader) *CachingReader
NewCachingReader buffers reads from r.
r is only read from when Read() is called.
func (*CachingReader) NewReader ¶
func (cr *CachingReader) NewReader() io.Reader
NewReader returns a new io.Reader that reads cr from offset 0.
type LazyOpener ¶
type LazyOpener struct {
// contains filtered or unexported fields
}
LazyOpener is a lazy io.Reader.
LazyOpener will use a given open function to derive an io.Reader when Read is first called on the LazyOpener.
type LazyOpenerAt ¶
type LazyOpenerAt struct {
// contains filtered or unexported fields
}
LazyOpenerAt is a lazy io.ReaderAt.
LazyOpenerAt will use a given open function to derive an io.ReaderAt when ReadAt is first called.
func (*LazyOpenerAt) Close ¶
func (loa *LazyOpenerAt) Close() error
Close implements io.Closer.Close.
type Lexer ¶ added in v0.4.0
type Lexer struct {
*Buffer
// contains filtered or unexported fields
}
Lexer is a convenient encoder/decoder for buffers.
Use:
func (s *something) Unmarshal(l *Lexer) {
s.Foo = l.Read8()
s.Bar = l.Read8()
s.Baz = l.Read16()
return l.Error()
}
func NewBigEndianBuffer ¶ added in v0.4.0
NewBigEndianBuffer returns a new big endian coder for a new buffer.
func NewLittleEndianBuffer ¶ added in v0.4.0
NewLittleEndianBuffer returns a new little endian coder for a new buffer.
func NewNativeEndianBuffer ¶ added in v0.4.0
NewNativeEndianBuffer returns a new native endian coder for a new buffer.
func (*Lexer) Append ¶ added in v0.4.0
Append returns a newly appended n-size Buffer to write to.
If an error occured, Error() will return a non-nil error.
func (*Lexer) Consume ¶ added in v0.4.0
Consume returns a slice of the next n bytes from the buffer.
Consume gives direct access to the underlying data.
func (*Lexer) CopyN ¶ added in v0.4.0
CopyN returns a copy of the next n bytes.
If an error occured, Error() will return a non-nil error.
func (*Lexer) Error ¶ added in v0.4.0
Error returns an error if an error occured reading from the buffer.
func (*Lexer) FinError ¶ added in v0.4.0
FinError returns an error if an error occured or if there is more data left to read in the buffer.
func (*Lexer) Read16 ¶ added in v0.4.0
Read16 reads a 16-bit value from the Buffer.
If an error occured, Error() will return a non-nil error.
func (*Lexer) Read32 ¶ added in v0.4.0
Read32 reads a 32-bit value from the Buffer.
If an error occured, Error() will return a non-nil error.
func (*Lexer) Read64 ¶ added in v0.4.0
Read64 reads a 64-bit value from the Buffer.
If an error occured, Error() will return a non-nil error.
func (*Lexer) Read8 ¶ added in v0.4.0
Read8 reads a byte from the Buffer.
If an error occured, Error() will return a non-nil error.
func (*Lexer) ReadAll ¶ added in v0.4.0
ReadAll Consumes and returns a copy of all remaining bytes in the Buffer.
If an error occured, Error() will return a non-nil error.
func (*Lexer) ReadBytes ¶ added in v0.4.0
ReadBytes reads exactly len(p) values from the Buffer.
If an error occured, Error() will return a non-nil error.
func (*Lexer) ReadData ¶ added in v0.4.0
func (l *Lexer) ReadData(data interface{})
ReadData reads the binary representation of data from the buffer.
See binary.Read.
If an error occured, Error() will return a non-nil error.
func (*Lexer) Write ¶ added in v0.4.0
Write implements io.Writer.Write.
If an error occured, Error() will return a non-nil error.
func (*Lexer) Write16 ¶ added in v0.4.0
Write16 writes a 16-bit value to the Buffer.
If an error occured, Error() will return a non-nil error.
func (*Lexer) Write32 ¶ added in v0.4.0
Write32 writes a 32-bit value to the Buffer.
If an error occured, Error() will return a non-nil error.
func (*Lexer) Write64 ¶ added in v0.4.0
Write64 writes a 64-bit value to the Buffer.
If an error occured, Error() will return a non-nil error.
func (*Lexer) Write8 ¶ added in v0.4.0
Write8 writes a byte to the Buffer.
If an error occured, Error() will return a non-nil error.
func (*Lexer) WriteBytes ¶ added in v0.4.0
WriteBytes writes p to the Buffer.
If an error occured, Error() will return a non-nil error.
type Marshaler ¶ added in v0.4.0
type Marshaler interface {
Marshal(l *Lexer)
}
Marshaler is the interface implemented by an object that can marshal itself into binary form.
Marshal appends data to the buffer b.
type ReadAtCloser ¶
ReadAtCloser is an io.ReaderAt and an io.Closer.
func NewLazyOpenerAt ¶
func NewLazyOpenerAt(open func() (io.ReaderAt, error)) ReadAtCloser
NewLazyOpenerAt returns a lazy io.ReaderAt based on `open`.
type Unmarshaler ¶ added in v0.4.0
Unmarshaler is the interface implemented by an object that can unmarshal a binary representation of itself.
Unmarshal Consumes data from the buffer b.