Ejemplo n.º 1
0
 public void Write(QRBitBuffer buffer)
 {
     for (int i = 0; i < m_data.Length; ++i)
     {
         //item
         buffer.Put(m_data[i], 8);
     }
     ///buffer = Data;
 }
Ejemplo n.º 2
0
        private DataCache CreateData(int typeNumber, QRErrorCorrectLevel errorCorrectLevel, List <QR8bitByte> dataList)
        {
            List <QRRSBlock> rsBlocks = QRRSBlock.GetRSBlocks(typeNumber, errorCorrectLevel);

            var buffer = new QRBitBuffer();

            for (int i = 0; i < dataList.Count; i++)
            {
                QR8bitByte 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.
            int totalDataCount = 0;

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

            if (buffer.GetLengthInBits() > totalDataCount * 8)
            {
                throw new Error("code length overflow. ("
                                + buffer.GetLengthInBits()
                                + ">"
                                + totalDataCount * 8
                                + ")");
            }

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

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

            // padding
            while (true)
            {
                if (buffer.GetLengthInBits() >= totalDataCount * 8)
                {
                    break;
                }
                buffer.Put(QRCode.PAD0, 8);

                if (buffer.GetLengthInBits() >= totalDataCount * 8)
                {
                    break;
                }
                buffer.Put(QRCode.PAD1, 8);
            }

            return(CreateBytes(buffer, rsBlocks));
        }