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

	bson.Next(buf, 4)
	values := make([]*ZkNode, 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 %v", kind, name))
		}
		bson.ExpectIndex(buf, i)
		zkNode := &ZkNode{}
		zkNode.UnmarshalBson(buf)
		values = append(values, zkNode)
		kind = bson.NextByte(buf)
	}
	return values
}
Example #2
0
func UnmarshalStatementsBson(buf *bytes.Buffer, kind byte) []Statement {
	switch kind {
	case bson.Array:
		// valid
	case bson.Null:
		return nil
	default:
		panic(bson.NewBsonError("Unexpected data type %v for BinlogTransaction.Statements", kind))
	}

	bson.Next(buf, 4)
	statements := make([]Statement, 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 statement Statement
		statement.UnmarshalBson(buf)
		statements = append(statements, statement)
		kind = bson.NextByte(buf)
	}
	return statements
}
Example #3
0
func UnmarshalPKRowBson(buf *bytes.Buffer, kind byte) []interface{} {
	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([]interface{}, 0, 8)
	kind = bson.NextByte(buf)
	for i := 0; kind != bson.EOO; i++ {
		bson.ExpectIndex(buf, i)
		var val interface{}
		switch kind {
		case bson.Binary, bson.String:
			val = bson.DecodeString(buf, kind)
		case bson.Long:
			val = bson.DecodeInt64(buf, kind)
		case bson.Ulong:
			val = bson.DecodeUint64(buf, kind)
		}
		row = append(row, val)
		kind = bson.NextByte(buf)
	}
	return row
}
Example #4
0
func DecodeSrvShardArray(buf *bytes.Buffer, kind byte) []SrvShard {
	switch kind {
	case bson.Array:
		// valid
	case bson.Null:
		return nil
	default:
		panic(bson.NewBsonError("Unexpected data type %v for SrvShard array", kind))
	}

	bson.Next(buf, 4)
	values := make([]SrvShard, 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 SrvShard array", kind))
		}
		bson.ExpectIndex(buf, i)
		value := &SrvShard{}
		value.UnmarshalBson(buf)
		values = append(values, *value)
		kind = bson.NextByte(buf)
	}
	return values
}
Example #5
0
func decodeShardSessionsBson(buf *bytes.Buffer, kind byte) []*ShardSession {
	switch kind {
	case bson.Array:
		// valid
	case bson.Null:
		return nil
	default:
		panic(bson.NewBsonError("Unexpected data type %v for ShardSessions", kind))
	}

	bson.Next(buf, 4)
	shardSessions := make([]*ShardSession, 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 ShardSession", kind))
		}
		bson.ExpectIndex(buf, i)
		shardSession := new(ShardSession)
		shardSession.UnmarshalBson(buf)
		shardSessions = append(shardSessions, shardSession)
		kind = bson.NextByte(buf)
	}
	return shardSessions
}
Example #6
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 #7
0
func UnmarshalPKValuesBson(buf *bytes.Buffer, kind byte) [][]interface{} {
	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([][]interface{}, 0, 8)
	kind = bson.NextByte(buf)
	for i := 0; kind != bson.EOO; i++ {
		bson.ExpectIndex(buf, i)
		rows = append(rows, UnmarshalPKRowBson(buf, kind))
		kind = bson.NextByte(buf)
	}
	return rows
}
Example #8
0
func DecodeResultsBson(buf *bytes.Buffer, kind byte) (results []mproto.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([]mproto.QueryResult, 0, 8)
	kind = bson.NextByte(buf)
	var result mproto.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 #9
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 #10
0
func DecodeTabletTypeArray(buf *bytes.Buffer, kind byte) []TabletType {
	switch kind {
	case bson.Array:
		// valid
	case bson.Null:
		return nil
	default:
		panic(bson.NewBsonError("Unexpected data type %v for TabletType array", kind))
	}

	bson.Next(buf, 4)
	values := make([]TabletType, 0, 8)
	kind = bson.NextByte(buf)
	for i := 0; kind != bson.EOO; i++ {
		if kind != bson.Binary {
			panic(bson.NewBsonError("Unexpected data type %v for TabletType array", kind))
		}
		bson.ExpectIndex(buf, i)
		values = append(values, TabletType(bson.DecodeString(buf, kind)))
		kind = bson.NextByte(buf)
	}
	return values
}
Example #11
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
}