def encode(obj):
    """ Encode an object for proper decoding by Java or ObjC
    """
    if hasattr(obj, '__id__'):
        return msgpack.ExtType(ExtType.REF, msgpack.packb(obj.__id__))
    return obj