+bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) throw() {
+ // Get hex string
+ static char buffer[8192];
+ std::ifstream infile(pathfile.c_str(), std::ifstream::in);
+
+ if(infile.is_open()) {
+ infile >> buffer;
+ std::string hexString(buffer, strlen(buffer));
+ // Allow colon separator in hex string: we have to remove them before processing with 'fromHexString':
+ hexString.erase(std::remove(hexString.begin(), hexString.end(), ':'), hexString.end());
+ LOGDEBUG(
+ std::string msg = "Hex string (remove colons if exists): ";
+ msg += hexString;
+ anna::Logger::debug(msg, ANNA_FILE_LOCATION);
+ );
+ anna::functions::fromHexString(hexString, db);
+ // Close file
+ infile.close();
+ return true;
+ }
+
+ return false;
+}
+
+
+void _exit(const std::string &message, int resultCode = 1) {
+ if(resultCode)
+ std::cerr << message << std::endl << std::endl;
+ else
+ std::cout << message << std::endl << std::endl;
+
+ exit(resultCode);
+}
+
+// Decodes a diameter message coming from a datablock
+void decodeDataBlock(const anna::DataBlock &db, unsigned int & detectedApplicationId) throw() {
+ try {
+ detectedApplicationId = anna::diameter::codec::functions::getApplicationId(db);
+ G_codecEngine->setDictionary(detectedApplicationId);
+ G_codecMsg.decode(db);
+ } catch(RuntimeException &ex) {
+ _exit(ex.asString());
+ }
+}
+
+