03 Calls and ownership
| Call | Purpose |
|---|---|
stardust_decode(input, options, output, error) |
Copy notation bytes into an owned immutable Document |
stardust_open(config, output, error) |
Open a database and its worker runtimes |
stardust_submit(database, requests, count, accepted, error) |
Copy and accept request Documents |
stardust_poll(database, wait_ticks, output, capacity, count, error) |
Transfer up to capacity owned response Documents to the host |
stardust_encode(document, options, output, error) |
Return notation bytes and their owner |
stardust_release(handle, error) |
Release a Document, database or encoded-byte owner |
A stardust_bytes input contains data and length. Its bytes need not end
with a zero byte. A stardust_buffer output contains data, length and
owner. Read exactly length bytes, then release owner. Do not free or
release data.
Each returned Document, database and encoded-byte owner has one release
obligation. stardust_release(NULL, NULL) is permitted. Copying a handle
pointer makes an alias to the same object; it does not retain it or create
another ownership reference. There is no retain or clone call. Release an
existing owned value before reusing its output variable.
Decode copies its input. Submit copies each accepted request. The host can
release its request Documents after submit returns, including on failure.
accepted reports the accepted prefix when a batch is only partly accepted.
Documents returned by poll and buffers returned by encode remain valid after
the database closes. Releasing a Document does not release an encoded buffer
made from it; the buffer has its own owner.
A text, bytes or Bitset value in a Document holds at most 4,294,967,295 bytes,
and a container at most 4,294,967,295 items: a cell stores its length in 32
bits. A longer text or a container with more items is refused, not shortened:
stardust_decode reports it as an invalid value. Keep larger payloads in the
objects plugin, which reads a payload by byte range.
A value that crosses into or out of a runtime (bindings, a result, one page of query results) holds at most 2,147,483,647 cells, 2,147,483,647 bytes of text and 2,147,483,647 facts. This runtime bound comes from the runtime's 32-bit counts. Past it, the request fails with a resource limit error that names the bound.
Documents are immutable value snapshots. They do not contain live sessions, cursors, subscriptions or callable handles. Links and pointers are inert data, not native pointers or automatic database lookups. Encoding and decoding do not execute a request. Copy a value independently by encoding and decoding it; TRON preserves native value and floating-point kinds.
Document reads can overlap. Submit supports multiple submitting threads, but
only one poll call can be active for a database: overlapping polls return
STARDUST_BUSY. A release must not overlap a call using the same handle.
Database release cancels outstanding work, joins workers, closes sessions and
releases undelivered responses. The library does not call back into host code.
3.1. Raw bytes
A host can send and receive bytes without a notation and without base64.
Both calls name a value with a path: the map member names from the root of
the Document, joined by /. An empty path names the root.
stardust_bytes_get writes the bytes of the Bytes or UUID value at a path to
its output. The bytes belong to the Document until you release it, so a host
reads a response page without a copy. For example, the path "result"
names the bytes of an objects/payloads/open page.
stardust_bytes_with writes a new Document to its output: a copy of a
Document whose Bytes value at a path holds the given bytes. The input
Document does not change. Decode a request once with a placeholder, such as
bytes #b64 "" in the params of objects/uploads/append, and make each
request with the path "params/bytes". If the value at the path is not
Bytes, the call returns STARDUST_WRONG_KIND.
In Go, Database.UploadPayload reads an io.Reader and publishes its bytes
with the objects plugin, and Database.WritePayload writes a published
payload to an io.Writer. Both use these calls, so the payload bytes are
never in a notation. The Go binding also reads the identity of each response
with stardust_bytes_get, so it does not encode a response to route it.