-
Notifications
You must be signed in to change notification settings - Fork 19
/
wire_update.go
70 lines (51 loc) · 1.16 KB
/
wire_update.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
package mongonet
func (m *UpdateMessage) HasResponse() bool {
return false
}
func (m *UpdateMessage) Header() MessageHeader {
return m.header
}
func (m *UpdateMessage) Serialize() []byte {
size := 16 /* header */ + 8 /* update header */
size += len(m.Namespace) + 1
size += int(m.Filter.Size)
size += int(m.Update.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)
m.Update.Copy(&loc, buf)
return buf
}
func parseUpdateMessage(header MessageHeader, buf []byte) (Message, error) {
m := &UpdateMessage{}
m.header = header
var err error
loc := 0
m.Reserved = readInt32(buf[loc:])
loc += 4
m.Namespace, err = readCString(buf[loc:])
if err != nil {
return m, err
}
loc += len(m.Namespace) + 1
m.Flags = readInt32(buf[loc:])
loc += 4
m.Filter, err = parseSimpleBSON(buf[loc:])
if err != nil {
return m, err
}
loc += int(m.Filter.Size)
m.Update, err = parseSimpleBSON(buf[loc:])
if err != nil {
return m, err
}
loc += int(m.Filter.Size)
return m, nil
}