Implement CTF 2 JSON requirements
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 27 May 2022 12:18:29 +0000 (08:18 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 23 Aug 2022 16:06:16 +0000 (12:06 -0400)
commitcef7e55e851c11e38a26da3f51e2e66e05481479
tree8080a244feaeb6009aec452b6b7ab40e6f40a423
parent73c5947855d5ff001f2eb7f8867171e7b60b57bf
Implement CTF 2 JSON requirements

This patch implements all the CTF 2 JSON requirements.

The internal "public" API is the `Ctf2JsonAnyFragmentValReq` PImpl class
which validates a single CTF 2 fragment. That's all the CTF 2 metadata
stream parser will need.

Here's an example:

Code:
    Ctf2JsonAnyFragValReq {}.validate(*bt2_common::parseJson(jsonText));

JSON text:
    {
      "type": "data-stream-class",
      "namespace": "lol",
      "name": "salut",
      "packet-context-field-class": {
        "type": "structure",
        "member-classes": [
          {
            "name": "meow",
            "field-class": {
              "type": "null-terminated-string"
            }
          },
          {
            "name": "meow",
            "field-class": {
              "type": "dynamic-length-array",
              "length-field-location": ["data-stream-class", "lel"],
              "element-field-class": {
                "type": "fixed-length-signed-integer",
                "length": 23,
                "byte-order": "little-endian",
                "alignment": 24,
                "user-attributes": {}
              }
            }
          }
        ]
      }
    }

Exception message:
    [1:1] Invalid data stream class fragment:
    [5:33] In object property `packet-context-field-class`:
    [5:33] Invalid scope field class:
    [5:33] Invalid structure field class:
    [7:23] In object property `member-classes`:
    [14:7] In array element #2:
    [14:7] Invalid structure field member class:
    [16:24] In object property `field-class`:
    [16:24] Invalid dynamic-length array field class:
    [19:34] In object property `element-field-class`:
    [19:34] Invalid fixed-length signed integer field class:
    [23:26] In object property `alignment`:
    [23:26] Invalid alignment: 24 is not a power of two.

I'd say that Ctf2JsonAnyFragValReq::validate() can validate 95 % of a
CTF 2 metadata stream. See its class comment to learn what it can't do.

There are a few clang-format off/on comments because I hate what it does
with nested brace-enclosed lists.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic622a099a1e0aa5daa896cdfa910d24b817a9a5f
configure.ac
src/plugins/ctf/common/metadata/Makefile.am
src/plugins/ctf/common/metadata/json/strings.hpp [new file with mode: 0644]
src/plugins/ctf/common/src/metadata/Makefile.am
src/plugins/ctf/common/src/metadata/json/Makefile.am [new file with mode: 0644]
src/plugins/ctf/common/src/metadata/json/val-req.cpp [new file with mode: 0644]
src/plugins/ctf/common/src/metadata/json/val-req.hpp [new file with mode: 0644]
This page took 0.027358 seconds and 5 git commands to generate.