validateFrozenBuffer method

void validateFrozenBuffer(
  1. NativeOwnedBuffer buffer, {
  2. int? maximumLength,
})

Check that buffer is live, immutable and belongs to this native library. An optional limit is checked against native storage metadata.

Implementation

void validateFrozenBuffer(
  NativeOwnedBuffer buffer, {
  int? maximumLength,
}) {
  _require();
  buffer._handle.check();
  if (buffer._handle.api._identity != _identity) {
    throw ArgumentError('Buffer belongs to a different native library');
  }
  final info = _getInfo(buffer._handle);
  if (info.writable != 0 || info.length != buffer.length) {
    throw StateError('Buffer is not a matching immutable native view');
  }
  if (maximumLength != null && info.length > maximumLength) {
    throw RangeError.range(info.length, 0, maximumLength, 'buffer.length');
  }
}