func (pc *PointerCodec) EncodeValue(ec EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error {
	if val.Kind() != reflect.Ptr {
		if !val.IsValid() {
			return vw.WriteNull()
		}
		return ValueEncoderError{Name: "PointerCodec.EncodeValue", Kinds: []reflect.Kind{reflect.Ptr}, Received: val}
	}

	if val.IsNil() {
		return vw.WriteNull()
	}

	pc.l.RLock()
	enc, ok := pc.ecache[val.Type()]
	pc.l.RUnlock()
	if ok {
		if enc == nil {
			return ErrNoEncoder{Type: val.Type()}
		}
		return enc.EncodeValue(ec, vw, val.Elem())
	}

	enc, err := ec.LookupEncoder(val.Type().Elem())
	pc.l.Lock()
	pc.ecache[val.Type()] = enc
	pc.l.Unlock()
	if err != nil {
		return err
	}

	return enc.EncodeValue(ec, vw, val.Elem())
}
// EncodeValue handles encoding a pointer by either encoding it to BSON Null if the pointer is nil
// or looking up an encoder for the type of value the pointer points to.
EncodeValue handles encoding a pointer by either encoding it to BSON Null if the pointer is nil
or looking up an encoder for the type of value the pointer points to.
// EncodeValue handles encoding a pointer by either encoding it to BSON Null if the pointer is nil // or looking up an encoder for the type of value the pointer points to .
func (pc *PointerCodec) EncodeValue(ec EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error {
	if val.Kind() != reflect.Ptr {
		if !val.IsValid() {
			return vw.WriteNull()
		}
		return ValueEncoderError{Name: "PointerCodec.EncodeValue", Kinds: []reflect.Kind{reflect.Ptr}, Received: val}
	}
	if val.IsNil() {
		return vw.WriteNull()
	}
	pc.l.RLock()
	enc, ok := pc.ecache[val.Type()]
	pc.l.RUnlock()
	if ok {
		if enc == nil {
			return ErrNoEncoder{Type: val.Type()}
		}
		return enc.EncodeValue(ec, vw, val.Elem())
	}
	enc, err := ec.LookupEncoder(val.Type().Elem())
	pc.l.Lock()
	pc.ecache[val.Type()] = enc
	pc.l.Unlock()
	if err != nil {
		return err
	}
	return enc.EncodeValue(ec, vw, val.Elem())
}
func ( pc * PointerCodec ) EncodeValue ( ec EncodeContext , vw bsonrw . ValueWriter , val reflect . Value ) error { if val . Kind ( ) != reflect . Ptr { if ! val . IsValid ( ) { return vw . WriteNull ( ) } return ValueEncoderError { Name : " " , Kinds : [ ] reflect . Kind { reflect . Ptr } , Received : val } } if val . IsNil ( ) { return vw . WriteNull ( ) } pc . l . RLock ( ) enc , ok := pc . ecache [ val . Type ( ) ] pc . l . RUnlock ( ) if ok { if enc == nil { return ErrNoEncoder { Type : val . Type ( ) } } return enc . EncodeValue ( ec , vw , val . Elem ( ) ) } enc , err := ec . LookupEncoder ( val . Type ( ) . Elem ( ) ) pc . l . Lock ( ) pc . ecache [ val . Type ( ) ] = enc pc . l . Unlock ( ) if err != nil { return err } return enc . EncodeValue ( ec , vw , val . Elem ( ) ) }
EncodeValue handles encoding a pointer by either encoding it to BSON Null if the pointer is nil
or looking up an encoder for the type of value the pointer points to.
EncodeValue handles encoding a pointer by either encoding it to BSON Null if the pointer is nil or looking up an encoder for the type of value the pointer points to .