-
Notifications
You must be signed in to change notification settings - Fork 1
/
writer.go
52 lines (42 loc) · 1.01 KB
/
writer.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package fdelta
var zDigits = [...]rune{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', '~',
}
type writer struct {
a []byte
}
func newWriter() *writer {
return &writer{
a: make([]byte, 0),
}
}
func (writer *writer) PutChar(c rune) {
writer.a = append(writer.a, byte(c))
}
func (writer *writer) PutInt(v uint32) {
var i, j int
zBuf := make([]uint32, 20)
if v == 0 {
writer.PutChar('0')
return
}
for i = 0; v > 0; i++ {
zBuf[i] = uint32(zDigits[v&0x3f])
v >>= 6
}
for j = i - 1; j >= 0; j-- {
writer.a = append(writer.a, byte(zBuf[j]))
}
}
func (writer *writer) PutArray(a []byte, start, end int) {
for i := start; i < end; i++ {
writer.a = append(writer.a, a[i])
}
}
func (writer *writer) ToArray() []byte {
return writer.a
}