Documentation ¶
Overview ¶
Package uio unifies commonly used io utilities for u-root.
uio's most used feature is the Buffer/Lexer combination to parse binary data of arbitrary endianness into data structures.
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 FullLineWriter(w LineWriter) io.WriteCloser
- func MultiWriteCloser(w ...io.Writer) io.WriteCloser
- 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 AlignReader
- type AlignWriter
- type Buffer
- type CachingReader
- type LazyOpener
- type LazyOpenerAt
- type Lexer
- func (l *Lexer) Align(n int)
- 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 LineWriter
- type Marshaler
- type ReadAtCloser
- type Unmarshaler
- type WriteNameCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromBigEndian ¶
func FromBigEndian(obj Unmarshaler, b []byte) error
FromBigEndian unmarshals b into obj in big endian byte order.
func FromBytes ¶
func FromBytes(obj Unmarshaler, b []byte, order binary.ByteOrder) error
FromBytes unmarshals b into obj in the given byte order.
func FromLittleEndian ¶
func FromLittleEndian(obj Unmarshaler, b []byte) error
FromLittleEndian unmarshals b into obj in little endian byte order.
func FullLineWriter ¶
func FullLineWriter(w LineWriter) io.WriteCloser
FullLineWriter returns an io.Writer that waits for a full line of prints before calling w.Write on one line each.
func MultiWriteCloser ¶
func MultiWriteCloser(w ...io.Writer) io.WriteCloser
MultiWriteCloser is an io.MultiWriter that has an io.Closer and attempts to close those w's that have optional io.Closers.
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 ¶
ReaderAtEqual compares the contents of r1 and r2.
func ToBigEndian ¶
ToBigEndian marshals m to big endian byte order.
func ToLittleEndian ¶
ToLittleEndian marshals m to little endian byte order.
Types ¶
type AlignReader ¶
AlignReader keeps track of how many bytes were read so the reader can be aligned at a future time.
func (*AlignReader) Align ¶
func (r *AlignReader) Align(n int) ([]byte, error)
Align aligns the reader to the given number of bytes and returns the bytes read to pad it.
func (*AlignReader) Read ¶
func (r *AlignReader) Read(b []byte) (int, error)
Read reads from the underlying io.Reader.
func (*AlignReader) ReadByte ¶
func (r *AlignReader) ReadByte() (byte, error)
ReadByte reads one byte from the underlying io.Reader.
type AlignWriter ¶
AlignWriter keeps track of how many bytes were written so the writer can be aligned at a future time.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer implements functions to manipulate byte slices in a zero-copy way.
func (*Buffer) Preallocate ¶
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 ¶
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 ¶
NewBigEndianBuffer returns a new big endian coder for a new buffer.
func NewLittleEndianBuffer ¶
NewLittleEndianBuffer returns a new little endian coder for a new buffer.
func NewNativeEndianBuffer ¶
NewNativeEndianBuffer returns a new native endian coder for a new buffer.
func (*Lexer) Append ¶
Append returns a newly appended n-size Buffer to write to.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) Consume ¶
Consume returns a slice of the next n bytes from the buffer.
Consume gives direct access to the underlying data.
func (*Lexer) CopyN ¶
CopyN returns a copy of the next n bytes.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) FinError ¶
FinError returns an error if an error occurred or if there is more data left to read in the buffer.
func (*Lexer) Read16 ¶
Read16 reads a 16-bit value from the Buffer.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) Read32 ¶
Read32 reads a 32-bit value from the Buffer.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) Read64 ¶
Read64 reads a 64-bit value from the Buffer.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) Read8 ¶
Read8 reads a byte from the Buffer.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) ReadAll ¶
ReadAll Consumes and returns a copy of all remaining bytes in the Buffer.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) ReadBytes ¶
ReadBytes reads exactly len(p) values from the Buffer.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) ReadData ¶
func (l *Lexer) ReadData(data interface{})
ReadData reads the binary representation of data from the buffer.
See binary.Read.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) Write ¶
Write implements io.Writer.Write.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) Write16 ¶
Write16 writes a 16-bit value to the Buffer.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) Write32 ¶
Write32 writes a 32-bit value to the Buffer.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) Write64 ¶
Write64 writes a 64-bit value to the Buffer.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) Write8 ¶
Write8 writes a byte to the Buffer.
If an error occurred, Error() will return a non-nil error.
func (*Lexer) WriteBytes ¶
WriteBytes writes p to the Buffer.
If an error occurred, Error() will return a non-nil error.
type LineWriter ¶
type LineWriter interface { // OneLine is always called with exactly one line of output. OneLine(b []byte) }
LineWriter processes one line of log output at a time.
type Marshaler ¶
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 NewLazyFile ¶
func NewLazyFile(path string) ReadAtCloser
NewLazyFile returns a lazy ReaderAt opened from path.
func NewLazyOpenerAt ¶
func NewLazyOpenerAt(open func() (io.ReaderAt, error)) ReadAtCloser
NewLazyOpenerAt returns a lazy io.ReaderAt based on `open`.
type Unmarshaler ¶
Unmarshaler is the interface implemented by an object that can unmarshal a binary representation of itself.
Unmarshal Consumes data from the buffer b.
type WriteNameCloser ¶
WriteNameCloser is the interface that groups Write, Close, and Name methods.
var Discard WriteNameCloser = devNull(0)
Discard is a WriteNameCloser on which all Write and Close calls succeed without doing anything, and the Name call returns "null".