本文整理汇总了C++中Encoder::finish方法的典型用法代码示例。如果您正苦于以下问题:C++ Encoder::finish方法的具体用法?C++ Encoder::finish怎么用?C++ Encoder::finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encoder
的用法示例。
在下文中一共展示了Encoder::finish方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: encode_decode_chunkwise
void encode_decode_chunkwise(bool encode, const Codec *codec,
const QByteArray &infile_buffer, QFile &outfile)
{
Encoder *enc = 0;
Decoder *dec = 0;
QByteArray indata(inbufsize);
QByteArray outdata(outbufsize);
// we're going to need this below:
#define write_full_outdata_then_reset do { \
kdDebug( verbose ) << " flushing output buffer." << endl; \
if ( writing ) { \
Q_LONG outlen = outfile.writeBlock( outdata.data(), \
outdata.size() ); \
if ( outlen != (int)outdata.size() ) \
exit(OUTFILE_WRITE_ERR); \
} \
oit = outdata.begin(); \
} while ( false )
#define report_status(x,y) do { \
kdDebug( verbose ) << " " #x "() returned " #y " after processing " \
<< iit - indata.begin() << " bytes of input.\n" \
<< " output iterator now at position " \
<< oit - outdata.begin() << " of " \
<< outdata.size() << endl; \
} while ( false )
#define report_finish_status(y) do { \
kdDebug( verbose ) << " finish() returned " #y "\n" \
<< " output iterator now at position " \
<< oit - outdata.begin() << " of " \
<< outdata.size() << endl; \
} while ( false )
// Initialize the output iterators:
QByteArray::Iterator oit = outdata.begin();
QByteArray::Iterator oend = outdata.end();
// Get an encoder. This one you have to delete!
if(encode)
{
enc = codec->makeEncoder(withCRLF);
assert(enc);
}
else
{
dec = codec->makeDecoder(withCRLF);
assert(dec);
}
//
// Loop over input chunks:
//
uint offset = 0;
while(offset < infile_buffer.size())
{
uint reallyRead = QMIN(indata.size(), infile_buffer.size() - offset);
indata.duplicate(infile_buffer.begin() + offset, reallyRead);
offset += reallyRead;
kdDebug(verbose) << " read " << reallyRead << " bytes (max: "
<< indata.size() << ") from input." << endl;
// setup input iterators:
QByteArray::ConstIterator iit = indata.begin();
QByteArray::ConstIterator iend = indata.begin() + reallyRead;
if(encode)
{
//
// Loop over encode() calls:
//
while(!enc->encode(iit, iend, oit, oend))
{
report_status(encode, false);
if(oit == oend)
// output buffer full:
write_full_outdata_then_reset;
}
report_status(encode, true);
}
else
{
//
// Loop over decode() calls:
//
while(!dec->decode(iit, iend, oit, oend))
{
report_status(decode, false);
if(oit == oend)
// output buffer full:
write_full_outdata_then_reset;
}
report_status(decode, true);
}
} // end loop over input chunks
//.........这里部分代码省略.........