@staticmethod
def get_read_sorted_int_length(buf, offset):
    """
        Returns the number of bytes that would be read by
        :py:meth:`read_sorted_int`.

        Because the length is stored in the first byte, this method may be
        called with only the first byte of the packed integer in the given
        buffer. This method only accesses one byte at the given offset.

        :param buf: the buffer to read from.
        :type buf: bytearray
        :param offset: the offset in the buffer at which to start reading.
        :type offset: int
        :returns: the number of bytes that would be read.
        :rtype: int
        """
    b1 = buf[offset] & 255
    if b1 < 8:
        return 1 + 8 - b1
    if b1 > 247:
        return 1 + b1 - 247
    return 1
