encode method

  1. @override
Uint8List encode(
  1. BigInt value
)
override

Implementation

@override
Uint8List encode(BigInt value) {
  if (value < BigInt.zero) {
    throw Exception('Negative value');
  }
  if (value.bitLength > 256) {
    throw Exception('Value is too big');
  }
  final byteData = ByteData(size_unit);
  final bytes = value.toRadixString(16).padLeft(64, '0');
  final bytesList = bytes.hexToBytes;

  for (var i = 0; i < bytesList.length; i++) {
    byteData.setUint8(size_unit - bytesList.length + i, bytesList[i]);
  }

  return byteData.buffer.asUint8List();
}