decodeLimit function
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;
}