LCOV - code coverage report
Current view: top level - app/MessageDef - CommandDataIB.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 51 52 98.1 %
Date: 2024-02-15 08:20:41 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /**
       2             :  *
       3             :  *    Copyright (c) 2020 Project CHIP Authors
       4             :  *    Copyright (c) 2018 Google LLC.
       5             :  *    Copyright (c) 2016-2017 Nest Labs, Inc.
       6             :  *    Licensed under the Apache License, Version 2.0 (the "License");
       7             :  *    you may not use this file except in compliance with the License.
       8             :  *    You may obtain a copy of the License at
       9             :  *
      10             :  *        http://www.apache.org/licenses/LICENSE-2.0
      11             :  *
      12             :  *    Unless required by applicable law or agreed to in writing, software
      13             :  *    distributed under the License is distributed on an "AS IS" BASIS,
      14             :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15             :  *    See the License for the specific language governing permissions and
      16             :  *    limitations under the License.
      17             :  */
      18             : 
      19             : #include "CommandDataIB.h"
      20             : 
      21             : #include "MessageDefHelper.h"
      22             : 
      23             : #include <inttypes.h>
      24             : #include <stdarg.h>
      25             : #include <stdio.h>
      26             : 
      27             : #include <app/AppConfig.h>
      28             : 
      29             : namespace chip {
      30             : namespace app {
      31             : #if CHIP_CONFIG_IM_PRETTY_PRINT
      32          55 : CHIP_ERROR CommandDataIB::Parser::PrettyPrint() const
      33             : {
      34          55 :     CHIP_ERROR err = CHIP_NO_ERROR;
      35             :     TLV::TLVReader reader;
      36             : 
      37          55 :     PRETTY_PRINT("CommandDataIB =");
      38          55 :     PRETTY_PRINT("{");
      39             : 
      40             :     // make a copy of the reader
      41          55 :     reader.Init(mReader);
      42             : 
      43         167 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      44             :     {
      45         112 :         if (!TLV::IsContextTag(reader.GetTag()))
      46             :         {
      47           0 :             continue;
      48             :         }
      49         112 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      50             : 
      51         112 :         switch (tagNum)
      52             :         {
      53          55 :         case to_underlying(Tag::kPath): {
      54          55 :             CommandPathIB::Parser path;
      55          55 :             ReturnErrorOnFailure(path.Init(reader));
      56          55 :             PRETTY_PRINT_INCDEPTH();
      57          55 :             ReturnErrorOnFailure(path.PrettyPrint());
      58          55 :             PRETTY_PRINT_DECDEPTH();
      59             :         }
      60             : 
      61          55 :         break;
      62          50 :         case to_underlying(Tag::kFields):
      63          50 :             PRETTY_PRINT_INCDEPTH();
      64          50 :             ReturnErrorOnFailure(CheckIMPayload(reader, 0, "CommandFields"));
      65          50 :             PRETTY_PRINT_DECDEPTH();
      66          50 :             break;
      67           6 :         case to_underlying(Tag::kRef):
      68           6 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      69             :             {
      70             :                 uint16_t reference;
      71           6 :                 ReturnErrorOnFailure(reader.Get(reference));
      72           6 :                 PRETTY_PRINT("\tRef = 0x%x,", reference);
      73             :             }
      74           6 :             break;
      75           1 :         default:
      76           1 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      77           1 :             break;
      78             :         }
      79             :     }
      80             : 
      81          55 :     PRETTY_PRINT("},");
      82          55 :     PRETTY_PRINT_BLANK_LINE();
      83             : 
      84          55 :     if (CHIP_END_OF_TLV == err)
      85             :     {
      86          55 :         err = CHIP_NO_ERROR;
      87             :     }
      88             : 
      89          55 :     ReturnErrorOnFailure(err);
      90          55 :     return reader.ExitContainer(mOuterContainerType);
      91             : }
      92             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
      93             : 
      94          78 : CHIP_ERROR CommandDataIB::Parser::GetPath(CommandPathIB::Parser * const apPath) const
      95             : {
      96             :     TLV::TLVReader reader;
      97          78 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kPath), reader));
      98          78 :     return apPath->Init(reader);
      99             : }
     100             : 
     101          35 : CHIP_ERROR CommandDataIB::Parser::GetFields(TLV::TLVReader * const apReader) const
     102             : {
     103          35 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kFields), *apReader));
     104          33 :     return CHIP_NO_ERROR;
     105             : }
     106             : 
     107          42 : CHIP_ERROR CommandDataIB::Parser::GetRef(uint16_t * const apRef) const
     108             : {
     109          42 :     return GetUnsignedInteger(to_underlying(Tag::kRef), apRef);
     110             : }
     111             : 
     112          71 : CommandPathIB::Builder & CommandDataIB::Builder::CreatePath()
     113             : {
     114          71 :     mError = mPath.Init(mpWriter, to_underlying(Tag::kPath));
     115          71 :     return mPath;
     116             : }
     117             : 
     118          16 : CHIP_ERROR CommandDataIB::Builder::Ref(const uint16_t aRef)
     119             : {
     120          16 :     return mpWriter->Put(TLV::ContextTag(Tag::kRef), aRef);
     121             : }
     122             : 
     123          67 : CHIP_ERROR CommandDataIB::Builder::EndOfCommandDataIB()
     124             : {
     125          67 :     EndOfContainer();
     126          67 :     return GetError();
     127             : }
     128             : } // namespace app
     129             : } // namespace chip

Generated by: LCOV version 1.14