|
predsync C ABI 0.1.0
C bindings for deterministic low-bandwidth state sync
|
#include <stdarg.h>#include <stdbool.h>#include <stdint.h>#include <stdlib.h>#include <stddef.h>#include "predsync.h"Go to the source code of this file.
Classes | |
| struct | PredsyncValue |
| One value crossing the C boundary. More... | |
| struct | PredsyncEncodeInfo |
| Counts from one successful encode. More... | |
| struct | DemoTelemetry |
| Fixed-capacity message struct for schema message telemetry. More... | |
Macros | |
| #define | PREDSYNC_GENERATED_MESSAGES_H |
Typedefs | |
| typedef uint32_t | PredsyncStatus |
| typedef uint32_t | PredsyncValueKind |
| typedef uint32_t | PredsyncScalarKind |
| typedef uint32_t | PredsyncValidity |
| typedef struct PredsyncDecoded | PredsyncDecoded |
| Opaque handle to one fully decoded frame. | |
| typedef struct PredsyncDecoder | PredsyncDecoder |
| Opaque handle to one incoming stream decoder. | |
| typedef struct PredsyncEncoder | PredsyncEncoder |
| Opaque handle to one message encoder. | |
| typedef struct PredsyncRegistry | PredsyncRegistry |
| Opaque handle to an explicit runtime predictor registry. | |
| typedef struct PredsyncSet | PredsyncSet |
| Opaque handle to a validated schema set. | |
| typedef void(*) | PredsyncModelReset(void *ctx) |
| C callback signature for a runtime custom predictor model. | |
| typedef int32_t(*) | PredsyncModelUpdate(void *ctx, uint64_t t, double x) |
| typedef int32_t(*) | PredsyncModelPredict(void *ctx, uint64_t t, double *out) |
| typedef uint64_t(*) | PredsyncModelStateHash(void *ctx) |
| typedef struct PredsyncValue | PredsyncValue |
| One value crossing the C boundary. | |
| typedef struct PredsyncEncodeInfo | PredsyncEncodeInfo |
| Counts from one successful encode. | |
| typedef enum DemoTelemetryMode | DemoTelemetryMode |
| Generated enum for schema enum Mode. | |
| typedef struct DemoTelemetry | DemoTelemetry |
| Fixed-capacity message struct for schema message telemetry. | |
Enumerations | |
| enum | PredsyncStatus { Ok = 0 , NullPointer = 1 , InvalidSchema = 2 , InvalidHandle = 3 , BufferTooSmall = 4 , InvalidValue = 5 , EncodeError = 6 , DecodeError = 7 , Panic = 8 } |
| Status returned by every C entry point. More... | |
| enum | PredsyncValueKind { Scalar = 0 , Str = 1 , List = 2 } |
| Which representation a PredsyncValue carries. More... | |
| enum | PredsyncScalarKind { None = 0 , Bool = 1 , U8 = 2 , U16 = 3 , U32 = 4 , U64 = 5 , I8 = 6 , I16 = 7 , I32 = 8 , I64 = 9 , F32 = 10 , F64 = 11 , Enum = 12 } |
| The schema scalar carried by a PredsyncValue. More... | |
| enum | PredsyncValidity { Valid = 0 , Predicted = 1 , Unknown = 2 , ReSync = 3 } |
| The trust state of a decoded field. More... | |
| enum | DemoTelemetryMode { DEMO_TELEMETRY_MODE_IDLE = 0 , DEMO_TELEMETRY_MODE_ACTIVE = 1 , DEMO_TELEMETRY_MODE_FAULT = 2 } |
| Generated enum for schema enum Mode. More... | |
Functions | |
| struct PredsyncRegistry * | predsync_registry_new (void) |
| Create an empty explicit predictor registry. | |
| void | predsync_registry_free (struct PredsyncRegistry *registry) |
| Free a predictor registry. | |
| PredsyncStatus | predsync_registry_register_model (struct PredsyncRegistry *registry, const char *name, void *ctx, PredsyncModelReset reset, PredsyncModelUpdate update, PredsyncModelPredict predict, PredsyncModelStateHash state_hash) |
| Register a C callback custom predictor model in an explicit registry. | |
| PredsyncStatus | predsync_encoder_new_with_registry (const struct PredsyncSet *set, const struct PredsyncRegistry *registry, uintptr_t message_index, uint64_t tick_ns, uint8_t max_resets_per_frame, bool has_max_resets_per_frame, struct PredsyncEncoder **out) |
| Construct an encoder using an explicit runtime registry. | |
| PredsyncStatus | predsync_decoder_new_with_registry (const struct PredsyncSet *set, const struct PredsyncRegistry *registry, uint8_t resync_n, struct PredsyncDecoder **out) |
| Construct a decoder using an explicit runtime registry. | |
| PredsyncStatus | predsync_set_from_yaml (const char *yaml, uintptr_t len, struct PredsyncSet **out) |
| Parse a schema set from UTF-8 YAML and return an owned opaque handle. | |
| PredsyncStatus | predsync_set_free (struct PredsyncSet *set) |
| Free a schema-set handle. | |
| PredsyncStatus | predsync_encoder_new (const struct PredsyncSet *set, uintptr_t message_index, uint64_t tick_ns, uint16_t max_resets, struct PredsyncEncoder **out) |
| Construct an encoder for one message in a schema set. | |
| PredsyncStatus | predsync_encoder_free (struct PredsyncEncoder *encoder) |
| Free an encoder handle. | |
| PredsyncStatus | predsync_encode (struct PredsyncEncoder *encoder, const struct PredsyncValue *values, uintptr_t value_count, uint64_t now_ns, uint8_t *out, uintptr_t out_cap, uintptr_t *out_len, struct PredsyncEncodeInfo *info, uint32_t *error) |
| Encode one frame into a caller-provided buffer. | |
| PredsyncStatus | predsync_decoder_new (const struct PredsyncSet *set, uint8_t resync_n, struct PredsyncDecoder **out) |
| Construct a decoder for one incoming stream. | |
| PredsyncStatus | predsync_decoder_free (struct PredsyncDecoder *decoder) |
| Free a decoder handle. | |
| PredsyncStatus | predsync_decode_feed (struct PredsyncDecoder *decoder, const uint8_t *frame, uintptr_t frame_len, struct PredsyncDecoded **out, uint32_t *error) |
| Feed one frame to a decoder and return an owned decoded-frame handle. | |
| PredsyncStatus | predsync_decoded_info (const struct PredsyncDecoded *decoded, uintptr_t *message_index, uint32_t *missed, uint8_t *resynced) |
| Read the message index, missed-frame count and resync flag from a decoded frame. | |
| PredsyncStatus | predsync_decoded_field_count (const struct PredsyncDecoded *decoded, uintptr_t *out) |
| Return the number of decoded fields. | |
| PredsyncStatus | predsync_decoded_field (const struct PredsyncDecoded *decoded, uintptr_t index, PredsyncValidity *validity, struct PredsyncValue *value) |
| Copy one decoded field into a caller-provided value buffer. | |
| PredsyncStatus | predsync_decoded_free (struct PredsyncDecoded *decoded) |
| Free a decoded-frame handle. | |
| PredsyncStatus | demo_telemetry_pack (const DemoTelemetry *msg, PredsyncValue *out, size_t cap, size_t *out_len, uint64_t *scratch, size_t scratch_cap) |
| Convert a typed message into engine values. | |
| PredsyncStatus | demo_telemetry_unpack (const PredsyncValue *values, size_t len, DemoTelemetry *out) |
| Fill a typed message from engine values. | |
| #define PREDSYNC_GENERATED_MESSAGES_H |
| typedef struct DemoTelemetry DemoTelemetry |
Fixed-capacity message struct for schema message telemetry.
| typedef enum DemoTelemetryMode DemoTelemetryMode |
Generated enum for schema enum Mode.
| typedef struct PredsyncDecoded PredsyncDecoded |
Opaque handle to one fully decoded frame.
| typedef struct PredsyncDecoder PredsyncDecoder |
Opaque handle to one incoming stream decoder.
| typedef struct PredsyncEncodeInfo PredsyncEncodeInfo |
Counts from one successful encode.
| typedef struct PredsyncEncoder PredsyncEncoder |
Opaque handle to one message encoder.
| typedef int32_t(*) PredsyncModelPredict(void *ctx, uint64_t t, double *out) |
| typedef void(*) PredsyncModelReset(void *ctx) |
C callback signature for a runtime custom predictor model.
reset, update, predict and state_hash must all be non-null. ctx is passed through unchanged on every call. The callback is outside predsync's cross-platform bit-exactness guarantees.
| typedef uint64_t(*) PredsyncModelStateHash(void *ctx) |
| typedef int32_t(*) PredsyncModelUpdate(void *ctx, uint64_t t, double x) |
| typedef struct PredsyncRegistry PredsyncRegistry |
Opaque handle to an explicit runtime predictor registry.
| typedef uint32_t PredsyncScalarKind |
| typedef struct PredsyncSet PredsyncSet |
Opaque handle to a validated schema set.
| typedef uint32_t PredsyncStatus |
| typedef uint32_t PredsyncValidity |
| typedef struct PredsyncValue PredsyncValue |
One value crossing the C boundary.
| typedef uint32_t PredsyncValueKind |
| enum DemoTelemetryMode |
| enum PredsyncScalarKind |
The schema scalar carried by a PredsyncValue.
| enum PredsyncStatus |
Status returned by every C entry point.
| enum PredsyncValidity |
| enum PredsyncValueKind |
Which representation a PredsyncValue carries.
| Enumerator | |
|---|---|
| Scalar | An eight-byte scalar in scalar. |
| Str | UTF-8 bytes at ptr with length len. |
| List | Slot bits at ptr with element count len. |
| PredsyncStatus demo_telemetry_pack | ( | const DemoTelemetry * | msg, |
| PredsyncValue * | out, | ||
| size_t | cap, | ||
| size_t * | out_len, | ||
| uint64_t * | scratch, | ||
| size_t | scratch_cap ) |
Convert a typed message into engine values.
out holds at most cap values; scratch holds at most scratch_cap words.
| PredsyncStatus demo_telemetry_unpack | ( | const PredsyncValue * | values, |
| size_t | len, | ||
| DemoTelemetry * | out ) |
Fill a typed message from engine values.
values holds len entries; out is caller-owned.
| PredsyncStatus predsync_decode_feed | ( | struct PredsyncDecoder * | decoder, |
| const uint8_t * | frame, | ||
| uintptr_t | frame_len, | ||
| struct PredsyncDecoded ** | out, | ||
| uint32_t * | error ) |
| PredsyncStatus predsync_decoded_field | ( | const struct PredsyncDecoded * | decoded, |
| uintptr_t | index, | ||
| PredsyncValidity * | validity, | ||
| struct PredsyncValue * | value ) |
| PredsyncStatus predsync_decoded_field_count | ( | const struct PredsyncDecoded * | decoded, |
| uintptr_t * | out ) |
| PredsyncStatus predsync_decoded_free | ( | struct PredsyncDecoded * | decoded | ) |
| PredsyncStatus predsync_decoded_info | ( | const struct PredsyncDecoded * | decoded, |
| uintptr_t * | message_index, | ||
| uint32_t * | missed, | ||
| uint8_t * | resynced ) |
| PredsyncStatus predsync_decoder_free | ( | struct PredsyncDecoder * | decoder | ) |
| PredsyncStatus predsync_decoder_new | ( | const struct PredsyncSet * | set, |
| uint8_t | resync_n, | ||
| struct PredsyncDecoder ** | out ) |
| PredsyncStatus predsync_decoder_new_with_registry | ( | const struct PredsyncSet * | set, |
| const struct PredsyncRegistry * | registry, | ||
| uint8_t | resync_n, | ||
| struct PredsyncDecoder ** | out ) |
| PredsyncStatus predsync_encode | ( | struct PredsyncEncoder * | encoder, |
| const struct PredsyncValue * | values, | ||
| uintptr_t | value_count, | ||
| uint64_t | now_ns, | ||
| uint8_t * | out, | ||
| uintptr_t | out_cap, | ||
| uintptr_t * | out_len, | ||
| struct PredsyncEncodeInfo * | info, | ||
| uint32_t * | error ) |
| PredsyncStatus predsync_encoder_free | ( | struct PredsyncEncoder * | encoder | ) |
| PredsyncStatus predsync_encoder_new | ( | const struct PredsyncSet * | set, |
| uintptr_t | message_index, | ||
| uint64_t | tick_ns, | ||
| uint16_t | max_resets, | ||
| struct PredsyncEncoder ** | out ) |
| PredsyncStatus predsync_encoder_new_with_registry | ( | const struct PredsyncSet * | set, |
| const struct PredsyncRegistry * | registry, | ||
| uintptr_t | message_index, | ||
| uint64_t | tick_ns, | ||
| uint8_t | max_resets_per_frame, | ||
| bool | has_max_resets_per_frame, | ||
| struct PredsyncEncoder ** | out ) |
| void predsync_registry_free | ( | struct PredsyncRegistry * | registry | ) |
Free a predictor registry.
registry must be null or a live handle returned by predsync_registry_new.
| struct PredsyncRegistry * predsync_registry_new | ( | void | ) |
Create an empty explicit predictor registry.
| PredsyncStatus predsync_registry_register_model | ( | struct PredsyncRegistry * | registry, |
| const char * | name, | ||
| void * | ctx, | ||
| PredsyncModelReset | reset, | ||
| PredsyncModelUpdate | update, | ||
| PredsyncModelPredict | predict, | ||
| PredsyncModelStateHash | state_hash ) |
| PredsyncStatus predsync_set_free | ( | struct PredsyncSet * | set | ) |
| PredsyncStatus predsync_set_from_yaml | ( | const char * | yaml, |
| uintptr_t | len, | ||
| struct PredsyncSet ** | out ) |