Project
Loading...
Searching...
No Matches
Codecs.h
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_FRAMEWORK_AODNATIVE_CODECS_H_
13#define O2_FRAMEWORK_AODNATIVE_CODECS_H_
14
15#include <cstddef>
16#include <cstdint>
17#include <memory>
18#include <span>
19#include <string>
20#include <vector>
21
22namespace o2::aod::native
23{
24
31{
32 public:
33 PayloadDecompressor(std::span<const uint8_t> src, uint32_t objLen, std::string const& file, uint64_t fileOffset);
37
40 void read(uint8_t* dst, size_t n);
44 void readPrefix(uint8_t* dst, size_t n);
46 size_t produced() const { return mProduced; }
47
48 private:
49 struct Codec;
50 void nextChunk();
51 size_t produceFromChunk(uint8_t* dst, size_t n);
52 size_t zstdPrefix(uint8_t* dst, size_t n);
53
54 std::span<const uint8_t> mSrc;
55 uint32_t mObjLen;
56 std::string const& mFile;
57 uint64_t mFileOffset;
58 size_t mSrcPos = 0;
59 size_t mProduced = 0;
60 // Current chunk
61 char mTag[2] = {0, 0};
62 std::span<const uint8_t> mChunkIn;
63 size_t mChunkOut = 0; // uncompressed size of the current chunk
64 size_t mChunkDone = 0; // produced from the current chunk
65 std::unique_ptr<Codec> mCodec;
66 std::vector<uint8_t> mScratch; // LZ4 chunk decoded ahead of a partial read, or the last zstd blocks of a prefix
67 bool mPrefixOnly = false;
68};
69
72size_t decompressBounded(std::span<const uint8_t> src, uint32_t objLen, uint8_t* dst, size_t maxOut,
73 std::string const& file = "<memory>", uint64_t fileOffset = 0);
74
76uint64_t xxh64(std::span<const uint8_t> data);
77
78} // namespace o2::aod::native
79
80#endif // O2_FRAMEWORK_AODNATIVE_CODECS_H_
PayloadDecompressor(PayloadDecompressor const &)=delete
PayloadDecompressor & operator=(PayloadDecompressor const &)=delete
size_t produced() const
Bytes produced so far.
Definition Codecs.h:46
void read(uint8_t *dst, size_t n)
Definition Codecs.cxx:289
void readPrefix(uint8_t *dst, size_t n)
Definition Codecs.cxx:280
GLdouble n
Definition glcorearb.h:1982
GLenum src
Definition glcorearb.h:1767
GLenum GLenum dst
Definition glcorearb.h:1767
GLboolean * data
Definition glcorearb.h:298
size_t decompressBounded(std::span< const uint8_t > src, uint32_t objLen, uint8_t *dst, size_t maxOut, std::string const &file="<memory>", uint64_t fileOffset=0)
Definition Codecs.cxx:310
uint64_t xxh64(std::span< const uint8_t > data)
XXH64 with seed 0, as used for the LZ4 chunk checksum.
Definition Codecs.cxx:319