zvariant

Function serialized_size

source
pub fn serialized_size<B, T>(
    ctxt: EncodingContext<B>,
    value: &T,
) -> Result<usize>
Expand description

Calculate the serialized size of T.

§Panics

This function will panic if the value to serialize contains file descriptors. Use serialized_size_fds if T (potentially) contains FDs.

§Examples

use zvariant::{EncodingContext, serialized_size};

let ctxt = EncodingContext::<byteorder::LE>::new_dbus(0);
let len = serialized_size(ctxt, "hello world").unwrap();
assert_eq!(len, 16);

let len = serialized_size(ctxt, &("hello world!", 42_u64)).unwrap();
assert_eq!(len, 32);