plasmite 2.0.0__py3-none-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plasmite/__init__.py +1545 -0
- plasmite/_cli.py +89 -0
- plasmite/_include/plasmite.h +545 -0
- plasmite/_native/plasmite.exe +0 -0
- plasmite/_native/plasmite2.dll +0 -0
- plasmite/_views.py +229 -0
- plasmite/_views_fallback.py +626 -0
- plasmite/aio.py +798 -0
- plasmite/py.typed +0 -0
- plasmite-2.0.0.dist-info/METADATA +205 -0
- plasmite-2.0.0.dist-info/RECORD +16 -0
- plasmite-2.0.0.dist-info/WHEEL +5 -0
- plasmite-2.0.0.dist-info/entry_points.txt +3 -0
- plasmite-2.0.0.dist-info/licenses/LICENSE +21 -0
- plasmite-2.0.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +31 -0
- plasmite-2.0.0.dist-info/top_level.txt +1 -0
plasmite/_cli.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Purpose: Expose a Python console script that forwards to the bundled plasmite CLI.
|
|
3
|
+
Key Exports: main()
|
|
4
|
+
Role: Keep `plasmite` command available from Python wheel installs.
|
|
5
|
+
Invariants: Uses package-local binary first, then a native SDK executable on PATH.
|
|
6
|
+
Invariants: Never launches a console wrapper as its fallback.
|
|
7
|
+
Invariants: Exit code mirrors the invoked process status.
|
|
8
|
+
Notes: This wrapper does not interpret arguments; it forwards them verbatim.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
import shutil
|
|
16
|
+
import subprocess
|
|
17
|
+
import sys
|
|
18
|
+
import zipfile
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _bundled_cli_path() -> Path:
|
|
22
|
+
cli_name = "plasmite.exe" if os.name == "nt" else "plasmite"
|
|
23
|
+
return Path(__file__).resolve().parent / "_native" / cli_name
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _is_python_console_launcher(candidate: Path) -> bool:
|
|
27
|
+
# Older setuptools launchers execute a companion script. Distlib launchers
|
|
28
|
+
# put __main__.py in a ZIP appended to the PE executable instead.
|
|
29
|
+
if candidate.with_name(candidate.stem + "-script.py").exists():
|
|
30
|
+
return True
|
|
31
|
+
try:
|
|
32
|
+
with zipfile.ZipFile(candidate) as payload:
|
|
33
|
+
return "__main__.py" in payload.namelist()
|
|
34
|
+
except zipfile.BadZipFile:
|
|
35
|
+
return False # An ordinary native executable has no appended ZIP.
|
|
36
|
+
except OSError:
|
|
37
|
+
return True # An unreadable candidate cannot establish a safe fallback.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _system_cli_path() -> Path | None:
|
|
41
|
+
# Source installs provide this same console command. Search past wrappers
|
|
42
|
+
# to the SDK binary instead of recursively invoking another Python entrypoint.
|
|
43
|
+
excluded = {Path(sys.argv[0]).resolve(), Path(sys.executable).resolve()}
|
|
44
|
+
native_magic = {
|
|
45
|
+
b"\x7fELF",
|
|
46
|
+
b"\xfe\xed\xfa\xce", b"\xce\xfa\xed\xfe", # Mach-O
|
|
47
|
+
b"\xfe\xed\xfa\xcf", b"\xcf\xfa\xed\xfe",
|
|
48
|
+
b"\xca\xfe\xba\xbe", b"\xbe\xba\xfe\xca", # universal Mach-O
|
|
49
|
+
b"\xca\xfe\xba\xbf", b"\xbf\xba\xfe\xca",
|
|
50
|
+
}
|
|
51
|
+
for directory in os.get_exec_path():
|
|
52
|
+
discovered = shutil.which("plasmite", path=directory)
|
|
53
|
+
if not discovered:
|
|
54
|
+
continue
|
|
55
|
+
candidate = Path(discovered).resolve()
|
|
56
|
+
if candidate in excluded:
|
|
57
|
+
continue
|
|
58
|
+
try:
|
|
59
|
+
with candidate.open("rb") as executable:
|
|
60
|
+
magic = executable.read(4)
|
|
61
|
+
except OSError:
|
|
62
|
+
continue
|
|
63
|
+
if magic in native_magic:
|
|
64
|
+
return candidate
|
|
65
|
+
if magic.startswith(b"MZ") and not _is_python_console_launcher(candidate):
|
|
66
|
+
return candidate
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def main() -> int:
|
|
71
|
+
bundled = _bundled_cli_path()
|
|
72
|
+
if bundled.exists():
|
|
73
|
+
cli_path = str(bundled)
|
|
74
|
+
else:
|
|
75
|
+
discovered = _system_cli_path()
|
|
76
|
+
if discovered is None:
|
|
77
|
+
print(
|
|
78
|
+
"plasmite native CLI not found; install the Plasmite system SDK "
|
|
79
|
+
"and add its bin directory to PATH, or reinstall a wheel with bundled assets",
|
|
80
|
+
file=sys.stderr,
|
|
81
|
+
)
|
|
82
|
+
return 1
|
|
83
|
+
cli_path = str(discovered)
|
|
84
|
+
completed = subprocess.run([cli_path, *sys.argv[1:]], check=False)
|
|
85
|
+
return int(completed.returncode)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if __name__ == "__main__":
|
|
89
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Plasmite C ABI, major version 2.
|
|
3
|
+
|
|
4
|
+
Plasmite stores JSON messages in pools: bounded ring buffers on disk that many
|
|
5
|
+
processes can write and read at once. Feed writes a message, follow waits for
|
|
6
|
+
new ones, and fetch reads what the pool holds and stops. A pool reference is a
|
|
7
|
+
name in the client's directory, a file path, or an https:// URL on a server
|
|
8
|
+
saved with `plasmite access connect`. The Go, Python and Node bindings wrap
|
|
9
|
+
this library; spec/v2/SPEC.md in the Plasmite repository holds the contract.
|
|
10
|
+
|
|
11
|
+
Return values:
|
|
12
|
+
- Functions that return int return 0 on success and -1 on failure. On
|
|
13
|
+
failure they store a new pls_error_t in *out_err. Pass NULL for out_err
|
|
14
|
+
to get the -1 without details.
|
|
15
|
+
- Next calls (pls_reader_next, pls_udp_follow_next_view)
|
|
16
|
+
return PLS_READ_MESSAGE for an item, PLS_READ_TIMEOUT when timeout_ms
|
|
17
|
+
passes, PLS_READ_COMPLETE when a finite read ends, PLS_READ_CANCELLED
|
|
18
|
+
after a cancel, and PLS_READ_ERROR on failure. A timeout leaves the reader
|
|
19
|
+
open. Pass zero to poll once or PLS_WAIT_FOREVER to wait without a limit.
|
|
20
|
+
- A PLS_ERROR_RETENTION_GAP error means the pool overwrote messages before
|
|
21
|
+
the reader reached them. `missing` holds the first missed sequence and
|
|
22
|
+
`next_seq` the oldest sequence still retained. Reopen at next_seq to
|
|
23
|
+
accept the loss.
|
|
24
|
+
|
|
25
|
+
Handles and their release calls. Every release call accepts NULL; never use a
|
|
26
|
+
handle after releasing it.
|
|
27
|
+
pls_client_t pls_client_new pls_client_free
|
|
28
|
+
pls_pool_t pls_pool_open, pls_pool_create pls_pool_free
|
|
29
|
+
pls_reader_t pls_pool_follow, pls_pool_fetch pls_reader_free
|
|
30
|
+
pls_udp_client_t pls_udp_client_new pls_udp_client_free
|
|
31
|
+
pls_udp_pool_t pls_udp_client_open_pool pls_udp_pool_free
|
|
32
|
+
pls_udp_follow_t pls_udp_pool_follow/fetch pls_udp_follow_free
|
|
33
|
+
pls_message_t reader items pls_message_release
|
|
34
|
+
pls_view_cursor_t pls_value_iter pls_cursor_free
|
|
35
|
+
pls_selector_t pls_selector_new pls_selector_free
|
|
36
|
+
pls_builder_t pls_builder_new pls_builder_free
|
|
37
|
+
pls_error_t any failing call pls_error_free
|
|
38
|
+
|
|
39
|
+
Buffers and outputs:
|
|
40
|
+
- Initialize output structs to zero. Free a successful pls_buf_t with
|
|
41
|
+
pls_buf_free and a UDP event with pls_udp_event_free.
|
|
42
|
+
- A stored message owns its encoded payload. Its borrowed spans stay valid
|
|
43
|
+
until the last owner releases it, including after reader and pool closure.
|
|
44
|
+
- pls_pool_info and pls_pool_list return typed snapshots of pool details.
|
|
45
|
+
- Strings inside pls_error_t belong to the error and go away with
|
|
46
|
+
pls_error_free. Free any previous error before reusing its output slot.
|
|
47
|
+
|
|
48
|
+
Example: print every retained message from a saved sequence onward.
|
|
49
|
+
|
|
50
|
+
pls_client_t *client = NULL;
|
|
51
|
+
pls_pool_t *pool = NULL;
|
|
52
|
+
pls_reader_t *stream = NULL;
|
|
53
|
+
pls_error_t *err = NULL;
|
|
54
|
+
pls_open_options_t open = { sizeof open, 1, NULL };
|
|
55
|
+
pls_read_options_t from = { sizeof from, PLS_READ_SEQUENCE, checkpoint, NULL, 0 };
|
|
56
|
+
|
|
57
|
+
if (pls_client_new("./data", &client, &err) == 0 &&
|
|
58
|
+
pls_pool_open(client, "sensors", &open, &pool, &err) == 0 &&
|
|
59
|
+
pls_pool_fetch(pool, &from, &stream, &err) == 0) {
|
|
60
|
+
for (;;) {
|
|
61
|
+
const pls_message_t *message = NULL;
|
|
62
|
+
pls_read_status_t status = pls_reader_next(stream, 1000, &message, &err);
|
|
63
|
+
if (status == PLS_READ_MESSAGE) {
|
|
64
|
+
printf("message %llu\n", (unsigned long long)pls_message_seq(message));
|
|
65
|
+
pls_message_release(message);
|
|
66
|
+
} else if (status != PLS_READ_TIMEOUT) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (err && err->kind == PLS_ERROR_RETENTION_GAP)
|
|
72
|
+
fprintf(stderr, "lost from %llu; reopen at %llu\n",
|
|
73
|
+
(unsigned long long)err->missing, (unsigned long long)err->next_seq);
|
|
74
|
+
else if (err)
|
|
75
|
+
fprintf(stderr, "plasmite: %s\n", err->message);
|
|
76
|
+
pls_error_free(err);
|
|
77
|
+
pls_reader_free(stream);
|
|
78
|
+
pls_pool_free(pool);
|
|
79
|
+
pls_client_free(client);
|
|
80
|
+
|
|
81
|
+
Use pls_pool_follow instead of pls_pool_fetch to keep waiting for new
|
|
82
|
+
messages.
|
|
83
|
+
|
|
84
|
+
Threads:
|
|
85
|
+
- Serialize all calls on each client, pool or stream handle, including
|
|
86
|
+
reads and free. Separate handles may run concurrently.
|
|
87
|
+
- A local stream cancel may overlap a read; wait for the read to return
|
|
88
|
+
before freeing the stream.
|
|
89
|
+
- UDP pool send and read calls may overlap while the handle stays alive;
|
|
90
|
+
wait for all of them before freeing it. A UDP follow cancel may run during
|
|
91
|
+
next; cancel and wait for active calls before close.
|
|
92
|
+
|
|
93
|
+
Caller obligations: every non-NULL pointer and pointer/length pair must refer
|
|
94
|
+
to valid, suitably aligned storage for the whole call. Handles and errors must
|
|
95
|
+
come from this library and go to their release call exactly once. Using a
|
|
96
|
+
handle after release, releasing it twice, passing an arbitrary non-NULL
|
|
97
|
+
address or overstating a buffer or tag length is undefined behavior; Plasmite
|
|
98
|
+
cannot turn it into an error.
|
|
99
|
+
|
|
100
|
+
ABI stability: within a major version this header only grows. Struct members
|
|
101
|
+
keep their order, enum values keep their numbers, and new functions and
|
|
102
|
+
fields go at the end. A breaking change takes a new major version, and each
|
|
103
|
+
major version has its own library file name.
|
|
104
|
+
|
|
105
|
+
Linking:
|
|
106
|
+
- Dynamic: libplasmite.2.dylib, libplasmite.so.2 or plasmite2.dll.
|
|
107
|
+
- Static: libplasmite.a, plus the system libraries -lpthread -ldl -lm.
|
|
108
|
+
- pkg-config: `pkg-config --cflags --libs plasmite` works after a Homebrew
|
|
109
|
+
or release SDK install.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
#ifndef PLASMITE_H
|
|
113
|
+
#define PLASMITE_H
|
|
114
|
+
|
|
115
|
+
#include <stdint.h>
|
|
116
|
+
#include <stdbool.h>
|
|
117
|
+
#include <stddef.h>
|
|
118
|
+
|
|
119
|
+
#define PLS_ABI_MAJOR 2
|
|
120
|
+
|
|
121
|
+
#ifdef __cplusplus
|
|
122
|
+
extern "C" {
|
|
123
|
+
#endif
|
|
124
|
+
|
|
125
|
+
#ifdef PLS_INTERNAL_ABI
|
|
126
|
+
#define pls_pool_feed_builder_view pls_internal_pool_feed_builder_view
|
|
127
|
+
#define pls_pool_feed_json_message pls_internal_pool_feed_json
|
|
128
|
+
#define pls_pool_feed_json_view pls_internal_pool_feed_json_view
|
|
129
|
+
#define pls_pool_feed_view pls_internal_pool_feed_view
|
|
130
|
+
#define pls_stream_next_wait pls_internal_stream_next_wait
|
|
131
|
+
#define pls_view_stream_next pls_internal_view_stream_next
|
|
132
|
+
#endif
|
|
133
|
+
|
|
134
|
+
uint32_t pls_abi_major(void);
|
|
135
|
+
|
|
136
|
+
typedef struct pls_client pls_client_t;
|
|
137
|
+
typedef struct pls_pool pls_pool_t;
|
|
138
|
+
typedef struct pls_reader pls_reader_t;
|
|
139
|
+
typedef struct pls_udp_client pls_udp_client_t;
|
|
140
|
+
typedef struct pls_udp_pool pls_udp_pool_t;
|
|
141
|
+
typedef struct pls_udp_follow pls_udp_follow_t;
|
|
142
|
+
|
|
143
|
+
typedef enum pls_error_kind {
|
|
144
|
+
PLS_ERROR_INTERNAL = 1,
|
|
145
|
+
PLS_ERROR_USAGE = 2,
|
|
146
|
+
PLS_ERROR_NOT_FOUND = 3,
|
|
147
|
+
PLS_ERROR_ALREADY_EXISTS = 4,
|
|
148
|
+
PLS_ERROR_BUSY = 5,
|
|
149
|
+
PLS_ERROR_PERMISSION = 6,
|
|
150
|
+
PLS_ERROR_CORRUPT = 7,
|
|
151
|
+
PLS_ERROR_IO = 8,
|
|
152
|
+
PLS_ERROR_RETENTION_GAP = 9
|
|
153
|
+
} pls_error_kind_t;
|
|
154
|
+
|
|
155
|
+
typedef struct pls_buf {
|
|
156
|
+
uint8_t *data;
|
|
157
|
+
size_t len;
|
|
158
|
+
} pls_buf_t;
|
|
159
|
+
|
|
160
|
+
typedef enum pls_udp_event_kind {
|
|
161
|
+
PLS_UDP_EVENT_FRAME = 1,
|
|
162
|
+
PLS_UDP_EVENT_SKIP = 2,
|
|
163
|
+
PLS_UDP_EVENT_PROGRESS = 3
|
|
164
|
+
} pls_udp_event_kind_t;
|
|
165
|
+
|
|
166
|
+
typedef enum pls_udp_skip_reason {
|
|
167
|
+
PLS_UDP_SKIP_UNKNOWN = 0, /* Reserved ABI value; invalid in wire SKIP packets. */
|
|
168
|
+
PLS_UDP_SKIP_OVERSIZED = 1,
|
|
169
|
+
PLS_UDP_SKIP_RETENTION = 2,
|
|
170
|
+
PLS_UDP_SKIP_PRESSURE = 3
|
|
171
|
+
} pls_udp_skip_reason_t;
|
|
172
|
+
|
|
173
|
+
/* Initialize to zero. Free every event with pls_udp_event_free after reading it. */
|
|
174
|
+
typedef struct pls_udp_event {
|
|
175
|
+
uint32_t kind;
|
|
176
|
+
uint32_t reason;
|
|
177
|
+
uint64_t seq;
|
|
178
|
+
uint64_t time;
|
|
179
|
+
uint64_t first;
|
|
180
|
+
uint64_t last;
|
|
181
|
+
uint64_t start_seq;
|
|
182
|
+
uint64_t next_seq;
|
|
183
|
+
uint64_t end_seq;
|
|
184
|
+
uint8_t has_end;
|
|
185
|
+
uint8_t terminal;
|
|
186
|
+
uint8_t reserved;
|
|
187
|
+
pls_buf_t payload;
|
|
188
|
+
} pls_udp_event_t;
|
|
189
|
+
|
|
190
|
+
/* A caller-owned receipt from a successful feed. Time counts Unix nanoseconds.
|
|
191
|
+
* A failed call leaves the output untouched. */
|
|
192
|
+
typedef struct pls_feed_receipt {
|
|
193
|
+
uint64_t seq;
|
|
194
|
+
uint64_t time;
|
|
195
|
+
} pls_receipt_t;
|
|
196
|
+
|
|
197
|
+
#ifdef PLS_INTERNAL_ABI
|
|
198
|
+
typedef pls_receipt_t pls_feed_receipt_t;
|
|
199
|
+
#endif
|
|
200
|
+
|
|
201
|
+
typedef struct pls_error {
|
|
202
|
+
int32_t kind;
|
|
203
|
+
char *message;
|
|
204
|
+
char *path;
|
|
205
|
+
uint64_t seq;
|
|
206
|
+
uint64_t offset;
|
|
207
|
+
uint8_t has_seq;
|
|
208
|
+
uint8_t has_offset;
|
|
209
|
+
uint64_t missing; /* For a retention gap. Zero otherwise. */
|
|
210
|
+
uint64_t next_seq; /* Oldest retained at gap detection. Zero otherwise. */
|
|
211
|
+
} pls_error_t;
|
|
212
|
+
|
|
213
|
+
typedef struct { const uint8_t *data; size_t len; } pls_text_t;
|
|
214
|
+
|
|
215
|
+
/* Read and feed options (pls_read_options_t, pls_feed_options_t): pass NULL
|
|
216
|
+
* for defaults, or set struct_size to sizeof the struct. Tag arrays and their
|
|
217
|
+
* strings must stay valid for the call; a stream keeps its own copy.
|
|
218
|
+
* start_value means: SEQUENCE, the first sequence to read; TIME, Unix
|
|
219
|
+
* nanoseconds; AGO, nanoseconds before now; LAST, a message count. DEFAULT
|
|
220
|
+
* starts a follow at the next new message and a fetch at the oldest. */
|
|
221
|
+
typedef enum pls_read_start_kind {
|
|
222
|
+
PLS_READ_DEFAULT = 0,
|
|
223
|
+
PLS_READ_OLDEST = 1,
|
|
224
|
+
PLS_READ_SEQUENCE = 2,
|
|
225
|
+
PLS_READ_TIME = 3,
|
|
226
|
+
PLS_READ_AGO = 4,
|
|
227
|
+
PLS_READ_LAST = 5,
|
|
228
|
+
PLS_READ_AFTER = 6
|
|
229
|
+
} pls_read_start_kind_t;
|
|
230
|
+
|
|
231
|
+
typedef struct pls_read_options {
|
|
232
|
+
uint32_t struct_size;
|
|
233
|
+
uint32_t start_kind;
|
|
234
|
+
uint64_t start_value; /* Time and duration are in nanoseconds. */
|
|
235
|
+
const pls_text_t *tags;
|
|
236
|
+
size_t tags_len;
|
|
237
|
+
} pls_read_options_t;
|
|
238
|
+
|
|
239
|
+
typedef struct pls_feed_options {
|
|
240
|
+
uint32_t struct_size;
|
|
241
|
+
uint32_t durability; /* 0=fast, 1=flush */
|
|
242
|
+
const pls_text_t *tags;
|
|
243
|
+
size_t tags_len;
|
|
244
|
+
} pls_feed_options_t;
|
|
245
|
+
|
|
246
|
+
/* Bounds are inclusive. Both sequences are zero when no messages remain.
|
|
247
|
+
* Text is UTF-8 with a length in bytes. An absent description or example has
|
|
248
|
+
* a NULL pointer and zero length. An example, when present, is a JSON object.
|
|
249
|
+
* The size and layout of these output structs are fixed for ABI major 2. */
|
|
250
|
+
typedef struct pls_pool_info {
|
|
251
|
+
pls_buf_t path;
|
|
252
|
+
uint64_t file_size;
|
|
253
|
+
uint64_t oldest_seq;
|
|
254
|
+
uint64_t newest_seq;
|
|
255
|
+
pls_buf_t about;
|
|
256
|
+
pls_buf_t example_json;
|
|
257
|
+
pls_buf_t warning; /* A legacy file appears in lists with a warning and no bounds. */
|
|
258
|
+
} pls_pool_info_t;
|
|
259
|
+
|
|
260
|
+
typedef struct pls_pool_list {
|
|
261
|
+
const pls_pool_info_t *entries;
|
|
262
|
+
size_t len;
|
|
263
|
+
} pls_pool_list_t;
|
|
264
|
+
|
|
265
|
+
/* Initialize output structs to zero and free each successful result with its
|
|
266
|
+
* matching free call before reusing it. Treat the views as read-only and free
|
|
267
|
+
* them only through the owning info result or list. Retained
|
|
268
|
+
* bounds can go stale immediately after inspection. */
|
|
269
|
+
int pls_pool_info(pls_pool_t *, pls_pool_info_t *, pls_error_t **);
|
|
270
|
+
void pls_pool_info_free(pls_pool_info_t *);
|
|
271
|
+
int pls_pool_list(pls_client_t *, pls_pool_list_t *, pls_error_t **);
|
|
272
|
+
void pls_pool_list_free(pls_pool_list_t *);
|
|
273
|
+
|
|
274
|
+
#ifdef PLS_INTERNAL_ABI
|
|
275
|
+
int pls_internal_pool_info_json(pls_pool_t *, pls_buf_t *, pls_error_t **);
|
|
276
|
+
int pls_internal_pool_list_json(pls_client_t *, pls_buf_t *, pls_error_t **);
|
|
277
|
+
#endif
|
|
278
|
+
/* Description JSON is an object with optional about and example fields. Set
|
|
279
|
+
* replaces both fields. See the pool size and ownership rules for create. */
|
|
280
|
+
int pls_pool_create_described(pls_client_t *, const char *, uint64_t,
|
|
281
|
+
const uint8_t *, size_t, pls_pool_t **, pls_error_t **);
|
|
282
|
+
int pls_pool_set_description(pls_pool_t *, const uint8_t *, size_t, pls_error_t **);
|
|
283
|
+
int pls_pool_delete(pls_client_t *, const char *, pls_error_t **);
|
|
284
|
+
|
|
285
|
+
#ifdef PLS_INTERNAL_ABI
|
|
286
|
+
int pls_pool_feed_json_message(pls_pool_t *, const uint8_t *, size_t,
|
|
287
|
+
const pls_feed_options_t *, pls_buf_t *, pls_error_t **);
|
|
288
|
+
#endif
|
|
289
|
+
int pls_pool_fetch(pls_pool_t *, const pls_read_options_t *, pls_reader_t **, pls_error_t **);
|
|
290
|
+
/* Pass NULL to open an existing pool without a source label. Set struct_size
|
|
291
|
+
* to sizeof the struct. Set create to 1 to create a missing pool with defaults.
|
|
292
|
+
* source is an optional UTF-8 label for new messages. The pool copies it. */
|
|
293
|
+
typedef struct pls_open_options {
|
|
294
|
+
uint32_t struct_size;
|
|
295
|
+
uint32_t create;
|
|
296
|
+
const char *source;
|
|
297
|
+
} pls_open_options_t;
|
|
298
|
+
/* A NULL client uses the default pool directory. */
|
|
299
|
+
int pls_pool_open(pls_client_t *, const char *, const pls_open_options_t *,
|
|
300
|
+
pls_pool_t **, pls_error_t **);
|
|
301
|
+
/* A NULL receipt skips the output. */
|
|
302
|
+
int pls_pool_feed_json(pls_pool_t *, const uint8_t *, size_t,
|
|
303
|
+
const pls_feed_options_t *, pls_receipt_t *, pls_error_t **);
|
|
304
|
+
/* Feed count JSON objects as one batch. Pass NULL to skip all receipts.
|
|
305
|
+
* Otherwise receipts points to count slots, filled only after a successful feed.
|
|
306
|
+
* An invalid input object leaves the pool unchanged. */
|
|
307
|
+
int pls_pool_feed_many_json(pls_pool_t *, const pls_text_t *messages, size_t count,
|
|
308
|
+
const pls_feed_options_t *, pls_receipt_t *receipts, pls_error_t **);
|
|
309
|
+
int pls_pool_follow(pls_pool_t *, const pls_read_options_t *, pls_reader_t **, pls_error_t **);
|
|
310
|
+
|
|
311
|
+
/* A NULL pool_dir uses the default directory, ~/.plasmite/pools. */
|
|
312
|
+
int pls_client_new(const char *pool_dir, pls_client_t **out_client, pls_error_t **out_err);
|
|
313
|
+
void pls_client_free(pls_client_t *client);
|
|
314
|
+
|
|
315
|
+
/* pool_ref names resolve in the client's directory. Native path separators
|
|
316
|
+
* select a file path; use ./bare.plasmite (or .\bare.plasmite on Windows)
|
|
317
|
+
* for an explicit bare file. Windows drive-relative forms are unsupported. */
|
|
318
|
+
int pls_pool_create(pls_client_t *client, const char *pool_ref, uint64_t size_bytes, pls_pool_t **out_pool, pls_error_t **out_err);
|
|
319
|
+
void pls_pool_free(pls_pool_t *pool);
|
|
320
|
+
|
|
321
|
+
void pls_reader_free(pls_reader_t *stream);
|
|
322
|
+
|
|
323
|
+
void pls_buf_free(pls_buf_t *buf);
|
|
324
|
+
void pls_error_free(pls_error_t *err);
|
|
325
|
+
|
|
326
|
+
/*
|
|
327
|
+
* UDP uses one explicit endpoint and a separate client/pool/follow handle.
|
|
328
|
+
* `pool_name` must be a named pool. Send calls report local validation and OS
|
|
329
|
+
* send errors only; success does not confirm that the server stored a message.
|
|
330
|
+
* Follow delivers matching DATA in arrival order, including late messages and
|
|
331
|
+
* duplicates. Only explicit server skips produce gap events. Progress describes
|
|
332
|
+
* server attempts and never suppresses a later-arriving DATA packet.
|
|
333
|
+
* Finite follows end on terminal progress after draining accepted events;
|
|
334
|
+
* DATA still in flight may go unread. Completion does not confirm full delivery.
|
|
335
|
+
*/
|
|
336
|
+
int pls_udp_client_new(
|
|
337
|
+
const char *endpoint,
|
|
338
|
+
pls_udp_client_t **out_client,
|
|
339
|
+
pls_error_t **out_err);
|
|
340
|
+
void pls_udp_client_free(pls_udp_client_t *client);
|
|
341
|
+
int pls_udp_client_open_pool(
|
|
342
|
+
pls_udp_client_t *client,
|
|
343
|
+
const char *pool_name,
|
|
344
|
+
pls_udp_pool_t **out_pool,
|
|
345
|
+
pls_error_t **out_err);
|
|
346
|
+
void pls_udp_pool_free(pls_udp_pool_t *pool);
|
|
347
|
+
/* UDP feed confirms local socket admission. It has no storage receipt. */
|
|
348
|
+
int pls_udp_pool_feed_json(pls_udp_pool_t *, const uint8_t *, size_t,
|
|
349
|
+
const pls_feed_options_t *, pls_error_t **);
|
|
350
|
+
void pls_udp_follow_cancel(pls_udp_follow_t *follow);
|
|
351
|
+
void pls_udp_follow_free(pls_udp_follow_t *follow);
|
|
352
|
+
void pls_udp_event_free(pls_udp_event_t *event);
|
|
353
|
+
/*
|
|
354
|
+
* Reader waits: 1=message, 0=wait expired, 2=reader finished, 3=cancelled,
|
|
355
|
+
* -1=error. A timeout leaves the reader open. Zero polls once; UINT64_MAX
|
|
356
|
+
* waits without a time limit. A read failure remains visible on later calls.
|
|
357
|
+
* The wait cannot interrupt a file operation already waiting on an OS lock.
|
|
358
|
+
* Cancel may overlap a read and is permanent. Wait for the read before free.
|
|
359
|
+
* Output buffers belong to the caller only on status 1.
|
|
360
|
+
*/
|
|
361
|
+
#ifdef PLS_INTERNAL_ABI
|
|
362
|
+
int pls_stream_next_wait(pls_reader_t *stream, uint64_t timeout_ms,
|
|
363
|
+
pls_buf_t *out_message, pls_error_t **out_err);
|
|
364
|
+
#endif
|
|
365
|
+
void pls_reader_cancel(pls_reader_t *stream);
|
|
366
|
+
|
|
367
|
+
/* Value kinds returned by native message views. */
|
|
368
|
+
typedef enum pls_field_kind {
|
|
369
|
+
PLS_FIELD_MISSING = 0, PLS_FIELD_NULL = 1, PLS_FIELD_BOOL = 2,
|
|
370
|
+
PLS_FIELD_I64 = 3, PLS_FIELD_F64 = 4, PLS_FIELD_STRING = 5,
|
|
371
|
+
PLS_FIELD_BYTES = 6, PLS_FIELD_OBJECT = 7, PLS_FIELD_ARRAY = 8
|
|
372
|
+
} pls_field_kind_t;
|
|
373
|
+
/* Additive immutable snapshot API. Owners retain four-byte-aligned private
|
|
374
|
+
* bytes independently of pool/stream lifetime. Retain/release and immutable
|
|
375
|
+
* reads may run concurrently on independently held references. Keep an owner
|
|
376
|
+
* alive through every borrowed access; never alter or forge a value_ref.
|
|
377
|
+
* Readers return owned snapshots.
|
|
378
|
+
* Value references and borrowed key/string/byte spans need no individual free.
|
|
379
|
+
* Mutation requires copying. A zero owner represents an absent value.
|
|
380
|
+
*/
|
|
381
|
+
typedef struct pls_message_view pls_message_view_t;
|
|
382
|
+
typedef pls_message_view_t pls_message_t;
|
|
383
|
+
int pls_udp_pool_follow(pls_udp_pool_t *, const pls_read_options_t *, pls_udp_follow_t **, pls_error_t **);
|
|
384
|
+
int pls_udp_pool_fetch(pls_udp_pool_t *, const pls_read_options_t *, pls_udp_follow_t **, pls_error_t **);
|
|
385
|
+
|
|
386
|
+
typedef enum pls_read_status {
|
|
387
|
+
PLS_READ_ERROR = -1,
|
|
388
|
+
PLS_READ_TIMEOUT = 0,
|
|
389
|
+
PLS_READ_MESSAGE = 1,
|
|
390
|
+
PLS_READ_COMPLETE = 2,
|
|
391
|
+
PLS_READ_CANCELLED = 3
|
|
392
|
+
} pls_read_status_t;
|
|
393
|
+
#define PLS_WAIT_FOREVER UINT64_MAX
|
|
394
|
+
|
|
395
|
+
/* Wait for one owned message. A timeout leaves the reader open. */
|
|
396
|
+
pls_read_status_t pls_reader_next(pls_reader_t *, uint64_t timeout_ms,
|
|
397
|
+
const pls_message_t **, pls_error_t **);
|
|
398
|
+
/* Wait for one message, then read up to max available messages. The caller
|
|
399
|
+
* provides max output slots and releases each of the count returned messages. */
|
|
400
|
+
pls_read_status_t pls_reader_next_many(pls_reader_t *, uint64_t timeout_ms, size_t max,
|
|
401
|
+
const pls_message_t **messages, size_t *count, pls_error_t **);
|
|
402
|
+
/* Borrow the sender's UTF-8 bytes while the owner lives. NULL means absent. */
|
|
403
|
+
const uint8_t *pls_message_sender(const pls_message_t *, size_t *len);
|
|
404
|
+
/* Borrow the declared source's UTF-8 bytes while the owner lives. NULL means absent. */
|
|
405
|
+
const uint8_t *pls_message_source(const pls_message_t *, size_t *len);
|
|
406
|
+
typedef struct pls_value_ref {
|
|
407
|
+
const pls_message_view_t *owner;
|
|
408
|
+
size_t offset;
|
|
409
|
+
} pls_value_ref_t;
|
|
410
|
+
/* Borrow the tags array and data while the message owner lives. */
|
|
411
|
+
pls_value_ref_t pls_message_tags(const pls_message_t *);
|
|
412
|
+
typedef struct pls_view_value {
|
|
413
|
+
uint32_t kind; /* pls_field_kind_t; zero means absent */
|
|
414
|
+
int64_t integer;
|
|
415
|
+
double real;
|
|
416
|
+
const uint8_t *bytes;
|
|
417
|
+
size_t len; /* bytes for strings/bytes, unique count for containers */
|
|
418
|
+
} pls_view_value_t;
|
|
419
|
+
typedef struct pls_view_entry {
|
|
420
|
+
const uint8_t *key; /* NULL for array entries */
|
|
421
|
+
size_t key_len;
|
|
422
|
+
pls_value_ref_t value;
|
|
423
|
+
} pls_view_entry_t;
|
|
424
|
+
#ifdef PLS_INTERNAL_ABI
|
|
425
|
+
/* New view API: exact integer tokens must fit i64; rejects before publication. */
|
|
426
|
+
int pls_pool_feed_json_view(pls_pool_t *pool, const uint8_t *json, size_t len,
|
|
427
|
+
const pls_feed_options_t *options, const pls_message_view_t **out, pls_error_t **err);
|
|
428
|
+
int pls_pool_feed_view(pls_pool_t *pool, const pls_message_view_t *source,
|
|
429
|
+
const pls_feed_options_t *options, const pls_message_view_t **out,
|
|
430
|
+
pls_feed_receipt_t *receipt, pls_error_t **err);
|
|
431
|
+
#endif
|
|
432
|
+
void pls_message_retain(const pls_message_view_t *view);
|
|
433
|
+
void pls_message_release(const pls_message_view_t *view);
|
|
434
|
+
pls_value_ref_t pls_view_root(const pls_message_view_t *view);
|
|
435
|
+
pls_value_ref_t pls_message_data(const pls_message_view_t *view);
|
|
436
|
+
/* Conservative whole-owner property: finite numbers, exact binary64 integers,
|
|
437
|
+
* and no native bytes. False for NULL or an owner whose builder did not track it. */
|
|
438
|
+
bool pls_view_json_native_safe(const pls_message_view_t *view);
|
|
439
|
+
uint64_t pls_message_seq(const pls_message_view_t *view);
|
|
440
|
+
uint64_t pls_message_time(const pls_message_view_t *view);
|
|
441
|
+
/* Reserved payload storage capacity, excluding owner/index metadata. Shared
|
|
442
|
+
* children/forwarded owners retain the same storage; NULL returns zero. */
|
|
443
|
+
size_t pls_view_retained_bytes(const pls_message_view_t *view);
|
|
444
|
+
int pls_value_get(pls_value_ref_t value, const uint8_t *key, size_t len,
|
|
445
|
+
pls_value_ref_t *out, pls_error_t **err);
|
|
446
|
+
int pls_value_index(pls_value_ref_t value, uint32_t index,
|
|
447
|
+
pls_value_ref_t *out, pls_error_t **err);
|
|
448
|
+
int pls_value_read(pls_value_ref_t value, pls_view_value_t *out, pls_error_t **err);
|
|
449
|
+
/* For a valid container, out_count receives the required capacity. A smaller
|
|
450
|
+
* buffer returns Usage without filling slots. Keys use unique canonical
|
|
451
|
+
* last-entry values. */
|
|
452
|
+
int pls_value_entries(pls_value_ref_t value, pls_view_entry_t *slots,
|
|
453
|
+
size_t capacity, size_t *out_count, pls_error_t **err);
|
|
454
|
+
/* Sequential cursor retains one owner and bounded state. Serialize calls on
|
|
455
|
+
* each cursor. next fills at most capacity slots; zero written means end when
|
|
456
|
+
* capacity > 0. No collection-sized entry array or full scan per chunk. */
|
|
457
|
+
typedef struct PlsmViewCursor pls_view_cursor_t;
|
|
458
|
+
int pls_value_iter(pls_value_ref_t value, pls_view_cursor_t **out, pls_error_t **err);
|
|
459
|
+
int pls_cursor_next(pls_view_cursor_t *cursor, pls_view_entry_t *slots,
|
|
460
|
+
size_t capacity, size_t *written, pls_error_t **err);
|
|
461
|
+
void pls_cursor_free(pls_view_cursor_t *cursor);
|
|
462
|
+
/* Compile JSON Pointers once; reuse without parsing paths or validating the
|
|
463
|
+
* immutable message again. Selection returns borrowed refs, no string copies.
|
|
464
|
+
* Keep selector immutable and alive during calls; free it independently. */
|
|
465
|
+
typedef struct PlsmSelector pls_selector_t;
|
|
466
|
+
int pls_selector_new(const char *const *paths, size_t count,
|
|
467
|
+
pls_selector_t **out, pls_error_t **err);
|
|
468
|
+
void pls_selector_free(pls_selector_t *selector);
|
|
469
|
+
int pls_view_select(const pls_message_view_t *view,
|
|
470
|
+
const pls_selector_t *selector, pls_value_ref_t *slots,
|
|
471
|
+
size_t capacity, pls_error_t **err);
|
|
472
|
+
int pls_value_to_json(pls_value_ref_t value, pls_buf_t *out, pls_error_t **err);
|
|
473
|
+
/* Native-copy helper preserves view key order; normal JSON output stays canonical. */
|
|
474
|
+
int pls_value_to_json_stored(pls_value_ref_t value, pls_buf_t *out, pls_error_t **err);
|
|
475
|
+
/* Complete seq/time/meta/data envelope, with no intermediate native object tree. */
|
|
476
|
+
int pls_message_to_json(const pls_message_view_t *view, pls_buf_t *out, pls_error_t **err);
|
|
477
|
+
|
|
478
|
+
/* Native input walkers. All calls on a builder require caller serialization.
|
|
479
|
+
* Text spans borrow input for the call only; embedded NUL is valid in values
|
|
480
|
+
* and tags, but object keys reject it. NULL key means an array element; a
|
|
481
|
+
* non-NULL empty span names the empty object key. Kinds match pls_view_value_t.
|
|
482
|
+
* Nodes are opaque handles, not byte offsets; pass them back unchanged and
|
|
483
|
+
* use only nodes returned by this builder. Container puts return a child node.
|
|
484
|
+
* A successful feed consumes the builder contents. Free the handle once
|
|
485
|
+
* afterward. A build error stops publication.
|
|
486
|
+
* A flush error can follow publication, as for other appends. */
|
|
487
|
+
typedef struct pls_builder pls_builder_t;
|
|
488
|
+
#ifdef PLS_INTERNAL_ABI
|
|
489
|
+
/* View reads: pls_view_stream_next reads immutable message views from a
|
|
490
|
+
* pls_reader_t opened by pls_pool_follow or pls_pool_fetch, as an
|
|
491
|
+
* alternative to pls_stream_next_wait. The caller owns each returned view.
|
|
492
|
+
* Use pls_reader_cancel and pls_reader_free. Serialize reads. Cancel may run
|
|
493
|
+
* concurrently.
|
|
494
|
+
* next waits for the first matching item. Local reads then acquire available
|
|
495
|
+
* companions without waiting. Each HTTPS call returns at most one item.
|
|
496
|
+
* max_count/max_bytes must be positive; bytes bound encoded payload snapshots.
|
|
497
|
+
* An oversized first record errors without consuming it. Each returned owner
|
|
498
|
+
* requires pls_message_release, including any prefix returned before an error.
|
|
499
|
+
* Zero polls once; UINT64_MAX waits without a time limit.
|
|
500
|
+
* Status: 0=wait expired, 1=items, 2=finished, 3=cancelled, -1=error.
|
|
501
|
+
* out has max_count slots; count always reports initialized owners. */
|
|
502
|
+
int pls_view_stream_next(pls_reader_t *stream, uint64_t timeout_ms,
|
|
503
|
+
size_t max_count, size_t max_bytes, const pls_message_view_t **out,
|
|
504
|
+
size_t *count, pls_error_t **err);
|
|
505
|
+
#endif
|
|
506
|
+
|
|
507
|
+
/* UDP waits use 1/event, 0/timeout, 2/end, 3/cancelled and -1/error.
|
|
508
|
+
* Initialize event to zero
|
|
509
|
+
* and free it normally; payload stays empty. DATA returns an independent owner
|
|
510
|
+
* (release with pls_message_release); controls return NULL. Other statuses leave
|
|
511
|
+
* outputs untouched. Close only after active calls return. */
|
|
512
|
+
pls_read_status_t pls_udp_follow_next_view(pls_udp_follow_t *follow, uint64_t timeout_ms,
|
|
513
|
+
pls_udp_event_t *out_event, const pls_message_view_t **out_owner,
|
|
514
|
+
pls_error_t **err);
|
|
515
|
+
|
|
516
|
+
int pls_builder_new(const pls_text_t *tags, size_t count,
|
|
517
|
+
pls_builder_t **out, size_t *data_node, pls_error_t **err);
|
|
518
|
+
int pls_builder_put(pls_builder_t *builder, size_t parent,
|
|
519
|
+
const uint8_t *key, size_t key_len, const pls_view_value_t *value,
|
|
520
|
+
size_t *child_node, pls_error_t **err);
|
|
521
|
+
#ifdef PLS_INTERNAL_ABI
|
|
522
|
+
int pls_pool_feed_builder_view(pls_pool_t *pool, pls_builder_t *builder,
|
|
523
|
+
const pls_feed_options_t *options, const pls_message_view_t **out, pls_error_t **err);
|
|
524
|
+
/* With try_only, 1 means defer and leaves the builder available to retry. */
|
|
525
|
+
int pls_internal_pool_feed_builder_receipt(pls_pool_t *pool, pls_builder_t *builder,
|
|
526
|
+
const pls_feed_options_t *options, pls_feed_receipt_t *out, pls_error_t **err,
|
|
527
|
+
bool try_only);
|
|
528
|
+
int pls_internal_pool_feed_many_builders(pls_pool_t *pool, pls_builder_t *const *builders,
|
|
529
|
+
size_t count, const pls_feed_options_t *options, pls_feed_receipt_t *receipts,
|
|
530
|
+
pls_error_t **error);
|
|
531
|
+
|
|
532
|
+
#endif
|
|
533
|
+
/* Copy a checked subtree while the source owner remains alive. SIZE_MAX parent
|
|
534
|
+
* fills an empty data object from a source object and requires NULL key/zero
|
|
535
|
+
* length. It preserves the data_node returned by builder_new; other parents use
|
|
536
|
+
* the ordinary object-key/array-item rule. No host scalar conversion occurs. */
|
|
537
|
+
int pls_builder_copy_value(pls_builder_t *builder, size_t parent,
|
|
538
|
+
const uint8_t *key, size_t key_len, pls_value_ref_t source, pls_error_t **err);
|
|
539
|
+
void pls_builder_free(pls_builder_t *builder);
|
|
540
|
+
|
|
541
|
+
#ifdef __cplusplus
|
|
542
|
+
} // extern "C"
|
|
543
|
+
#endif
|
|
544
|
+
|
|
545
|
+
#endif // PLASMITE_H
|
|
Binary file
|
|
Binary file
|