Documentation ¶
Overview ¶
Package bitio implements a simple bitwise reader and writer.
The client can use BitReader.ReadBit() to read a bit from an io.ByteReader, and also use BitWriter.WriteBit() to write a bit to an io.ByteWriter. After write with BitWriter.WriteBit(), you must call BitWriter.Flush() or BitWriter.FlushWithOnes().
BitReader examples:
r := NewBitReader(bytes.NewBuffer([]byte{0b10110100})) bit, err := r.ReadBit() // 1, nil bit, err := r.ReadBit() // 0, nil bit, err := r.ReadBit() // 1, nil bit, err := r.ReadBit() // 1, nil bit, err := r.ReadBit() // 0, nil bit, err := r.ReadBit() // 1, nil bit, err := r.ReadBit() // 0, nil bit, err := r.ReadBit() // 0, nil bit, err := r.ReadBit() // 0, io.EOF
BitWriter examples:
buf := new(bytes.Buffer) w := NewBitWriter(buf) defer w.Flush() err := w.WriteBit(1) err := w.WriteBit(0) err := w.WriteBit(1) err := w.WriteBit(1) err := w.WriteBit(0) err := w.WriteBit(1) byte, err := buf.ReadByte() // 0b10110100, nil
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BitReader ¶
type BitReader struct {
// contains filtered or unexported fields
}
BitReader implements a bitwise reader.
func NewBitReader ¶
func NewBitReader(r io.ByteReader) *BitReader
NewBitReader returns a new BitReader. The reader changes the state of br internally.
type BitWriter ¶
type BitWriter struct {
// contains filtered or unexported fields
}
BitWriter implements a bitwise writer. The client should call the Flush or FlushWithOnes method when all data have been written.
func NewBitWriter ¶
func NewBitWriter(w io.ByteWriter) *BitWriter
NewBitWriter returns a new BifWriter. The writer changes the state of w internally.
func (*BitWriter) Flush ¶
Flush writes down an internal buffer with zeros. The client should call this method when the all data have been written.
func (*BitWriter) FlushWithOnes ¶
FlushWithOnes writes down an internal buffer with ones. The client should call this method when the all data have been written.
type NotBitError ¶
type NotBitError struct {
// contains filtered or unexported fields
}
NotBitError will be used when calling WriteBit with an incorrect argument.
func (*NotBitError) Error ¶
func (e *NotBitError) Error() string
Error returns a NotBitError message.