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: coverage_cleared.info Lines: 15 18 83.3 %
Date: 2018-12-05 17:11:35 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_error_query_response.hpp"
      13             : #include "backend/protobuf/query_responses/proto_role_permissions_response.hpp"
      14             : #include "backend/protobuf/query_responses/proto_roles_response.hpp"
      15             : #include "backend/protobuf/query_responses/proto_signatories_response.hpp"
      16             : #include "backend/protobuf/query_responses/proto_transaction_response.hpp"
      17             : #include "common/byteutils.hpp"
      18             : #include "utils/reference_holder.hpp"
      19             : #include "utils/variant_deserializer.hpp"
      20             : 
      21             : namespace {
      22             :   /// type of proto variant
      23             :   using ProtoQueryResponseVariantType =
      24             :       boost::variant<shared_model::proto::AccountAssetResponse,
      25             :                      shared_model::proto::AccountDetailResponse,
      26             :                      shared_model::proto::AccountResponse,
      27             :                      shared_model::proto::ErrorQueryResponse,
      28             :                      shared_model::proto::SignatoriesResponse,
      29             :                      shared_model::proto::TransactionsResponse,
      30             :                      shared_model::proto::AssetResponse,
      31             :                      shared_model::proto::RolesResponse,
      32             :                      shared_model::proto::RolePermissionsResponse>;
      33             : 
      34             :   /// list of types in variant
      35             :   using ProtoQueryResponseListType = ProtoQueryResponseVariantType::types;
      36             : }  // namespace
      37             : 
      38             : namespace shared_model {
      39             :   namespace proto {
      40             : 
      41             :     struct QueryResponse::Impl {
      42             :       explicit Impl(const TransportType &ref) : proto_{ref} {}
      43             :       explicit Impl(TransportType &&ref) : proto_{std::move(ref)} {}
      44             : 
      45             :       detail::ReferenceHolder<TransportType> proto_;
      46             : 
      47             :       const ProtoQueryResponseVariantType variant_{[this] {
      48         378 :         auto &&ar = *proto_;
      49         378 :         int which =
      50         378 :             ar.GetDescriptor()->FindFieldByNumber(ar.response_case())->index();
      51         378 :         return shared_model::detail::variant_impl<ProtoQueryResponseListType>::
      52             :             template load<ProtoQueryResponseVariantType>(
      53         378 :                 std::forward<decltype(ar)>(ar), which);
      54             :       }()};
      55             : 
      56         345 :       const QueryResponseVariantType ivariant_{variant_};
      57             : 
      58         347 :       const crypto::Hash hash_{
      59         346 :           iroha::hexstringToBytestring(proto_->query_hash()).get()};
      60             :     };
      61             : 
      62             :     QueryResponse::QueryResponse(const QueryResponse &o)
      63           0 :         : QueryResponse(*o.impl_->proto_) {}
      64             :     QueryResponse::QueryResponse(QueryResponse &&o) noexcept = default;
      65             : 
      66             :     QueryResponse::QueryResponse(const TransportType &ref) {
      67          31 :       impl_ = std::make_unique<Impl>(ref);
      68          31 :     }
      69             :     QueryResponse::QueryResponse(TransportType &&ref) {
      70         347 :       impl_ = std::make_unique<Impl>(std::move(ref));
      71         347 :     }
      72             : 
      73             :     QueryResponse::~QueryResponse() = default;
      74             : 
      75             :     const QueryResponse::QueryResponseVariantType &QueryResponse::get() const {
      76         233 :       return impl_->ivariant_;
      77             :     }
      78             : 
      79             :     const interface::types::HashType &QueryResponse::queryHash() const {
      80          40 :       return impl_->hash_;
      81             :     }
      82             : 
      83             :     const QueryResponse::TransportType &QueryResponse::getTransport() const {
      84         143 :       return *impl_->proto_;
      85             :     }
      86             : 
      87             :     QueryResponse *QueryResponse::clone() const {
      88           0 :       return new QueryResponse(*impl_->proto_);
      89           0 :     }
      90             : 
      91             :   }  // namespace proto
      92             : }  // namespace shared_model

Generated by: LCOV version 1.13