chatMaxBase64EncodedLength function

int chatMaxBase64EncodedLength(
  1. int decodedByteLimit
)

Returns the largest Base64 length needed for decodedByteLimit.

The calculation rejects values whose encoded result would exceed Dart's exact cross-platform integer range.

Implementation

int chatMaxBase64EncodedLength(int decodedByteLimit) {
  _requirePositive(decodedByteLimit, 'decodedByteLimit');
  final groups = decodedByteLimit ~/ 3 + (decodedByteLimit % 3 == 0 ? 0 : 1);
  if (groups > _maxSafeBudgetInteger ~/ 4) {
    throw ArgumentError.value(
      decodedByteLimit,
      'decodedByteLimit',
      'Base64 encoded limit exceeds the cross-platform safe integer range',
    );
  }
  return groups * 4;
}