forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xdr.go
59 lines (49 loc) · 1.14 KB
/
xdr.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
package nfs
import (
"encoding/binary"
)
type Xdr struct {
data []byte
offset uint32
}
func (xdr *Xdr) getInt() int32 {
i := int32(binary.BigEndian.Uint32(xdr.data[xdr.offset : xdr.offset+4]))
xdr.offset += 4
return int32(i)
}
func (xdr *Xdr) getUInt() uint32 {
i := uint32(binary.BigEndian.Uint32(xdr.data[xdr.offset : xdr.offset+4]))
xdr.offset += 4
return i
}
func (xdr *Xdr) getHyper() int64 {
i := int64(binary.BigEndian.Uint64(xdr.data[xdr.offset : xdr.offset+8]))
xdr.offset += 8
return i
}
func (xdr *Xdr) getUHyper() uint64 {
i := uint64(binary.BigEndian.Uint64(xdr.data[xdr.offset : xdr.offset+8]))
xdr.offset += 8
return i
}
func (xdr *Xdr) getString() string {
return string(xdr.getDynamicOpaque())
}
func (xdr *Xdr) getOpaque(length uint32) []byte {
padding := (4 - (length & 3)) & 3
b := xdr.data[xdr.offset : xdr.offset+length]
xdr.offset += length + padding
return b
}
func (xdr *Xdr) getDynamicOpaque() []byte {
l := xdr.getUInt()
return xdr.getOpaque(l)
}
func (xdr *Xdr) getUIntVector() []uint32 {
l := xdr.getUInt()
v := make([]uint32, int(l))
for i := 0; i < len(v); i++ {
v[i] = xdr.getUInt()
}
return v
}