writeTo method

int writeTo(
  1. BytesBuffer out
)

Writes this BigInt to out. See toBytes for encoding description.

Implementation

int writeTo(BytesBuffer out) {
  if (bitLength > 32) {
    var bs = toString().encodeLatin1Bytes();
    assert(bs.isNotEmpty);

    out.writeInt32(-bs.length);
    out.writeBytes(bs);

    return 4 + bs.length;
  } else {
    var bs = toInt().int32ToBytes();
    assert(bs.length == 4);

    out.writeByte(0);
    out.writeAllBytes(bs);
    return 1 + 4;
  }
}