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

          Line data    Source code
       1             : /**
       2             :  *
       3             :  *    Copyright (c) 2021 Project CHIP Authors
       4             :  *    Licensed under the Apache License, Version 2.0 (the "License");
       5             :  *    you may not use this file except in compliance with the License.
       6             :  *    You may obtain a copy of the License at
       7             :  *
       8             :  *        http://www.apache.org/licenses/LICENSE-2.0
       9             :  *
      10             :  *    Unless required by applicable law or agreed to in writing, software
      11             :  *    distributed under the License is distributed on an "AS IS" BASIS,
      12             :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13             :  *    See the License for the specific language governing permissions and
      14             :  *    limitations under the License.
      15             :  */
      16             : 
      17             : #include "StructParser.h"
      18             : 
      19             : namespace chip {
      20             : namespace app {
      21       46505 : CHIP_ERROR StructParser::Init(const TLV::TLVReader & aReader)
      22             : {
      23       46505 :     mReader.Init(aReader);
      24       46505 :     VerifyOrReturnError(TLV::kTLVType_Structure == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      25       46505 :     ReturnErrorOnFailure(mReader.EnterContainer(mOuterContainerType));
      26       46505 :     return CheckSchemaOrdering();
      27             : }
      28             : 
      29       46505 : CHIP_ERROR StructParser::CheckSchemaOrdering() const
      30             : {
      31       46505 :     CHIP_ERROR err = CHIP_NO_ERROR;
      32             :     TLV::TLVReader reader;
      33       46505 :     reader.Init(mReader);
      34       46505 :     uint32_t preTagNum = 0;
      35       46505 :     bool first         = true;
      36      150992 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      37             :     {
      38      104487 :         if (!TLV::IsContextTag(reader.GetTag()))
      39             :         {
      40             :             // Just skip over non-context tags, for forward compat.
      41           0 :             continue;
      42             :         }
      43      104487 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      44      104487 :         if (first || (preTagNum < tagNum))
      45             :         {
      46      104487 :             preTagNum = tagNum;
      47             :         }
      48             :         else
      49             :         {
      50           0 :             return CHIP_ERROR_INVALID_TLV_TAG;
      51             :         }
      52      104487 :         first = false;
      53             :     }
      54       46505 :     if (CHIP_END_OF_TLV == err)
      55             :     {
      56       46505 :         err = CHIP_NO_ERROR;
      57             :     }
      58       46505 :     ReturnErrorOnFailure(err);
      59       46505 :     return reader.ExitContainer(mOuterContainerType);
      60             : }
      61             : } // namespace app
      62             : } // namespace chip

Generated by: LCOV version 1.14