#ifndef FASTNET_H
#define FASTNET_H
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum FastNetEventType {
FASTNET_EVENT_NONE = 0, FASTNET_EVENT_CONNECTED = 1, FASTNET_EVENT_DATA = 2, FASTNET_EVENT_DISCONNECTED = 3, FASTNET_EVENT_ERROR = 4 } FastNetEventType;
typedef struct FastNetEvent {
FastNetEventType type; uint16_t peer_id; uint8_t channel; uint8_t* data; uint32_t data_len; int32_t error_code; } FastNetEvent;
typedef enum FastNetChannel {
FASTNET_CHANNEL_RELIABLE_ORDERED = 0, FASTNET_CHANNEL_UNRELIABLE = 1, FASTNET_CHANNEL_RELIABLE = 2, FASTNET_CHANNEL_UNRELIABLE_SEQUENCED = 3 } FastNetChannel;
typedef void* FastNetClient;
typedef void* FastNetServer;
FastNetClient fastnet_client_connect(const char* host, uint16_t port);
void fastnet_client_disconnect(FastNetClient client);
int32_t fastnet_client_send(
FastNetClient client,
uint8_t channel,
const uint8_t* data,
uint32_t data_len
);
bool fastnet_client_poll(FastNetClient client, FastNetEvent* event);
uint64_t fastnet_client_rtt_us(FastNetClient client);
FastNetServer fastnet_server_create(
uint16_t udp_port,
uint16_t tcp_port,
const char* cert_path,
const char* key_path
);
void fastnet_server_destroy(FastNetServer server);
int32_t fastnet_server_send(
FastNetServer server,
uint16_t peer_id,
uint8_t channel,
const uint8_t* data,
uint32_t data_len
);
bool fastnet_server_poll(FastNetServer server, FastNetEvent* event);
uint32_t fastnet_server_peer_count(FastNetServer server);
typedef void* FastNetDeltaEncoder;
typedef void* FastNetDeltaDecoder;
FastNetDeltaEncoder fastnet_delta_encoder_create(void);
void fastnet_delta_encoder_destroy(FastNetDeltaEncoder encoder);
int32_t fastnet_delta_encode(
FastNetDeltaEncoder encoder,
const uint8_t* old_state,
uint32_t old_len,
const uint8_t* new_state,
uint32_t new_len,
uint8_t* output,
uint32_t output_capacity,
uint32_t* output_len
);
FastNetDeltaDecoder fastnet_delta_decoder_create(void);
void fastnet_delta_decoder_destroy(FastNetDeltaDecoder decoder);
int32_t fastnet_delta_apply(
FastNetDeltaDecoder decoder,
const uint8_t* delta,
uint32_t delta_len,
uint8_t* state,
uint32_t state_len
);
#ifdef __cplusplus
}
#endif
#endif