LCOV - code coverage report
Current view: top level - source/common/config - opaque_resource_decoder_impl.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 11 11 100.0 %
Date: 2024-01-05 06:35:25 Functions: 13 36 36.1 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "envoy/config/subscription.h"
       4             : 
       5             : #include "source/common/protobuf/utility.h"
       6             : 
       7             : namespace Envoy {
       8             : namespace Config {
       9             : 
      10             : template <typename Current> class OpaqueResourceDecoderImpl : public Config::OpaqueResourceDecoder {
      11             : public:
      12             :   OpaqueResourceDecoderImpl(ProtobufMessage::ValidationVisitor& validation_visitor,
      13             :                             absl::string_view name_field)
      14         205 :       : validation_visitor_(validation_visitor), name_field_(name_field) {}
      15             : 
      16             :   // Config::OpaqueResourceDecoder
      17         398 :   ProtobufTypes::MessagePtr decodeResource(const ProtobufWkt::Any& resource) override {
      18         398 :     auto typed_message = std::make_unique<Current>();
      19             :     // If the Any is a synthetic empty message (e.g. because the resource field was not set in
      20             :     // Resource, this might be empty, so we shouldn't decode.
      21         398 :     if (!resource.type_url().empty()) {
      22         398 :       MessageUtil::anyConvertAndValidate<Current>(resource, *typed_message, validation_visitor_);
      23         398 :     }
      24         398 :     return typed_message;
      25         398 :   }
      26             : 
      27         354 :   std::string resourceName(const Protobuf::Message& resource) override {
      28         354 :     return MessageUtil::getStringField(resource, name_field_);
      29         354 :   }
      30             : 
      31             : private:
      32             :   ProtobufMessage::ValidationVisitor& validation_visitor_;
      33             :   const std::string name_field_;
      34             : };
      35             : 
      36             : } // namespace Config
      37             : } // namespace Envoy

Generated by: LCOV version 1.15