blob: 3c1efb79bb7998f2535bf23157f31162ba8e90e8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#pragma once
#include <library/cpp/archive/yarchive.h>
#include <util/generic/string.h>
#include <util/generic/ptr.h>
#include <util/generic/yexception.h>
#include <util/memory/blob.h>
template <class TrieType, size_t N>
TrieType LoadTrieFromArchive(const TString& key,
const unsigned char (&data)[N],
bool ignoreErrors = false) {
TArchiveReader archive(TBlob::NoCopy(data, sizeof(data)));
if (archive.Has(key)) {
TAutoPtr<IInputStream> trie = archive.ObjectByKey(key);
return TrieType(TBlob::FromStream(*trie));
}
if (!ignoreErrors) {
ythrow yexception() << "Resource " << key << " not found";
}
return TrieType();
}
|