LibMISB - LibMISB Introduction - Functionalities supported
LibMISB |
---|
Introduction |
Supported Standards |
Getting Started |
Examples |
Evaluating |
Contact Us |
General
The functionalities of the library, regardless of the standard used, are as follows:
Set debug level
Sets the level at which messages will be logged. The method header is:
/** * @brief Sets the level for which the messages will be logged * The orders from less to most verbose modes are: * LIBMISB_NONE * LIBMISB_ERROR * LIBMISB_WARN * LIBMISB_INFO * LIBMISB_DEBUG * * @param level Level for messages to be logged */ void SetLogLevel(LogLevel level);
Use case:
libmisb::LibMisb libmisb; libmisb.SetLogLevel(LIBMISB_DEBUG);
Set Formatter
Formatter is in charge of assigning which kind of format file (JSON, HTML, etc.) the library will use to receive or deliver the metadata. This library uses the formatter in two cases:
- Encode: this library uses the formatter to parse the incoming metadata (that comes from a specific format file) to metadata object, that stores the standard key and the metadata to encode.
- Decode: this library uses the formatter to deliver to the user the encoded metadata from a KLV package.
In other words, the user chooses which file format to use for both encoding and decoding actions.
Important: before using encode or decode methods you need to set a formatter. |
- Composition input format: To encode the input file, it must follow the following structure (a use case will be shown using the JSON format).
{ "key": "<MISB KEY>", "items": [ { "tag": "<TAG NUMBER>", "value": "<TAG VALUE>" } ] }
An example of the previous structure is:
{ "key": "060E2B34020B01010E01030101000000", "items": [ { "tag": "2", "value": "Oct. 24, 2008. 00:13:29.913" }, { "tag": "3", "value": "MISSION01" }, { "tag": "5", "value": "159.97436" } ] }
Note: Some tags are mandatory depending on the standard. In this case, tag 2 is mandatory. |
The method header is:
/** * @brief Set the Formatter object to convert between format to metadata * object and viceversa * * @param formatter formatter object that manages the format type that codec * will use */ void SetFormatter(std::shared_ptr<libmisb::formatter::iFormatter> formatter);
Use case: Remeber to include the formatter header in your code:
#include "libmisb/formatter/jsonformatter.hpp"
libmisb::LibMisb libmisb; std::shared_ptr<libmisb::formatter::iFormatter> json_formatter = std::make_shared<libmisb::formatter::JsonFormatter>(); libmisb.SetFormatter(json_formatter);
Encode
Performs the encoding of the metadata that was parsed by the Formatter. Encoding will depend on the MISB standard key found in the input file.
The method header is:
/** * @brief Receive string metadata that will convert to KLV * bytes in MISB * * @param data String metadata that is in the formatter format valid * @return std::vector<unsigned char> Return KLV bytes in MISB but if there is * any internal problem will return empty vector */ std::vector<unsigned char> Encode(std::string data);
Note: The formatter must be set, otherwise the encode method will send an error. |
Use case:
libmisb::LibMisb libmisb; // Remember to set formatter std::shared_ptr<libmisb::formatter::iFormatter> json_formatter = std::make_shared<libmisb::formatter::JsonFormatter>(); libmisb.SetFormatter(json_formatter); std::vector<unsigned char> packet_encoded = libmisb.Encode(data);
Decode
Performs decoding of the metadata found in a KLV byte packet. The decoding will depend on the MISB standard key found in the packet. Once decoded, it will return the data according to the configured format type. The method header is:
/** * @brief Receive packet encoded metadata that will convert to the formatter * format in MISB * * @param packet Vector with encoded metadata * @return std::string Return string with metadata decoded */ std::string Decode(std::vector<unsigned char> packet);
Note: The formatter must be set, otherwise the decode method will send an error. |
Use case:
libmisb::LibMisb libmisb; // Remember to set formatter std::shared_ptr<libmisb::formatter::iFormatter> json_formatter = std::make_shared<libmisb::formatter::JsonFormatter>(); libmisb.SetFormatter(json_formatter); std::string data_decoded = libmisb.Decode(packet);