LCOV - code coverage report
Current view: top level - stack - Format.cpp (source / functions) Coverage Total Hit
Test: final-coverage.info Lines: 29.4 % 17 5
Test Date: 2025-02-10 18:26:37 Functions: 33.3 % 3 1

            Line data    Source code
       1              : /*
       2              :  ________________________________________________________________________
       3              : |                                                                        |
       4              : |       _ _                      _                         _             |
       5              : |      | (_)                    | |                       | |            |
       6              : |    __| |_  __ _ _ __ ___   ___| |_ ___ _ __ ___ ___   __| | ___  ___   |
       7              : |   / _` | |/ _` | '_ ` _ \ / _ \ __/ _ \ '__/ __/ _ \ / _` |/ _ \/ __|  |
       8              : |  | (_| | | (_| | | | | | |  __/ ||  __/ | | (_| (_) | (_| |  __/ (__   |
       9              : |   \__,_|_|\__,_|_| |_| |_|\___|\__\___|_|  \___\___/ \__,_|\___|\___|  |
      10              : |                                                                        |
      11              : |________________________________________________________________________|
      12              : 
      13              : C++ CODEC FOR DIAMETER PROTOCOL (RFC 6733)
      14              : Version 0.0.z
      15              : https://github.com/testillano/diametercodec
      16              : 
      17              : Licensed under the MIT License <http://opensource.org/licenses/MIT>.
      18              : SPDX-License-Identifier: MIT
      19              : Copyright (c) 2021 Eduardo Ramos
      20              : 
      21              : Permission is hereby  granted, free of charge, to any  person obtaining a copy
      22              : of this software and associated  documentation files (the "Software"), to deal
      23              : in the Software  without restriction, including without  limitation the rights
      24              : to  use, copy,  modify, merge,  publish, distribute,  sublicense, and/or  sell
      25              : copies  of  the Software,  and  to  permit persons  to  whom  the Software  is
      26              : furnished to do so, subject to the following conditions:
      27              : 
      28              : The above copyright notice and this permission notice shall be included in all
      29              : copies or substantial portions of the Software.
      30              : 
      31              : THE SOFTWARE  IS PROVIDED "AS  IS", WITHOUT WARRANTY  OF ANY KIND,  EXPRESS OR
      32              : IMPLIED,  INCLUDING BUT  NOT  LIMITED TO  THE  WARRANTIES OF  MERCHANTABILITY,
      33              : FITNESS FOR  A PARTICULAR PURPOSE AND  NONINFRINGEMENT. IN NO EVENT  SHALL THE
      34              : AUTHORS  OR COPYRIGHT  HOLDERS  BE  LIABLE FOR  ANY  CLAIM,  DAMAGES OR  OTHER
      35              : LIABILITY, WHETHER IN AN ACTION OF  CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      36              : OUT OF OR IN CONNECTION WITH THE SOFTWARE  OR THE USE OR OTHER DEALINGS IN THE
      37              : SOFTWARE.
      38              : */
      39              : 
      40              : 
      41              : // Project
      42              : #include <ert/diametercodec/stack/Dictionary.hpp>
      43              : #include <ert/diametercodec/stack/Format.hpp>
      44              : 
      45              : 
      46              : namespace ert
      47              : {
      48              : namespace diametercodec
      49              : {
      50              : namespace stack
      51              : {
      52              : 
      53              : assign_enum(Format::Type) = { "Unknown", "Any", "OctetString", "Integer32", "Integer64", "Unsigned32", "Unsigned64", "Float32", "Float64", "Grouped", "Address", "Time", "UTF8String", "DiameterIdentity", "DiameterURI", "Enumerated", "IPFilterRule", "QoSFilterRule", nullptr /* list end indicator */};
      54              : 
      55            0 : nlohmann::json Format::asJson(void) const {
      56            0 :     nlohmann::json result;
      57              : 
      58            0 :     result["name"] = name_;
      59            0 :     if (!parent_name_.empty()) result["parent-type"] = parent_name_;
      60              : 
      61            0 :     return result;
      62            0 : }
      63              : 
      64            0 : Format::Type::_v Format::getBasicType(void) const {
      65            0 :     if(isDerived()) return dictionary_->getFormat(parent_name_)->getBasicType();
      66            0 :     if(isReserved())
      67            0 :         throw std::runtime_error("Develop error: there is no basic format type for reserved type");
      68              : 
      69            0 :     return (Format::Type::asEnum(name_));
      70              : }
      71              : 
      72          200 : void Format::setParentName(const std::string & parentName) {
      73          200 :     const Format * parent = dictionary_->getFormat(parentName);
      74          200 :     if(parent && !parent->isBasic()) // 'Any' should not be allowed
      75            0 :         throw std::runtime_error("Only basic diameter format allowed for parent type");
      76              : 
      77          200 :     parent_name_ = parentName;
      78          200 : }
      79              : 
      80              : }
      81              : }
      82              : }
      83              : 
        

Generated by: LCOV version 2.0-1