Skip to content

Commit

Permalink
Use FastWriter for TlvJson
Browse files Browse the repository at this point in the history
TlvJson now outputs a more RPC-friendly string, instead of a
human-readable string.
  • Loading branch information
CodeChronos928 committed May 14, 2022
1 parent 9f755f9 commit ad6a1c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/lib/support/jsontlv/TlvJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ void InsertKeyValue(Json::Value & json, const KeyContext & keyContext, T val)

std::string JsonToString(Json::Value & json)
{
Json::StyledWriter writer;
Json::FastWriter writer;
writer.omitEndingLineFeed();
return writer.write(json);
}

Expand Down
12 changes: 9 additions & 3 deletions src/lib/support/tests/TestTlvToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ CHIP_ERROR SetupReader()

bool Matches(const char * referenceString, Json::Value & generatedValue)
{
Json::StyledWriter writer;
auto generatedStr = JsonToString(generatedValue);

auto matches = (generatedStr == std::string(referenceString));
Json::Reader reader;
Json::StyledWriter writer;
Json::Value reparsedGeneratedValue;

reader.parse(generatedStr, reparsedGeneratedValue);
auto normalizedGeneratedStr = writer.write(reparsedGeneratedValue);

auto matches = (normalizedGeneratedStr == std::string(referenceString));

if (!matches)
{
Expand All @@ -66,7 +72,7 @@ bool Matches(const char * referenceString, Json::Value & generatedValue)
printf("%s\n", referenceString);

printf("Generated:\n");
printf("%s\n", generatedStr.c_str());
printf("%s\n", normalizedGeneratedStr.c_str());
}

return matches;
Expand Down

0 comments on commit ad6a1c4

Please sign in to comment.