-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
56 lines (51 loc) · 1.23 KB
/
get.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
package rpc
import (
"encoding/binary"
)
func (p *Pipe) getBytes(variable *[]byte) error {
var length int32
if err := binary.Read(p.reader, binary.LittleEndian, &length); err != nil {
return err
}
data := make([]byte, length)
if err := binary.Read(p.reader, binary.LittleEndian, &data); err != nil {
return err
}
*variable = data
return nil
}
func (p *Pipe) getInt(variable *int) error {
var value int16
if err := binary.Read(p.reader, binary.LittleEndian, &value); err != nil {
return err
}
*variable = int(value)
return nil
}
func (p *Pipe) getInts(variable *[]int) error {
var length int16
if err := binary.Read(p.reader, binary.LittleEndian, &length); err != nil {
return err
}
*variable = make([]int, length)
for i := 0; i < int(length); i++ {
var value int16
if err := binary.Read(p.reader, binary.LittleEndian, &value); err != nil {
return err
}
(*variable)[i] = int(value)
}
return nil
}
func (p *Pipe) getString(variable *string) error {
var length int32
if err := binary.Read(p.reader, binary.LittleEndian, &length); err != nil {
return err
}
data := make([]byte, length)
if err := binary.Read(p.reader, binary.LittleEndian, &data); err != nil {
return err
}
*variable = string(data)
return nil
}