diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Jamfile.jam | 1 | ||||
-rw-r--r-- | src/ingestor.cpp | 35 | ||||
-rw-r--r-- | src/ingestor.hpp | 1 | ||||
-rw-r--r-- | src/logTypes.hpp | 3 |
4 files changed, 40 insertions, 0 deletions
diff --git a/src/Jamfile.jam b/src/Jamfile.jam index 40ec28e..637ddb8 100644 --- a/src/Jamfile.jam +++ b/src/Jamfile.jam @@ -1,6 +1,7 @@ lib webstat : ingestor.cpp logTypes.cpp : <include>. <library>../thirdparty//scn + <library>..//z : : <include>. ; diff --git a/src/ingestor.cpp b/src/ingestor.cpp index 5724b33..17310c2 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -1,8 +1,43 @@ #include "ingestor.hpp" #include <scn/scan.h> #include <syslog.h> +#include <utility> +#include <zlib.h> namespace WebStat { + namespace { + Crc32Value + crc32(const std::string_view value) + { + return static_cast<Crc32Value>(::crc32(::crc32(0, Z_NULL, 0), reinterpret_cast<const Bytef *>(value.data()), + static_cast<uInt>(value.length()))); + } + + Entity + addCrc32(const std::string_view value) + { + return {crc32(value), value}; + } + + std::optional<Entity> + addCrc32o(const std::optional<std::string_view> value) + { + return value.transform(addCrc32); + } + + auto + crc32ScanValues(const Ingestor::ScanValues & values) + { + return std::apply( + [](auto &&... value) { + return std::make_tuple(addCrc32(value...[0]), value...[1], value...[2], value...[3], + addCrc32(value...[4]), addCrc32o(value...[5]), value...[6], value...[7], value...[8], + value...[9], addCrc32o(value...[10]), addCrc32o(value...[11])); + }, + values); + } + } + Ingestor::ScanResult Ingestor::scanLogLine(std::string_view input) { diff --git a/src/ingestor.hpp b/src/ingestor.hpp index 97ce9f9..3bb9ddd 100644 --- a/src/ingestor.hpp +++ b/src/ingestor.hpp @@ -10,6 +10,7 @@ namespace WebStat { using ScanResult = decltype(scn::scan<std::string_view, std::string_view, uint64_t, std::string_view, QuotedString, QueryString, std::string_view, unsigned short, unsigned int, unsigned int, CLFString, CLFString>(std::declval<std::string_view>(), "")); + using ScanValues = std::remove_cvref_t<decltype(std::declval<WebStat::Ingestor::ScanResult>()->values())>; [[nodiscard]] static ScanResult scanLogLine(std::string_view); diff --git a/src/logTypes.hpp b/src/logTypes.hpp index d4f1b7b..7439733 100644 --- a/src/logTypes.hpp +++ b/src/logTypes.hpp @@ -21,6 +21,9 @@ namespace WebStat { using std::optional<std::string>::operator=; bool operator<=>(const CLFString &) const = default; }; + + using Crc32Value = uint32_t; + using Entity = std::pair<Crc32Value, std::string_view>; } namespace scn { |