pushInt method

void pushInt(
  1. int majorTag,
  2. int value, {
  3. CborLengthEncoding lengthEncoding = CborLengthEncoding.canonical,
})

Append an integer value with a specified major tag to the byte sequence in the buffer.

Implementation

void pushInt(
  int majorTag,
  int value, {
  CborLengthEncoding lengthEncoding = CborLengthEncoding.canonical,
}) {
  majorTag <<= 5;
  final int? length = bytesLength(value, lengthEncoding: lengthEncoding);
  pushUInt8(majorTag | (length ?? value));
  if (length == null) return;
  final int len = 1 << (length - 24);
  if (len <= 4) {
    pushBytes(value.toBeBytes(length: len));
  } else {
    pushUint64(BigInt.from(value));
  }
}