CborBigInt constructor

CborBigInt(
  1. BigInt value, [
  2. List<int>? tags
])

Implementation

factory CborBigInt(
  BigInt value, [
  List<int>? tags,
]) {
  final negative = value.isNegative;
  if (value.isNegative) {
    tags ??= [CborTag.negativeBignum];
    value = ~value;
  } else {
    tags ??= [CborTag.positiveBignum];
  }

  final b = Uint8List((value.bitLength + 7) ~/ 8);

  for (var i = b.length - 1; i >= 0; i--) {
    b[i] = value.toUnsigned(8).toInt();
    value >>= 8;
  }

  if (negative) {
    return CborBigInt.fromNegativeBytes(b, tags: tags);
  } else {
    return CborBigInt.fromBytes(b, tags: tags);
  }
}