LCOV - code coverage report
Current view: top level - shared_model/backend/protobuf/query_responses/impl - proto_query_response.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 15 18 83.3 %
Date: 2019-03-07 14:46:43 Functions: 17 22 77.3 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "backend/protobuf/query_responses/proto_query_response.hpp"
       7             : 
       8             : #include "backend/protobuf/query_responses/proto_account_asset_response.hpp"
       9             : #include "backend/protobuf/query_responses/proto_account_detail_response.hpp"
      10             : #include "backend/protobuf/query_responses/proto_account_response.hpp"
      11             : #include "backend/protobuf/query_responses/proto_asset_response.hpp"
      12             : #include "backend/protobuf/query_responses/proto_get_block_response.hpp"
      13             : #include "backend/protobuf/query_responses/proto_error_query_response.hpp"
      14             : #include "backend/protobuf/query_responses/proto_role_permissions_response.hpp"
      15             : #include "backend/protobuf/query_responses/proto_roles_response.hpp"
      16             : #include "backend/protobuf/query_responses/proto_signatories_response.hpp"
      17             : #include "backend/protobuf/query_responses/proto_transaction_response.hpp"
      18             : #include "backend/protobuf/query_responses/proto_transactions_page_response.hpp"
      19             : #include "common/byteutils.hpp"
      20             : #include "utils/variant_deserializer.hpp"
      21             : 
      22             : namespace {
      23             :   /// type of proto variant
      24             :   using ProtoQueryResponseVariantType =
      25             :       boost::variant<shared_model::proto::AccountAssetResponse,
      26             :                      shared_model::proto::AccountDetailResponse,
      27             :                      shared_model::proto::AccountResponse,
      28             :                      shared_model::proto::ErrorQueryResponse,
      29             :                      shared_model::proto::SignatoriesResponse,
      30             :                      shared_model::proto::TransactionsResponse,
      31             :                      shared_model::proto::AssetResponse,
      32             :                      shared_model::proto::RolesResponse,
      33             :                      shared_model::proto::RolePermissionsResponse,
      34             :                      shared_model::proto::TransactionsPageResponse,
      35             :                      shared_model::proto::GetBlockResponse>;
      36             : 
      37             :   /// list of types in variant
      38             :   using ProtoQueryResponseListType = ProtoQueryResponseVariantType::types;
      39             : }  // namespace
      40             : 
      41             : namespace shared_model {
      42             :   namespace proto {
      43             : 
      44             :     struct QueryResponse::Impl {
      45             :       explicit Impl(const TransportType &ref) : proto_{ref} {}
      46             :       explicit Impl(TransportType &&ref) : proto_{std::move(ref)} {}
      47             : 
      48             :       TransportType proto_;
      49             : 
      50             :       const ProtoQueryResponseVariantType variant_{[this] {
      51         400 :         const auto &ar = proto_;
      52         400 :         int which =
      53         400 :             ar.GetDescriptor()->FindFieldByNumber(ar.response_case())->index();
      54         400 :         return shared_model::detail::variant_impl<ProtoQueryResponseListType>::
      55             :             template load<ProtoQueryResponseVariantType>(
      56         400 :                 std::forward<decltype(ar)>(ar), which);
      57             :       }()};
      58             : 
      59         368 :       const QueryResponseVariantType ivariant_{variant_};
      60             : 
      61         368 :       const crypto::Hash hash_{
      62         368 :           iroha::hexstringToBytestring(proto_.query_hash()).get()};
      63             :     };
      64             : 
      65             :     QueryResponse::QueryResponse(const QueryResponse &o)
      66           0 :         : QueryResponse(o.impl_->proto_) {}
      67             :     QueryResponse::QueryResponse(QueryResponse &&o) noexcept = default;
      68             : 
      69             :     QueryResponse::QueryResponse(const TransportType &ref) {
      70          33 :       impl_ = std::make_unique<Impl>(ref);
      71          33 :     }
      72             :     QueryResponse::QueryResponse(TransportType &&ref) {
      73         368 :       impl_ = std::make_unique<Impl>(std::move(ref));
      74         368 :     }
      75             : 
      76             :     QueryResponse::~QueryResponse() = default;
      77             : 
      78             :     const QueryResponse::QueryResponseVariantType &QueryResponse::get() const {
      79         257 :       return impl_->ivariant_;
      80             :     }
      81             : 
      82             :     const interface::types::HashType &QueryResponse::queryHash() const {
      83          45 :       return impl_->hash_;
      84             :     }
      85             : 
      86             :     const QueryResponse::TransportType &QueryResponse::getTransport() const {
      87         143 :       return impl_->proto_;
      88             :     }
      89             : 
      90             :     QueryResponse *QueryResponse::clone() const {
      91           0 :       return new QueryResponse(impl_->proto_);
      92           0 :     }
      93             : 
      94             :   }  // namespace proto
      95             : }  // namespace shared_model

Generated by: LCOV version 1.13