<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Oh, OK, I should write them inside of array (i.e. use
      QCborStreamWriter::startArray). Sorry... xD<br>
    </p>
    <div class="moz-cite-prefix">On 5/20/2022 6:28 AM, Alexander
      Dyagilev wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:856a92ac-36c7-aece-d13a-c48836daa917@gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <p>Hello,</p>
      <p>I'm trying to write and read 2 byte arrays. Getting assertion
        failure when reading second array. <br>
      </p>
      <p>Write: <br>
      </p>
      <p><span style=" color:#800080;">QByteArray</span><span style="
          color:#c0c0c0;"> </span><span style=" font-weight:700;
          color:#092e64;">ba</span>; </p>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#800080;">QCborStreamWriter</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:700; color:#092e64;">w</span>(&<span style=" font-style:italic; color:#092e64;">ba</span>);</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#800080;">QByteArray</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:700; color:#092e64;">a1</span>(<span style=" color:#000080;">10</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">'A'</span>);</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#800080;">QByteArray</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:700; color:#092e64;">a2</span>(<span style=" color:#000080;">10</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">'B'</span>);</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#092e64;">w</span>.<span style=" color:#00677c;">append</span>(<span style=" color:#092e64;">a1</span>);</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#092e64;">w</span>.<span style=" color:#00677c;">append</span>(<span style=" color:#092e64;">a2</span>);</pre>
      <p>Read: <br>
      </p>
      <p><span style=" color:#800080;">QByteArray</span><span style="
          color:#c0c0c0;"> </span><span style=" font-weight:700;
          color:#00677c;">readByteArray</span>(<span style="
          color:#800080;">QCborStreamReader</span><span style="
          color:#c0c0c0;"> </span>&<span style=" font-weight:700;
          color:#092e64;">cbor</span>)<br>
        {</p>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">Q_ASSERT</span>(<span style=" color:#092e64;">cbor</span>.<span style=" color:#00677c;">hasNext</span>());<span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">//</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">getting</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">assertion</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">failure</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">here</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">when</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">reading</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">|aa2|</span></pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#000080;">Q_ASSERT</span>(<span style=" color:#092e64;">cbor</span>.<span style=" color:#00677c;">isByteArray</span>());</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">QByteArray</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:700; color:#092e64;">result</span>;</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">for</span><span style=" color:#c0c0c0;"> </span>(;;)</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span>{</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">        </span><span style=" color:#808000;">auto</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:700; color:#092e64;">r</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">cbor</span>.<span style=" color:#00677c;">readByteArray</span>();</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">        </span><span style=" color:#800080;">Q_ASSERT</span>(<span style=" color:#092e64;">r</span>.<span style=" color:#800000;">status</span><span style=" color:#c0c0c0;"> </span>!=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">QCborStreamReader</span>::<span style=" color:#800080;">Error</span>);</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">        </span><span style=" color:#092e64;">result</span><span style=" color:#c0c0c0;"> </span><span style=" color:#00677c;">+=</span><span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">r</span>.<span style=" color:#800000;">data</span>;</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">        </span><span style=" color:#808000;">if</span><span style=" color:#c0c0c0;"> </span>(<span style=" color:#092e64;">r</span>.<span style=" color:#800000;">status</span><span style=" color:#c0c0c0;"> </span>==<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">QCborStreamReader</span>::<span style=" color:#800080;">EndOfString</span>)</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">            </span><span style=" color:#808000;">return</span><span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">result</span>;</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span>}</pre>
      <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">}

<span style=" color:#800080;">QCborStreamReader</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:700; color:#092e64;">r</span>(<span style=" color:#092e64;">ba</span>);

<span style=" color:#800080;">auto</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:700; color:#092e64;">aa1</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#00677c;">readByteArray</span>(<span style=" font-style:italic; color:#092e64;">r</span>);
<span style=" color:#800080;">auto</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:700; color:#092e64;">aa2</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#00677c;">readByteArray</span>(<span style=" font-style:italic; color:#092e64;">r</span>);


</pre>
      What am I doing wrong?..<br>
    </blockquote>
  </body>
</html>