diff --git a/src/core/lib/transport/metadata_batch.cc b/src/core/lib/transport/metadata_batch.cc index 483fc3d414b..27ea2e77b88 100644 --- a/src/core/lib/transport/metadata_batch.cc +++ b/src/core/lib/transport/metadata_batch.cc @@ -93,7 +93,7 @@ StaticSlice ContentTypeMetadata::Encode(ValueType x) { return StaticSlice::FromStaticString("unrepresentable value")); } -const char* ContentTypeMetadata::DisplayValue(MementoType content_type) { +const char* ContentTypeMetadata::DisplayValue(ValueType content_type) { switch (content_type) { case ValueType::kApplicationGrpc: return "application/grpc"; @@ -137,7 +137,7 @@ TeMetadata::MementoType TeMetadata::ParseMemento( return out; } -const char* TeMetadata::DisplayValue(MementoType te) { +const char* TeMetadata::DisplayValue(ValueType te) { switch (te) { case ValueType::kTrailers: return "trailers"; @@ -168,7 +168,7 @@ StaticSlice HttpSchemeMetadata::Encode(ValueType x) { } } -const char* HttpSchemeMetadata::DisplayValue(MementoType content_type) { +const char* HttpSchemeMetadata::DisplayValue(ValueType content_type) { switch (content_type) { case kHttp: return "http"; @@ -211,7 +211,7 @@ StaticSlice HttpMethodMetadata::Encode(ValueType x) { } } -const char* HttpMethodMetadata::DisplayValue(MementoType content_type) { +const char* HttpMethodMetadata::DisplayValue(ValueType content_type) { switch (content_type) { case kPost: return "POST"; @@ -253,7 +253,7 @@ Slice LbCostBinMetadata::Encode(const ValueType& x) { return Slice(std::move(slice)); } -std::string LbCostBinMetadata::DisplayValue(MementoType x) { +std::string LbCostBinMetadata::DisplayValue(ValueType x) { return absl::StrCat(x.name, ":", x.cost); } diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index f882159f6b9..635eea01c8f 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -64,7 +64,8 @@ struct GrpcTimeoutMetadata { static MementoType ParseMemento(Slice value, MetadataParseErrorFn on_error); static ValueType MementoToValue(MementoType timeout); static Slice Encode(ValueType x); - static std::string DisplayValue(MementoType x) { return x.ToString(); } + static std::string DisplayValue(ValueType x) { return x.ToString(); } + static std::string DisplayMemento(MementoType x) { return x.ToString(); } }; // TE metadata trait. @@ -85,7 +86,8 @@ struct TeMetadata { GPR_ASSERT(x == kTrailers); return StaticSlice::FromStaticString("trailers"); } - static const char* DisplayValue(MementoType te); + static const char* DisplayValue(ValueType te); + static const char* DisplayMemento(MementoType te) { return DisplayValue(te); } }; // content-type metadata trait. @@ -107,7 +109,10 @@ struct ContentTypeMetadata { } static StaticSlice Encode(ValueType x); - static const char* DisplayValue(MementoType content_type); + static const char* DisplayValue(ValueType content_type); + static const char* DisplayMemento(ValueType content_type) { + return DisplayValue(content_type); + } }; // scheme metadata trait. @@ -129,7 +134,10 @@ struct HttpSchemeMetadata { return content_type; } static StaticSlice Encode(ValueType x); - static const char* DisplayValue(MementoType content_type); + static const char* DisplayValue(ValueType content_type); + static const char* DisplayMemento(MementoType content_type) { + return DisplayValue(content_type); + } }; // method metadata trait. @@ -148,7 +156,10 @@ struct HttpMethodMetadata { return content_type; } static StaticSlice Encode(ValueType x); - static const char* DisplayValue(MementoType content_type); + static const char* DisplayValue(ValueType content_type); + static const char* DisplayMemento(MementoType content_type) { + return DisplayValue(content_type); + } }; // Base type for metadata pertaining to a single compression algorithm @@ -162,13 +173,14 @@ struct CompressionAlgorithmBasedMetadata { GPR_ASSERT(x != GRPC_COMPRESS_ALGORITHMS_COUNT); return Slice::FromStaticString(CompressionAlgorithmAsString(x)); } - static const char* DisplayValue(MementoType x) { + static const char* DisplayValue(ValueType x) { if (const char* p = CompressionAlgorithmAsString(x)) { return p; } else { return ""; } } + static const char* DisplayMemento(MementoType x) { return DisplayValue(x); } }; // grpc-encoding metadata trait. @@ -194,7 +206,10 @@ struct GrpcAcceptEncodingMetadata { } static ValueType MementoToValue(MementoType x) { return x; } static Slice Encode(ValueType x) { return x.ToSlice(); } - static absl::string_view DisplayValue(MementoType x) { return x.ToString(); } + static absl::string_view DisplayValue(ValueType x) { return x.ToString(); } + static absl::string_view DisplayMemento(MementoType x) { + return DisplayValue(x); + } }; struct SimpleSliceBasedMetadata { @@ -205,7 +220,10 @@ struct SimpleSliceBasedMetadata { } static ValueType MementoToValue(MementoType value) { return value; } static Slice Encode(const ValueType& x) { return x.Ref(); } - static absl::string_view DisplayValue(const MementoType& value) { + static absl::string_view DisplayValue(const ValueType& value) { + return value.as_string_view(); + } + static absl::string_view DisplayMemento(const MementoType& value) { return value.as_string_view(); } }; @@ -273,7 +291,8 @@ struct SimpleIntBasedMetadataBase { using MementoType = Int; static ValueType MementoToValue(MementoType value) { return value; } static Slice Encode(ValueType x) { return Slice::FromInt64(x); } - static Int DisplayValue(MementoType x) { return x; } + static Int DisplayValue(ValueType x) { return x; } + static Int DisplayMemento(MementoType x) { return x; } }; template @@ -312,6 +331,7 @@ struct GrpcRetryPushbackMsMetadata { static ValueType MementoToValue(MementoType x) { return x; } static Slice Encode(Duration x) { return Slice::FromInt64(x.millis()); } static int64_t DisplayValue(Duration x) { return x.millis(); } + static int64_t DisplayMemento(Duration x) { return DisplayValue(x); } static Duration ParseMemento(Slice value, MetadataParseErrorFn on_error); }; @@ -333,7 +353,10 @@ struct GrpcLbClientStatsMetadata { using MementoType = ValueType; static ValueType MementoToValue(MementoType value) { return value; } static Slice Encode(ValueType) { abort(); } - static const char* DisplayValue(MementoType) { return ""; } + static const char* DisplayValue(ValueType) { return ""; } + static const char* DisplayMemento(MementoType) { + return ""; + } static MementoType ParseMemento(Slice, MetadataParseErrorFn) { return nullptr; } @@ -356,7 +379,8 @@ struct LbCostBinMetadata { using MementoType = ValueType; static ValueType MementoToValue(MementoType value) { return value; } static Slice Encode(const ValueType& x); - static std::string DisplayValue(MementoType x); + static std::string DisplayValue(ValueType x); + static std::string DisplayMemento(MementoType x) { return DisplayValue(x); } static MementoType ParseMemento(Slice value, MetadataParseErrorFn on_error); }; @@ -677,6 +701,11 @@ struct AdaptDisplayValueToLog { } }; +template <> +struct AdaptDisplayValueToLog { + static std::string ToString(const char* value) { return std::string(value); } +}; + template <> struct AdaptDisplayValueToLog { static absl::string_view ToString(StaticSlice value) { @@ -718,7 +747,7 @@ struct Value::TrivialTraitVTable() { return metadata_detail::MakeDebugStringPipeline( Which::key(), value, metadata_detail::FieldFromTrivial, - Which::DisplayValue); + Which::DisplayMemento); }, // key Which::key(), @@ -334,7 +334,7 @@ ParsedMetadata::NonTrivialTraitVTable() { return metadata_detail::MakeDebugStringPipeline( Which::key(), value, metadata_detail::FieldFromPointer, - Which::DisplayValue); + Which::DisplayMemento); }, // key Which::key(), @@ -362,7 +362,7 @@ ParsedMetadata::SliceTraitVTable() { [](const Buffer& value) { return metadata_detail::MakeDebugStringPipeline( Which::key(), value, metadata_detail::SliceFromBuffer, - Which::DisplayValue); + Which::DisplayMemento); }, // key Which::key(), diff --git a/test/core/transport/parsed_metadata_test.cc b/test/core/transport/parsed_metadata_test.cc index 387226b0c30..a9fec9180cb 100644 --- a/test/core/transport/parsed_metadata_test.cc +++ b/test/core/transport/parsed_metadata_test.cc @@ -41,6 +41,9 @@ struct CharTrait { return slice[0]; } static std::string DisplayValue(char value) { return std::string(1, value); } + static std::string DisplayMemento(MementoType memento) { + return DisplayValue(memento); + } }; struct Int32Trait { @@ -58,6 +61,9 @@ struct Int32Trait { static std::string DisplayValue(int32_t value) { return std::to_string(value); } + static std::string DisplayMemento(MementoType memento) { + return DisplayValue(memento); + } }; struct Int64Trait { @@ -75,6 +81,9 @@ struct Int64Trait { static std::string DisplayValue(int64_t value) { return std::to_string(value); } + static std::string DisplayMemento(MementoType memento) { + return DisplayValue(memento); + } }; struct IntptrTrait { @@ -92,6 +101,9 @@ struct IntptrTrait { static std::string DisplayValue(intptr_t value) { return std::to_string(value); } + static std::string DisplayMemento(MementoType memento) { + return DisplayValue(memento); + } }; struct StringTrait { @@ -108,6 +120,9 @@ struct StringTrait { return std::string(view.begin(), view.end()); } static std::string DisplayValue(const std::string& value) { return value; } + static std::string DisplayMemento(MementoType memento) { + return DisplayValue(memento); + } }; class FakeContainer {