LibMISB/Examples/Library basic usage: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 44: Line 44:
</syntaxhighlight>
</syntaxhighlight>


Or alternitevly if you want to use the 0903 standard:
<syntaxhighlight lang=json>
{
    "key": "060E2B34020B01010E01030306000000",
    "items": [
      {
        "tag": "2",
        "value": "Apr. 19, 2001. 04:25:21.000"
      },
      {
          "tag": "101",
          "value": [
            {
              "tag": "targetId",
              "value": "1234"
            },
            {
              "tag": "1",
              "value": "409600"
            },
            {
              "tag": "3",
              "value": "409600"
            },
            {
              "tag": "5",
              "value": "80"
            },
            {
              "tag": "targetId",
              "value": "1235"
            },
            {
              "tag": "1",
              "value": "409601"
            },
            {
              "tag": "3",
              "value": "409601"
            }
          ]
      },
      {
        "tag": "6",
        "value": "2"
      }
    ]
  }
</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 following command is executed to perform the encoding. 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=bash>
<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>
or
<syntaxhighlight lang=bash>
./misb-converter --verbose --encode -i misb_ST0903_sample.json -o klv.bin
</syntaxhighlight>
</syntaxhighlight>


Once the command is executed (with the <code>--verbose</code> flag), the KLV bytes are displayed. 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 0601 klv.bin file contains the encoded bytes.


<syntaxhighlight>
<syntaxhighlight>
Line 59: Line 115:
=== Decode command ===
=== Decode command ===


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 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 containing the decoded metadata.  


The encoded bytes found inside the klv.bin file are:  
The encoded bytes found inside the 0601 klv.bin file are:  
  <syntaxhighlight>
  <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  
Line 106: Line 162:
}
}
</syntaxhighlight>
</syntaxhighlight>
and for the 0903:
<syntaxhighlight lang=json>
{
  "key": "060E2B34020B01010E01030306000000",
  "items": [
    {
      "tag": "2",
      "value": "Apr. 19, 2001. 04:25:21.000"
    },
    {
      "tag": "101",
      "value": [
        {
          "tag": "id",
          "value": "1234"
        },
        {
          "tag": "1",
          "value": "409600"
        },
        {
          "tag": "3",
          "value": "409600"
        },
        {
          "tag": "5",
          "value": "80"
        },
        {
          "tag": "id",
          "value": "1235"
        },
        {
          "tag": "1",
          "value": "409601"
        },
        {
          "tag": "3",
          "value": "409601"
        }
      ]
    },
    {
      "tag": "6",
      "value": "2"
    },
    {
      "tag": "4",
      "value": "6"
    }
  ]
}
<syntaxhighlight lang=json>


As seen here some extra flags can be present after the decoding process since the encoding might add required tags to the encoding.
As seen here some extra flags can be present after the decoding process since the encoding might add required tags to the encoding.
437

edits