ensureSizeOrGrow method

dynamic ensureSizeOrGrow(
  1. int bytes
)

Implementation

ensureSizeOrGrow(int bytes) {
  final requiredSize = _bytePosition + bytes;
  if (requiredSize > _size) {
    final nextSize = min(_maxSize, _size + _allocateSize);
    if (requiredSize > nextSize) {
      throw ArgumentError(
        "Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: $_size, Max size: $_maxSize, Required size: $requiredSize"
      );
    }

    _size = nextSize;
    final nextBuffer = Uint8List(_size);
    nextBuffer.setAll(0, _dataView.buffer.asUint8List());
    _dataView = ByteData.view(nextBuffer.buffer);
  }
}