forked from davyxu/tabtoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabreader.go
58 lines (44 loc) · 1.01 KB
/
tabreader.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
package tabtoy
import "encoding/binary"
type binaryReader struct {
buf []byte
}
func (self *binaryReader) ReadBool(x *bool) {
n := self.buf[0]
self.buf = self.buf[1:]
*x = n != 0
}
func (self *binaryReader) ReadUInt16(x *uint16) {
*x = binary.LittleEndian.Uint16(self.buf[0:2])
self.buf = self.buf[2:]
}
func (self *binaryReader) ReadUInt32(x *uint32) {
*x = binary.LittleEndian.Uint32(self.buf[0:4])
self.buf = self.buf[4:]
}
func (self *binaryReader) ReadUInt64(x *uint64) {
*x = binary.LittleEndian.Uint64(self.buf[0:8])
self.buf = self.buf[8:]
}
func (self *binaryReader) ReadBytes(x *[]byte) {
var l uint16
self.ReadUInt16(&l)
*x = make([]byte, l)
copy(*x, self.buf[0:l])
self.buf = self.buf[l:]
}
func (self *binaryReader) ReadInt16(x *int16) {
var v uint16
self.ReadUInt16(&v)
*x = int16(v)
}
func (self *binaryReader) ReadInt32(x *int32) {
var v uint32
self.ReadUInt32(&v)
*x = int32(v)
}
func (self *binaryReader) ReadInt64(x *int64) {
var v uint64
self.ReadUInt64(&v)
*x = int64(v)
}