Skip to content

Integrated compile time type checking and error detection for data structure parsing.#12

Open
nathan-disguise wants to merge 3 commits into
mosys:mainfrom
disguise-one:json-type-checking
Open

Integrated compile time type checking and error detection for data structure parsing.#12
nathan-disguise wants to merge 3 commits into
mosys:mainfrom
disguise-one:json-type-checking

Conversation

@nathan-disguise

@nathan-disguise nathan-disguise commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

At present the opentrackio-cpp library is able in a vast number of cases to correctly extract and convert JSON packet data into its OpenTrackIOSample structure for easy use in an existing codebase. However, when parsing incorrect JSON data there are at present no checks to validate the type being extracted prior to calling getFieldFromJson(). As the subsequent API call in question forwards to a noexcept call if the type serialises incorrectly, resulting in a SIGABRT/std::abort signal being raised instead of an error being returned in turn leading to a crash. For live production uses of this library this is a major concern given that the format of the JSON packet data cannot be guaranteed.

The existing codebase implies there was a mechanism previously for this kind of checking build into the assignField() function via the typeStr parameter, however this is at present unused and does not have a consistent set of expected strings which could be validated as well as ignoring the potential for more robust type checking mechanisms which validate extraction.

This change seeks to address both these issues via the addition of a new suite of compile type checks to assignField() which will select the corresponding JSON type (via the nlohmann::json library structures) from the provided C++ field parameter. Should a JSON type mismatch be detected we return an error with a message detailing the field extraction failure within the structure. Ensuring that parsing is fault-tolerant as well as aiding ensuring consistency between the JSON and C++ data structures.

Comment on lines +318 to +319
* Number that identifies the index of the stream from a source from which data is being transported.
* This is most important in the case where a source is producing multiple streams of samples. */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Number that identifies the index of the stream from a source from which data is being transported.
* This is most important in the case where a source is producing multiple streams of samples. */
* Number that identifies the index of the stream from a source from which data is being transported.
* This is most important in the case where a source is producing multiple streams of samples. */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant