// MarshalBson bson-encodes SrvKeyspace.
func (srvKeyspace *SrvKeyspace) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	// map[TabletType]*KeyspacePartition
	{
		bson.EncodePrefix(buf, bson.Object, "Partitions")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v1 := range srvKeyspace.Partitions {
			// *KeyspacePartition
			if _v1 == nil {
				bson.EncodePrefix(buf, bson.Null, string(_k))
			} else {
				(*_v1).MarshalBson(buf, string(_k))
			}
		}
		lenWriter.Close()
	}
	// []SrvShard
	{
		bson.EncodePrefix(buf, bson.Array, "Shards")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v2 := range srvKeyspace.Shards {
			_v2.MarshalBson(buf, bson.Itoa(_i))
		}
		lenWriter.Close()
	}
	// []TabletType
	{
		bson.EncodePrefix(buf, bson.Array, "TabletTypes")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v3 := range srvKeyspace.TabletTypes {
			_v3.MarshalBson(buf, bson.Itoa(_i))
		}
		lenWriter.Close()
	}
	bson.EncodeString(buf, "ShardingColumnName", srvKeyspace.ShardingColumnName)
	srvKeyspace.ShardingColumnType.MarshalBson(buf, "ShardingColumnType")
	// map[TabletType]string
	{
		bson.EncodePrefix(buf, bson.Object, "ServedFrom")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v4 := range srvKeyspace.ServedFrom {
			bson.EncodeString(buf, string(_k), _v4)
		}
		lenWriter.Close()
	}
	bson.EncodeInt32(buf, "SplitShardCount", srvKeyspace.SplitShardCount)

	lenWriter.Close()
}
Exemple #2
0
// MarshalBson bson-encodes MyType.
func (myType *MyType) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeFloat64(buf, "Float64", myType.Float64)
	bson.EncodeString(buf, "String", myType.String)
	bson.EncodeBool(buf, "Bool", myType.Bool)
	bson.EncodeInt64(buf, "Int64", myType.Int64)
	bson.EncodeInt32(buf, "Int32", myType.Int32)
	bson.EncodeInt(buf, "Int", myType.Int)
	bson.EncodeUint64(buf, "Uint64", myType.Uint64)
	bson.EncodeUint32(buf, "Uint32", myType.Uint32)
	bson.EncodeUint(buf, "Uint", myType.Uint)
	bson.EncodeBinary(buf, "Bytes", myType.Bytes)
	bson.EncodeTime(buf, "Time", myType.Time)
	bson.EncodeInterface(buf, "Interface", myType.Interface)

	lenWriter.Close()
}