示例#1
0
// MarshalBson bson-encodes QueryResult.
func (queryResult *QueryResult) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	// []Field
	{
		bson.EncodePrefix(buf, bson.Array, "Fields")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v1 := range queryResult.Fields {
			_v1.MarshalBson(buf, bson.Itoa(_i))
		}
		lenWriter.Close()
	}
	bson.EncodeUint64(buf, "RowsAffected", queryResult.RowsAffected)
	bson.EncodeUint64(buf, "InsertId", queryResult.InsertId)
	// [][]sqltypes.Value
	{
		bson.EncodePrefix(buf, bson.Array, "Rows")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v2 := range queryResult.Rows {
			// []sqltypes.Value
			{
				bson.EncodePrefix(buf, bson.Array, bson.Itoa(_i))
				lenWriter := bson.NewLenWriter(buf)
				for _i, _v3 := range _v2 {
					_v3.MarshalBson(buf, bson.Itoa(_i))
				}
				lenWriter.Close()
			}
		}
		lenWriter.Close()
	}

	lenWriter.Close()
}
示例#2
0
文件: bson.go 项目: rudyLi/vitess
func (qr *QueryResult) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	EncodeFieldsBson(qr.Fields, "Fields", buf)
	bson.EncodeUint64(buf, "RowsAffected", qr.RowsAffected)
	bson.EncodeUint64(buf, "InsertId", qr.InsertId)
	EncodeRowsBson(qr.Rows, "Rows", buf)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#3
0
func (session *Session) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Long, "TransactionId")
	bson.EncodeUint64(buf, uint64(session.TransactionId))

	bson.EncodePrefix(buf, bson.Long, "ConnectionId")
	bson.EncodeUint64(buf, uint64(session.ConnectionId))

	bson.EncodePrefix(buf, bson.Long, "SessionId")
	bson.EncodeUint64(buf, uint64(session.SessionId))

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#4
0
func (pos *BinlogPosition) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Object, "Position")
	pos.Position.MarshalBson(buf)

	bson.EncodePrefix(buf, bson.Long, "Timestamp")
	bson.EncodeUint64(buf, uint64(pos.Timestamp))

	bson.EncodePrefix(buf, bson.Ulong, "Xid")
	bson.EncodeUint64(buf, pos.Xid)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#5
0
// MarshalBson bson-encodes QueryResult.
func (queryResult *QueryResult) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	// []*query.Field
	{
		bson.EncodePrefix(buf, bson.Array, "Fields")
		lenWriter := bson.NewLenWriter(buf)
		var f BSONField
		for _i, _v1 := range queryResult.Fields {
			// *query.Field
			// This part was manually changed.
			f.Name = _v1.Name
			f.Type, f.Flags = sqltypes.TypeToMySQL(_v1.Type)
			bson.EncodeOptionalPrefix(buf, bson.Object, bson.Itoa(_i))
			bson.MarshalToBuffer(buf, &f)
		}
		lenWriter.Close()
	}
	bson.EncodeUint64(buf, "RowsAffected", queryResult.RowsAffected)
	bson.EncodeUint64(buf, "InsertId", queryResult.InsertId)
	// [][]sqltypes.Value
	{
		bson.EncodePrefix(buf, bson.Array, "Rows")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v2 := range queryResult.Rows {
			// []sqltypes.Value
			{
				bson.EncodePrefix(buf, bson.Array, bson.Itoa(_i))
				lenWriter := bson.NewLenWriter(buf)
				for _i, _v3 := range _v2 {
					_v3.MarshalBson(buf, bson.Itoa(_i))
				}
				lenWriter.Close()
			}
		}
		lenWriter.Close()
	}
	// *RPCError
	if queryResult.Err == nil {
		bson.EncodePrefix(buf, bson.Null, "Err")
	} else {
		(*queryResult.Err).MarshalBson(buf, "Err")
	}

	lenWriter.Close()
}
示例#6
0
func (pos *BinlogPosition) encodeReplCoordinates(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Binary, "RelayFilename")
	bson.EncodeString(buf, pos.Position.RelayFilename)

	bson.EncodePrefix(buf, bson.Ulong, "RelayPosition")
	bson.EncodeUint64(buf, pos.Position.RelayPosition)

	bson.EncodePrefix(buf, bson.Binary, "MasterFilename")
	bson.EncodeString(buf, pos.Position.MasterFilename)

	bson.EncodePrefix(buf, bson.Ulong, "MasterPosition")
	bson.EncodeUint64(buf, pos.Position.MasterPosition)
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#7
0
// MarshalBson marshals request to the given writer with optional prefix
func (req *RequestBson) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeString(buf, "ServiceMethod", req.ServiceMethod)
	bson.EncodeUint64(buf, "Seq", req.Seq)

	lenWriter.Close()
}
示例#8
0
func (qr *QueryResult) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Array, "Fields")
	encodeFieldsBson(qr.Fields, buf)

	bson.EncodePrefix(buf, bson.Long, "RowsAffected")
	bson.EncodeUint64(buf, uint64(qr.RowsAffected))

	bson.EncodePrefix(buf, bson.Long, "InsertId")
	bson.EncodeUint64(buf, uint64(qr.InsertId))

	bson.EncodePrefix(buf, bson.Array, "Rows")
	encodeRowsBson(qr.Rows, buf)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#9
