[go: up one dir, main page]

File: DLTADecode.cpp

package info (click to toggle)
ancient 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,168 kB
  • sloc: cpp: 15,188; makefile: 217; sh: 31
file content (54 lines) | stat: -rw-r--r-- 1,364 bytes parent folder | download | duplicates (2)
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
/* 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();
}

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)
{
	uint8_t ctr{0};
	for (size_t i=0;i<size;i++)
	{
		ctr+=bufferSrc[offset+i];
		bufferDest[offset+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());
}

}