def _encode_dbref(name, value, check_keys, opts):
 buf = bytearray((('\x03' + name) + '\x00\x00\x00\x00'))
 begin = (len(buf) - 4)
 buf += _name_value_to_bson('$ref\x00', value.collection, check_keys, opts)
 buf += _name_value_to_bson('$id\x00', value.id, check_keys, opts)
 if (value.database is not None):
  buf += _name_value_to_bson('$db\x00', value.database, check_keys, opts)
 for (key, val) in iteritems(value._DBRef__kwargs):
  buf += _element_to_bson(key, val, check_keys, opts)
 buf += '\x00'
 buf[begin:(begin + 4)] = _PACK_INT((len(buf) - begin))
 return bytes(buf)

def _encode_dbref ( name , value , check_keys , opts ) : buf = bytearray ( ( ( '\x03' + name ) + '\x00\x00\x00\x00' ) ) begin = ( len ( buf ) - 4 ) buf += _name_value_to_bson ( '$ref\x00' , value . collection , check_keys , opts ) buf += _name_value_to_bson ( '$id\x00' , value . id , check_keys , opts ) if ( value . database is not None ) : buf += _name_value_to_bson ( '$db\x00' , value . database , check_keys , opts ) for ( key , val ) in iteritems ( value . _DBRef__kwargs ) : buf += _element_to_bson ( key , val , check_keys , opts ) buf += '\x00' buf [ begin : ( begin + 4 ) ] = _PACK_INT ( ( len ( buf ) - begin ) ) return bytes ( buf )
encode bson .