Skip to content

Commit

Permalink
LZ4 - add special magic number
Browse files Browse the repository at this point in the history
For better defferentiation between normal and compressed traffic.
  • Loading branch information
BonnyAD9 committed Mar 28, 2024
1 parent 6690040 commit 0edfc31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions output/ipfix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,11 @@ int CompressBuffer::compress() {
auto com = compressed;
auto comSize = compressedSize;

// set the magic number
*reinterpret_cast<uint32_t *>(com) = htonl(LZ4_MAGIC);
com += sizeof(uint32_t);
comSize -= sizeof(uint32_t);

if (shouldReset) {
// when reset, the buffer must start at 0
if (readIndex != 0) {
Expand Down
8 changes: 7 additions & 1 deletion output/ipfix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,13 @@ class CompressBuffer {
// the maximum aditional size required to send metadata that are needed to
// to decompress the data, the +4 is there for four 0 bytes that identify
// ipfix_start_compress_header_t
static constexpr size_t C_ADD_SIZE = sizeof(ipfix_compress_header_t) + sizeof(ipfix_start_compress_header_t) + 4;
static constexpr size_t C_ADD_SIZE =
sizeof(ipfix_compress_header_t)
+ sizeof(ipfix_start_compress_header_t)
+ sizeof(uint32_t) * 2;

// LZ4c
static constexpr uint32_t LZ4_MAGIC = 0x4c5a3463;

private:

Expand Down

0 comments on commit 0edfc31

Please sign in to comment.