Skip to content

Commit

Permalink
Apply code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin committed Jul 11, 2023
1 parent 23c90eb commit 7505c08
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions examples/common/tracing/TraceDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
constexpr uint16_t kMaxLineLen = 4096;
constexpr const char * jsonPrefix = " json\t";

namespace chip {
namespace trace {
namespace {

// Json keys
constexpr const char * kProtocolIdKey = "protocol_id";
constexpr const char * kProtocolCodeKey = "protocol_opcode";
Expand All @@ -47,30 +51,18 @@ constexpr const char * kNeedsAckKey = "is_ack_requested";
constexpr const char * kAckMsgKey = "acknowledged_msg_counter";
constexpr const char * kPayloadDataKey = "payload_hex";
constexpr const char * kPayloadSizeKey = "payload_size";

namespace chip {
namespace trace {
namespace {

constexpr const char * kDirectionKey = "direction";
constexpr const char * kPeerAddress = "peer_address";

bool IsOutbound(const Json::Value & json)
{
if (!json.isMember(kDirectionKey))
{
return false; // unknown
}

VerifyOrReturnValue(json.isMember(kDirectionKey), false);
return strcmp(json[kDirectionKey].asCString(), "outbound") == 0;
}

bool IsInbound(const Json::Value & json)
{
if (!json.isMember(kDirectionKey))
{
return false; // unknown
}

VerifyOrReturnValue(json.isMember(kDirectionKey), false);
return strcmp(json[kDirectionKey].asCString(), "inbound") == 0;
}

Expand Down Expand Up @@ -182,9 +174,9 @@ CHIP_ERROR TraceDecoder::LogAndConsumeProtocol(Json::Value & json)

builder.Add(IsInbound(json) ? "<< from " : ">> to ");

if (json.isMember("peer_address"))
if (json.isMember(kPeerAddress))
{
builder.Add(json["peer_address"].asCString());
builder.Add(json[kPeerAddress].asCString());
}
else
{
Expand Down

0 comments on commit 7505c08

Please sign in to comment.