blob: 0c50a1a5be81b9485c3f495600422eefeacb1c22 (
plain) (
blame)
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
|
#include "example.h"
#include <library/cpp/codecs/static/static.h>
#include <util/generic/yexception.h>
extern "C" {
extern const ui8 codec_info_huff_20160707[];
extern const ui32 codec_info_huff_20160707Size;
extern const ui8 codec_info_sa_huff_20160707[];
extern const ui32 codec_info_sa_huff_20160707Size;
};
namespace NStaticCodecExample {
static const NCodecs::TCodecConstPtr CODECS[] = {
nullptr,
NCodecs::RestoreCodecFromArchive(codec_info_huff_20160707, codec_info_huff_20160707Size),
NCodecs::RestoreCodecFromArchive(codec_info_sa_huff_20160707, codec_info_sa_huff_20160707Size),
};
static_assert(Y_ARRAY_SIZE(CODECS) == DV_COUNT, "bad array size");
void Encode(TBuffer& out, TStringBuf in, EDictVersion dv) {
Y_ENSURE(dv > DV_NULL && dv < DV_COUNT, "invalid dict version: " << (int)dv);
out.Clear();
if (!in) {
return;
}
CODECS[dv]->Encode(in, out);
out.Append((char)dv);
}
void Decode(TBuffer& out, TStringBuf in) {
out.Clear();
if (!in) {
return;
}
EDictVersion dv = (EDictVersion)in.back();
Y_ENSURE(dv > DV_NULL && dv < DV_COUNT, "invalid dict version: " << (int)dv);
in.Chop(1);
CODECS[dv]->Decode(in, out);
}
}
|