642
edits
mNo edit summary |
(→Code) |
||
Line 55: | Line 55: | ||
#include <stdlib.h> | #include <stdlib.h> | ||
#include <string.h> | #include <string.h> | ||
#include <iostream> | |||
#include <string> | |||
#include <libmisb/libmisb.hpp> | |||
#include "libmisb/formatter/jsonformatter.hpp" | |||
#include <arpa/inet.h> | #include <arpa/inet.h> | ||
Line 91: | Line 95: | ||
} | } | ||
std::string converter(const char *json_path){ | |||
/* Initialize MISB object*/ | |||
std::string input_file; | |||
libmisb::LibMisb libmisb; | |||
libmisb.SetDebuggerLever(LIBMISB_DEBUG); | |||
std::shared_ptr<libmisb::formatter::iFormatter> json_formatter = | |||
std::make_shared<libmisb::formatter::JsonFormatter>(); | |||
libmisb.SetFormatter(json_formatter); | |||
input_file = json_path; | |||
std::ifstream file(input_file); | |||
std::string data; | |||
std::stringstream buffer; | |||
if (file.is_open()) { | |||
buffer << file.rdbuf(); | |||
data = buffer.str(); | |||
file.close(); | |||
} | |||
std::vector<unsigned char> packet_encoded = libmisb.Encode(data); | |||
if (packet_encoded.empty()) { | |||
LOGGER.Log("Encode result packet is empty", LIBMISB_ERROR); | |||
} | |||
std::string string_packet = ""; | |||
std::string string_byte; | |||
for (uint i = 0; i < packet_encoded.size(); i++) { | |||
string_byte = std::to_string(packet_encoded[i]); | |||
string_packet += string_byte; | |||
string_packet += " "; | |||
} | } | ||
LOGGER.Log(string_packet, LIBMISB_INFO); | |||
return string_packet; | |||
} | } | ||
int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | ||
Line 161: | Line 143: | ||
printf("JSON Path: %s\n", json_path); | printf("JSON Path: %s\n", json_path); | ||
GstMetaDemo *metademo = static_cast<GstMetaDemo*>(g_malloc(sizeof(GstMetaDemo))); | |||
GstMetaDemo *metademo = g_malloc(sizeof(GstMetaDemo)); | |||
if(!metademo){ | if(!metademo){ | ||
g_print("Could not create demo\n"); | g_print("Could not create demo\n"); | ||
Line 182: | Line 163: | ||
g_print("Usage: %s <IP address> <Port number> <JSON file path>\n", argv[0]); | g_print("Usage: %s <IP address> <Port number> <JSON file path>\n", argv[0]); | ||
} | } | ||
char *output_converter = | |||
std::string string_converter = converter(json_path); | |||
const int length = string_converter.length(); | |||
char* output_converter = new char[length + 1]; | |||
strcpy(output_converter, string_converter.c_str()); | |||
if (!create_pipeline(metademo, ip, port, output_converter)) { | if (!create_pipeline(metademo, ip, port, output_converter)) { | ||
Line 260: | Line 246: | ||
// Use snprintf to format the string with the new values | // Use snprintf to format the string with the new values | ||
output_converter[strlen(output_converter) - 1] = '\0'; | |||
snprintf(modified_pipeline, sizeof(modified_pipeline), actual_pipeline, output_converter, ip, port); | snprintf(modified_pipeline, sizeof(modified_pipeline), actual_pipeline, output_converter, ip, port); | ||
Line 277: | Line 262: | ||
/*We need to copy the array since the GByteArray will be the new owner and free it for us*/ | /*We need to copy the array since the GByteArray will be the new owner and free it for us*/ | ||
metalen = sizeof(klv_metadata); | metalen = sizeof(klv_metadata); | ||
array_copy = g_malloc (metalen); | array_copy = static_cast<guint8*>(g_malloc(metalen)); | ||
memcpy (array_copy, klv_metadata, metalen); | memcpy (array_copy, klv_metadata, metalen); | ||