//
//  tb_endpoint_private.h
//  Tightbeam

#ifndef __TIGHTBEAM_ENDPOINT_PRIVATE_H
#define __TIGHTBEAM_ENDPOINT_PRIVATE_H

#include <sys/cdefs.h>
__ptrcheck_abi_assume_single()

#include <Tightbeam/tightbeam.h>
#include <Tightbeam/tb_endpoint.h>

TB_ASSUME_NONNULL_BEGIN
__TB_BEGIN_DECLS

typedef struct _tb_endpoint_s {
    tb_transport_type_t type;
    tb_endpoint_options_t options;

    tb_interface_identifier_t interface_identifier;

    tb_endpoint_data_destructor_f _Nullable d_destructor;
    void *_Nullable d_destructor_context;

    union _tb_endpoint_data_u {
        tb_endpoint_data_t _Nullable data;
        uint64_t value;
    } transport_data;

    bool is_dynamic;

    // tb_endpoint_s is padded for extra space in the future,
#if defined(__RTKIT__) && defined(__ILP32__)
    // RTKit builds for 32-bit platforms and the padding here
    // must account for the decreased size of pointer sized
    // fields in this structure.
    uint32_t _pad[15];
#else
    uint64_t _pad[6];
#endif
} _tb_endpoint_s, *_tb_endpoint_t __TB_WARN_UNUSED_RESULT;

// watchOS 32 bit needs to build, but will never run
#if !defined(__ILP32__) ||  !TARGET_OS_WATCH
_Static_assert(sizeof(struct tb_endpoint_s) == sizeof(struct _tb_endpoint_s), "");
#endif // !defined(__ILP32__) ||  !TARGET_OS_WATCH

__TB_END_DECLS
TB_ASSUME_NONNULL_END

#endif // __TIGHTBEAM_ENDPOINT_PRIVATE_H
