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

          Line data    Source code
       1             : /**
       2             :  *
       3             :  *    Copyright (c) 2020-2021 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 "AttributeDataIB.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        5936 : CHIP_ERROR AttributeDataIB::Parser::PrettyPrint() const
      33             : {
      34        5936 :     CHIP_ERROR err = CHIP_NO_ERROR;
      35             :     TLV::TLVReader reader;
      36             : 
      37        5936 :     PRETTY_PRINT("AttributeDataIB =");
      38        5936 :     PRETTY_PRINT("{");
      39             : 
      40             :     // make a copy of the Path reader
      41        5936 :     reader.Init(mReader);
      42             : 
      43       21270 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      44             :     {
      45       15334 :         if (!TLV::IsContextTag(reader.GetTag()))
      46             :         {
      47           0 :             continue;
      48             :         }
      49       15334 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      50       15334 :         switch (tagNum)
      51             :         {
      52        3462 :         case to_underlying(Tag::kDataVersion):
      53        3462 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      54             : #if CHIP_DETAIL_LOGGING
      55             :             {
      56             :                 chip::DataVersion version;
      57        3462 :                 ReturnErrorOnFailure(reader.Get(version));
      58        3462 :                 PRETTY_PRINT("\tDataVersion = 0x%" PRIx32 ",", version);
      59             :             }
      60             : #endif // CHIP_DETAIL_LOGGING
      61        3462 :             break;
      62        5936 :         case to_underlying(Tag::kPath): {
      63        5936 :             AttributePathIB::Parser path;
      64        5936 :             ReturnErrorOnFailure(path.Init(reader));
      65             : 
      66        5936 :             PRETTY_PRINT_INCDEPTH();
      67        5936 :             ReturnErrorOnFailure(path.PrettyPrint());
      68        5936 :             PRETTY_PRINT_DECDEPTH();
      69             :         }
      70        5936 :         break;
      71        5936 :         case to_underlying(Tag::kData):
      72        5936 :             PRETTY_PRINT_INCDEPTH();
      73        5936 :             ReturnErrorOnFailure(CheckIMPayload(reader, 0, "Data"));
      74        5936 :             PRETTY_PRINT_DECDEPTH();
      75        5936 :             break;
      76           0 :         default:
      77           0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      78           0 :             break;
      79             :         }
      80             :     }
      81        5936 :     PRETTY_PRINT("},");
      82        5936 :     PRETTY_PRINT_BLANK_LINE();
      83             : 
      84             :     // if we have exhausted this container
      85        5936 :     if (CHIP_END_OF_TLV == err)
      86             :     {
      87        5936 :         err = CHIP_NO_ERROR;
      88             :     }
      89        5936 :     ReturnErrorOnFailure(err);
      90        5936 :     return reader.ExitContainer(mOuterContainerType);
      91             : }
      92             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
      93             : 
      94        5924 : CHIP_ERROR AttributeDataIB::Parser::GetPath(AttributePathIB::Parser * const apPath) const
      95             : {
      96             :     TLV::TLVReader reader;
      97        5924 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kPath), reader));
      98        5924 :     return apPath->Init(reader);
      99             : }
     100             : 
     101        5912 : CHIP_ERROR AttributeDataIB::Parser::GetDataVersion(chip::DataVersion * const apVersion) const
     102             : {
     103        5912 :     return GetUnsignedInteger(to_underlying(Tag::kDataVersion), apVersion);
     104             : }
     105             : 
     106        5920 : CHIP_ERROR AttributeDataIB::Parser::GetData(TLV::TLVReader * const apReader) const
     107             : {
     108        5920 :     return mReader.FindElementWithTag(TLV::ContextTag(Tag::kData), *apReader);
     109             : }
     110             : 
     111        7627 : AttributePathIB::Builder & AttributeDataIB::Builder::CreatePath()
     112             : {
     113        7627 :     if (mError == CHIP_NO_ERROR)
     114             :     {
     115        7594 :         mError = mPath.Init(mpWriter, to_underlying(Tag::kPath));
     116             :     }
     117        7627 :     return mPath;
     118             : }
     119             : 
     120        3684 : AttributeDataIB::Builder & AttributeDataIB::Builder::DataVersion(const chip::DataVersion aDataVersion)
     121             : {
     122             :     // skip if error has already been set
     123        3684 :     if (mError == CHIP_NO_ERROR)
     124             :     {
     125        3684 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kDataVersion), aDataVersion);
     126             :     }
     127        3684 :     return *this;
     128             : }
     129             : 
     130        6103 : CHIP_ERROR AttributeDataIB::Builder::EndOfAttributeDataIB()
     131             : {
     132        6103 :     EndOfContainer();
     133        6103 :     return GetError();
     134             : }
     135             : } // namespace app
     136             : } // namespace chip

Generated by: LCOV version 1.14