Documentation ¶
Overview ¶
Package writer contains the data writer that implements io.Writer, io.ByteWriter and allows to write single bits. The writer WriteBit method might be used in a dual way. By default it writes next bit starting from the LSB - least significant bit. By creating the Writer with NewMSB function the writer would write all bits starting from the MSB - most significant bit.
Index ¶
- type BinaryWriter
- type BitWriter
- type Buffer
- func (b *Buffer) Data() []byte
- func (b *Buffer) FinishByte()
- func (b *Buffer) Len() int
- func (b *Buffer) Reset()
- func (b *Buffer) ResetBitIndex()
- func (b *Buffer) SkipBits(skip int) error
- func (b *Buffer) Write(d []byte) (int, error)
- func (b *Buffer) WriteBit(bit int) error
- func (b *Buffer) WriteBits(bits uint64, number int) (n int, err error)
- func (b *Buffer) WriteByte(bt byte) error
- type Writer
- func (w *Writer) Data() []byte
- func (w *Writer) FinishByte()
- func (w *Writer) ResetBit()
- func (w *Writer) SkipBits(skip int) error
- func (w *Writer) UseMSB() bool
- func (w *Writer) Write(p []byte) (int, error)
- func (w *Writer) WriteBit(bit int) error
- func (w *Writer) WriteBits(bits uint64, number int) (n int, err error)
- func (w *Writer) WriteByte(c byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinaryWriter ¶
BinaryWriter is the interface that implements writer.BitWriter, io.Writer and io.ByteWriter.
type BitWriter ¶
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 }
BitWriter is the interface that allows to write single bits.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is the Writer implementation that works on expandable data slices.
func BufferedMSB ¶
func BufferedMSB() *Buffer
BufferedMSB creates a buffered writer with MSB bit writing method.
func (*Buffer) Data ¶
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 (*Buffer) FinishByte ¶
func (b *Buffer) FinishByte()
FinishByte finishes current bit written byte and sets the current byte index pointe to the next byte.
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset resets the data buffer as well as the bit and byte indexes.
func (*Buffer) ResetBitIndex ¶
func (b *Buffer) ResetBitIndex()
ResetBitIndex resets the current bit index.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
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: 'New' and 'NewMSB', where the first creates default writer and the second the 'msb' flagged writer. Implements io.Writer, io.ByteWriter interfaces.
func NewMSB ¶
NewMSB 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 (*Writer) FinishByte ¶
func (w *Writer) FinishByte()
FinishByte implements BitWriter interface.
func (*Writer) ResetBit ¶
func (w *Writer) ResetBit()
ResetBit resets the bit counter setting it to '0'.