LCOV - code coverage report
Current view: top level - shared_model/backend/protobuf/impl - proto_block_json_converter.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 14 15 93.3 %
Date: 2018-12-05 17:11:35 Functions: 2 2 100.0 %

          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/proto_block_json_converter.hpp"
       7             : 
       8             : #include <google/protobuf/util/json_util.h>
       9             : #include <string>
      10             : 
      11             : #include "backend/protobuf/block.hpp"
      12             : 
      13             : using namespace shared_model;
      14             : using namespace shared_model::proto;
      15             : 
      16             : iroha::expected::Result<interface::types::JsonType, std::string>
      17             : ProtoBlockJsonConverter::serialize(const interface::Block &block) const
      18             :     noexcept {
      19        1241 :   const auto &proto_block = static_cast<const Block &>(block).getTransport();
      20        1241 :   std::string result;
      21             :   auto status =
      22        1241 :       google::protobuf::util::MessageToJsonString(proto_block, &result);
      23             : 
      24        1241 :   if (not status.ok()) {
      25           0 :     return iroha::expected::makeError(status.error_message());
      26             :   }
      27        1241 :   return iroha::expected::makeValue(result);
      28        1241 : }
      29             : 
      30             : iroha::expected::Result<std::unique_ptr<interface::Block>, std::string>
      31             : ProtoBlockJsonConverter::deserialize(
      32             :     const interface::types::JsonType &json) const noexcept {
      33        1344 :   iroha::protocol::Block block;
      34        1340 :   auto status = google::protobuf::util::JsonStringToMessage(json, &block);
      35        1344 :   if (not status.ok()) {
      36           2 :     return iroha::expected::makeError(status.error_message());
      37             :   }
      38        1342 :   std::unique_ptr<interface::Block> result =
      39        1342 :       std::make_unique<Block>(std::move(block));
      40        1342 :   return iroha::expected::makeValue(std::move(result));
      41        1344 : }

Generated by: LCOV version 1.13