forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_custom.go
75 lines (65 loc) · 1.71 KB
/
output_custom.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
// 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 mytype
import (
"github.com/youtube/vitess/go/bytes2"
"bytes"
"github.com/youtube/vitess/go/bson"
)
// DO NOT EDIT.
// FILE GENERATED BY BSONGEN.
// MarshalBson bson-encodes MyType.
func (myType *MyType) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
bson.EncodeOptionalPrefix(buf, bson.Object, key)
lenWriter := bson.NewLenWriter(buf)
myType.Cust1.MarshalBson(buf, "Cust1")
// *Custom1
if myType.Cust2 == nil {
bson.EncodePrefix(buf, bson.Null, "Cust2")
} else {
(*myType.Cust2).MarshalBson(buf, "Cust2")
}
myType.Cust3.MarshalBson(buf, "Cust3")
// *pkg.Custom2
if myType.Cust4 == nil {
bson.EncodePrefix(buf, bson.Null, "Cust4")
} else {
(*myType.Cust4).MarshalBson(buf, "Cust4")
}
lenWriter.Close()
}
// UnmarshalBson bson-decodes into MyType.
func (myType *MyType) 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 MyType", kind))
}
bson.Next(buf, 4)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
switch bson.ReadCString(buf) {
case "Cust1":
myType.Cust1.UnmarshalBson(buf, kind)
case "Cust2":
// *Custom1
if kind != bson.Null {
myType.Cust2 = new(Custom1)
(*myType.Cust2).UnmarshalBson(buf, kind)
}
case "Cust3":
myType.Cust3.UnmarshalBson(buf, kind)
case "Cust4":
// *pkg.Custom2
if kind != bson.Null {
myType.Cust4 = new(pkg.Custom2)
(*myType.Cust4).UnmarshalBson(buf, kind)
}
default:
bson.Skip(buf, kind)
}
}
}