Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrOutOfRange = errors.New("index out of range") ErrInvalidBitValue = errors.New("invalid bit value") )
var ErrNotEnoughBits = errors.New("not enough bits")
Functions ¶
This section is empty.
Types ¶
type BitStream ¶
type BitStream struct {
// contains filtered or unexported fields
}
BitStream represents a sequence of bits storedd in a byte slice.
func FromFileWithLimit ¶
FromFileWithLimit reads a file containing a list of numbers and returns a Bitstream. It only reads the first 'limit' lines from the file.
func NewBitStream ¶
NewBitStream creates a new Bitstream from the provided byte slice.
func (*BitStream) Append ¶
Append appends a bit to the end of the bitstream. It returns an error if the provided bit value is not 0 or 1.
func (*BitStream) Bit ¶
Bit returns the bit value at the sepcified index. It returns an error if the index is out of range.
type BitStreamReader ¶
type BitStreamReader struct {
// contains filtered or unexported fields
}
BitStreamReader provides a way to read bits from a Bitstream.
func NewBitStreamReader ¶
func NewBitStreamReader(bs *BitStream) *BitStreamReader
NewBitStreamReader creates a new BitStreamReader from the provided Bitstream.
func (*BitStreamReader) Read ¶
func (r *BitStreamReader) Read(n int) ([]byte, error)
Read reads the specified number of bits from the Bitstream and returns them as a byte slice.
It returns an error if there are not enough bits to read.
func (*BitStreamReader) ReadBit ¶
func (r *BitStreamReader) ReadBit() (byte, error)
ReadBit reads a single bit from the BitStream and returns it as a byte. It returns an error if there are not enough bits to read.
func (*BitStreamReader) ReadByte ¶
func (r *BitStreamReader) ReadByte() (byte, error)
ReadByte reads a 8 bits from the Bitstream and returns them as a byte. It returns an error if there are not enough bits to read.
type BitStreamWriter ¶
type BitStreamWriter struct {
// contains filtered or unexported fields
}
BitStreamWriter provides a way to write bits to a Bitstream.
func NewBitStreamWriter ¶
func NewBitStreamWriter(bs *BitStream) *BitStreamWriter
NewBitStreamWriter creates a new BitStreamWriter from the given Bitstream.
func (*BitStreamWriter) Flush ¶
func (w *BitStreamWriter) Flush() error
Flush writes the buffred bits to the Bitstream. It clears the buffer after writing.
func (*BitStreamWriter) Write ¶
func (w *BitStreamWriter) Write(bits []byte) error
Write writes the provided byte slice to the BitStreamWriter. Each byte is written as 8 individual bits.
func (*BitStreamWriter) WriteBit ¶
func (w *BitStreamWriter) WriteBit(bit byte) error
WriteBit writes a single bit to the BitStreamWriter. It returns an error if the given bit value is not 0 or 1.