writeByteData method

void writeByteData(
  1. ByteData value,
  2. [int index = 0,
  3. int writtenLength]
)

Writes bytes from ByteData.

Implementation

void writeByteData(ByteData value, [int index = 0, int writtenLength]) {
  if (writtenLength == null) {
    writtenLength = value.lengthInBytes - index;
  }
  ensureAvailableLength(writtenLength);

  final byteData = this._byteData;
  var bufferLength = this._length;
  if (writtenLength >= _minLengthForUin32CopyMethod) {
    final hostEndian = Endian.host;
    while (writtenLength >= 4) {
      byteData.setUint32(
        bufferLength,
        value.getUint32(index, hostEndian),
        hostEndian,
      );
      bufferLength += 4;
      index += 4;
      writtenLength -= 4;
    }
  }
  while (writtenLength > 0) {
    byteData.setUint8(bufferLength, value.getUint8(index));
    bufferLength++;
    index++;
    writtenLength--;
  }
  this._length = bufferLength;
}