Exemplo n.º 1
0
func (qrl *QueryResultList) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)
	EncodeResultsBson(qrl.List, "List", buf)
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 2
0
func EncodeStruct(buf *bytes2.ChunkedWriter, val reflect.Value) {
	// check the Marshaler interface on T
	if marshaler, ok := val.Interface().(Marshaler); ok {
		marshaler.MarshalBson(buf)
		return
	}
	// check the Marshaler interface on *T
	if val.CanAddr() {
		if marshaler, ok := val.Addr().Interface().(Marshaler); ok {
			marshaler.MarshalBson(buf)
			return
		}
	}

	lenWriter := NewLenWriter(buf)
	t := val.Type()
	for i := 0; i < t.NumField(); i++ {
		key := t.Field(i).Name

		// NOTE(szopa): Ignore private fields (copied from
		// encoding/json). Yes, it feels like a hack.
		if t.Field(i).PkgPath != "" {
			continue
		}
		encodeField(buf, key, val.Field(i))
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 3
0
// EncodeString encodes a string.
func EncodeString(buf *bytes2.ChunkedWriter, key string, val string) {
	// Encode strings as binary; go strings are not necessarily unicode
	EncodePrefix(buf, Binary, key)
	putUint32(buf, uint32(len(val)))
	buf.WriteByte(0)
	buf.WriteString(val)
}
Exemplo n.º 4
0
func EncodeBool(buf *bytes2.ChunkedWriter, val bool) {
	if val {
		buf.WriteByte(1)
	} else {
		buf.WriteByte(0)
	}
}
Exemplo n.º 5
0
func (blt *BinlogTransaction) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)
	MarshalStatementsBson(buf, "Statements", blt.Statements)
	bson.EncodeInt64(buf, "GroupId", blt.GroupId)
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 6
0
func (stmt *Statement) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)
	bson.EncodeInt64(buf, "Category", int64(stmt.Category))
	bson.EncodeBinary(buf, "Sql", stmt.Sql)
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 7
0
func (query *Query) encodeBindVariablesBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)
	for k, v := range query.BindVariables {
		bson.EncodeField(buf, k, v)
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 8
0
func (ps *PrivateStruct) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := NewLenWriter(buf)

	EncodeUint64(buf, "Type", ps.veryPrivate)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 9
0
func (blt *BinlogTransaction) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)
	MarshalStatementsBson(buf, "Statements", blt.Statements)
	bson.EncodeInt64(buf, "GroupId", blt.GroupId)
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 10
0
func (stmt *Statement) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)
	bson.EncodeInt(buf, "Category", stmt.Category)
	bson.EncodeBinary(buf, "Sql", stmt.Sql)
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 11
0
func EncodeSlice(buf *bytes2.ChunkedWriter, val reflect.Value) {
	lenWriter := NewLenWriter(buf)
	for i := 0; i < val.Len(); i++ {
		encodeField(buf, Itoa(i), val.Index(i))
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 12
0
func (zkPathV *ZkPathV) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeStringArray(buf, "Paths", zkPathV.Paths)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 13
0
func (zkPath *ZkPath) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeString(buf, "Path", zkPath.Path)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 14
0
func (kp *KeyspacePartition) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	EncodeSrvShardArray(buf, "Shards", kp.Shards)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 15
0
func (zkNodeV *ZkNodeV) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	marshalZkNodeArray(buf, "Nodes", zkNodeV.Nodes)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 16
0
// EncodeBool encodes a bool.
func EncodeBool(buf *bytes2.ChunkedWriter, key string, val bool) {
	EncodePrefix(buf, Boolean, key)
	if val {
		buf.WriteByte(1)
	} else {
		buf.WriteByte(0)
	}
}
Exemplo n.º 17
0
func (ps *PrivateStruct) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	EncodeOptionalPrefix(buf, Object, key)
	lenWriter := NewLenWriter(buf)

	EncodeUint64(buf, "Type", ps.veryPrivate)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 18
0
func MarshalPKRowBson(buf *bytes2.ChunkedWriter, key string, pkRow []interface{}) {
	bson.EncodePrefix(buf, bson.Array, key)
	lenWriter := bson.NewLenWriter(buf)
	for i, v := range pkRow {
		bson.EncodeField(buf, bson.Itoa(i), v)
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 19
0
func MarshalPKValuesBson(buf *bytes2.ChunkedWriter, key string, pkValues [][]interface{}) {
	bson.EncodePrefix(buf, bson.Array, key)
	lenWriter := bson.NewLenWriter(buf)
	for i, row := range pkValues {
		MarshalPKRowBson(buf, bson.Itoa(i), row)
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 20
0
func (req *RequestBson) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeString(buf, "ServiceMethod", req.ServiceMethod)
	bson.EncodeInt64(buf, "Seq", int64(req.Seq))

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 21
0
func EncodeBindVariablesBson(buf *bytes2.ChunkedWriter, key string, bindVars map[string]interface{}) {
	bson.EncodePrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)
	for k, v := range bindVars {
		bson.EncodeField(buf, k, v)
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 22
0
func (bdq *BoundQuery) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeString(buf, "Sql", bdq.Sql)
	EncodeBindVariablesBson(buf, "BindVariables", bdq.BindVariables)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 23
0
func (session *Session) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeInt64(buf, "TransactionId", session.TransactionId)
	bson.EncodeInt64(buf, "SessionId", session.SessionId)

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 24
0
func EncodeResultsBson(results []mproto.QueryResult, key string, buf *bytes2.ChunkedWriter) {
	bson.EncodePrefix(buf, bson.Array, key)
	lenWriter := bson.NewLenWriter(buf)
	for i, v := range results {
		v.MarshalBson(buf, bson.Itoa(i))
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 25
0
func EncodeServedFrom(buf *bytes2.ChunkedWriter, name string, servedFrom map[TabletType]string) {
	bson.EncodePrefix(buf, bson.Object, name)
	lenWriter := bson.NewLenWriter(buf)
	for k, v := range servedFrom {
		bson.EncodeString(buf, string(k), v)
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 26
0
func EncodeQueriesBson(queries []BoundQuery, key string, buf *bytes2.ChunkedWriter) {
	bson.EncodePrefix(buf, bson.Array, key)
	lenWriter := bson.NewLenWriter(buf)
	for i, v := range queries {
		v.MarshalBson(buf, bson.Itoa(i))
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 27
0
func EncodeFieldsBson(fields []Field, key string, buf *bytes2.ChunkedWriter) {
	bson.EncodePrefix(buf, bson.Array, key)
	lenWriter := bson.NewLenWriter(buf)
	for i, v := range fields {
		MarshalFieldBson(v, bson.Itoa(i), buf)
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 28
0
func EncodeRowsBson(rows [][]sqltypes.Value, key string, buf *bytes2.ChunkedWriter) {
	bson.EncodePrefix(buf, bson.Array, key)
	lenWriter := bson.NewLenWriter(buf)
	for i, v := range rows {
		EncodeRowBson(v, bson.Itoa(i), buf)
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 29
0
func (kr *KeyRange) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeString(buf, "Start", string(kr.Start))
	bson.EncodeString(buf, "End", string(kr.End))

	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Exemplo n.º 30
0
func encodeShardSessionsBson(shardSessions []*ShardSession, key string, buf *bytes2.ChunkedWriter) {
	bson.EncodePrefix(buf, bson.Array, key)
	lenWriter := bson.NewLenWriter(buf)
	for i, v := range shardSessions {
		v.MarshalBson(buf, bson.Itoa(i))
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}