1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/* Copyright (C) Teemu Suutari */
#include "DLTADecode.hpp"
#include "common/OverflowCheck.hpp"
#include "common/Common.hpp"
namespace ancient::internal
{
bool DLTADecode::detectHeaderXPK(uint32_t hdr) noexcept
{
return hdr==FourCC("DLTA");
}
std::shared_ptr<XPKDecompressor> DLTADecode::create(uint32_t hdr,uint32_t recursionLevel,const Buffer &packedData,std::shared_ptr<XPKDecompressor::State> &state,bool verify)
{
return std::make_shared<DLTADecode>(hdr,recursionLevel,packedData,state,verify);
}
DLTADecode::DLTADecode(uint32_t hdr,uint32_t recursionLevel,const Buffer &packedData,std::shared_ptr<XPKDecompressor::State> &state,bool verify) :
XPKDecompressor(recursionLevel),
_packedData(packedData)
{
if (!detectHeaderXPK(hdr)) throw Decompressor::InvalidFormatError();
}
DLTADecode::~DLTADecode()
{
// nothing needed
}
const std::string &DLTADecode::getSubName() const noexcept
{
static std::string name="XPK-DLTA: Delta encoding";
return name;
}
void DLTADecode::decode(Buffer &bufferDest,const Buffer &bufferSrc,size_t offset,size_t size)
{
if (OverflowCheck::sum(offset,size)>bufferSrc.size()) throw Buffer::OutOfBoundsError();
if (OverflowCheck::sum(offset,size)>bufferDest.size()) throw Buffer::OutOfBoundsError();
const uint8_t *src=bufferSrc.data()+offset;
uint8_t *dest=bufferDest.data()+offset;
uint8_t ctr=0;
for (size_t i=0;i<size;i++)
{
ctr+=src[i];
dest[i]=ctr;
}
}
void DLTADecode::decompressImpl(Buffer &rawData,const Buffer &previousData,bool verify)
{
if (rawData.size()<_packedData.size()) throw Decompressor::DecompressionError();
decode(rawData,_packedData,0,_packedData.size());
}
}
|