-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
38 lines (30 loc) · 1 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
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
*/
package bitio