Example #1
0
func decodeFieldsBson(buf *bytes.Buffer, kind byte) []Field {
	switch kind {
	case bson.Array:
		// valid
	case bson.Null:
		return nil
	default:
		panic(bson.NewBsonError("Unexpected data type %v for Query.Fields", kind))
	}

	bson.Next(buf, 4)
	fields := make([]Field, 0, 8)
	kind = bson.NextByte(buf)
	for i := 0; kind != bson.EOO; i++ {
		if kind != bson.Object {
			panic(bson.NewBsonError("Unexpected data type %v for Query.Field", kind))
		}
		bson.ExpectIndex(buf, i)
		var field Field
		UnmarshalFieldBson(&field, buf)
		fields = append(fields, field)
		kind = bson.NextByte(buf)
	}
	return fields
}
Example #2
0
func decodeRowsBson(buf *bytes.Buffer, kind byte) [][]sqltypes.Value {
	switch kind {
	case bson.Array:
		// valid
	case bson.Null:
		return nil
	default:
		panic(bson.NewBsonError("Unexpected data type %v for Query.Rows", kind))
	}

	bson.Next(buf, 4)
	rows := make([][]sqltypes.Value, 0, 8)
	kind = bson.NextByte(buf)
	for i := 0; kind != bson.EOO; i++ {
		bson.ExpectIndex(buf, i)
		rows = append(rows, decodeRowBson(buf, kind))
		kind = bson.NextByte(buf)
	}
	return rows
}
Example #3
0
func DecodeResultsBson(buf *bytes.Buffer, kind byte) (results []eproto.QueryResult) {
	switch kind {
	case bson.Array:
		// valid
	case bson.Null:
		return nil
	default:
		panic(bson.NewBsonError("Unexpected data type %v for Queries", kind))
	}

	bson.Next(buf, 4)
	results = make([]eproto.QueryResult, 0, 8)
	kind = bson.NextByte(buf)
	var result eproto.QueryResult
	for i := 0; kind != bson.EOO; i++ {
		bson.ExpectIndex(buf, i)
		result.UnmarshalBson(buf)
		results = append(results, result)
		kind = bson.NextByte(buf)
	}
	return results
}
Example #4
0
func DecodeQueriesBson(buf *bytes.Buffer, kind byte) (queries []BoundQuery) {
	switch kind {
	case bson.Array:
		// valid
	case bson.Null:
		return nil
	default:
		panic(bson.NewBsonError("Unexpected data type %v for Queries", kind))
	}

	bson.Next(buf, 4)
	queries = make([]BoundQuery, 0, 8)
	kind = bson.NextByte(buf)
	var bdq BoundQuery
	for i := 0; kind != bson.EOO; i++ {
		bson.ExpectIndex(buf, i)
		bdq.UnmarshalBson(buf)
		queries = append(queries, bdq)
		kind = bson.NextByte(buf)
	}
	return queries
}
Example #5
0
func decodeRowBson(buf *bytes.Buffer, kind byte) []sqltypes.Value {
	switch kind {
	case bson.Array:
		// valid
	case bson.Null:
		return nil
	default:
		panic(bson.NewBsonError("Unexpected data type %v for Query.Row", kind))
	}

	bson.Next(buf, 4)
	row := make([]sqltypes.Value, 0, 8)
	kind = bson.NextByte(buf)
	for i := 0; kind != bson.EOO; i++ {
		bson.ExpectIndex(buf, i)
		if kind != bson.Null {
			row = append(row, sqltypes.MakeString(bson.DecodeBytes(buf, kind)))
		} else {
			row = append(row, sqltypes.Value{})
		}
		kind = bson.NextByte(buf)
	}
	return row
}