writeBytes method

void writeBytes(
  1. List<int> bytes
)

Writes a list of bytes

  • bytes: The list of bytes

Note: The list may be retained until takeBytes is called

Implementation

void writeBytes(List<int> bytes) {
  final length = bytes.length;
  if (length == 0) {
    return;
  }
  _ensureSize(length);
  if (_scratchOffset == 0) {
    // we can add it directly
    _builder.add(bytes);
  } else {
    // there is enough room in _scratchBuffer, otherwise _ensureSize
    // would have added _scratchBuffer to _builder and _scratchOffset would
    // be 0
    if (bytes is Uint8List) {
      _scratchBuffer!
          .setRange(_scratchOffset, _scratchOffset + length, bytes);
    } else {
      for (var i = 0; i < length; i++) {
        _scratchBuffer![_scratchOffset + i] = bytes[i];
      }
    }
    _scratchOffset += length;
  }
}