Decodes byte messages

@param qr QR code
@param data encoded data
@return Location it has read up to in bits
777764
private int decodeByte( QrCode qr , PackedBits8 data, int bitLocation ) {
		int lengthBits = QrCodeEncoder.getLengthBitsBytes(qr.version);

		int length = data.read(bitLocation,lengthBits,true);
		bitLocation += lengthBits;

		if( length*8 > data.size-bitLocation ) {
			qr.failureCause = QrCode.Failure.MESSAGE_OVERFLOW;
			return -1;
		}

		byte rawdata[] = new byte[ length ];

		for (int i = 0; i < length; i++) {
			rawdata[i] = (byte)data.read(bitLocation,8,true);
			bitLocation += 8;
		}

		// If ECI encoding is not specified use the default encoding. Unfortunately the specification is ignored
		// by most people here and UTF-8 is used. If an encoding is specified then that is used.
		String encoding = encodingEci == null ? (forceEncoding!=null?forceEncoding:guessEncoding(rawdata))
				: encodingEci;

		try {
			workString.append( new String(rawdata, encoding) );
		} catch (UnsupportedEncodingException ignored) {
			qr.failureCause = JIS_UNAVAILABLE;
			return -1;
		}
		return bitLocation;
	}
617183
public static final void decodeBuffer(byte[] data, byte encryptionCode)
   {
      for (int i = 0; i < data.length; i++)
      {
         data[i] = (byte) (data[i] ^ encryptionCode);
      }
   }
1139281
boolean checkPaddingBytes(QrCode qr, int lengthBytes) {
		boolean a = true;

		for (int i = lengthBytes; i < qr.corrected.length; i++) {
			if (a) {
				if (0b00110111 != (qr.corrected[i] & 0xFF))
					return false;
			} else {
				if (0b10001000 != (qr.corrected[i] & 0xFF)) {
					// the pattern starts over at the beginning of a block. Strictly enforcing the standard
					// requires knowing size of a data chunk and where it starts. Possible but
					// probably not worth the effort the implement as a strict requirement.
					if (0b00110111 == (qr.corrected[i] & 0xFF)) {
						a = true;
					} else {
						return false;
					}
				}
			}
			a = !a;
		}

		return true;
	}
665150
public static byte[] decode(byte[] data)
	{
		if (data.length == 0)
		{
			return data;
		}
		int lastRealDataIndex = data.length - 1;
		while (data[lastRealDataIndex] == equalSign)
		{
			lastRealDataIndex--;
		}
		// original data digit is 8 bits long, but base64 digit is 6 bits long
		int padBytes = data.length - 1 - lastRealDataIndex;
		int byteLength = data.length * 6 / 8 - padBytes;
		byte[] result = new byte[byteLength];
		// Each 4 bytes of input (encoded) we end up with 3 bytes of output
		int dataIndex = 0;
		int resultIndex = 0;
		int allBits = 0;
		// how many result chunks we can process before getting to pad bytes
		int resultChunks = (lastRealDataIndex + 1) / 4;
		for (int i = 0; i < resultChunks; i++)
		{
			allBits = 0;
			// Loop 4 times gathering input bits (4 * 6 = 24)
			for (int j = 0; j < 4; j++)
			{
				allBits = allBits << 6 | decodeDigit(data[dataIndex++]);
			}
			// Loop 3 times generating output bits (3 * 8 = 24)
			for (int j = resultIndex + 2; j >= resultIndex; j--)
			{
				result[j] = (byte) (allBits & 0xff); // Bottom 8 bits
				allBits = allBits >>> 8;
			}
			resultIndex += 3; // processed 3 result bytes
		}
		// Now we do the extra bytes in case the original (non-encoded) data
		// was not multiple of 3 bytes
		switch (padBytes)
		{
			case 1:
				// 1 pad byte means 3 (4-1) extra Base64 bytes of input, 18
				// bits, of which only 16 are meaningful
				// Or: 2 bytes of result data
				allBits = 0;
				// Loop 3 times gathering input bits
				for (int j = 0; j < 3; j++)
				{
					allBits = allBits << 6 | decodeDigit(data[dataIndex++]);
				}
				// NOTE - The code below ends up being equivalent to allBits =
				// allBits>>>2
				// But we code it in a non-optimized way for clarity
				// The 4th, missing 6 bits are all 0
				allBits = allBits << 6;
				// The 3rd, missing 8 bits are all 0
				allBits = allBits >>> 8;
				// Loop 2 times generating output bits
				for (int j = resultIndex + 1; j >= resultIndex; j--)
				{
					result[j] = (byte) (allBits & 0xff); // Bottom 8
					// bits
					allBits = allBits >>> 8;
				}
				break;
			case 2:
				// 2 pad bytes mean 2 (4-2) extra Base64 bytes of input, 12 bits
				// of data, of which only 8 are meaningful
				// Or: 1 byte of result data
				allBits = 0;
				// Loop 2 times gathering input bits
				for (int j = 0; j < 2; j++)
				{
					allBits = allBits << 6 | decodeDigit(data[dataIndex++]);
				}
				// NOTE - The code below ends up being equivalent to allBits =
				// allBits>>>4
				// But we code it in a non-optimized way for clarity
				// The 3rd and 4th, missing 6 bits are all 0
				allBits = allBits << 6;
				allBits = allBits << 6;
				// The 3rd and 4th, missing 8 bits are all 0
				allBits = allBits >>> 8;
				allBits = allBits >>> 8;
				result[resultIndex] = (byte) (allBits & 0xff); // Bottom
				// 8
				// bits
				break;
		}
		return result;
	}
