apple / foundationdb

FoundationDB - the open source, distributed, transactional key-value store
https://apple.github.io/foundationdb/
Apache License 2.0
14.54k stars 1.31k forks source link

Missing tuple documentation for Positive / Negative arbitrary precision integers #2732

Open josephg opened 4 years ago

josephg commented 4 years ago

The document describing tuples is missing documentation for the wire format of +/- arbitrary precision integers.

These are already implemented in the python and java bindings, and as a result are unlikely to change. We should document the format.

The python binding code is here:

    elif code == POS_INT_END:  # 0x1d; Positive 9-255 byte integer
        length = six.indexbytes(v, pos + 1)
        val = 0
        for i in _range(length):
            val = val << 8
            val += six.indexbytes(v, pos + 2 + i)
        return val, pos + 2 + length
    elif code == NEG_INT_START:  # 0x0b; Negative 9-255 byte integer
        length = six.indexbytes(v, pos + 1) ^ 0xff
        val = 0
        for i in _range(length):
            val = val << 8
            val += six.indexbytes(v, pos + 2 + i)
        return val - (1 << (length * 8)) + 1, pos + 2 + length
ajbeamon commented 4 years ago

One word of caution — there is actually a small bug in the Python version of these that may end up getting fixed, and the bug results in a different encoding than the other bindings for one positive and one negative integer (see https://forums.foundationdb.org/t/request-for-feedback-tuple-encoding-bug/936 for details). The correct encoding would be based on the other implementations.