presto-orc/src/main/java/io/prestosql/orc/stream/DecimalInputStream.java/DecimalInputStream/decodeShortDecimalTail
class DecimalInputStream:    private int decodeShortDecimalTail(long[] result, int count, int batchSize)
            throws IOException
    {
        long low = 0;
        long high = 0;

        long value;
        boolean last = false;

        int offset = 0;

        if (blockOffset == block.length()) {
            advance();
        }

        while (true) {
            value = block.getByte(blockOffset);
            blockOffset++;

            if (offset == 0) {
                low |= (value & 0x7F);
            }
            else if (offset < 8) {
                low |= (value & 0x7F) << (offset * 7);
            }
            else if (offset < 11) {
                high |= (value & 0x7F) << ((offset - 8) * 7);
            }
            else {
                throw new OrcCorruptionException(chunkLoader.getOrcDataSourceId(), "Decimal does not fit long (invalid table schema?)");
            }

            offset++;

            if ((value & 0x80) == 0) {
                if (high > 0xFF) { // only 63 - (55) = 8 bits allowed in high
                    throw new OrcCorruptionException(chunkLoader.getOrcDataSourceId(), "Decimal does not fit long (invalid table schema?)");
                }

                emitShortDecimal(result, count, low, high);
                count++;

                low = 0;
                high = 0;
                offset = 0;

                if (blockOffset == block.length()) {
                    // the last value aligns with the end of the block, so just
                    // reset the block and loop around to optimized decoding
                    break;
                }

                if (last || count == batchSize) {
                    break;
                }
            }
            else if (blockOffset == block.length()) {
                last = true;
                advance();
            }
        }
        return count;
    }