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

        long value;
        boolean last = false;

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

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

            if (offset == 0) {
                negative = (value & 1) == 1;
                low |= (value & 0x7F);
            }
            else if (offset < 8) {
                low |= (value & 0x7F) << (offset * 7);
            }
            else if (offset < 16) {
                middle |= (value & 0x7F) << ((offset - 8) * 7);
            }
            else if (offset < 19) {
                high |= (value & 0x7F) << ((offset - 16) * 7);
            }
            else {
                throw new OrcCorruptionException(chunkLoader.getOrcDataSourceId(), "Decimal exceeds 128 bits");
            }

            offset++;

            if ((value & 0x80) == 0) {
                if (high > 0xFF_FF) { // only 127 - (55 + 56) = 16 bits allowed in high
                    throw new OrcCorruptionException(chunkLoader.getOrcDataSourceId(), "Decimal exceeds 128 bits");
                }

                emitLongDecimal(result, count, low, middle, high, negative);
                count++;

                low = 0;
                middle = 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;
    }