12#ifndef O2_FRAMEWORK_AODNATIVE_TEST_ROOTFRAMING_H_
13#define O2_FRAMEWORK_AODNATIVE_TEST_ROOTFRAMING_H_
41 std::vector<uint8_t> out;
44 out.resize(ZSTD_compressBound(in.size()));
45 out.resize(ZSTD_compress(out.data(), out.size(), in.data(), in.size(), 5));
48 uLongf
n = compressBound(in.size());
50 compress2(out.data(), &
n, in.data(), in.size(), 6);
54 out.resize(lzma_stream_buffer_bound(in.size()));
56 lzma_easy_buffer_encode(6, LZMA_CHECK_CRC32,
nullptr, in.data(), in.size(), out.data(), &
pos, out.size());
60 std::vector<uint8_t> block(LZ4_compressBound(in.size()));
61 block.resize(LZ4_compress_default((
char const*)in.data(), (
char*)block.data(), in.size(), block.size()));
62 auto checksum =
xxh64(block);
63 for (
int i = 7;
i >= 0; --
i) {
64 out.push_back((checksum >> (8 *
i)) & 0xff);
66 out.insert(out.end(), block.begin(), block.end());
69 throw std::logic_error(
"no chunk for uncompressed data");
76inline std::vector<uint8_t>
rootCompress(
Algo algo, std::span<const uint8_t> in,
size_t chunkSize = 0xffffff)
78 static const char* tags[] = {
"ZS",
"ZL",
"XZ",
"L4"};
79 std::vector<uint8_t> out;
80 for (
size_t pos = 0;
pos < in.size();
pos += chunkSize) {
81 auto piece = in.subspan(
pos, std::min(chunkSize, in.size() -
pos));
83 out.push_back(tags[(
int)algo][0]);
84 out.push_back(tags[(
int)algo][1]);
86 for (
auto v : {
c.size(), piece.size()}) {
87 out.push_back(
v & 0xff);
88 out.push_back((
v >> 8) & 0xff);
89 out.push_back((
v >> 16) & 0xff);
91 out.insert(out.end(),
c.begin(),
c.end());
101 for (
int i =
sizeof(T) - 1;
i >= 0; --
i) {
102 bytes.push_back((uint64_t(
v) >> (8 *
i)) & 0xff);
107 bytes.push_back(s.size());
108 bytes.insert(
bytes.end(), s.begin(), s.end());
114inline std::vector<uint8_t>
makeBasket(
Algo algo, std::span<const uint8_t>
values, int32_t nevbuf,
size_t tailBytes = 0,
size_t chunkSize = 0xffffff)
118 raw.resize(
values.size() + tailBytes, 0xEE);
122 auto build = [&](uint16_t keylen) {
124 h.put<uint32_t>(keylen + payload.size());
126 h.put<uint32_t>(
raw.size());
128 h.put<uint16_t>(keylen);
136 h.put<int32_t>(32000);
138 h.put<int32_t>(nevbuf);
139 h.put<int32_t>(keylen +
values.size());
140 h.put<uint8_t>(tailBytes ? 1 : 2);
143 auto keylen = (uint16_t)
h.bytes.size();
145 h.bytes.insert(
h.bytes.end(), payload.begin(), payload.end());
154 uint64_t
size()
const override {
return mData.size(); }
157 if (off > mData.size() ||
len > mData.size() - off) {
158 throw CorruptData(
"memory", off,
"read past the end");
163 std::memcpy(
dst, mData.data() + off,
len);
167 void readvInto(std::span<ReadRequest> requests)
override
169 for (
auto&
r : requests) {
173 std::span<const uint8_t>
tryMap(uint64_t off,
size_t len)
override
178 if (off > mData.size() ||
len > mData.size() - off) {
179 throw CorruptData(
"memory", off,
"map past the end");
181 return std::span<const uint8_t>(mData).subspan(off,
len);
185 std::string
url()
const override {
return "memory"; }
188 std::vector<uint8_t> mData;
190 uint64_t mBytes = 0, mCalls = 0;
o2::raw::RawFileWriter * raw
Class for time synchronization of RawReader instances.
A file made of concatenated in-memory buffers.
std::span< const uint8_t > tryMap(uint64_t off, size_t len) override
A view of the bytes without copying them, if the backend can provide it.
void readInto(uint64_t off, size_t len, void *dst) override
Throws IoError, or CorruptData when the range is past the end of the file.
uint64_t size() const override
MemoryByteSource(std::vector< uint8_t > data, bool mappable=true)
uint64_t bytesRead() const override
uint64_t readCalls() const override
std::string url() const override
void readvInto(std::span< ReadRequest > requests) override
GLenum GLsizei GLsizei GLint * values
GLenum GLenum GLsizei len
std::vector< uint8_t > compressChunk(Algo algo, std::span< const uint8_t > in)
std::vector< uint8_t > makeBasket(Algo algo, std::span< const uint8_t > values, int32_t nevbuf, size_t tailBytes=0, size_t chunkSize=0xffffff)
std::vector< uint8_t > rootCompress(Algo algo, std::span< const uint8_t > in, size_t chunkSize=0xffffff)
uint64_t xxh64(std::span< const uint8_t > data)
XXH64 with seed 0, as used for the LZ4 chunk checksum.
std::vector< uint8_t > bytes
void string(std::string const &s)
Marks an empty item in the context.