167355
private String decode(byte[] data, String encoding) {

        try {
            return new String(data, encoding);
        } catch (UnsupportedEncodingException e) {
            LOG.warn(e.getLocalizedMessage(), e);
            return new String(data);
        }
    }
148537
function decode(data) {
    var prefix = protocols[data[0]];
    if (!prefix) { // 36 to 255 should be ""
        prefix = "";
    }    
    return prefix + util.bytesToString(data.slice(1));      
}
1316508
private boolean extractFormatInfo(QrCode qr) {
		for (int i = 0; i < 2; i++) {
			// probably a better way to do this would be to go with the region that has the smallest
			// hamming distance
			if (i == 0)
				readFormatRegion0(qr);
			else
				readFormatRegion1(qr);
			int bitField = this.bits.read(0,15,false);
			bitField ^= QrCodePolynomialMath.FORMAT_MASK;

			int message;
			if (QrCodePolynomialMath.checkFormatBits(bitField)) {
				message = bitField >> 10;
			} else {
				message = QrCodePolynomialMath.correctFormatBits(bitField);
			}
			if (message >= 0) {
				QrCodePolynomialMath.decodeFormatMessage(message, qr);
				return true;
			}
		}
		return false;
	}
579047
public static String encode(byte[] data) {
	StringBuilder builder = new StringBuilder();
	for (int position = 0; position < data.length; position += 3) {
	    builder.append(encodeGroup(data, position));
	}
	return builder.toString();
    }
365532
private boolean readVersionRegion0(QrCode qr) {
		// set the coordinate system to the closest pp to reduce position errors
		gridReader.setSquare(qr.ppRight, (float) qr.threshRight);

		bits.resize(18);
		bits.zero();
		for (int i = 0; i < 18; i++) {
			int row = i/3;
			int col = i%3;
			read(i,row,col-4);
		}
//		System.out.println(" decoder version region 0 =  "+Integer.toBinaryString(bits.data[0]));


		return true;
	}
787348
static public String decodeString(final ByteBuffer bb) {
        final int strlength = bb.getInt();
        final int position = bb.position();
        String decoded = new String(bb.array(), bb.arrayOffset() + position, strlength, Charsets.UTF_8);
        bb.position(position + strlength);
        return decoded;
    }
1020745
private static double decode(
        byte[] data,
        int pointer
    ) {

        long ntp = 0L;

        for (int i = 0; i < 8; i++) {
            long unsigned = (data[i + pointer] & 0xFF);
            ntp |= (unsigned << (56 - i * 8));
        }

        // Festkomma vor Bit 32, deshalb Bits nach rechts schieben
        long integer = ((ntp >>> 32) & 0xFFFFFFFFL);
        long fraction = (((ntp & 0xFFFFFFFFL) * MIO) >>> 32);
        long off = (((integer & 0x80000000L) == 0) ? OFFSET_2036 : OFFSET_1900);
        long ut1 = (integer * MIO) + fraction - off;

        return ((ut1 + OFFSET_1900) / MIO_AS_DOUBLE);

    }
1053937
function(data) {

    var _mode = QRMode.MODE_8BIT_BYTE;
    var _data = data;
    var _parsedData = [];

    var _this = {};


    // Added to support UTF-8 Characters
    for (var i = 0, l = _data.length; i < l; i++) {
	var byteArray = [];
	var code = _data.charCodeAt(i);

	if (code > 0x10000) {
	    byteArray[0] = 0xF0 | ((code & 0x1C0000) >>> 18);
	    byteArray[1] = 0x80 | ((code & 0x3F000) >>> 12);
	    byteArray[2] = 0x80 | ((code & 0xFC0) >>> 6);
	    byteArray[3] = 0x80 | (code & 0x3F);
	} else if (code > 0x800) {
	    byteArray[0] = 0xE0 | ((code & 0xF000) >>> 12);
	    byteArray[1] = 0x80 | ((code & 0xFC0) >>> 6);
	    byteArray[2] = 0x80 | (code & 0x3F);
	} else if (code > 0x80) {
	    byteArray[0] = 0xC0 | ((code & 0x7C0) >>> 6);
	    byteArray[1] = 0x80 | (code & 0x3F);
	} else {
	    byteArray[0] = code;
	}

        // Fix Unicode corruption bug
        _parsedData.push(byteArray);
    }

    _parsedData = Array.prototype.concat.apply([], _parsedData);

    if (_parsedData.length != _data.length) {
	_parsedData.unshift(191);
	_parsedData.unshift(187);
	_parsedData.unshift(239);
    }

    var _bytes = _parsedData;

    _this.getMode = function() {
	return _mode;
    };

    _this.getLength = function(buffer) {
	return _bytes.length;
    };

    _this.write = function(buffer) {
	for (var i = 0; i < _bytes.length; i += 1) {
	    buffer.put(_bytes[i], 8);
	}
    };

    return _this;
}
94298
static int decodeDigit(byte data)
	{
		char charData = (char) data;
		if (charData <= 'Z' && charData >= 'A')
		{
			return charData - 'A';
		}
		if (charData <= 'z' && charData >= 'a')
		{
			return charData - 'a' + 26;
		}
		if (charData <= '9' && charData >= '0')
		{
			return charData - '0' + 52;
		}
		switch (charData)
		{
			case '+':
				return 62;
			case '/':
				return 63;
			default:
				throw new IllegalArgumentException("Invalid char to decode: " + data); //$NON-NLS-1$
		}
	}
