sizeHint method

  1. @override
int sizeHint(
  1. int value
)
override

If possible give a hint of expected size of the encoding.

This method is used inside default implementation of encode to avoid re-allocations.

Implementation

@override
int sizeHint(int value) {
  if (value <= 0x3F) {
    return 1;
  } else if (value <= 0x3FFF) {
    return 2;
  } else if (value <= 0x3FFFFFFF) {
    return 4;
  } else {
    return ((value.bitLength + 7) >> 3) + 1;
  }
}