private static int decode(byte[] src, int srcOffset, byte[][] valueRef, int xorMask) {
        // Scan ahead, looking for terminator.
        int srcEnd = srcOffset;
        while (true) {
            byte b = src[srcEnd++];
            if (-32 <= b && b < 32) {
                if (b == NULL_BYTE_HIGH || b == NULL_BYTE_LOW) {
                    if ((srcEnd - 1) <= srcOffset) {
                        valueRef[0] = null;
                        return 1;
                    }
                }
                break;
            }
        }

        if (srcEnd - srcOffset == 1) {
            valueRef[0] = EMPTY_BYTE_ARRAY;
            return 1;
        }

        // Value is decoded from base-32768.

        int valueLength = ((srcEnd - srcOffset - 1) * 120) >> 7;
        byte[] value = new byte[valueLength];
        int valueOffset = 0;

        final int originalOffset = srcOffset;

        int accumBits = 0;
        int accum = 0;

        while (true) {
            int d = (src[srcOffset++] ^ xorMask) & 0xff;
            int b;
            if (srcOffset == srcEnd ||
                (b = (src[srcOffset++] ^ xorMask) & 0xff) < 32 || b > 223) {
                // Handle special case where one byte was emitted for digit.
                d -= 32;
                // To produce digit, multiply d by 192 and add 191 to adjust
                // for missing remainder. The lower bits are discarded anyhow.
                d = (d << 7) + (d << 6) + 191;

                // Shift decoded digit into accumulator.
                accumBits += 15;
                accum = (accum << 15) | d;

                break;
            }

            d -= 32;
            // To produce digit, multiply d by 192 and add in remainder.
            d = ((d << 7) + (d << 6)) + b - 32;

            // Shift decoded digit into accumulator.
            accumBits += 15;
            accum = (accum << 15) | d;

            if (accumBits == 15) {
                value[valueOffset++] = (byte)(accum >> 7);
            } else {
                value[valueOffset++] = (byte)(accum >> (accumBits - 8));
                accumBits -= 8;
                value[valueOffset++] = (byte)(accum >> (accumBits - 8));
            }
            accumBits -= 8;
        }

        if (accumBits >= 8 && valueOffset < valueLength) {
            value[valueOffset] = (byte)(accum >> (accumBits - 8));
        }

        valueRef[0] = value;

        return srcOffset - originalOffset;
    }
private static int decode ( byte [ ] src , int srcOffset , byte [ ] [ ] valueRef , int xorMask ) { int srcEnd = srcOffset ; while ( true ) { byte b = src [ srcEnd ++ ] ; if ( - 32 <= b && b < 32 ) { if ( b == NULL_BYTE_HIGH || b == NULL_BYTE_LOW ) { if ( ( srcEnd - 1 ) <= srcOffset ) { valueRef [ 0 ] = null ; return 1 ; } } break ; } } if ( srcEnd - srcOffset == 1 ) { valueRef [ 0 ] = EMPTY_BYTE_ARRAY ; return 1 ; } int valueLength = ( ( srcEnd - srcOffset - 1 ) * 120 ) > > 7 ; byte [ ] value = new byte [ valueLength ] ; int valueOffset = 0 ; final int originalOffset = srcOffset ; int accumBits = 0 ; int accum = 0 ; while ( true ) { int d = ( src [ srcOffset ++ ] ^ xorMask ) & 0xff ; int b ; if ( srcOffset == srcEnd || ( b = ( src [ srcOffset ++ ] ^ xorMask ) & 0xff ) < 32 || b > 223 ) { d -= 32 ; d = ( d << 7 ) + ( d << 6 ) + 191 ; accumBits += 15 ; accum = ( accum << 15 ) | d ; break ; } d -= 32 ; d = ( ( d << 7 ) + ( d << 6 ) ) + b - 32 ; accumBits += 15 ; accum = ( accum << 15 ) | d ; if ( accumBits == 15 ) { value [ valueOffset ++ ] = ( byte ) ( accum > > 7 ) ; } else { value [ valueOffset ++ ] = ( byte ) ( accum > > ( accumBits - 8 ) ) ; accumBits -= 8 ; value [ valueOffset ++ ] = ( byte ) ( accum > > ( accumBits - 8 ) ) ; } accumBits -= 8 ; } if ( accumBits >= 8 && valueOffset < valueLength ) { value [ valueOffset ] = ( byte ) ( accum > > ( accumBits - 8 ) ) ; } valueRef [ 0 ] = value ; return srcOffset - originalOffset ; }
@param xorMask 0 for normal decoding, -1 for descending decoding