appendSignedInt method

void appendSignedInt(
  1. int value
)

the first bit of each byte is used for continuation info, the other six (last byte) or seven (all other bytes) bits for data. the value of the first bit is 1 if the following byte belongs to the field, 0 otherwise. each byte holds six (last byte) or seven (all other bytes) bits of the numeric value, starting with the least significant ones. the second bit in the last byte indicates the sign of the number. A value of 0 means positive, 1 negative. numeric value is stored as magnitude for negative values (as opposed to two's complement).

Implementation

void appendSignedInt(int value) {
  _bufferPosition += 10;
  _ensureBuffer();
  int realByteCount = 0;
  int sign = 0;
  if (value < 0) {
    sign = 0x40;
    value = value * -1;
  }
  while (value > 0x3f) {
    _bufferData.add((value & 0x7f) | 0x80);
    value = value >> 7;
    ++realByteCount;
  }
  _bufferData.add(value | sign);
  ++realByteCount;
  _bufferPosition -= (10 - realByteCount);
}