2026-04-09 17:43:58 +02:00
|
|
|
#ifndef TYPES_HPP
|
|
|
|
|
#define TYPES_HPP
|
|
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
2026-04-09 17:43:58 +02:00
|
|
|
|
|
|
|
|
/// Mutable byte buffer.
|
2026-04-10 16:22:33 +02:00
|
|
|
typedef struct Bytes {
|
|
|
|
|
uint8_t* data;
|
|
|
|
|
size_t size;
|
|
|
|
|
} Bytes;
|
2026-04-09 17:43:58 +02:00
|
|
|
|
|
|
|
|
/// Immutable byte buffer.
|
2026-04-10 16:22:33 +02:00
|
|
|
typedef struct ConstBytes {
|
|
|
|
|
const uint8_t* data;
|
|
|
|
|
size_t size;
|
|
|
|
|
} ConstBytes;
|
2026-04-09 17:43:58 +02:00
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
typedef enum StatusCode {
|
|
|
|
|
StatusCode_Ok = 0,
|
|
|
|
|
StatusCode_DynError = 1,
|
|
|
|
|
StatusCode_InvalidInput = 2,
|
|
|
|
|
StatusCode_OutOfMemory = 3,
|
|
|
|
|
} StatusCode;
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
static bool status_code_is_ok(const StatusCode code) {
|
|
|
|
|
return code == StatusCode_Ok;
|
|
|
|
|
}
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
static bool status_code_is_error(const StatusCode code) {
|
|
|
|
|
return !status_code_is_ok(code);
|
|
|
|
|
}
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
/// A status code with an optional human-readable description.
|
|
|
|
|
typedef struct Status {
|
|
|
|
|
StatusCode code;
|
|
|
|
|
const char* message;
|
|
|
|
|
} Status;
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
static Status status_from_code(const StatusCode code) { return Status { code, NULL }; }
|
|
|
|
|
static Status status_ok() { return status_from_code(StatusCode_Ok); }
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
static bool status_is_ok(const Status status) { return status_code_is_ok(status.code); }
|
|
|
|
|
static bool status_is_error(const Status status) { return status_code_is_error(status.code); }
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-10 16:22:33 +02:00
|
|
|
#ifdef __cplusplus
|
2026-04-10 12:15:33 +02:00
|
|
|
}
|
2026-04-10 16:22:33 +02:00
|
|
|
#endif
|
2026-04-10 12:15:33 +02:00
|
|
|
|
2026-04-09 17:43:58 +02:00
|
|
|
#endif // TYPES_HPP
|