Beispiel #1
0
    void DecodeRLE(const uint8_t* data, std::size_t size, Dump& result)
    {
      Dump tmp;
      tmp.reserve(MAX_SECTOR_SIZE);
      ByteStream stream(data, size);
      while (!stream.Eof())
      {
        const uint_t len = 2 * stream.GetByte();
        Require(!stream.Eof());
        const uint_t count = stream.GetByte();
        Require(count != 0);

        const bool isRLE = len != 0;
        const uint_t blockSize = isRLE ? len : count;
        Require(stream.GetRestBytes() >= blockSize);
        for (uint_t idx = 0; idx != blockSize; ++idx)
        {
          tmp.push_back(stream.GetByte());
        }
        if (isRLE)
        {
          Require(CopyFromBack(len, tmp, len * (count - 1)));
        }
      }
      result.swap(tmp);
    }
Beispiel #2
0
 void ApplyInsertions(Dump& result) const
 {
   if (0 == SizeAddon)
   {
     return;
   }
   Dump tmp(result.size() + SizeAddon);
   Dump::const_iterator src = result.begin();
   const Dump::const_iterator srcEnd = result.end();
   auto dst = tmp.begin();
   std::size_t oldOffset = 0;
   for (const auto& ins : Insertions)
   {
     if (const std::size_t toCopy = ins.first - oldOffset)
     {
       const Dump::const_iterator nextEnd = src + toCopy;
       dst = std::copy(src, nextEnd, dst);
       src = nextEnd;
       oldOffset += toCopy;
     }
     dst = std::copy(ins.second.begin(), ins.second.end(), dst);
   }
   std::copy(src, srcEnd, dst);
   result.swap(tmp);
 }
Beispiel #3
0
 void DecodeR2P(const uint8_t* data, std::size_t size, Dump& result)
 {
   Require(size % sizeof(R2PEntry) == 0);
   Dump tmp;
   tmp.reserve(MAX_SECTOR_SIZE);
   for (const R2PEntry* it = safe_ptr_cast<const R2PEntry*>(data), *lim = it + size / sizeof(*it); it != lim; ++it)
   {
     const uint_t count = fromLE(it->Count);
     Require(count != 0);
     tmp.push_back(it->Data[0]);
     tmp.push_back(it->Data[1]);
     Require(CopyFromBack(sizeof(it->Data), tmp, sizeof(it->Data) * (count - 1)));
   }
   result.swap(tmp);
 }