No matching definitions.

msgpack/buf

src/msgpack/buf.tur

an owned, length-prefixed byte buffer.

Since: Phase MP1

defopaque

Buf

(Buf)

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

defn

buf-alloc

(buf-alloc [n : int] :)

allocate a zeroed buffer of `n` bytes.

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

A fresh owned Buf; release it with buf-free.

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

Since: Phase MP1

defn

buf-len

(buf-len [b : Buf] :)

the number of data bytes the buffer holds.

bthe buffer to measure

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

(buf-len (hex->buf "c3"))   ; => 1

Since: Phase MP1

defn

buf-data

(buf-data [b : Buf] :)

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 (buf-alloc 8)] (buf-data b))

Since: Phase MP1

defn

buf-free

(buf-free [b : Buf] :)

release the buffer.

bthe buffer whose owning handle is being dropped
(buf-free (encode-mp 42))

Since: Phase MP1

defn

buf-concat

(buf-concat [a : Buf b : Buf] :)

concatenate two buffers, CONSUMING both.

athe left fragment (consumed)
bthe right fragment (consumed)

A fresh owned Buf holding a's bytes followed by b's.

(buf->hex (buf-concat (encode-mp 1) (encode-mp 2)))   ; => "0102"

Since: Phase MP1

defn

buf-byte

(buf-byte [b : Buf i : int] :)

the i-th data byte, as an int in 0..255.

bthe buffer to read
izero-based byte index

int -- the byte, or -1 when i is out of range.

(buf-byte (encode-mp true) 0)   ; => 195   (0xc3)

Since: Phase MP1

defn

buf-empty?

(buf-empty? [b : Buf] :)

true when the buffer holds no data bytes.

bthe buffer to test

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

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

Since: Phase MP1

defn

buf->hex

(buf->hex [b : Buf] :)

render the buffer as lowercase hex.

bthe buffer to render

cstr -- a freshly malloc'd hex string; the caller frees it.

(buf->hex (encode-mp 128))   ; => "cc80"

Since: Phase MP1

defn

hex->buf

(hex->buf [s : cstr] :)

parse a lowercase-or-uppercase hex string into a Buf.

san even-length string of hex digits

A fresh owned Buf; an EMPTY buf when `s` is malformed (odd length or a non-hex digit).

(buf-byte (hex->buf "c0") 0)   ; => 192

Since: Phase MP1

Internal definitions
__buf-alloc-raw-- internal: allocate a zeroed buffer, as a bare pointer.
__buf-concat-raw-- internal: concatenate, as a bare pointer.
buf-- byte-for-byte equality.
__buf-null-ptr?-- internal: is this a null pointer?
__hex->buf-raw-- internal: parse hex, as a bare pointer (NULL on error).