No matching definitions.

nng/payload

src/nng/payload.tur

an owned, length-prefixed byte buffer for nng messages.

Since: Phase NG2

defopaque

Payload

(Payload)

an owned length-prefixed byte buffer (ABI: ptr<void>).

defn

payload-alloc

(payload-alloc [n : int] :)

allocate a zeroed buffer of `n` bytes.

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

A fresh owned Payload; release it with payload-free.

(let [b (payload-alloc 4)] (payload-len b))  ; => 4

Since: Phase NG2

defn

payload-of-cstr

(payload-of-cstr [s : cstr] :)

copy a NUL-terminated string into a fresh buffer.

sthe string to copy (borrowed; the caller keeps ownership)

A fresh owned Payload; release it with payload-free.

(let [b (payload-of-cstr "job:42")] (payload-len b))  ; => 6

Since: Phase NG2

defn

payload-len

(payload-len [b : Payload] :)

the number of data bytes the buffer holds.

bthe buffer to measure

int -- the byte length (0 for a null handle).

(payload-len (payload-of-cstr "abc"))  ; => 3

Since: Phase NG2

defn

payload-data

(payload-data [b : Payload] :)

a borrowed pointer to the buffer's first data byte.

bthe buffer to borrow from

ptr<void> -- the data region (past the length prefix).

(let [b (payload-alloc 8)] (payload-data b))

Since: Phase NG2

defn

payload-free

(payload-free [b : Payload] :)

release the buffer.

bthe buffer whose owning handle is being dropped
(payload-free (ok-val (recv-payload s)))

Since: Phase NG2

defn

payload-byte

(payload-byte [b : Payload i : int] :)

the byte at index i, or -1 when out of range.

bthe buffer to read
izero-based byte index

int -- 0..255, or -1 if i is outside [0, len).

(payload-byte (payload-of-cstr "A") 0)  ; => 65

Since: Phase NG2

defn

payload-empty?

(payload-empty? [b : Payload] :)

true when the buffer carries no data bytes.

bthe buffer to test

bool -- true for a zero-length buffer (and for a null handle).

(payload-empty? (payload-alloc 0))  ; => true

Since: Phase NG2

defn

payload->cstr

(payload->cstr [b : Payload] :)

a fresh NUL-terminated copy of the payload.

bthe buffer to copy from (borrowed)

cstr -- a malloc'd string the caller owns.

(payload->cstr (payload-of-cstr "pong"))  ; => "pong"

Since: Phase NG2

defn

payload->hex

(payload->hex [b : Payload] :)

lowercase hex rendering of the payload, for tests and logs.

bthe buffer to render (borrowed)

cstr -- a malloc'd string the caller owns; "" for an empty buffer.

(payload->hex (payload-of-cstr "A"))  ; => "41"

Since: Phase NG2

Internal definitions
__payload-alloc-raw-- internal: allocate a zeroed buffer, as a bare pointer.
__payload-of-cstr-raw-- internal: copy a cstr's bytes, as a bare pointer.
payload-- byte-wise equality.