0
// MarshalBson bson-encodes QueryResult.
func (queryResult *QueryResult) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	// []mproto.Field
	{
		bson.EncodePrefix(buf, bson.Array, "Fields")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v1 := range queryResult.Fields {
			_v1.MarshalBson(buf, bson.Itoa(_i))
		}
		lenWriter.Close()
	}
	bson.EncodeUint64(buf, "RowsAffected", queryResult.RowsAffected)
	bson.EncodeUint64(buf, "InsertId", queryResult.InsertId)
	// [][]sqltypes.Value
	{
		bson.EncodePrefix(buf, bson.Array, "Rows")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v2 := range queryResult.Rows {
			// []sqltypes.Value
			{
				bson.EncodePrefix(buf, bson.Array, bson.Itoa(_i))
				lenWriter := bson.NewLenWriter(buf)
				for _i, _v3 := range _v2 {
					_v3.MarshalBson(buf, bson.Itoa(_i))
				}
				lenWriter.Close()
			}
		}
		lenWriter.Close()
	}
	// *Session
	if queryResult.Session == nil {
		bson.EncodePrefix(buf, bson.Null, "Session")
	} else {
		(*queryResult.Session).MarshalBson(buf, "Session")
	}
	bson.EncodeString(buf, "Error", queryResult.Error)

	lenWriter.Close()
}
示例#10
0
func (resp *ResponseBson) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeString(buf, "ServiceMethod", resp.ServiceMethod)
	bson.EncodeUint64(buf, "Seq", resp.Seq)
	bson.EncodeString(buf, "Error", resp.Error)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#11
