writeUtf8NullEnding method

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

Writes an UTF-8 string. Returns number of written bytes, including the final null-character.

Throws ArgumentError if any rune is 0.

Implementation

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