forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_bson.go
102 lines (93 loc) · 2.68 KB
/
query_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// 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 proto
// DO NOT EDIT.
// FILE GENERATED BY BSONGEN.
import (
"bytes"
"github.com/youtube/vitess/go/bson"
"github.com/youtube/vitess/go/bytes2"
tproto "github.com/youtube/vitess/go/vt/tabletserver/proto"
)
// MarshalBson bson-encodes Query.
func (query *Query) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
bson.EncodeOptionalPrefix(buf, bson.Object, key)
lenWriter := bson.NewLenWriter(buf)
// *tproto.CallerID
if query.CallerID == nil {
bson.EncodePrefix(buf, bson.Null, "CallerID")
} else {
(*query.CallerID).MarshalBson(buf, "CallerID")
}
bson.EncodeString(buf, "Sql", query.Sql)
// map[string]interface{}
{
bson.EncodePrefix(buf, bson.Object, "BindVariables")
lenWriter := bson.NewLenWriter(buf)
for _k, _v1 := range query.BindVariables {
bson.EncodeInterface(buf, _k, _v1)
}
lenWriter.Close()
}
query.TabletType.MarshalBson(buf, "TabletType")
// *Session
if query.Session == nil {
bson.EncodePrefix(buf, bson.Null, "Session")
} else {
(*query.Session).MarshalBson(buf, "Session")
}
bson.EncodeBool(buf, "NotInTransaction", query.NotInTransaction)
lenWriter.Close()
}
// UnmarshalBson bson-decodes into Query.
func (query *Query) 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 Query", kind))
}
bson.Next(buf, 4)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
switch bson.ReadCString(buf) {
case "CallerID":
// *tproto.CallerID
if kind != bson.Null {
query.CallerID = new(tproto.CallerID)
(*query.CallerID).UnmarshalBson(buf, kind)
}
case "Sql":
query.Sql = bson.DecodeString(buf, kind)
case "BindVariables":
// map[string]interface{}
if kind != bson.Null {
if kind != bson.Object {
panic(bson.NewBsonError("unexpected kind %v for query.BindVariables", kind))
}
bson.Next(buf, 4)
query.BindVariables = make(map[string]interface{})
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
_k := bson.ReadCString(buf)
var _v1 interface{}
_v1 = bson.DecodeInterface(buf, kind)
query.BindVariables[_k] = _v1
}
}
case "TabletType":
query.TabletType.UnmarshalBson(buf, kind)
case "Session":
// *Session
if kind != bson.Null {
query.Session = new(Session)
(*query.Session).UnmarshalBson(buf, kind)
}
case "NotInTransaction":
query.NotInTransaction = bson.DecodeBool(buf, kind)
default:
bson.Skip(buf, kind)
}
}
}