Skip to content

Commit

Permalink
fix: trace outgoing echo calls (#710)
Browse files Browse the repository at this point in the history
* fix: trace outgoing echo calls

* protobuf/echo/TracingEcho: Trace message members

* protobuf/echo/TracingEcho: Use the proper '0' padding

* Resolve warning
  • Loading branch information
richardapeters authored Sep 17, 2024
1 parent 4f2a49e commit 279bb62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions protobuf/echo/TracingEcho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace services
{
tracer.Continue() << "[";
for (auto v : value)
tracer.Continue() << infra::hex << infra::Width(2, 0) << v;
tracer.Continue() << infra::hex << infra::Width(2, '0') << v;
tracer.Continue() << "]";
}

Expand Down Expand Up @@ -168,7 +168,7 @@ namespace services
auto save = stream.Reader().ConstructSaveMarker();
auto [contents, methodId] = parser.GetPartialField();

if (stream.Failed() || (contents.Is<infra::PartialProtoLengthDelimited>() && contents.Get<infra::PartialProtoLengthDelimited>().length <= writerBuffer.max_size() - writerBuffer.size()))
if (stream.Failed() || !contents.Is<infra::PartialProtoLengthDelimited>() || contents.Get<infra::PartialProtoLengthDelimited>().length > writerBuffer.max_size() - writerBuffer.size())
break;

if (contents.Is<infra::PartialProtoLengthDelimited>() && contents.Get<infra::PartialProtoLengthDelimited>().length > stream.Available())
Expand Down
13 changes: 4 additions & 9 deletions protobuf/echo/TracingEcho.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,17 @@ namespace services
PrintField(static_cast<uint32_t>(value), tracer);
}

template<std::size_t I, class T, class Enable>
void PrintSubFields(const T& value, services::Tracer& tracer, typename T::template Type<I>* = 0)
template<class T, std::size_t... I>
void PrintSubFields(const T& value, services::Tracer& tracer, std::index_sequence<I...>)
{
PrintField(value.Get(std::integral_constant<uint32_t, I>()), tracer);
PrintSubFields<I + 1>(value, tracer);
(void)((PrintField(value.Get(std::integral_constant<uint32_t, I>()), tracer), true) && ...);
}

template<std::size_t I, class T>
void PrintSubFields(const T& value, services::Tracer& tracer, ...)
{}

template<class T>
void PrintField(const T& value, services::Tracer& tracer, typename T::template Type<0>* = 0)
{
tracer.Continue() << "{";
PrintSubFields<0>(value, tracer);
PrintSubFields(value, tracer, std::make_index_sequence<T::numberOfFields>{});
tracer.Continue() << "}";
}

Expand Down

0 comments on commit 279bb62

Please sign in to comment.