ZBytes class

A Zenoh byte payload.

Wraps z_owned_bytes_t. Use ZBytes.fromString or ZBytes.fromUint8List to create a payload, and toStr to extract its content as a string.

Must be disposed when no longer needed to release native memory.

Single-shot scalar conversions

Every canon scalar width has a single-shot pair here: ZBytes.fromUint8 / toUint8 through ZBytes.fromUint64 / toUint64, ZBytes.fromInt8 / toInt8 through ZBytes.fromInt / toInt, ZBytes.fromFloat / toFloat, ZBytes.fromDouble / toDouble and ZBytes.fromBool / toBool. Each composes over the shipped ZSerializer / ZDeserializer pair and produces output byte-identical to canon's own one-shot family -- measured across all eleven scalar widths, which is why none of them needed a shim function of its own.

The names are widths. ZBytes.fromInt / toInt are int64 and ZBytes.fromDouble / toDouble are binary64, unchanged and named for Dart's types rather than canon's. ZBytes.fromFloat / toFloat are binary32 -- a different width, not a synonym for the double pair. And ZBytes.fromString / toStr are raw unframed UTF-8, NOT the serializer's length-prefixed string form: those two payloads differ by the prefix and are not interchangeable.

Conventions. Every parameter and return is non-nullable (CONV-2): after the domain guard each width is total, so there is no "unspecified, canon decides" case for a nullable to stand for. Each constructor takes one positional parameter (CONV-2b), so a parameter and not an options class. The narrow integer widths carry a Dart-side domain guard naming the domain (CONV-4(c)) -- inherited from ZSerializer by composition, deliberately not duplicated here, so one policy governs the whole surface. ZBytes.fromUint64 and ZBytes.fromFloat carry no guard, for the same reasons the serializer's do not: every Dart int is a valid 64-bit pattern, and every finite f64 has a defined nearest binary32.

Two failure codes, and never one. A payload SHORTER than the width fails with canon's own -7 (Z_EDESERIALIZE), measured on the streaming family these methods call. A payload carrying data BEYOND the value fails with 12, which is binding-owned and positive on purpose: on that path canon's streaming deserializer returns Z_OK -- it accepts the bytes, and the leftover is detected Dart-side through ZDeserializer.isDone. A canon negative there would masquerade as a rejection canon never made, so codes minted by this binding live in canon-free positive space beside the shipped 10 (capacity out of range) and 11 (allocation failure). One policy governs all eleven conversions: toInt, toDouble and toBool once reported -1 (Z_EINVAL) here and no longer do.

This object holds a native handle, so it cannot cross an isolate boundary: a copy would share this one's native address while carrying its own fresh disposal flag, and the second release would be a use-after-free. Sending it throws ArgumentError naming the class.

It carries a NativeFinalizer safety net: if it is dropped without an explicit release, its native resources are reclaimed when the object is collected. ⛔ The net is not a substitute for releasing it explicitly — a finalizer runs at an unpredictable time, or not at all if the program exits first.

Implemented types
Available extensions

Constructors

ZBytes.fromBool(bool value)
Creates ZBytes containing a serialized bool value.
factory
ZBytes.fromDouble(double value)
Creates ZBytes containing a serialized double value.
factory
ZBytes.fromFloat(double value)
Creates ZBytes containing a serialized float (binary32) value.
factory
ZBytes.fromInt(int value)
Creates ZBytes containing a serialized int64 value.
factory
ZBytes.fromInt8(int value)
Creates ZBytes containing a serialized int8 value.
factory
ZBytes.fromInt16(int value)
Creates ZBytes containing a serialized int16 value.
factory
ZBytes.fromInt32(int value)
Creates ZBytes containing a serialized int32 value.
factory
ZBytes.fromString(String value)
Creates ZBytes by copying the given value string.
factory
ZBytes.fromUint8(int value)
Creates ZBytes containing a serialized uint8 value.
factory
ZBytes.fromUint8List(Uint8List data)
Creates ZBytes by copying the given data buffer.
factory
ZBytes.fromUint16(int value)
Creates ZBytes containing a serialized uint16 value.
factory
ZBytes.fromUint32(int value)
Creates ZBytes containing a serialized uint32 value.
factory
ZBytes.fromUint64(int value)
Creates ZBytes containing a serialized uint64 value.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isShmBacked bool

Available on ZBytes, provided by the ShmBytes extension

Returns whether this payload is backed by shared memory.
no setter
nativePtr Pointer<Void>
Converts the payload to a Dart string.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
slices Iterable<Uint8List>
Returns the internal byte slices.
no setter

Methods

clone() ZBytes
Creates an independent shallow copy of this ZBytes.
dispose() → void
Releases native resources held by this payload.
markConsumed() → void
Internal: called by a send site after the bytes have been moved into zenoh-c via z_bytes_move.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toBool() bool
Deserializes the payload as a bool value.
toBytes() Uint8List
Reads the payload content as a Uint8List.
toDouble() double
Deserializes the payload as a double value.
toFloat() double
Deserializes the payload as a float value.
toInt() int
Deserializes the payload as an int64 value.
toInt16() int
Deserializes the payload as a int16 value.
toInt32() int
Deserializes the payload as a int32 value.
toInt8() int
Deserializes the payload as a int8 value.
toStr() String
Converts the payload to a Dart string via a lenient UTF-8 decode.
toString() String
A string representation of this object.
inherited
toUint16() int
Deserializes the payload as a uint16 value.
toUint32() int
Deserializes the payload as a uint32 value.
toUint64() int
Deserializes the payload as a uint64 value.
toUint8() int
Deserializes the payload as a uint8 value.

Operators

operator ==(Object other) bool
The equality operator.
inherited