Skip to main content

Module bytes

Module bytes 

Source
Expand description

§Payload primitives and encoding

The ZBytes type is Zenoh’s representation of raw byte data. It provides mechanisms for zero-copy creation and access (From<Vec<u8>> and ZBytes::slices), as well as methods for sequential reading/writing (ZBytes::reader, ZBytes::writer).

The zenoh-ext crate provides serialization and deserialization of basic types and structures for ZBytes via z_serialize and z_deserialize.

The module also provides the Encoding enum to specify the encoding of the payload.

§Examples

§Creating ZBytes

let zbytes = zenoh::bytes::ZBytes::from("Hello, world!");

§Converting ZBytes to String

let s = zbytes.try_to_string().unwrap();
assert_eq!(s, "Hello, world!");

§Converting ZBytes to Vec<u8>

let vec = zbytes.to_bytes();
assert_eq!(vec.as_ref(), b"Hello, world!");

Structs§

Encoding
Encoding information
OptionZBytes
Technical wrapper type for API ergonomicity.
ZBytes
ZBytes contains the raw bytes data.
ZBytesReader
A reader that implements std::io::Read trait to deserialize from a ZBytes.
ZBytesSliceIterator
An iterator to iterate on raw bytes slices contained in a ZBytes.
ZBytesWriter
A writer that implements std::io::Write trait to serialize into a ZBytes.