Skip to main content

Module consts

Module consts 

Source
Expand description

Compile-time serialization helpers (const fn, panic on overflow).

Inside const evaluation a panic is a compile error, which turns these into checked builders for constant CBOR items:

use const_cbor::encode::consts;

const HEARTBEAT: ([u8; 3], usize) = {
    let mut buf = [0u8; 3];
    let n = consts::put_u64(&mut buf, 0);
    (buf, n)
};
assert_eq!(&HEARTBEAT.0[..HEARTBEAT.1], &[0x00]);

Functionsยง

chunk_len
Encoded length of a string/bytes item with payload_len content bytes.
i64_len
Preferred encoded length of signed integer v.
put_i64
Writes signed integer v into buf; returns bytes written.
put_u64
Writes unsigned integer v into buf; returns bytes written.
uint_len
Preferred encoded length of unsigned integer v.