예제 #1
0
size_t
Encoder::appendVarNumber(uint64_t varNumber)
{
  if (varNumber < 253) {
    appendByte(static_cast<uint8_t>(varNumber));
    return 1;
  }
  else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
    appendByte(253);
    uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
    appendByteArray(reinterpret_cast<const uint8_t*>(&value), 2);
    return 3;
  }
  else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
    appendByte(254);
    uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
    appendByteArray(reinterpret_cast<const uint8_t*>(&value), 4);
    return 5;
  }
  else {
    appendByte(255);
    uint64_t value = htobe64(varNumber);
    appendByteArray(reinterpret_cast<const uint8_t*>(&value), 8);
    return 9;
  }
}
예제 #2
0
size_t
Encoder::appendByteArrayBlock(uint32_t type, const uint8_t* array, size_t arraySize)
{
  size_t totalLength = appendVarNumber(type);
  totalLength += appendVarNumber(arraySize);
  totalLength += appendByteArray(array, arraySize);

  return totalLength;
}
예제 #3
0
size_t
Encoder::appendBlock(const Block& block)
{
  if (block.hasWire()) {
    return appendByteArray(block.wire(), block.size());
  }
  else {
    return appendByteArrayBlock(block.type(), block.value(), block.value_size());
  }
}
예제 #4
0
size_t
Encoder::appendNonNegativeInteger(uint64_t varNumber)
{
  if (varNumber <= std::numeric_limits<uint8_t>::max()) {
    return appendByte(static_cast<uint8_t>(varNumber));
  }
  else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
    uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
    return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 2);
  }
  else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
    uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
    return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 4);
  }
  else {
    uint64_t value = htobe64(varNumber);
    return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 8);
  }
}
예제 #5
0
파일: k3bcdtext.cpp 프로젝트: KDE/k3b
QByteArray K3b::Device::CdText::rawPackData() const
{
    if( d->rawData.isEmpty() ) {
        // FIXME: every pack block may only consist of up to 255 packs.

        int pc = 0;
        int alreadyCountedPacks = 0;


        //
        // prepare the size information block
        //
        text_size_block tsize;
        ::memset( &tsize, 0, sizeof(text_size_block) );
        tsize.charcode = 0;              // ISO 8859-1
        tsize.first_track = 1;
        tsize.last_track = count();
        tsize.pack_count[0xF] = 3;
        tsize.language_codes[0] = 0x09;  // English (from cdrecord)


        //
        // create the CD-Text packs
        //
        QByteArray data;
        for( int i = 0; i <= 6; ++i ) {
            if( d->textLengthForPackType( 0x80 | i ) ) {
                appendByteArray( data, d->createPackData( 0x80 | i, pc ) );
                tsize.pack_count[i] = pc - alreadyCountedPacks;
                alreadyCountedPacks = pc;
            }
        }
        if( d->textLengthForPackType( 0x8E ) ) {
            appendByteArray( data, d->createPackData( 0x8E, pc ) );
            tsize.pack_count[0xE] = pc - alreadyCountedPacks;
            alreadyCountedPacks = pc;
        }


        // pc is the number of the next pack and we add 3 size packs
        tsize.last_seqnum[0] = pc + 2;


        //
        // create the size info packs
        //
        int dataFill = data.size();
        data.resize( data.size() + 3 * sizeof(cdtext_pack) );
        for( int i = 0; i < 3; ++i ) {
            cdtext_pack pack;
            ::memset( &pack, 0, sizeof(cdtext_pack) );
            pack.id1 = 0x8F;
            pack.id2 = i;
            pack.id3 = pc+i;
            ::memcpy( pack.data, &reinterpret_cast<char*>(&tsize)[i*12], 12 );
            savePack( &pack, data, dataFill );
        }

        //
        // add MMC header
        //
        QByteArray a( 4, 0 );
        a[0] = (data.size()+2)>>8 & 0xff;
        a[1] = (data.size()+2) & 0xff;
        a[2] = a[3] = 0;
        appendByteArray( a, data );

        d->rawData = a;
    }