Integrated compile time type checking and error detection for data structure parsing.#12
Open
nathan-disguise wants to merge 3 commits into
Open
Integrated compile time type checking and error detection for data structure parsing.#12nathan-disguise wants to merge 3 commits into
nathan-disguise wants to merge 3 commits into
Conversation
nathan-disguise
commented
Jul 7, 2026
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. */ |
Contributor
Author
There was a problem hiding this comment.
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. */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 anoexceptcall if the type serialises incorrectly, resulting in aSIGABRT/std::abortsignal 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 thetypeStrparameter, 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 thenlohmann::jsonlibrary 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.