forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zknode_bson.go
83 lines (74 loc) · 2.14 KB
/
zknode_bson.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
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zk
// DO NOT EDIT.
// FILE GENERATED BY BSONGEN.
import (
"bytes"
"github.com/youtube/vitess/go/bson"
"github.com/youtube/vitess/go/bytes2"
)
// MarshalBson bson-encodes ZkNode.
func (zkNode *ZkNode) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
bson.EncodeOptionalPrefix(buf, bson.Object, key)
lenWriter := bson.NewLenWriter(buf)
bson.EncodeString(buf, "Path", zkNode.Path)
bson.EncodeString(buf, "Data", zkNode.Data)
zkNode.Stat.MarshalBson(buf, "Stat")
// []string
{
bson.EncodePrefix(buf, bson.Array, "Children")
lenWriter := bson.NewLenWriter(buf)
for _i, _v1 := range zkNode.Children {
bson.EncodeString(buf, bson.Itoa(_i), _v1)
}
lenWriter.Close()
}
bson.EncodeBool(buf, "Cached", zkNode.Cached)
bson.EncodeBool(buf, "Stale", zkNode.Stale)
lenWriter.Close()
}
// UnmarshalBson bson-decodes into ZkNode.
func (zkNode *ZkNode) UnmarshalBson(buf *bytes.Buffer, kind byte) {
switch kind {
case bson.EOO, bson.Object:
// valid
case bson.Null:
return
default:
panic(bson.NewBsonError("unexpected kind %v for ZkNode", kind))
}
bson.Next(buf, 4)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
switch bson.ReadCString(buf) {
case "Path":
zkNode.Path = bson.DecodeString(buf, kind)
case "Data":
zkNode.Data = bson.DecodeString(buf, kind)
case "Stat":
zkNode.Stat.UnmarshalBson(buf, kind)
case "Children":
// []string
if kind != bson.Null {
if kind != bson.Array {
panic(bson.NewBsonError("unexpected kind %v for zkNode.Children", kind))
}
bson.Next(buf, 4)
zkNode.Children = make([]string, 0, 8)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
bson.SkipIndex(buf)
var _v1 string
_v1 = bson.DecodeString(buf, kind)
zkNode.Children = append(zkNode.Children, _v1)
}
}
case "Cached":
zkNode.Cached = bson.DecodeBool(buf, kind)
case "Stale":
zkNode.Stale = bson.DecodeBool(buf, kind)
default:
bson.Skip(buf, kind)
}
}
}