writeInt method

void writeInt(
  1. int? value
)

Implementation

void writeInt(int? value) {
  if (value == null) {
    writeNil();
    return;
  }

  switch (value) {
    case >= 0:
      switch (value) {
        case <= MessagePackCode.maxFixInt:
          _bytesBuilder.addByte(value);
        case <= _maxUint8:
          _bytesBuilder.add(<int>[MessagePackCode.uint8, value]);
        case <= _maxUint16:
          _bytesBuilder.addByte(MessagePackCode.uint16);
          _writeBigEndianShort(value);
        case <= _maxUint32:
          _bytesBuilder.addByte(MessagePackCode.uint32);
          _writeBigEndianInt(value);
        default:
          _bytesBuilder.addByte(MessagePackCode.uint64);
          _writeBigEndianLong(value);
      }
    default:
      switch (value) {
        case >= MessagePackRange.minFixNegativeInt:
          _bytesBuilder.addByte(value);
        case >= _minInt8:
          _bytesBuilder.add(<int>[MessagePackCode.int8, value]);
        case >= _minInt16:
          _bytesBuilder.addByte(MessagePackCode.int16);
          _writeBigEndianShort(value);
        case >= _minInt32:
          _bytesBuilder.addByte(MessagePackCode.int32);
          _writeBigEndianInt(value);
        default:
          _bytesBuilder.addByte(MessagePackCode.int64);
          _writeBigEndianLong(value);
      }
  }
}