blob: 53d7644002ba4a5a81479ca8cdc046f3bac30ad3 (
plain)
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
|
#include <mbgl/util/blob.hpp>
#include <mbgl/util/compression.hpp>
namespace mbgl {
Blob::Blob() = default;
Blob::Blob(std::shared_ptr<const std::string> bytes_, bool compressed_)
: bytes(std::move(bytes_)), compressed(compressed_) {
}
Blob::Blob(std::string&& bytes_, bool compressed_)
: bytes(std::make_shared<const std::string>(std::move(bytes_))), compressed(compressed_) {
}
std::shared_ptr<const std::string> Blob::uncompressedData() const {
if (!bytes) {
throw std::runtime_error("invalid blob");
}
if (compressed) {
return std::make_shared<const std::string>(util::decompress(*bytes));
} else {
return bytes;
}
}
std::shared_ptr<const std::string> Blob::compressedData() const {
if (!bytes) {
throw std::runtime_error("invalid blob");
}
if (compressed) {
return bytes;
} else {
return std::make_shared<const std::string>(util::compress(*bytes));
}
}
void Blob::uncompress() {
if (compressed) {
bytes = uncompressedData();
compressed = false;
}
}
} // namespace mbgl
|