forked from tolsen/mongonet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wire_get_more.go
66 lines (49 loc) · 1.22 KB
/
wire_get_more.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
package mongonet
func (m *GetMoreMessage) HasResponse() bool {
return true
}
func (m *GetMoreMessage) IsExhaust() bool {
return false
}
func (m *GetMoreMessage) Header() MessageHeader {
return m.header
}
func (m *GetMoreMessage) Serialize() []byte {
size := 16 /* header */ + 16 /* query header */
size += len(m.Namespace) + 1
m.header.Size = int32(size)
buf := make([]byte, size)
m.header.WriteInto(buf)
writeInt32(0, buf, 16)
loc := 20
writeCString(m.Namespace, buf, &loc)
writeInt32(m.NReturn, buf, loc)
loc += 4
writeInt64(m.CursorId, buf, loc)
loc += 8
return buf
}
func parseGetMoreMessage(header MessageHeader, buf []byte) (Message, error) {
qm := &GetMoreMessage{}
qm.header = header
loc := 0
if len(buf) < 4 {
return qm, NewStackErrorf("invalid get more message -- message must have length of at least 4 bytes.")
}
qm.Reserved = readInt32(buf)
loc += 4
tmp, err := readCString(buf[loc:])
qm.Namespace = tmp
if err != nil {
return nil, err
}
loc += len(qm.Namespace) + 1
if len(buf) < loc+12 {
return qm, NewStackErrorf("invalid get more message -- message length is too short.")
}
qm.NReturn = readInt32(buf[loc:])
loc += 4
qm.CursorId = readInt64(buf[loc:])
loc += 8
return qm, nil
}