-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer.go
70 lines (59 loc) · 1.95 KB
/
buffer.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package vector
import (
"strconv"
)
// BufLen returns length of buffer.
func (vec *Vector) BufLen() int {
return len(vec.buf)
}
// Buf returns raw buffer bytes.
func (vec *Vector) Buf() []byte {
return vec.buf
}
// BufReplaceWith replaces buffer with b.
// Use with caution! Buffer replacing may break copy-versions of parsing methods.
func (vec *Vector) BufReplaceWith(b []byte) {
vec.buf = b
}
// Bufferize appends b to internal buffer and returns buffered value.
func (vec *Vector) Bufferize(b []byte) []byte {
off := vec.BufLen()
vec.buf = append(vec.buf, b...)
return vec.buf[off:]
}
// BufferizeString appends string to internal buffer and returns buffered value.
func (vec *Vector) BufferizeString(s string) []byte {
off := vec.BufLen()
vec.buf = append(vec.buf, s...)
return vec.buf[off:]
}
// BufferizeByte appends b to internal buffer and returns buffered value.
func (vec *Vector) BufferizeByte(b byte) []byte {
off := vec.BufLen()
vec.buf = append(vec.buf, b)
return vec.buf[off:]
}
// BufferizeInt appends integer to internal buffer and returns buffered value.
func (vec *Vector) BufferizeInt(i int64) []byte {
off := vec.BufLen()
vec.buf = strconv.AppendInt(vec.buf, i, 10)
return vec.buf[off:]
}
// BufferizeUint appends unsigned integer to internal buffer and returns buffered value.
func (vec *Vector) BufferizeUint(u uint64) []byte {
off := vec.BufLen()
vec.buf = strconv.AppendUint(vec.buf, u, 10)
return vec.buf[off:]
}
// BufferizeFloat appends unsigned integer to internal buffer and returns buffered value.
func (vec *Vector) BufferizeFloat(f float64) []byte {
off := vec.BufLen()
vec.buf = strconv.AppendFloat(vec.buf, f, 'f', -1, 64)
return vec.buf[off:]
}
// BufferizeFloatTune appends float to internal buffer and returns buffered value.
func (vec *Vector) BufferizeFloatTune(f float64, fmt byte, prec, bitSize int) []byte {
off := vec.BufLen()
vec.buf = strconv.AppendFloat(vec.buf, f, fmt, prec, bitSize)
return vec.buf[off:]
}