decodeLimit function

int? decodeLimit(
  1. int? expectedLength,
  2. int? maxOutputLength
)

Resolves the strictest output bound before allocating or decoding.

Implementation

int? decodeLimit(int? expectedLength, int? maxOutputLength) {
  if (expectedLength != null && expectedLength < 0) {
    throw RangeError.value(expectedLength, 'expectedLength');
  }
  if (maxOutputLength != null && maxOutputLength < 0) {
    throw RangeError.value(maxOutputLength, 'maxOutputLength');
  }
  if (expectedLength != null &&
      maxOutputLength != null &&
      expectedLength > maxOutputLength) {
    throw RangeError.range(
      expectedLength,
      0,
      maxOutputLength,
      'expectedLength',
    );
  }
  return expectedLength ?? maxOutputLength;
}