Esempio n. 1
0
// UnmarshalBson bson-decodes into MyType.
func (myType *MyType) UnmarshalBson(buf *bytes.Buffer, kind byte) {
	switch kind {
	case bson.EOO, bson.Object:
		// valid
	case bson.Null:
		return
	default:
		panic(bson.NewBsonError("unexpected kind %v for MyType", kind))
	}
	bson.Next(buf, 4)

	for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
		switch bson.ReadCString(buf) {
		case "Float64":
			myType.Float64 = bson.DecodeFloat64(buf, kind)
		case "String":
			myType.String = bson.DecodeString(buf, kind)
		case "Bool":
			myType.Bool = bson.DecodeBool(buf, kind)
		case "Int64":
			myType.Int64 = bson.DecodeInt64(buf, kind)
		case "Int32":
			myType.Int32 = bson.DecodeInt32(buf, kind)
		case "Int":
			myType.Int = bson.DecodeInt(buf, kind)
		case "Uint64":
			myType.Uint64 = bson.DecodeUint64(buf, kind)
		case "Uint32":
			myType.Uint32 = bson.DecodeUint32(buf, kind)
		case "Uint":
			myType.Uint = bson.DecodeUint(buf, kind)
		case "Bytes":
			myType.Bytes = bson.DecodeBinary(buf, kind)
		case "Time":
			myType.Time = bson.DecodeTime(buf, kind)
		case "Interface":
			myType.Interface = bson.DecodeInterface(buf, kind)
		default:
			bson.Skip(buf, kind)
		}
	}
}
Esempio n. 2
0
// UnmarshalBson bson-decodes into SrvKeyspace.
func (srvKeyspace *SrvKeyspace) UnmarshalBson(buf *bytes.Buffer, kind byte) {
	switch kind {
	case bson.EOO, bson.Object:
		// valid
	case bson.Null:
		return
	default:
		panic(bson.NewBsonError("unexpected kind %v for SrvKeyspace", kind))
	}
	bson.Next(buf, 4)

	for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
		switch bson.ReadCString(buf) {
		case "Partitions":
			// map[TabletType]*KeyspacePartition
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for srvKeyspace.Partitions", kind))
				}
				bson.Next(buf, 4)
				srvKeyspace.Partitions = make(map[TabletType]*KeyspacePartition)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := TabletType(bson.ReadCString(buf))
					var _v1 *KeyspacePartition
					// *KeyspacePartition
					if kind != bson.Null {
						_v1 = new(KeyspacePartition)
						(*_v1).UnmarshalBson(buf, kind)
					}
					srvKeyspace.Partitions[_k] = _v1
				}
			}
		case "Shards":
			// []SrvShard
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for srvKeyspace.Shards", kind))
				}
				bson.Next(buf, 4)
				srvKeyspace.Shards = make([]SrvShard, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v2 SrvShard
					_v2.UnmarshalBson(buf, kind)
					srvKeyspace.Shards = append(srvKeyspace.Shards, _v2)
				}
			}
		case "TabletTypes":
			// []TabletType
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for srvKeyspace.TabletTypes", kind))
				}
				bson.Next(buf, 4)
				srvKeyspace.TabletTypes = make([]TabletType, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v3 TabletType
					_v3.UnmarshalBson(buf, kind)
					srvKeyspace.TabletTypes = append(srvKeyspace.TabletTypes, _v3)
				}
			}
		case "ShardingColumnName":
			srvKeyspace.ShardingColumnName = bson.DecodeString(buf, kind)
		case "ShardingColumnType":
			srvKeyspace.ShardingColumnType.UnmarshalBson(buf, kind)
		case "ServedFrom":
			// map[TabletType]string
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for srvKeyspace.ServedFrom", kind))
				}
				bson.Next(buf, 4)
				srvKeyspace.ServedFrom = make(map[TabletType]string)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := TabletType(bson.ReadCString(buf))
					var _v4 string
					_v4 = bson.DecodeString(buf, kind)
					srvKeyspace.ServedFrom[_k] = _v4
				}
			}
		case "SplitShardCount":
			srvKeyspace.SplitShardCount = bson.DecodeInt32(buf, kind)
		default:
			bson.Skip(buf, kind)
		}
	}
}