LibMISB/Examples/Library basic usage: Difference between revisions

no edit summary
No edit summary
Line 5: Line 5:
== Testing library ==
== Testing library ==


This library has an example that you can execute. This example is a metadata converter that can encode or decode metadata. If you want to encode, the input file must respect one of the formats developed (only JSON format is currently supported) and will return a binary file with metadata encoded. On the other hand, if you want to decode the program receives a binary file and converts it to the format file selected (only JSON format is currently supported).  
This library has an example that you can execute. This example is a metadata converter that can encode or decode metadata. If you want to encode, the input file must respect one of the supported formats and will return a binary file with metadata encoded. On the other hand, if you want to decode the program receives a binary file and converts it to the format file selected. Currently JSON format is supported for the input and output encoding files.


The executable is located on <code>/misb-library/examples/misb/</code> or if you want to compile and execute the example file out of the project. The path of the example is located on <code>/misb-library/examples/misb/misb-converter.cpp</code>. To compile the example we suggest you follow the next Makefile:  
The executable is located on <code>/misb-library/examples/misb/</code> or if you want to compile and execute the example file out of the project. The path of the example is located on <code>/misb-library/examples/misb/misb-converter.cpp</code>. To compile the example we suggest you follow the next Makefile:  
Line 13: Line 13:
g++ -o misb-converter misb-converter.cpp $(FLAGS)
g++ -o misb-converter misb-converter.cpp $(FLAGS)
</syntaxhighlight>
</syntaxhighlight>
To perform the encoding, the following command is executed. Where the '''--encode''' flag indicates that encoding is to be performed. The '''-i''' flag indicates the input file, where the metadata must be raw without encoding. On the other hand, the '''-o''' flag indicates the output file, which contains the encoded bytes in a binary file. The '''--verbose''' flag shows the KLV bytes encoded on the terminal.


The input JSON file that is going to be used is as follows:  
The input JSON file that is going to be used is as follows:  
Line 44: Line 42:
   ]
   ]
}
}
</syntaxhighlight>


The command to encode:
 
</syntaxhighlight>
To perform the encoding, the following command is executed. Where the '''--encode''' flag indicates that encoding is to be performed. The '''-i''' flag indicates the input file, where the metadata must be raw without encoding. On the other hand, the '''-o''' flag indicates the output file, which contains the encoded bytes in a binary file. The '''--verbose''' flag shows the KLV bytes encoded on the terminal.
<syntaxhighlight lang=C>
 
<syntaxhighlight lang=bash>
./misb-converter --verbose --encode -i misb_ST0601_sample.json -o klv.bin
./misb-converter --verbose --encode -i misb_ST0601_sample.json -o klv.bin
</syntaxhighlight>
</syntaxhighlight>


Once the command is executed (with the --verbose flag), the KLV bytes are displayed in hexadecimal format. The klv.bin file contains the encoded bytes.
Once the command is executed (with the <code>--verbose</code> flag), the KLV bytes are displayed. The klv.bin file contains the encoded bytes.


<syntaxhighlight lang=C>
<syntaxhighlight>
INFO    6 14 43 52 2 11 1 1 14 1 3 1 1 0 0 0 44 2 8 0 4 89 249 174 32 34 168 3 9 77 73 83 83 73 79 78 48 49 4 6 65 70 45 49 48 49 5 2 113 194 15 2 194 33 65 1 17 1 2 164 125
INFO    6 14 43 52 2 11 1 1 14 1 3 1 1 0 0 0 44 2 8 0 4 89 249 174 32 34 168 3 9 77 73 83 83 73 79 78 48 49 4 6 65 70 45 49 48 49 5 2 113 194 15 2 194 33 65 1 17 1 2 164 125
</syntaxhighlight>
</syntaxhighlight>
Line 59: Line 59:
=== Decode command ===
=== Decode command ===


To perform the decoding, the following command is executed. Where the '''--decode''' flag indicates that decoding is to be performed. The '''-i''' flag indicates the input file, where the metadata must be encoded. The '''-o''' flag indicates the output file, which contains the metadata decoded.  
The following command is executed to perform the decoding. The '''--decode''' flag indicates that decoding is to be performed. The '''-i''' flag indicates the input file, where the metadata must be encoded. The '''-o''' flag indicates the output file, which contains the metadata decoded.  


The encoded bytes found inside the klv.bin file are (represented in hexadecimal form):  
The encoded bytes found inside the klv.bin file are:  
  <syntaxhighlight lang=C>
  <syntaxhighlight>
6 14 43 52 2 11 1 1 14 1 3 1 1 0 0 0 44 2 8 0  
6 14 43 52 2 11 1 1 14 1 3 1 1 0 0 0 44 2 8 0  
4 89 249 174 32 34 168 3 9 77 73 83 83 73 79  
4 89 249 174 32 34 168 3 9 77 73 83 83 73 79  
Line 69: Line 69:
</syntaxhighlight>
</syntaxhighlight>


<syntaxhighlight lang=C>
<syntaxhighlight lang=bash>
./misb-converter --decode -i klv.bin -o output.json
./misb-converter --decode -i klv.bin -o output.json
</syntaxhighlight>
</syntaxhighlight>
Line 106: Line 106:
}
}
</syntaxhighlight>
</syntaxhighlight>
As seen here some extra flags can be present after the decoding process since the encoding might add required tags to the encoding.


== Logging ==
== Logging ==
Line 111: Line 113:
You can enable the debugging using '''SetLogLevel''' in your application with the LibMISB. For example:
You can enable the debugging using '''SetLogLevel''' in your application with the LibMISB. For example:


<pre>
<syntaxhighlight lang=cpp>
   libmisb::LibMisb libmisb;
   libmisb::LibMisb libmisb;
   libmisb.SetLogLevel(LIBMISB_DEBUG);
   libmisb.SetLogLevel(LIBMISB_DEBUG);
</pre>
</syntaxhighlight>


<noinclude>{{LibMISB/Foot|Examples|Examples/Add_data_to_MPEG_Transport_Stream}}</noinclude>
<noinclude>{{LibMISB/Foot|Examples|Examples/Add_data_to_MPEG_Transport_Stream}}</noinclude>
437

edits