fill method

void fill(
  1. ByteBuffer buffer, [
  2. int offsetInBytes = 0,
  3. int? lengthInBytes
])

Fill the buffer with random values.

Paramters:

  • offsetInBytes the start offset in bytes for the fill operation.
  • lengthInBytes the total bytes to fill. If null, fills to the end.

Implementation

void fill(ByteBuffer buffer, [int offsetInBytes = 0, int? lengthInBytes]) {
  int i, n;
  i = offsetInBytes;
  n = lengthInBytes ?? buffer.lengthInBytes;
  if (n <= 0) return;
  var list8 = Uint8List.view(buffer);
  for (; n > 0 && i < list8.length && i & 3 != 0; i++, n--) {
    list8[i] = nextByte();
  }
  if (n <= 0) return;
  var list32 = Uint32List.view(buffer);
  for (i >>>= 2; n >= 4 && i < list32.length; i++, n -= 4) {
    list32[i] = nextInt();
  }
  if (n <= 0) return;
  for (i <<= 2; n > 0 && i < list8.length; i++, n--) {
    list8[i] = nextByte();
  }
}