-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: TLV-JSON-TLV converter #27279
Conversation
…oid tv-app platform and content apps)
@@ -139,6 +139,7 @@ CHIP_ERROR CastingServer::OpenBasicCommissioningWindow(std::function<void(CHIP_E | |||
mOnConnectionSuccessClientCallback = onConnectionSuccess; | |||
mOnConnectionFailureClientCallback = onConnectionFailure; | |||
mOnNewOrUpdatedEndpoint = onNewOrUpdatedEndpoint; | |||
ChipLogError(AppServer, "-----------------------CastingServer PrepareForCommissioning"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: remove
PR #27279: Size comparison from eef9529 to 09dc61b Increases (10 builds for bl602, cc32xx, cyw30739, esp32, nrfconnect, telink)
Decreases (8 builds for bl702, psoc6, telink)
Full report (46 builds for bl602, bl702, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Request changes: please add unit tests for such large code changes that are quite stand-alone (parsing and creating a JSON seems like it would be unit testable ... and unit tests would also explain how the JSON looks like)
return CHIP_NO_ERROR; | ||
} | ||
|
||
class JsonParser2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the 2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in some namespace of chip?
* @namespace chip::TLV::Json | ||
* | ||
* @brief | ||
* This namespace includes types and interfaces for json conversion of CHIP TLV. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these comments do not seem to help too much ... namespace re-states the namespace name and it seems obvious that chip::TLV::Json
describes a json interface for TLV
Can we add more useful commets (e.g. explaining what the json format is with examples and explaining what a context is and such)
void * mContext; | ||
}; | ||
|
||
extern CHIP_ERROR WriteJSON(const TLVReader & aReader, Encoding::BufferWriter & bWriter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably do not need "extern"
* buffer. On failure, the value of *octetCount is undefined. | ||
*/ | ||
template <typename F> | ||
CHIP_ERROR ConvertHexToBytes(chip::CharSpan hex, F bufferAllocator, size_t * octetCount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not seem TLV-specific so should probably not be in JSONTlv.h
We have some lib/support/BytesToHex ... maybe we want HexToBytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have HexToBytes too, inside the BytesToHex header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well.... that is confusing ... maybe we can find a better name or split headers.
class JsonTLVParser | ||
{ | ||
public: | ||
static CHIP_ERROR Put(chip::TLV::TLVWriter * writer, chip::TLV::Tag tag, Json::Value & value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like complex code in a header. Should probably be in a C++ file.
Also please add unit tests.
chip::TLV::TLVWriter writer; | ||
chip::TLV::TLVReader reader; | ||
|
||
uint8_t buf[74]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to explain the sizes here ...74 seems a very particular constant.
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR RunJsonTests() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests should be unit tests run during test execution, not a shell command (we can include it in the casting app as well, but a variant of unit tests that are stand alone should exist).
CHIP_ERROR RunJsonTests() | ||
{ | ||
char json[] = "{" | ||
"\"0x0\" : { \"tlvType\":\"0x00\", \"value\": 7 }," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may want some NULL tests as well.
@chrisdecenzo I moved your PR to draft since the title said so. |
|
||
if (TLVTypeIsContainer(type)) | ||
{ | ||
if (tagControl == TLVTagControl::ContextSpecific) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about profile tags in TLV lists?
} | ||
else | ||
{ | ||
if (tagControl == TLVTagControl::ContextSpecific) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this does not seem to handle profile tags right. But also, shouldn't that "tag" :
prefix just be written out independently of whether the tag is a container or not?
case kTLVType_ByteString: | ||
err = temp.GetDataPtr(strbuf); | ||
VerifyOrExit(err == CHIP_NO_ERROR, FormattedWrite(aWriter, "Error in kTLVType_ByteString")); | ||
FormattedWrite(aWriter, "hex:"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this produces valid JSON, unless I am missing something.....
uint64_t uVal; | ||
err = temp.Get(uVal); | ||
VerifyOrExit(err == CHIP_NO_ERROR, FormattedWrite(aWriter, "Error in kTLVType_UnsignedInteger")); | ||
FormattedWrite(aWriter, "%" PRIu64, uVal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're OK with the data corruptions for values > 2^53?
* buffer. On failure, the value of *octetCount is undefined. | ||
*/ | ||
template <typename F> | ||
CHIP_ERROR ConvertHexToBytes(chip::CharSpan hex, F bufferAllocator, size_t * octetCount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have HexToBytes too, inside the BytesToHex header.
{ | ||
public: | ||
// Returns whether the parse succeeded. | ||
static bool ParseComplexArgument(const char * label, const char * json, Json::Value & value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be duplicating the chip-tool complex argument parser, right? Is it different from that code? If so, maybe it should not be called ParseComplexArgument... If it's not different, why is it separate?
constexpr const char kHexNumPrefix[] = "0x"; | ||
constexpr size_t kHexNumPrefixLen = ArraySize(kHexNumPrefix) - 1; | ||
|
||
Json::Value objTlvType = value.get("tlvType", "0x0c"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document why the defaulting to 0x0c.
@chrisdecenzo we are preparing one pull request that provide the generic TLV-JSON-TLV converter using C++ along with documentation, similar to the kotlin one we provided in #26527 |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This stale pull request has been automatically closed. Thank you for your contributions. |
This seems in draft for over 1 year. @chrisdecenzo can we close it? |
Closing very old PR in draft form. |
(for message serialization between android tv-app platform and content apps)
TODO: