30using namespace ONIXS_ICEBOE_NAMESPACE::Encoding;
38 MessagePrinter(std::ofstream& outFile,
StrRef prefix)
43 template <
typename MessageType>
44 void operator()(
const MessageType& msg)
const
46 outFile_ << prefix_ << msg << std::endl << std::endl;
48 std::cout << prefix_ << msg << std::endl << std::endl;
51 std::ofstream& outFile_;
55 std::string getOutputFileName(
const std::string& entryName)
57 const char *
const DecodedSummaryFileExtension =
".txt";
58 return entryName.substr(0, entryName.find_last_of(
".")) + DecodedSummaryFileExtension;
61 size_t decodeSbeLogFile(
const std::string& summaryFileName)
63 const std::string outputFileName = getOutputFileName(summaryFileName);
64 std::ofstream decoded(outputFileName.c_str());
67 throw std::runtime_error(
"Cannot create file: '" + outputFileName +
"'");
69 std::ifstream file(summaryFileName.c_str());
72 throw std::runtime_error(
"Cannot open " + summaryFileName +
" log file.");
74 const size_t LogLinePrefixSize = 32;
78 size_t messageCounter = 0;
80 while (getline(file, line))
84 const StrRef Prefix(line.data(), LogLinePrefixSize);
85 const StrRef Base64SbeMessage(line.data() + LogLinePrefixSize, line.size() - LogLinePrefixSize);
90 throw std::runtime_error(
"Cannot decode an empty message");
94 assert(message.valid());
97 throw std::runtime_error(
"Unknown message type");
103 std::cerr <<
"Cannot decode '" << line <<
"'" << std::endl;
108 return messageCounter;
111 void gatherFiles(std::vector<std::string>& gatheredFiles,
const std::string& root)
116 gatheredFiles.push_back(root);
128 void operator()(
const std::string& name)
130 messagesCount_ += decodeSbeLogFile(name);
134 size_t messagesCount()
const
136 return messagesCount_;
139 size_t filesCount()
const
145 size_t messagesCount_;
150int main(
int argc,
char* argv[])
155 const auto location = cfg.location();
159 std::cerr <<
"'" + location +
"'" +
" does not exist.";
163 std::vector<std::string> inputFiles;
164 gatherFiles(inputFiles, location);
166 const FileDecoder decoder =
167 std::for_each(inputFiles.begin(), inputFiles.end(), FileDecoder());
169 std::clog << decoder.messagesCount() <<
" messages in " << decoder.filesCount() <<
" file(s) are decoded." << std::endl << std::endl;
#define ONIXS_ICEBOE_NAMESPACE
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE
int main(int argc, char *argv[])
static void decode(ByteArray &decoded, const std::string &encoded)
Reconstructs the binary data from a BASE64-encoded string.
SbeMessage message() const noexcept
Retrieves the underlying SBE message.
std::vector< unsigned char > ByteArray
Byte sequence.
bool exist(const std::string &entry)
void gatherFiles(std::vector< std::string > *gatheredFiles, const std::string &root, const std::string &extension)
Gathers files which are stored in a given folder.
bool isDirectory(const std::string &path)
bool processTypified(SbeMessage binary, Processor &&processor)
Casts a given binary message according to template/type information and processes the cast messages b...
UInt16 MessageSize
Message length type.
std::basic_string_view< Char > StrRef