Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Json to Tlv and Tlv to Json Converters Implementation in CPP (#27635)
* Json to Tlv and Tlv to Json Converters Implemented in CPP This implementation is equivalent to the Kotlin implementation in: src/controller/java/src/chip/jsontlv/ Note that NOT all TLV configurations are supported by the current implementation. Here is the list of limitations: - TLV Structure elements are expected to be sorted in a canonical tag order - TLV Lists are not supported - Multi-Dimensional TLV Arrays are not supported - All elements in an array MUST be of the same type - The top-level TLV element MUST be a single structure with AnonymousTag - The following tags are supported: - AnonymousTag are only used with TLV Array elements or a top-level structure. - ContextSpecificTag are used only with TLV Structure elements. - CommonProfileTag are used only with TLV Structure elements. - Infinity Float/Double values are not supported. Added README.md file that describing the format. Added unit tests for TLV to JSON, JSON to TLV, JSON to TLV back to JSON conversion cases. NOTE about the current implementation of the Tlv-to-Json converter in: src/lib/support/jsontlv/TlvJson.cpp I kept this implementation because it is currently used in a few places in the code for testing/logging purposes. As a follow up work item, this implementation should be replaced with the new one presented in this commit. * Update src/lib/support/jsontlv/JsonToTlv.cpp Co-authored-by: Robert Szewczyk <szewczyk@google.com> * Update src/lib/support/jsontlv/TlvToJson.cpp Co-authored-by: Robert Szewczyk <szewczyk@google.com> * Update src/lib/support/jsontlv/TlvToJson.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Update src/lib/support/jsontlv/TlvToJson.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Update src/lib/support/jsontlv/JsonToTlv.h Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Update src/lib/support/jsontlv/JsonToTlv.h Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Addressed Review Comments * Restyled by clang-format * Restyled by prettier-markdown * Removed Debug Prints * Added Support for Float/Double Infinity Values Those values should be encoded as "Infinity" and "-Infinity" strings. * Restyled by clang-format * Restyled by prettier-markdown * Update src/lib/support/jsontlv/JsonToTlv.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Addressed Review Comments * Switch from CommonTag to ProfileTag with an implicit profile id * Documentation update * Restyle * Fix type of variable in unit test * Update src/lib/support/jsontlv/README.md Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Update src/lib/support/jsontlv/TlvToJson.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Update src/lib/support/jsontlv/TlvToJson.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Update src/lib/support/jsontlv/TlvToJson.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Update src/lib/support/jsontlv/TlvJson.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Added more comments about kTemporaryImplicitProfileId not being actually used in stored values. Made the values consistent everywhere * Revert old code updates * Casing on json updated according to code review * Make the tlv element naming a bit more consistent, including invalid JSON in case element types are NOT as expected * Remove obsolete comment * Update src/lib/support/jsontlv/TlvToJson.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Update src/lib/support/jsontlv/TlvToJson.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Robert Szewczyk <szewczyk@google.com> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Andrei Litvin <andreilitvin@google.com> Co-authored-by: Andrei Litvin <andy314@gmail.com> Co-authored-by: yunhanw-google <yunhanw@google.com>
- Loading branch information