本文整理汇总了Golang中github.com/youtube/vitess/go/sqltypes.Value.UnmarshalBson方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.UnmarshalBson方法的具体用法?Golang Value.UnmarshalBson怎么用?Golang Value.UnmarshalBson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/sqltypes.Value
的用法示例。
在下文中一共展示了Value.UnmarshalBson方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UnmarshalBson
// UnmarshalBson bson-decodes into StreamEvent.
func (streamEvent *StreamEvent) 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 StreamEvent", kind))
}
bson.Next(buf, 4)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
switch bson.ReadCString(buf) {
case "Category":
streamEvent.Category = bson.DecodeString(buf, kind)
case "TableName":
streamEvent.TableName = bson.DecodeString(buf, kind)
case "PrimaryKeyFields":
// []mproto.Field
if kind != bson.Null {
if kind != bson.Array {
panic(bson.NewBsonError("unexpected kind %v for streamEvent.PrimaryKeyFields", kind))
}
bson.Next(buf, 4)
streamEvent.PrimaryKeyFields = make([]mproto.Field, 0, 8)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
bson.SkipIndex(buf)
var _v1 mproto.Field
_v1.UnmarshalBson(buf, kind)
streamEvent.PrimaryKeyFields = append(streamEvent.PrimaryKeyFields, _v1)
}
}
case "PrimaryKeyValues":
// [][]sqltypes.Value
if kind != bson.Null {
if kind != bson.Array {
panic(bson.NewBsonError("unexpected kind %v for streamEvent.PrimaryKeyValues", kind))
}
bson.Next(buf, 4)
streamEvent.PrimaryKeyValues = make([][]sqltypes.Value, 0, 8)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
bson.SkipIndex(buf)
var _v2 []sqltypes.Value
// []sqltypes.Value
if kind != bson.Null {
if kind != bson.Array {
panic(bson.NewBsonError("unexpected kind %v for _v2", kind))
}
bson.Next(buf, 4)
_v2 = make([]sqltypes.Value, 0, 8)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
bson.SkipIndex(buf)
var _v3 sqltypes.Value
_v3.UnmarshalBson(buf, kind)
_v2 = append(_v2, _v3)
}
}
streamEvent.PrimaryKeyValues = append(streamEvent.PrimaryKeyValues, _v2)
}
}
case "Sql":
streamEvent.Sql = bson.DecodeString(buf, kind)
case "Timestamp":
streamEvent.Timestamp = bson.DecodeInt64(buf, kind)
case "TransactionID":
streamEvent.TransactionID = bson.DecodeString(buf, kind)
default:
bson.Skip(buf, kind)
}
}
}
示例2: UnmarshalBson
// UnmarshalBson bson-decodes into QueryResult.
func (queryResult *QueryResult) 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 QueryResult", kind))
}
bson.Next(buf, 4)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
switch bson.ReadCString(buf) {
case "Fields":
// []Field
if kind != bson.Null {
if kind != bson.Array {
panic(bson.NewBsonError("unexpected kind %v for queryResult.Fields", kind))
}
bson.Next(buf, 4)
queryResult.Fields = make([]Field, 0, 8)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
bson.SkipIndex(buf)
var _v1 Field
_v1.UnmarshalBson(buf, kind)
queryResult.Fields = append(queryResult.Fields, _v1)
}
}
case "RowsAffected":
queryResult.RowsAffected = bson.DecodeUint64(buf, kind)
case "InsertId":
queryResult.InsertId = bson.DecodeUint64(buf, kind)
case "Rows":
// [][]sqltypes.Value
if kind != bson.Null {
if kind != bson.Array {
panic(bson.NewBsonError("unexpected kind %v for queryResult.Rows", kind))
}
bson.Next(buf, 4)
queryResult.Rows = make([][]sqltypes.Value, 0, 8)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
bson.SkipIndex(buf)
var _v2 []sqltypes.Value
// []sqltypes.Value
if kind != bson.Null {
if kind != bson.Array {
panic(bson.NewBsonError("unexpected kind %v for _v2", kind))
}
bson.Next(buf, 4)
_v2 = make([]sqltypes.Value, 0, 8)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
bson.SkipIndex(buf)
var _v3 sqltypes.Value
_v3.UnmarshalBson(buf, kind)
_v2 = append(_v2, _v3)
}
}
queryResult.Rows = append(queryResult.Rows, _v2)
}
}
default:
bson.Skip(buf, kind)
}
}
}
示例3: UnmarshalBson
// UnmarshalBson bson-decodes into QueryResult.
func (queryResult *QueryResult) 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 QueryResult", kind))
}
bson.Next(buf, 4)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
switch bson.ReadCString(buf) {
case "Fields":
// []*query.Field
if kind != bson.Null {
if kind != bson.Array {
panic(bson.NewBsonError("unexpected kind %v for queryResult.Fields", kind))
}
bson.Next(buf, 4)
queryResult.Fields = make([]*querypb.Field, 0, 8)
var f BSONField
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
bson.SkipIndex(buf)
var _v1 *querypb.Field
// *query.Field
_v1 = new(querypb.Field)
bson.UnmarshalFromBuffer(buf, &f)
_v1.Name = f.Name
_v1.Type = sqltypes.MySQLToType(f.Type, f.Flags)
queryResult.Fields = append(queryResult.Fields, _v1)
}
}
case "RowsAffected":
queryResult.RowsAffected = bson.DecodeUint64(buf, kind)
case "InsertId":
queryResult.InsertId = bson.DecodeUint64(buf, kind)
case "Rows":
// [][]sqltypes.Value
if kind != bson.Null {
if kind != bson.Array {
panic(bson.NewBsonError("unexpected kind %v for queryResult.Rows", kind))
}
bson.Next(buf, 4)
queryResult.Rows = make([][]sqltypes.Value, 0, 8)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
bson.SkipIndex(buf)
var _v2 []sqltypes.Value
// []sqltypes.Value
if kind != bson.Null {
if kind != bson.Array {
panic(bson.NewBsonError("unexpected kind %v for _v2", kind))
}
bson.Next(buf, 4)
_v2 = make([]sqltypes.Value, 0, 8)
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
bson.SkipIndex(buf)
var _v3 sqltypes.Value
_v3.UnmarshalBson(buf, kind)
_v2 = append(_v2, _v3)
}
}
queryResult.Rows = append(queryResult.Rows, _v2)
}
}
case "Err":
// *RPCError
if kind != bson.Null {
queryResult.Err = new(RPCError)
(*queryResult.Err).UnmarshalBson(buf, kind)
}
default:
bson.Skip(buf, kind)
}
}
}