Matter SDK Coverage Report
Current view: top level - app - AttributeValueDecoder.h (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 100.0 % 7 7
Test Date: 2025-01-17 19:00:11 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /*
       2              :  *    Copyright (c) 2021-2024 Project CHIP Authors
       3              :  *    All rights reserved.
       4              :  *
       5              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6              :  *    you may not use this file except in compliance with the License.
       7              :  *    You may obtain a copy of the License at
       8              :  *
       9              :  *        http://www.apache.org/licenses/LICENSE-2.0
      10              :  *
      11              :  *    Unless required by applicable law or agreed to in writing, software
      12              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14              :  *    See the License for the specific language governing permissions and
      15              :  *    limitations under the License.
      16              :  */
      17              : #pragma once
      18              : 
      19              : #include <access/SubjectDescriptor.h>
      20              : #include <app/data-model/Decode.h>
      21              : #include <app/data-model/FabricScoped.h>
      22              : #include <lib/core/TLVReader.h>
      23              : 
      24              : #include <type_traits>
      25              : 
      26              : namespace chip {
      27              : namespace app {
      28              : 
      29              : class AttributeValueDecoder
      30              : {
      31              : public:
      32         2453 :     AttributeValueDecoder(TLV::TLVReader & aReader, const Access::SubjectDescriptor & aSubjectDescriptor) :
      33         2453 :         mReader(aReader), mSubjectDescriptor(aSubjectDescriptor)
      34         2453 :     {}
      35              : 
      36              :     template <typename T, typename std::enable_if_t<!DataModel::IsFabricScoped<T>::value, bool> = true>
      37          143 :     CHIP_ERROR Decode(T & aArg)
      38              :     {
      39          143 :         mTriedDecode = true;
      40          143 :         return DataModel::Decode(mReader, aArg);
      41              :     }
      42              : 
      43              :     template <typename T, typename std::enable_if_t<DataModel::IsFabricScoped<T>::value, bool> = true>
      44              :     CHIP_ERROR Decode(T & aArg)
      45              :     {
      46              :         mTriedDecode = true;
      47              :         // The WriteRequest comes with no fabric index, this will happen when receiving a write request on a PASE session before
      48              :         // AddNOC.
      49              :         VerifyOrReturnError(AccessingFabricIndex() != kUndefinedFabricIndex, CHIP_IM_GLOBAL_STATUS(UnsupportedAccess));
      50              :         ReturnErrorOnFailure(DataModel::Decode(mReader, aArg));
      51              :         aArg.SetFabricIndex(AccessingFabricIndex());
      52              :         return CHIP_NO_ERROR;
      53              :     }
      54              : 
      55         2434 :     bool TriedDecode() const { return mTriedDecode; }
      56              : 
      57              :     /**
      58              :      * The accessing fabric index for this write interaction.
      59              :      */
      60              :     FabricIndex AccessingFabricIndex() const { return mSubjectDescriptor.fabricIndex; }
      61              : 
      62              :     /**
      63              :      * The accessing subject descriptor for this write interaction.
      64              :      */
      65              :     const Access::SubjectDescriptor & GetSubjectDescriptor() const { return mSubjectDescriptor; }
      66              : 
      67              : private:
      68              :     friend class TestOnlyAttributeValueDecoderAccessor;
      69              : 
      70              :     TLV::TLVReader & mReader;
      71              :     bool mTriedDecode = false;
      72              :     const Access::SubjectDescriptor mSubjectDescriptor;
      73              : };
      74              : 
      75              : } // namespace app
      76              : } // namespace chip
        

Generated by: LCOV version 2.0-1