writeUtf8SimpleNullEnding method

void writeUtf8SimpleNullEnding(
  1. String value
)

Writes a null-delimited UTF-8 string. Validates that all runes take only a single byte in UTF-8.

Throws ArgumentError if any rune is 0 or greater than 127.

Implementation

void writeUtf8SimpleNullEnding(String value) {
  ensureAvailableLength(value.length + 1);

  final byteData = this._byteData;
  var length = this._length;
  for (var i = 0; i < value.length; i++) {
    final byte = value.codeUnitAt(i);
    if (byte == 0 || byte > 0x7F) {
      throw new ArgumentError.value(value);
    }
    byteData.setUint8(length, byte);
    length++;
  }
  byteData.setUint8(length, 0);
  length++;
  this._length = length;
}