func EncodeResultsBson(results []eproto.QueryResult, key string, buf *bytes2.ChunkedWriter) { bson.EncodePrefix(buf, bson.Array, key) lenWriter := bson.NewLenWriter(buf) for i, v := range results { bson.EncodePrefix(buf, bson.Object, bson.Itoa(i)) v.MarshalBson(buf) } 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 { bson.EncodePrefix(buf, bson.Object, bson.Itoa(i)) v.MarshalBson(buf) } buf.WriteByte(0) lenWriter.RecordLen() }
func encodeRowBson(row []sqltypes.Value, key string, buf *bytes2.ChunkedWriter) { bson.EncodePrefix(buf, bson.Array, key) lenWriter := bson.NewLenWriter(buf) for i, v := range row { if v.IsNull() { bson.EncodePrefix(buf, bson.Null, bson.Itoa(i)) } else { bson.EncodeBinary(buf, bson.Itoa(i), v.Raw()) } } 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 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 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 MarshalFieldBson(field Field, key string, buf *bytes2.ChunkedWriter) { bson.EncodePrefix(buf, bson.Object, key) lenWriter := bson.NewLenWriter(buf) bson.EncodeString(buf, "Name", field.Name) bson.EncodeInt64(buf, "Type", field.Type) buf.WriteByte(0) lenWriter.RecordLen() }