Пример #1
0
        private byte[] CreateData(int typeNumber, ErrorCorrectLevel errorCorrectLevel, List <QR8BitByte> dataList)
        {
            var rsBlocks = QRRSBlock.GetRSBlocks(typeNumber, errorCorrectLevel);
            var buffer   = new QRBitBuffer();

            for (var i = 0; i < dataList.Count; i += 1)
            {
                var data = dataList[i];
                buffer.Put((int)data.Mode, 4);
                buffer.Put(data.Length, QRUtil.GetLengthInBits(data.Mode, typeNumber));
                data.Write(buffer);
            }

            // calc num max data.
            var totalDataCount = 0;

            for (var i = 0; i < rsBlocks.Length; i += 1)
            {
                totalDataCount += rsBlocks[i].DataCount;
            }

            if (buffer.LengthInBits > totalDataCount * 8)
            {
                throw new OverflowException(
                          $"code length overflow. ({buffer.LengthInBits}>{totalDataCount * 8})"
                          );
            }

            // end code
            if (buffer.LengthInBits + 4 <= totalDataCount * 8)
            {
                buffer.Put(0, 4);
            }

            // padding
            while (buffer.LengthInBits % 8 != 0)
            {
                buffer.PutBit(false);
            }

            // padding
            while (true)
            {
                if (buffer.LengthInBits >= totalDataCount * 8)
                {
                    break;
                }

                buffer.Put(Pad0, 8);

                if (buffer.LengthInBits >= totalDataCount * 8)
                {
                    break;
                }

                buffer.Put(Pad1, 8);
            }

            return(CreateBytes(buffer, rsBlocks));
        }
Пример #2
0
 public void Write(QRBitBuffer buffer)
 {
     for (var i = 0; i < _bytes.Length; i += 1)
     {
         buffer.Put(_bytes[i], 8);
     }
 }