33212
public static String decodeBZ(byte[] data) {
    try {
      return new String(decodeBZRaw(data), "UTF-8");
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
720721
public static String hexDecode(final char[] data) {
        try {
            val result = Hex.decodeHex(data);
            return new String(result, StandardCharsets.UTF_8);
        } catch (final Exception e) {
            return null;
        }
    }
1352038
public static String toBinaryString(final byte[] data) {
        if (data == null) {
            return null;
        }
        final StringBuilder buf = new StringBuilder(data.length * 8);
        for (final byte element : data) {
            byte bits = element;
            for (int j = 0; j < 8; j++) {
                if ((bits & 0x80) == 0x80) {
                    buf.append('1');
                } else {
                    buf.append('0');
                }
                bits <<= 1;
            }
        }
        return buf.toString();
    }
9809
public static Datagram decode(final byte[] data,
                                  boolean allowErr) throws IllegalRequestException {
        try {
            if (log.isDebugEnabled()) {
                log.debug("要解析的数据为：{}", Arrays.toString(data));
            }
            // 字符集数据
            int end = Datagram.CHARSET_OFFSET;
            for (int i = 0; i < Datagram.CHARSET_MAX; end += i, i++) {
                if (data[end] == 0) {
                    break;
                }
            }
            // 字符集
            final String charset = new String(data, Datagram.CHARSET_OFFSET,
                end - Datagram.CHARSET_OFFSET);
            // 版本号
            final byte version = data[Datagram.VERSION_INDEX];
            // 数据报数据类型
            final byte type = data[Datagram.TYPE_INDEX];
            // 长度
            final int len = readLen(data);
            log.debug("要解析的数据报的字符集为：{}，版本号为：{}，数据报类型为：{}", charset, version, type);

            byte[] buffer;
            if ((data.length - Datagram.HEADER_LEN) > len) {
                log.warn("数据报head中的长度字段为：{}，数据报body的实际长度为：{}", len,
                    data.length - Datagram.HEADER_LEN);
                if (allowErr) {
                    buffer = new byte[len + Datagram.HEADER_LEN];
                    System.arraycopy(data, 0, buffer, 0, buffer.length);
                } else {
                    throw new IllegalDataException("数据报head中的长度字段为：" + len + "，数据报body的实际长度为："
                                                   + (data.length - Datagram.HEADER_LEN));
                }
            } else if ((data.length - Datagram.HEADER_LEN) < len) {
                log.error("数据报head中的长度字段为：{}，数据报body的实际长度为：{}", len,
                    data.length - Datagram.HEADER_LEN);
                throw new IllegalDataException("数据报head中的长度字段为：" + len + "，数据报body的实际长度为："
                                               + (data.length - Datagram.HEADER_LEN));
            } else {
                buffer = data;
            }

            log.debug("获取id字段");
            byte[] idByte = new byte[40];
            System.arraycopy(data, 16, idByte, 0, idByte.length);
            String id = new String(idByte);
            log.debug("数据报ID为：{}", id);

            // 有可能是空报文的数据报
            Datagram datagram;
            if (len == 0) {
                log.debug("要解析的数据中head标志body长度为0，直接返回一个空body的datagram对象");
                datagram = new Datagram(buffer, len, null, version, charset, type, idByte);
            } else {
                // 真实的业务数据
                byte[] body = new byte[len];
                System.arraycopy(buffer, Datagram.HEADER_LEN, body, 0, body.length);
                datagram = new Datagram(buffer, len, body, version, charset, type, idByte);
            }
            if (log.isDebugEnabled()) {
                log.debug("封装好的数据报body为：{}", datagram);
            }
            return datagram;
        } catch (Exception e) {
            log.error("数据报解析错误，错误原因：{}", e);
            throw new IllegalRequestException(e);
        }
    }