writeUtf8NullEnding method

int writeUtf8NullEnding(
  1. String value, {
  2. int? maxLengthInBytes,
})

Writes a UTF-8 string with a trailing null byte.

Implementation

int writeUtf8NullEnding(String value, {int? maxLengthInBytes}) {
  for (var i = 0; i < value.length; i++) {
    if (value.codeUnitAt(i) == 0) {
      throw ArgumentError.value(value, "value", "contains null byte");
    }
  }
  final n = writeUtf8(value, maxLengthInBytes: maxLengthInBytes);
  writeUint8(0);
  return n + 1;
}