BinaryWriter is the interface that implements writer.BitWriter, io.Writer and io.ByteWriter.
type BinaryWriter interface { BitWriter io.Writer io.ByteWriter Data() []byte }
BitWriter is the interface that allows to write single bits.
type BitWriter interface { // WriteBit writes the 'bit' - {0,1} value to the writer. WriteBit(bit int) error // WriteBits writes 'number' of 'bits'. WriteBits(bits uint64, number int) (n int, err error) // FinishByte sets the bitIndex to the end of given byte. This resets the bitIndex to 0 // and the byte index to the next byte. FinishByte() // SkipBits skips the 'skip' number of bits in the writer - changes the index position of the bit and byte. // The value -1 sets the bitIndex to the beginning of the byte. SkipBits(skip int) error }
BufferedWriter is the Writer implementation that works on expandable data slices.
type BufferedWriter struct {
// contains filtered or unexported fields
}
func BufferedMSB() *BufferedWriter
BufferedMSB creates a buffered writer with MSB bit writing method.
func (b *BufferedWriter) Data() []byte
Data gets the buffer byte slice data. The buffer is the owner of the byte slice data, thus the data is available until next buffer Reset.
func (b *BufferedWriter) FinishByte()
FinishByte finishes current bit written byte and sets the current byte index pointe to the next byte.
func (b *BufferedWriter) Len() int
Len returns the number of bytes of the unwritten portion of the buffer.
func (b *BufferedWriter) Reset()
Reset resets the data buffer as well as the bit and byte indexes.
func (b *BufferedWriter) ResetBitIndex()
ResetBitIndex resets the current bit index.
func (b *BufferedWriter) SkipBits(skip int) error
SkipBits implements BitWriter interface.
func (b *BufferedWriter) Write(d []byte) (int, error)
Write implements io.Writer interface.
func (b *BufferedWriter) WriteBit(bit int) error
WriteBit implements BitWriter interface.
func (b *BufferedWriter) WriteBits(bits uint64, number int) (n int, err error)
WriteBits writes 'bits' values of a specific 'number' into the writer.BufferedWriter.
func (b *BufferedWriter) WriteByte(bt byte) error
WriteByte implements io.ByteWriter.
Reader is the bit reader implementation. Implements io.Reader, io.ByteReader, io.Seeker interfaces.
type Reader struct {
// contains filtered or unexported fields
}
func NewReader(data []byte) *Reader
NewReader creates a new reader.Reader using the byte slice data as input.
func (r *Reader) Align() (skipped byte)
Align implements StreamReader interface.
func (r *Reader) BitPosition() int
BitPosition implements StreamReader inteface.
func (r *Reader) ConsumeRemainingBits()
ConsumeRemainingBits consumes the remaining bits from the given reader.
func (r *Reader) Length() uint64
Length implements StreamReader interface.
func (r *Reader) Mark()
Mark implements StreamReader interface.
func (r *Reader) Read(p []byte) (n int, err error)
Read implements io.Reader interface.
func (r *Reader) ReadBit() (bit int, err error)
ReadBit implements StreamReader interface.
func (r *Reader) ReadBits(n byte) (u uint64, err error)
ReadBits implements StreamReader interface.
func (r *Reader) ReadBool() (bool, error)
ReadBool implements StreamReader interface.
func (r *Reader) ReadByte() (byte, error)
ReadByte implements io.ByteReader.
func (r *Reader) ReadUint32() (uint32, error)
ReadUint32 implements StreamReader interface.
func (r *Reader) Reset()
Reset implements StreamReader interface.
func (r *Reader) Seek(offset int64, whence int) (int64, error)
Seek implements the io.Seeker interface.
func (r *Reader) StreamPosition() int64
StreamPosition implements StreamReader interface.
StreamReader is the interface that allows to read bit, bits, byte, bytes, integers change and get the stream position, align the bits.
type StreamReader interface { io.Reader io.ByteReader io.Seeker // Align resets the bits position of the given reader. // It returns how many bits left were skipped. Align() byte // BitPosition gets the current bit position. BitPosition() int // Mark marks a position in the stream to be returned to by a subsequent call to 'Reset'. Mark() // Length returns the length of the total data used by the reader. Length() uint64 // ReadBit reads the next binary value from the current cache. // Equivalent of ReadBool method but returns an integer. ReadBit() (int, error) // ReadBits reads the bits of size 'n' from the reader. ReadBits(n byte) (uint64, error) // ReadBool reads the next binary value from the current cache. ReadBool() (bool, error) // ReadUint32 reads the unsigned uint32 from the reader. ReadUint32() (uint32, error) // Reset returns the stream pointer to its previous position, including the bit offset, // at the time of the most recent unmatched call to mark. Reset() // StreamPosition gets the stream position of the stream reader. StreamPosition() int64 }
SubstreamReader is the wrapper over the Reader's parts that is allowed only to operate on the selected data space.
type SubstreamReader struct {
// contains filtered or unexported fields
}
func NewSubstreamReader(r StreamReader, offset, length uint64) (*SubstreamReader, error)
NewSubstreamReader creates new SubStreamReader for the provided wrapped StreamReader 'r' with defined 'offset' and 'length'.
func (s *SubstreamReader) Align() (skipped byte)
Align implements StreamReader interface.
func (s *SubstreamReader) BitPosition() int
BitPosition implements StreamReader interface.
func (s *SubstreamReader) Length() uint64
Length implements StreamReader interface.
func (s *SubstreamReader) Mark()
Mark implements StreamReader interface.
func (s *SubstreamReader) Offset() uint64
Offset returns current SubstreamReader offset.
func (s *SubstreamReader) Read(b []byte) (n int, err error)
Read implements io.Reader interface.
func (s *SubstreamReader) ReadBit() (bit int, err error)
ReadBit implements StreamReader interface.
func (s *SubstreamReader) ReadBits(n byte) (u uint64, err error)
ReadBits implements StreamReader interface.
func (s *SubstreamReader) ReadBool() (bool, error)
ReadBool implements StreamReader interface.
func (s *SubstreamReader) ReadByte() (byte, error)
ReadByte implements io.ByteReader.
func (s *SubstreamReader) ReadUint32() (uint32, error)
ReadUint32 implements Streamreader interface.
func (s *SubstreamReader) Reset()
Reset implements StreamReader interface.
func (s *SubstreamReader) Seek(offset int64, whence int) (int64, error)
Seek implements the io.Seeker interface.
func (s *SubstreamReader) StreamPosition() int64
StreamPosition implements StreamReader interface.
Writer is the structure used to write bits, bytes into predefined data. It allows to write the bits in two modes. The first and default writes bytes with the initial bitIndex 0 as the LSB (Least Significant Bit) The second mode writes bits in an opposite manner starting from the MSB (Most Significant Bit). The writer is being created by the methods: 'NewWriter' and 'NewWriterMSB', where the first creates default writer and the second the 'msb' flagged writer. Implements io.Writer, io.ByteWriter interfaces.
type Writer struct {
// contains filtered or unexported fields
}
func NewWriter(data []byte) *Writer
NewWriter creates new writer for the provided data.
func NewWriterMSB(data []byte) *Writer
NewWriterMSB creates new writer with the msb flag. While default writer writes single bits into LSB, the msbWriter writes single bits starting from the MSB. Example:
InverseWriter contains following data: data - 10010100 01001110 00000000 ^ The default current bit index is pointed by '^'. Writing new '1' bit to the following data would result as: data - 10010100 01001110 10000000
func (w *Writer) Data() []byte
Data gets the writer data.
func (w *Writer) FinishByte()
FinishByte implements BitWriter interface.
func (w *Writer) ResetBit()
ResetBit resets the bit counter setting it to '0'.
func (w *Writer) SkipBits(skip int) error
SkipBits implements BitWriter interface.
func (w *Writer) UseMSB() bool
UseMSB gets the writer flag if it works on the MSB mode.
func (w *Writer) Write(p []byte) (int, error)
Write implements io.Writer interface.
func (w *Writer) WriteBit(bit int) error
WriteBit writes single bit into provided bit writer data.
func (w *Writer) WriteBits(bits uint64, number int) (n int, err error)
WriteBits writes the 'bits' of the specific 'number' into writer.
func (w *Writer) WriteByte(c byte) error
WriteByte implements io.ByteWriter interface.