#ifndef NET_SDK_H
#define NET_SDK_H
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void* net_handle_t;
typedef enum {
NET_SUCCESS = 0,
NET_ERR_NULL_POINTER = -1,
NET_ERR_INVALID_UTF8 = -2,
NET_ERR_INVALID_JSON = -3,
NET_ERR_INIT_FAILED = -4,
NET_ERR_INGESTION_FAILED = -5,
NET_ERR_POLL_FAILED = -6,
NET_ERR_BUFFER_TOO_SMALL = -7,
NET_ERR_SHUTTING_DOWN = -8,
NET_ERR_INT_OVERFLOW = -9,
NET_ERR_MISMATCHED_HANDLES = -10,
NET_ERR_INTERIOR_NUL = -11,
NET_ERR_INVALID_ARGUMENT = -12,
NET_ERR_UNKNOWN = -99
} net_error_t;
typedef struct {
uint16_t shard_id;
uint64_t timestamp;
} net_receipt_t;
typedef struct {
const char* id;
size_t id_len;
const char* raw;
size_t raw_len;
uint64_t insertion_ts;
uint16_t shard_id;
} net_event_t;
typedef struct {
net_event_t* events;
size_t count;
char* next_id;
int has_more;
} net_poll_result_t;
typedef struct {
uint64_t events_ingested;
uint64_t events_dropped;
uint64_t batches_dispatched;
} net_stats_t;
net_handle_t net_init(const char* config_json);
int net_shutdown(net_handle_t handle);
const char* net_version(void);
uint16_t net_num_shards(net_handle_t handle);
int net_ingest_raw(net_handle_t handle, const char* json, size_t len);
int net_ingest_raw_ex(net_handle_t handle, const char* json, size_t len, net_receipt_t* out);
int net_ingest(net_handle_t handle, const char* event_json, size_t len);
int net_ingest_raw_batch(
net_handle_t handle,
const char** jsons,
const size_t* lens,
size_t count
);
int net_ingest_batch(net_handle_t handle, const char* events_json);
int net_poll(
net_handle_t handle,
const char* request_json,
char* out_buffer,
size_t buffer_len
);
int net_poll_ex(
net_handle_t handle,
size_t limit,
const char* cursor,
net_poll_result_t* out
);
void net_free_poll_result(net_poll_result_t* result);
int net_stats(net_handle_t handle, char* out_buffer, size_t buffer_len);
int net_stats_ex(net_handle_t handle, net_stats_t* out);
int net_flush(net_handle_t handle);
char* net_generate_keypair(void);
void net_free_string(char* s);
typedef struct net_redis_dedup_s net_redis_dedup_t;
net_redis_dedup_t* net_redis_dedup_new(size_t capacity);
void net_redis_dedup_free(net_redis_dedup_t* handle);
int net_redis_dedup_is_duplicate(net_redis_dedup_t* handle, const char* dedup_id);
size_t net_redis_dedup_len(net_redis_dedup_t* handle);
size_t net_redis_dedup_capacity(net_redis_dedup_t* handle);
int net_redis_dedup_is_empty(net_redis_dedup_t* handle);
void net_redis_dedup_clear(net_redis_dedup_t* handle);
typedef struct net_registry_client_handle_t net_registry_client_handle_t;
#define NET_REGISTRY_OK 0
#define NET_REGISTRY_ERR_TRANSPORT 1
#define NET_REGISTRY_ERR_CODEC 2
#define NET_REGISTRY_ERR_UNKNOWN_TEMPLATE 3
#define NET_REGISTRY_ERR_DUPLICATE_GROUP_NAME 4
#define NET_REGISTRY_ERR_SPAWN_REJECTED 5
#define NET_REGISTRY_ERR_SPAWN_NOT_SUPPORTED 6
#define NET_REGISTRY_ERR_UNKNOWN_KIND 7
#define NET_REGISTRY_ERR_INVALID_ARGS 99
typedef enum {
NET_VISIBILITY_GLOBAL = 0,
NET_VISIBILITY_PARENT_VISIBLE = 1,
NET_VISIBILITY_EXPORTED = 2,
NET_VISIBILITY_SUBNET_LOCAL = 3,
} net_visibility_t;
net_registry_client_handle_t* net_registry_client_new(void* mesh_handle);
void net_registry_client_free(net_registry_client_handle_t* handle);
void net_registry_client_set_deadline(
net_registry_client_handle_t* handle,
uint64_t millis);
char* net_registry_client_list(
net_registry_client_handle_t* handle,
uint64_t target_node_id,
int* out_error_kind);
char* net_registry_client_spawn(
net_registry_client_handle_t* handle,
uint64_t target_node_id,
const char* template_name,
const char* group_name,
uint8_t replica_count,
int* out_error_kind);
int net_registry_client_unregister(
net_registry_client_handle_t* handle,
uint64_t target_node_id,
const char* group_name,
int* out_error_kind);
char* net_registry_last_error_detail(net_registry_client_handle_t* handle);
int net_register_channel(
void* mesh_handle,
const char* name,
int visibility);
typedef struct net_fold_query_client_handle_t net_fold_query_client_handle_t;
net_fold_query_client_handle_t* net_fold_query_client_new(void* mesh_handle);
void net_fold_query_client_free(net_fold_query_client_handle_t* handle);
void net_fold_query_client_set_ttl(
net_fold_query_client_handle_t* handle,
uint64_t millis);
void net_fold_query_client_set_deadline(
net_fold_query_client_handle_t* handle,
uint64_t millis);
char* net_fold_query_client_query_latest(
net_fold_query_client_handle_t* handle,
uint64_t target_node_id,
uint16_t kind,
int* out_error_kind);
char* net_fold_query_client_query_summarize_now(
net_fold_query_client_handle_t* handle,
uint64_t target_node_id,
uint16_t kind,
int* out_error_kind);
void net_fold_query_client_invalidate_cache(
net_fold_query_client_handle_t* handle);
void net_fold_query_client_invalidate_target(
net_fold_query_client_handle_t* handle,
uint64_t target_node_id);
char* net_fold_query_last_error_detail(
net_fold_query_client_handle_t* handle);
#ifdef __cplusplus
}
#endif
#endif