// UnmarshalBson bson-decodes into A. func (a *A) 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 A", kind)) } bson.Next(buf, 4) for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) { switch bson.ReadCString(buf) { case "Name": a.Name = bson.DecodeString(buf, kind) case "BirthDay": a.BirthDay = bson.DecodeTime(buf, kind) case "Phone": a.Phone = bson.DecodeString(buf, kind) case "Siblings": a.Siblings = bson.DecodeInt(buf, kind) case "Spouse": a.Spouse = bson.DecodeBool(buf, kind) case "Money": a.Money = bson.DecodeFloat64(buf, kind) default: bson.Skip(buf, kind) } } }
// 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) } } }