Skip to content

Commit

Permalink
TCP - Lz4 single magic
Browse files Browse the repository at this point in the history
  • Loading branch information
BonnyAD9 committed Mar 28, 2024
1 parent b1a60a2 commit ba33368
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/plugins/input/tcp/src/LZ4Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ namespace tcp_in {
using namespace std;

struct __attribute__((__packed__)) ipfix_compress_header {
uint32_t magic;
uint16_t decompressed_size;
uint16_t compressed_size;
};

struct __attribute__((__packed__)) ipfix_start_compress_header {
uint32_t magic;
uint32_t zeros;
uint32_t buffer_size;
uint16_t decompressed_size;
uint16_t compressed_size;
};

Lz4Decoder::Lz4Decoder(int fd) :
Expand All @@ -53,6 +49,7 @@ Lz4Decoder::Lz4Decoder(int fd) :
m_compressed_size(0),
m_decompressed_size(0)
{
uint32_t magic = 0;
if (!m_decoder) {
throw runtime_error("LZ4 Decoder: Failed to create stream decoder");
}
Expand Down Expand Up @@ -91,15 +88,17 @@ bool Lz4Decoder::read_header() {
return false;
}

auto hdr = reinterpret_cast<ipfix_compress_header *>(m_compressed.data());
if (hdr->compressed_size == 0 && hdr->decompressed_size == 0) {
return read_start_header();
if (m_decompressed.size() == 0) {
if (!read_start_header()) {
return false;
}
}

if (!read_until_n(CH_SIZE)) {
return false;
}

auto hdr = reinterpret_cast<ipfix_compress_header *>(m_compressed.data());
m_compressed_size = ntohs(hdr->compressed_size);
m_decompressed_size = ntohs(hdr->decompressed_size);

Expand All @@ -118,9 +117,6 @@ bool Lz4Decoder::read_start_header() {
auto hdr = reinterpret_cast<ipfix_start_compress_header *>(m_compressed.data());
auto new_buffer_size = ntohl(hdr->buffer_size);

m_compressed_size = ntohs(hdr->compressed_size);
m_decompressed_size = ntohs(hdr->decompressed_size);

m_compressed.clear();

reset_stream(new_buffer_size);
Expand Down

0 comments on commit ba33368

Please sign in to comment.