No matching definitions.

tur/serial

stdlib/serial.tur

serializable continuations for persistent workflow state.

Since: Phase 21

defopaque linear

Bytes

(Bytes)
defn

bytes-alloc

(bytes-alloc [n : int] :)

allocate a zeroed length-prefixed byte buffer of n bytes.

nnumber of data bytes to allocate (not counting the 8-byte length prefix)

A :ptr<void> to the new bytes value; free with bytes-free.

(def b (bytes-alloc 16))  ; => 16-byte zeroed buffer

Since: Phase 21

defn

bytes-len

(bytes-len [^borrow b : Bytes] :)

return the number of data bytes stored in a bytes value.

bbytes pointer from bytes-alloc or a serialize call

The data length as :int (0 for null pointer).

Since: Phase 21

defn

bytes-data

(bytes-data [^borrow b : Bytes] :)

return a raw pointer to the data region of a bytes value (past the length prefix).

bbytes pointer from bytes-alloc or a serialize call

:ptr<void> to the first data byte, or NULL for a null pointer.

Since: Phase 21

defn

bytes-free

(bytes-free [b : Bytes] :)

free a bytes value allocated by bytes-alloc or serialize.

bbytes pointer to free

Since: Phase 21

defn

bytes-concat

(bytes-concat [^borrow a : Bytes ^borrow b : Bytes] :)

concatenate two bytes values into a new heap-allocated bytes value.

afirst bytes value (may be null, treated as empty)
bsecond bytes value (may be null, treated as empty)

A new bytes value containing all bytes of a followed by all bytes of b.

(bytes-concat ba bb)  ; => new bytes with ba then bb

Since: Phase 21

definstance

Serializable[int]

(definstance Serializable [int])

serialize/deserialize int64 as 8 little-endian bytes.

Since: Phase 21

definstance

Serializable[bool]

(definstance Serializable [bool])

serialize/deserialize bool as a single byte (0 = false, 1 = true).

Since: Phase 21

definstance

Serializable[float]

(definstance Serializable [float])

serialize/deserialize float64 as 8 bytes IEEE 754 little-endian.

Since: Phase 21

definstance

Serializable[cstr]

(definstance Serializable [cstr])

serialize/deserialize a cstr as a 4-byte LE length prefix followed by UTF-8 bytes.

Since: Phase 21

definstance

Serializable[ptr<void>]

(definstance Serializable [ptr<void>])

serialize/deserialize a bytes value as an 8-byte LE length followed by raw data.

Since: Phase 21

defn

serial-pair-bytes

(serial-pair-bytes [fst : int snd : int] :)

raw [len=16][fst][snd] Pair byte layout from two int64

fstfirst element's int64 carrier
sndsecond element's int64 carrier

A raw :ptr<void> bytes value (see the module note on the raw-buffer surface).

Since: end-to-end-monomorphization (M4 bucket-D)

definstance

Serializable[Pair]

(definstance Serializable [Pair])

serialize a Pair[A B] as its two int64 element carriers.

Since: cps-transform-plan (value-typed cont env codec)

definstance

Serializable[Option]

(definstance Serializable [Option])

serialize an Option[A] as a presence flag + carrier.

Since: cps-transform-plan (value-typed cont env codec)

defn

cont-to-file

(cont-to-file [b ptr<void> path : cstr] :)

write a serialised continuation bytes value to a file.

bbytes value from serial-cont->bytes / save-cont!
pathfilesystem path to write (overwritten if it exists)

1 on success, 0 on failure.

(cont-to-file k-bytes "/tmp/checkpoint.bin")  ; => 1

Since: Phase 21

defn

cont-from-file

(cont-from-file [path : cstr] :)

read a serialised continuation bytes value from a file.

pathfilesystem path previously written by cont-to-file

A bytes :ptr<void> on success, NULL on any I/O or allocation failure.

(def k-bytes (cont-from-file "/tmp/checkpoint.bin"))

Since: Phase 21

defn

serial-cont->bytes

(serial-cont->bytes [k : serial-cont] :)

marshal a captured continuation to a bytes value.

kthe continuation the serial-shift receiver was passed

A caller-owned bytes :ptr<void> ({int64 len; data}), or NULL if k is nil.

(defn stash [k : serial-cont] : int
    (do (cont-to-file (serial-cont->bytes k) "/tmp/k.bin") 0))
  (serial-reset (+ 10 (serial-shift stash 0)))

Since: Phase 21 (typed surface 2026-09-02)

defn

bytes->serial-cont

(bytes->serial-cont [b ptr<void>] :)

rebuild a continuation from bytes, or say why not.

ba bytes value from serial-cont->bytes / save-cont! / cont-from-file

(Ok k) with a resumable serial-cont, or (Err msg) with a static cstr: "null bytes", "short buffer", "bad frame count", "truncated frame", "frame name too long", "unknown frame (written by a different program?)", "truncated env", "bad env kind", "bad frame tag" -- each prefixed with "bytes->serial-cont: ".

(match (bytes->serial-cont (cont-from-file "/tmp/k.bin"))
    (Ok k)  (serial-resume k 5)
    (Err m) (do (println m) 0))

Since: Phase 21 (typed surface 2026-09-02)

defn

serial-resume

(serial-resume [k : serial-cont v : int] :)

resume a continuation with a value.

ka serial-cont
vthe value to fill the hole with

The resumed computation's result.

(defn sk [k : serial-cont] : int (serial-resume k 5))
  (serial-reset (+ 10 (serial-shift sk 0)))   ; => 15

Since: Phase 21 (typed surface 2026-09-02)