In the Homa module for gRPC there are a few places where the code needs to iterate over all of the values in a grpc_metadata_batch, but there are currently cases where my code isn't seeing all of the values. Here is an example from my code that attempts to log all of the values in a batch. The code invokes the Encode method, passing it a MetataLogger object:
grpc_metadata_batch *batch;
MetadataLogger logger(separator);
batch->Encode(&logger);
Here is the definition of the logger object:
class MetadataLogger {
public:
MetadataLogger(const char *separator) : separator(separator) {}
void Encode(const grpc_core::Slice &key, const grpc_core::Slice &value)
{
uint32_t keyLength = key.length();
uint32_t valueLength = value.length();
Mock::logPrintf(separator, "metadata %.*s: %.*s", keyLength,
key.data(), valueLength, value.data());
}
template <typename MetadataTrait>
void Encode(MetadataTrait, const grpc_core::Slice &value)
{
absl::string_view key = MetadataTrait::key();
uint32_t keyLength = key.length();
uint32_t valueLength = value.length();
Mock::logPrintf(separator, "metadata %.*s: %.*s", keyLength,
key.data(), valueLength, value.data());
}
template <typename MetadataTrait>
void Encode(MetadataTrait, const typename MetadataTrait::ValueType& value)
{
absl::string_view key = MetadataTrait::key();
uint32_t keyLength = key.length();
const grpc_core::Slice& slice =
grpc_core::MetadataValueAsSlice<MetadataTrait>(value);
uint32_t valueLength = slice.length();
Mock::logPrintf(separator, "metadata %.*s: %.*s", keyLength,
key.data(), valueLength, slice.data());
}
const char *separator;
};
The class has 3 different Encode methods, intended to catch all of the different variants of metadata. However, it doesn't seem to be catching absolutely all of them. In particular, if I set the PeerString value, where the key is grpc_core::PeerString(), none of these methods gets invoked. Are there other variants of Encode that I need to define to catch this key? What do I need to do to be sure I'm catching absolutely all of the metadata entries? Is there a better way I should be doing this?
Thanks in advance for any help you can provide.
-John-