Documentation
¶
Overview ¶
Package binarystreams is an abstraction on stream reading and writing to support processing standard data types (int, string, float, etc.) from/to binary streams.
Index ¶
- type Reader
- func (r *Reader) IsEOF() bool
- func (r *Reader) PeekByte() (byte, error)
- func (r *Reader) ReadByte() (byte, error)
- func (r *Reader) ReadBytes(numBytes int) ([]byte, error)
- func (r *Reader) ReadFloat32() (float32, error)
- func (r *Reader) ReadFloat64() (float64, error)
- func (r *Reader) ReadInt8() (int8, error)
- func (r *Reader) ReadInt16() (int16, error)
- func (r *Reader) ReadInt32() (int32, error)
- func (r *Reader) ReadString(numChars int) (string, error)
- func (r *Reader) ReadStringToTerminator(terminator byte) (string, uint32, error)
- func (r *Reader) ReadUInt8() (uint8, error)
- func (r *Reader) ReadUInt16() (uint16, error)
- func (r *Reader) ReadUInt32() (uint32, error)
- func (r *Reader) ReadUInt64() (uint64, error)
- func (r *Reader) ReadUint64String(numChars int) (uint64, error)
- func (r *Reader) ReadWideStringToTerminator(terminator uint16) (string, uint32, error)
- func (r *Reader) SkipBytes(count int) error
- func (r *Reader) Slice(count int) (*Reader, error)
- type Writer
- func (w *Writer) Flush() error
- func (w *Writer) WriteByte(b byte) error
- func (w *Writer) WriteBytes(bytes []byte) error
- func (w *Writer) WriteFloat32(v float32) error
- func (w *Writer) WriteFloat64(v float64) error
- func (w *Writer) WriteInt8(i int8) error
- func (w *Writer) WriteInt16(i int16) error
- func (w *Writer) WriteInt32(i int32) error
- func (w *Writer) WriteUInt8(i uint8) error
- func (w *Writer) WriteUInt16(i uint16) error
- func (w *Writer) WriteUInt32(i uint32) error
- func (w *Writer) WriteUInt64(i uint64) error
- func (w *Writer) WriteUint64String(num uint64, numChars int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader implements a bytestream reader. For now it is LSB only.
func NewReader ¶
NewReader returns a new Reader based on an io.Reader. This will end up opening a bufio.Reader from the handed reader.
func NewReaderFromBytes ¶
NewReaderFromBytes returns a new Reader based on a byte array
func NewReaderFromFile ¶
NewReaderFromFile returns a new Reader based on using os.Open on the passed path. It also returns the opened file object, for you to be able to close when done.
func (*Reader) PeekByte ¶
PeekByte takes advantage of the bufio.Reader to read a byte without moving the underlying stream offset forward (usually called a "Peek" operation).
func (*Reader) ReadBytes ¶
ReadBytes reads a passed number of bytes from the stream and returns them as an array. If anything other than the exact requested number of bytes are read/returned, an error will be returned instead. ReadBytes handles re-issuing underlying IO reads to fill out the entire requested number of bytes.
func (*Reader) ReadFloat32 ¶
ReadFloat32 reads a single float32 from the stream
func (*Reader) ReadFloat64 ¶
ReadFloat64 reads a single float64 from the stream
func (*Reader) ReadString ¶
ReadString reads the passed number of bytes and returns them as a string.
func (*Reader) ReadStringToTerminator ¶
ReadStringToTerminator reads bytes until it runs into the passed terminator byte, and then returns everything up to (but not including) the terminator byte as a string.
func (*Reader) ReadUInt8 ¶
ReadUInt8 returns a single uint8 from the stream (same thing as ReadByte)
func (*Reader) ReadUInt16 ¶
ReadUInt16 returns a single uint16 from the stream
func (*Reader) ReadUInt32 ¶
ReadUInt32 returns a single uint32 from the stream
func (*Reader) ReadUInt64 ¶
ReadUInt64 returns a single uint64 from the stream
func (*Reader) ReadUint64String ¶
ReadUint64String reads the passed number of bytes in as a string and then converts them to a Uint64 with strconv.ParseUint (assumes base 10).
func (*Reader) ReadWideStringToTerminator ¶
ReadWideStringToTerminator reads runes until it runs into the passed terminator rune, and then returns everything up to (but not including) the terminator rune as a string, as well as the length of bytes read.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements a bytestream writer. For now it is LSB only.
func NewMemoryWriter ¶
NewMemoryWriter returns a new Writer that writes to a bytes.Buffer
func NewWriter ¶
NewWriter returns a Writer object from an io.Writer. Note: This will end up building a bufio.Writer from it.
func NewWriterToFile ¶
NewWriterToFile builds a new Writer by calling os.Create on the passed path and handing it to NewWriter. This also returns the underlying *os.File for the caller to manually close when complete.
func (*Writer) Flush ¶
Flush flushes the underlying bufio.Writer stream, so call this before closing a file, if you are using a file stream.
func (*Writer) WriteBytes ¶
WriteBytes writes all of the passed bytes to the underlying stream, erroring if anything other than the entire slice was written out successfully.
func (*Writer) WriteFloat32 ¶
WriteFloat32 writes a float32, in big-endian
func (*Writer) WriteFloat64 ¶
WriteFloat64 writes a float64, in big-endian
func (*Writer) WriteInt16 ¶
WriteInt16 writes a single passed int16 to the underlying stream.
func (*Writer) WriteInt32 ¶
WriteInt32 writes a single passed int32 to the underlying stream.
func (*Writer) WriteUInt8 ¶
WriteUInt8 writes a single passed uint8 to the underlying stream.
func (*Writer) WriteUInt16 ¶
WriteUInt16 writes a single passed uint16 to the underlying stream.
func (*Writer) WriteUInt32 ¶
WriteUInt32 writes a single passed uint32 to the underlying stream.
func (*Writer) WriteUInt64 ¶
WriteUInt64 writes a single passed uint64 to the underlying stream.
func (*Writer) WriteUint64String ¶
WriteUint64String takes a passed (uint64) number, converts it to a string, zero-pads it to make it numChars long, and then writes it out to the underlying stream (passes through to WriteBytes, in fact). If the stringified-number is longer than numChars characters, it will also error -- the intent of numChars is to write out exactly numChars bytes, no more, no fewer.