func (d *Decoder) Decode(val interface{}) error {
	if unmarshaler, ok := val.(Unmarshaler); ok {
		// TODO(skriptble): Reuse a []byte here and use the AppendDocumentBytes method.
		buf, err := bsonrw.Copier{}.CopyDocumentToBytes(d.vr)
		if err != nil {
			return err
		}
		return unmarshaler.UnmarshalBSON(buf)
	}

	rval := reflect.ValueOf(val)
	switch rval.Kind() {
	case reflect.Ptr:
		if rval.IsNil() {
			return ErrDecodeToNil
		}
		rval = rval.Elem()
	case reflect.Map:
		if rval.IsNil() {
			return ErrDecodeToNil
		}
	default:
		return fmt.Errorf("argument to Decode must be a pointer or a map, but got %v", rval)
	}
	decoder, err := d.dc.LookupDecoder(rval.Type())
	if err != nil {
		return err
	}
	return decoder.DecodeValue(d.dc, d.vr, rval)
}
// Decode reads the next BSON document from the stream and decodes it into the
// value pointed to by val.
//
// The documentation for Unmarshal contains details about of BSON into a Go
// value.
Decode reads the next BSON document from the stream and decodes it into the
value pointed to by val.

The documentation for Unmarshal contains details about of BSON into a Go
value.
// Decode reads the next BSON document from the stream and decodes it into the // value pointed to by val . // // The documentation for Unmarshal contains details about of BSON into a Go // value .
func (d *Decoder) Decode(val interface{}) error {
	if unmarshaler, ok := val.(Unmarshaler); ok {
		buf, err := bsonrw.Copier{}.CopyDocumentToBytes(d.vr)
		if err != nil {
			return err
		}
		return unmarshaler.UnmarshalBSON(buf)
	}
	rval := reflect.ValueOf(val)
	switch rval.Kind() {
	case reflect.Ptr:
		if rval.IsNil() {
			return ErrDecodeToNil
		}
		rval = rval.Elem()
	case reflect.Map:
		if rval.IsNil() {
			return ErrDecodeToNil
		}
	default:
		return fmt.Errorf("argument to Decode must be a pointer or a map, but got %v", rval)
	}
	decoder, err := d.dc.LookupDecoder(rval.Type())
	if err != nil {
		return err
	}
	return decoder.DecodeValue(d.dc, d.vr, rval)
}
func ( d * Decoder ) Decode ( val interface { } ) error { if unmarshaler , ok := val . ( Unmarshaler ) ; ok { buf , err := bsonrw . Copier { } . CopyDocumentToBytes ( d . vr ) if err != nil { return err } return unmarshaler . UnmarshalBSON ( buf ) } rval := reflect . ValueOf ( val ) switch rval . Kind ( ) { case reflect . Ptr : if rval . IsNil ( ) { return ErrDecodeToNil } rval = rval . Elem ( ) case reflect . Map : if rval . IsNil ( ) { return ErrDecodeToNil } default : return fmt . Errorf ( " " , rval ) } decoder , err := d . dc . LookupDecoder ( rval . Type ( ) ) if err != nil { return err } return decoder . DecodeValue ( d . dc , d . vr , rval ) }
Decode reads the next BSON document from the stream and decodes it into the
value pointed to by val.
Decode reads the next BSON document from the stream and decodes it into the value pointed to by val .
// TODO(skriptble): Reuse a []byte here and use the AppendDocumentBytes method.