calculatePadLength function

int calculatePadLength(
  1. int bodyLength, {
  2. bool allowEmpty = false,
})

Calculates the amount of padding bytes needed so that the length of the padding plus the bodyLength is a multiplicative of sizeUnitBytes. If allowEmpty (defaults to false) is true, an empty length is allowed. Otherwise an empty bodyLength will be given a full sizeUnitBytes padding.

Implementation

int calculatePadLength(int bodyLength, {bool allowEmpty = false}) {
  assert(bodyLength >= 0);

  if (bodyLength == 0 && !allowEmpty) return sizeUnitBytes;

  final remainder = bodyLength % sizeUnitBytes;
  return remainder == 0 ? 0 : sizeUnitBytes - remainder;
}