serializeString method

void serializeString(
  1. String value
)

Serializes a UTF-8 string value.

Encodes to UTF-8 bytes and passes an explicit length, so embedded NUL bytes are preserved (a NUL-terminated copy would truncate at the first NUL).

Implementation

void serializeString(String value) {
  _checkState();
  final utf8Bytes = utf8.encode(value);
  final nativeBuf = calloc.allocate<Uint8>(utf8Bytes.length);
  try {
    nativeBuf.asTypedList(utf8Bytes.length).setAll(0, utf8Bytes);
    final rc = bindings.zd_serializer_serialize_string(
      _loanMut().cast(),
      nativeBuf,
      utf8Bytes.length,
    );
    if (rc != 0) throw ZenohException('Failed to serialize string', rc);
  } finally {
    calloc.free(nativeBuf);
  }
}