LibMISB/LibMISB Introduction/ Functionalities supported: Difference between revisions

From RidgeRun Developer Wiki
No edit summary
No edit summary
Line 29: Line 29:
'''Use case''':
'''Use case''':
<syntaxhighlight lang=C>
<syntaxhighlight lang=C>
  misb::Misb misb;
   misb.SetDebuggerLever(MISB_DEBUG);
   misb.SetDebuggerLever(MISB_DEBUG);
</syntaxhighlight>
</syntaxhighlight>
Line 48: Line 49:
</syntaxhighlight>
</syntaxhighlight>


Note: some tags are mandatories depending on the standard.  
'''Note''': some tags are mandatories depending on the standard.  


The method header is:  
The method header is:  
Line 66: Line 67:
'''Use case''':
'''Use case''':
<syntaxhighlight lang=C>
<syntaxhighlight lang=C>
  misb::Misb misb;
   misb.SetFormatter(misb::formatter::JSON_FORMAT);
   misb.SetFormatter(misb::formatter::JSON_FORMAT);
</syntaxhighlight>
</syntaxhighlight>
Line 78: Line 80:


==== Encode ====
==== 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.  
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:  
The method header is:  
<syntaxhighlight lang=C>
<syntaxhighlight lang=C>
Line 90: Line 93:
   */
   */
   std::vector<unsigned char> Encode(std::string data);
   std::vector<unsigned char> Encode(std::string data);
</syntaxhighlight>
'''Note''': The formatter must be set, otherwise the encode method will send an error.
'''Use case''':
<syntaxhighlight lang=C>
  misb::Misb misb;
  std::vector<unsigned char> packet_encoded = misb.Encode(data);
</syntaxhighlight>
</syntaxhighlight>
==== Decode ====
==== 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.
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:
<syntaxhighlight lang=C>
/**
  * @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);
</syntaxhighlight>
'''Note''': The formatter must be set, otherwise the decode method will send an error.
'''Use case''':
<syntaxhighlight lang=C>
  misb::Misb misb;
  std::string data_decoded = misb.Decode(packet);
</syntaxhighlight>






<noinclude>{{LibMISB/Foot|LibMISB_Introduction/What_does_the_library_do|Getting_Started}}</noinclude>
<noinclude>{{LibMISB/Foot|LibMISB_Introduction/What_does_the_library_do|Getting_Started}}</noinclude>

Revision as of 16:18, 22 June 2022




Previous: LibMISB_Introduction/What_does_the_library_do Index Next: Getting_Started





LibMISB/Getting_Started

General

The functionalities of the library, regardless of the standard used, are as follows

Set Debugger 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:
   *  MISB_NONE
   *  MISB_ERROR
   *  MISB_WARN
   *  MISB_INFO
   *  MISB_DEBUG
   *
   * @param level Level for messages to be logged
   */
  void SetDebuggerLever(LogLevel level);

Use case:

  misb::Misb misb;
  misb.SetDebuggerLever(MISB_DEBUG);

Set Formatter

Sets the Formatter object to convert between format and metadata object. In other words, the user chooses which file format to use for both encoding and decoding actions.

  • Composition input format: To encode the input file, it must follow the following structure (an use case will be shown using the JSON format).
{ 
  "key": "<MISB KEY>",
  "items": [
    {
      "tag": "<TAG NUMBER>",
      "value": "<TAG VALUE>"
    }
  ]
}

Note: some tags are mandatories depending on the standard.

The method header is:

/**
   * @brief Set the Formatter object to convert between format to metadata
   * object and viceversa
   *
   * @param formatter Enum formatter that manages the format type that codec
   * will use
   */
  void SetFormatter(int formatter_number);

In which the formatter_number is dependent on formatter supported.

Use case:

  misb::Misb misb;
  misb.SetFormatter(misb::formatter::JSON_FORMAT);

The misb::formatter::JSON_FORMAT parameter corresponds to an enum indicating which format type is to be implemented. At the moment, the enum is as follows:

enum Formats { JSON_FORMAT };


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:

  misb::Misb misb;
  std::vector<unsigned char> packet_encoded = misb.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:

  misb::Misb misb;
  std::string data_decoded = misb.Decode(packet);



Previous: LibMISB_Introduction/What_does_the_library_do Index Next: Getting_Started