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() }
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() }
// 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) }
func EncodeBool(buf *bytes2.ChunkedWriter, val bool) { if val { buf.WriteByte(1) } else { buf.WriteByte(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() }
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() }
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() }
func (ps *PrivateStruct) MarshalBson(buf *bytes2.ChunkedWriter) { lenWriter := NewLenWriter(buf) EncodeUint64(buf, "Type", ps.veryPrivate) buf.WriteByte(0) lenWriter.RecordLen() }
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() }
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() }
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() }
func (zkPathV *ZkPathV) MarshalBson(buf *bytes2.ChunkedWriter) { lenWriter := bson.NewLenWriter(buf) bson.EncodeStringArray(buf, "Paths", zkPathV.Paths) buf.WriteByte(0) lenWriter.RecordLen() }
func (zkPath *ZkPath) MarshalBson(buf *bytes2.ChunkedWriter) { lenWriter := bson.NewLenWriter(buf) bson.EncodeString(buf, "Path", zkPath.Path) buf.WriteByte(0) lenWriter.RecordLen() }
func (kp *KeyspacePartition) MarshalBson(buf *bytes2.ChunkedWriter) { lenWriter := bson.NewLenWriter(buf) EncodeSrvShardArray(buf, "Shards", kp.Shards) buf.WriteByte(0) lenWriter.RecordLen() }
func (zkNodeV *ZkNodeV) MarshalBson(buf *bytes2.ChunkedWriter) { lenWriter := bson.NewLenWriter(buf) marshalZkNodeArray(buf, "Nodes", zkNodeV.Nodes) buf.WriteByte(0) lenWriter.RecordLen() }
// 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) } }
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() }
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() }
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() }
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() }
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() }
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() }
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() }
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() }
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() }
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() }
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() }
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() }
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() }
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() }