Exemplo n.º 1
0
// UnmarshalBson bson-decodes into ZkNode.
func (zkNode *ZkNode) 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 ZkNode", kind))
	}
	bson.Next(buf, 4)

	for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
		switch bson.ReadCString(buf) {
		case "Path":
			zkNode.Path = bson.DecodeString(buf, kind)
		case "Data":
			zkNode.Data = bson.DecodeString(buf, kind)
		case "Stat":
			zkNode.Stat.UnmarshalBson(buf, kind)
		case "Children":
			// []string
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for zkNode.Children", kind))
				}
				bson.Next(buf, 4)
				zkNode.Children = make([]string, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v1 string
					_v1 = bson.DecodeString(buf, kind)
					zkNode.Children = append(zkNode.Children, _v1)
				}
			}
		case "Cached":
			zkNode.Cached = bson.DecodeBool(buf, kind)
		case "Stale":
			zkNode.Stale = bson.DecodeBool(buf, kind)
		default:
			bson.Skip(buf, kind)
		}
	}
}
Exemplo n.º 2
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)
		}
	}
}
Exemplo n.º 3
0
// UnmarshalBson bson-decodes into Session.
func (session *Session) 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 Session", kind))
	}
	bson.Next(buf, 4)

	for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
		switch bson.ReadCString(buf) {
		case "InTransaction":
			session.InTransaction = bson.DecodeBool(buf, kind)
		case "ShardSessions":
			// []*ShardSession
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for session.ShardSessions", kind))
				}
				bson.Next(buf, 4)
				session.ShardSessions = make([]*ShardSession, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v1 *ShardSession
					// *ShardSession
					if kind != bson.Null {
						_v1 = new(ShardSession)
						(*_v1).UnmarshalBson(buf, kind)
					}
					session.ShardSessions = append(session.ShardSessions, _v1)
				}
			}
		default:
			bson.Skip(buf, kind)
		}
	}
}