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 ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidBitValue defines the error when invalid 'bit' value is provided. ErrInvalidBitValue = errors.New("invalid bit value") )
Functions ¶
This section is empty.
Types ¶
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