tur/serial

stdlib/serial.tur
defn

bytes-alloc

(bytes-alloc [n :int] :ptr<void>)

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

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

Since: Phase 21

defn

bytes-len

(bytes-len [b :ptr<void>] :int)

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

bbytes pointer from bytes-alloc or a serialize call

Since: Phase 21

defn

bytes-data

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

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

Since: Phase 21

defn

bytes-free

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

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

bbytes pointer to free

Since: Phase 21

defn

bytes-concat

(bytes-concat [a :ptr<void> b :ptr<void>] :ptr<void>)

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)

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

cont-to-file

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

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)

Since: Phase 21

defn

cont-from-file

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

read a serialised continuation bytes value from a file.

pathfilesystem path previously written by cont-to-file

Since: Phase 21