forked from tolsen/mongonet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wire_delete.go
72 lines (53 loc) · 1.29 KB
/
wire_delete.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
71
72
package mongonet
func (m *DeleteMessage) HasResponse() bool {
return false
}
func (m *DeleteMessage) IsExhaust() bool {
return false
}
func (m *DeleteMessage) Header() MessageHeader {
return m.header
}
func (m *DeleteMessage) Serialize() []byte {
size := 16 /* header */ + 8 /* update header */
size += len(m.Namespace) + 1
size += int(m.Filter.Size)
m.header.Size = int32(size)
buf := make([]byte, size)
m.header.WriteInto(buf)
loc := 16
writeInt32(0, buf, loc)
loc += 4
writeCString(m.Namespace, buf, &loc)
writeInt32(m.Flags, buf, loc)
loc += 4
m.Filter.Copy(&loc, buf)
return buf
}
func parseDeleteMessage(header MessageHeader, buf []byte) (Message, error) {
m := &DeleteMessage{}
m.header = header
var err error
loc := 0
if len(buf) < 4 {
return m, NewStackErrorf("invalid delete message -- message must have length of at least 4 bytes.")
}
m.Reserved = readInt32(buf[loc:])
loc += 4
m.Namespace, err = readCString(buf[loc:])
if err != nil {
return m, err
}
loc += len(m.Namespace) + 1
if len(buf) < loc+4 {
return m, NewStackErrorf("invalid delete message -- message length is too short.")
}
m.Flags = readInt32(buf[loc:])
loc += 4
m.Filter, err = parseSimpleBSON(buf[loc:])
if err != nil {
return m, err
}
loc += int(m.Filter.Size)
return m, nil
}