rippled
Loading...
Searching...
No Matches
Compression.h
1#pragma once
2
3#include <xrpl/basics/CompressionAlgorithms.h>
4#include <xrpl/basics/Log.h>
5
6namespace xrpl {
7
8namespace compression {
9
12
13// All values other than 'none' must have the high bit. The low order four bits
14// must be 0.
15enum class Algorithm : std::uint8_t { None = 0x00, LZ4 = 0x90 };
16
17enum class Compressed : std::uint8_t { On, Off };
18
27template <typename InputStream>
30 InputStream& in,
31 std::size_t inSize,
32 std::uint8_t* decompressed,
33 std::size_t decompressedSize,
34 Algorithm algorithm = Algorithm::LZ4)
35{
36 try
37 {
38 if (algorithm == Algorithm::LZ4)
39 return xrpl::compression_algorithms::lz4Decompress(in, inSize, decompressed, decompressedSize);
40 else
41 {
42 // LCOV_EXCL_START
43 JLOG(debugLog().warn()) << "decompress: invalid compression algorithm " << static_cast<int>(algorithm);
44 UNREACHABLE(
45 "xrpl::compression::decompress : invalid compression "
46 "algorithm");
47 // LCOV_EXCL_STOP
48 }
49 }
50 catch (...)
51 {
52 }
53 return 0;
54}
55
65template <class BufferFactory>
67compress(void const* in, std::size_t inSize, BufferFactory&& bf, Algorithm algorithm = Algorithm::LZ4)
68{
69 try
70 {
71 if (algorithm == Algorithm::LZ4)
73 else
74 {
75 // LCOV_EXCL_START
76 JLOG(debugLog().warn()) << "compress: invalid compression algorithm" << static_cast<int>(algorithm);
77 UNREACHABLE(
78 "xrpl::compression::compress : invalid compression "
79 "algorithm");
80 // LCOV_EXCL_STOP
81 }
82 }
83 catch (...)
84 {
85 }
86 return 0;
87}
88} // namespace compression
89
90} // namespace xrpl
T is_same_v
std::size_t lz4Decompress(std::uint8_t const *in, std::size_t inSizeUnchecked, std::uint8_t *decompressed, std::size_t decompressedSizeUnchecked)
std::size_t lz4Compress(void const *in, std::size_t inSize, BufferFactory &&bf)
LZ4 block compression.
std::size_t compress(void const *in, std::size_t inSize, BufferFactory &&bf, Algorithm algorithm=Algorithm::LZ4)
Compress input data.
Definition Compression.h:67
std::size_t constexpr headerBytes
Definition Compression.h:10
std::size_t constexpr headerBytesCompressed
Definition Compression.h:11
std::size_t decompress(InputStream &in, std::size_t inSize, std::uint8_t *decompressed, std::size_t decompressedSize, Algorithm algorithm=Algorithm::LZ4)
Decompress input stream.
Definition Compression.h:29
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
beast::Journal debugLog()
Returns a debug journal.
Definition Log.cpp:445