0
// MarshalBson marshals QueryResult into buf.
func (qr *QueryResult) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	mproto.EncodeFieldsBson(qr.Fields, "Fields", buf)
	bson.EncodeUint64(buf, "RowsAffected", qr.RowsAffected)
	bson.EncodeUint64(buf, "InsertId", qr.InsertId)
	mproto.EncodeRowsBson(qr.Rows, "Rows", buf)

	if qr.Session != nil {
		qr.Session.MarshalBson(buf, "Session")
	}

	if qr.Error != "" {
		bson.EncodeString(buf, "Error", qr.Error)
	}

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#12
0
func (query *Query) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Binary, "Sql")
	bson.EncodeString(buf, query.Sql)

	bson.EncodePrefix(buf, bson.Object, "BindVariables")
	query.encodeBindVariablesBson(buf)

	bson.EncodePrefix(buf, bson.Long, "TransactionId")
	bson.EncodeUint64(buf, uint64(query.TransactionId))

	bson.EncodePrefix(buf, bson.Long, "ConnectionId")
	bson.EncodeUint64(buf, uint64(query.ConnectionId))

	bson.EncodePrefix(buf, bson.Long, "SessionId")
	bson.EncodeUint64(buf, uint64(query.SessionId))

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#13
0
func MarshalFieldBson(field Field, buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Binary, "Name")
	bson.EncodeString(buf, field.Name)

	bson.EncodePrefix(buf, bson.Long, "Type")
	bson.EncodeUint64(buf, uint64(field.Type))

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#14
0
func (req *RequestBson) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Binary, "ServiceMethod")
	bson.EncodeString(buf, req.ServiceMethod)

	bson.EncodePrefix(buf, bson.Long, "Seq")
	bson.EncodeUint64(buf, uint64(req.Seq))

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#15
0
func (zkStat *ZkStat) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Long, "Czxid")
	bson.EncodeUint64(buf, uint64(zkStat.czxid))

	bson.EncodePrefix(buf, bson.Long, "Mzxid")
	bson.EncodeUint64(buf, uint64(zkStat.mzxid))

	bson.EncodePrefix(buf, bson.Datetime, "CTime")
	bson.EncodeTime(buf, zkStat.cTime)

	bson.EncodePrefix(buf, bson.Datetime, "MTime")
	bson.EncodeTime(buf, zkStat.mTime)

	bson.EncodePrefix(buf, bson.Int, "Version")
	bson.EncodeUint32(buf, uint32(zkStat.version))

	bson.EncodePrefix(buf, bson.Int, "CVersion")
	bson.EncodeUint32(buf, uint32(zkStat.cVersion))

	bson.EncodePrefix(buf, bson.Int, "AVersion")
	bson.EncodeUint32(buf, uint32(zkStat.aVersion))

	bson.EncodePrefix(buf, bson.Long, "EphemeralOwner")
	bson.EncodeUint64(buf, uint64(zkStat.ephemeralOwner))

	bson.EncodePrefix(buf, bson.Int, "DataLength")
	bson.EncodeUint32(buf, uint32(zkStat.dataLength))

	bson.EncodePrefix(buf, bson.Int, "NumChildren")
	bson.EncodeUint32(buf, uint32(zkStat.numChildren))

	bson.EncodePrefix(buf, bson.Long, "Pzxid")
	bson.EncodeUint64(buf, uint64(zkStat.pzxid))

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#16
0
func (repl *ReplicationCoordinates) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Binary, "MasterFilename")
	bson.EncodeString(buf, repl.MasterFilename)

	bson.EncodePrefix(buf, bson.Ulong, "MasterPosition")
	bson.EncodeUint64(buf, repl.MasterPosition)

	bson.EncodePrefix(buf, bson.Binary, "GroupId")
	bson.EncodeString(buf, repl.GroupId)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#17
0
func (bqs *BatchQueryShard) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Array, "Queries")
	encodeQueriesBson(bqs.Queries, buf)

	bson.EncodePrefix(buf, bson.Long, "SessionId")
	bson.EncodeUint64(buf, uint64(bqs.SessionId))

	bson.EncodePrefix(buf, bson.Binary, "Keyspace")
	bson.EncodeString(buf, bqs.Keyspace)

	bson.EncodeStringArray(buf, "Shards", bqs.Shards)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
示例#18
0
// MarshalBson bson-encodes MyType.
func (myType *MyType) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeFloat64(buf, "Float64", myType.Float64)
	bson.EncodeString(buf, "String", myType.String)
	bson.EncodeBool(buf, "Bool", myType.Bool)
	bson.EncodeInt64(buf, "Int64", myType.Int64)
	bson.EncodeInt32(buf, "Int32", myType.Int32)
	bson.EncodeInt(buf, "Int", myType.Int)
	bson.EncodeUint64(buf, "Uint64", myType.Uint64)
	bson.EncodeUint32(buf, "Uint32", myType.Uint32)
	bson.EncodeUint(buf, "Uint", myType.Uint)
	bson.EncodeBinary(buf, "Bytes", myType.Bytes)
	bson.EncodeTime(buf, "Time", myType.Time)
	bson.EncodeInterface(buf, "Interface", myType.Interface)

	lenWriter.Close()
}
示例#19
0
func (qrs *QueryShard) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodePrefix(buf, bson.Binary, "Sql")
	bson.EncodeString(buf, qrs.Sql)

	bson.EncodePrefix(buf, bson.Object, "BindVariables")
	vproto.EncodeBindVariablesBson(buf, qrs.BindVariables)

	bson.EncodePrefix(buf, bson.Long, "SessionId")
	bson.EncodeUint64(buf, uint64(qrs.SessionId))

	bson.EncodePrefix(buf, bson.Binary, "Keyspace")
	bson.EncodeString(buf, qrs.Keyspace)

	bson.EncodeStringArray(buf, "Shards", qrs.Shards)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}