Line data Source code
1 : /** 2 : * 3 : * Copyright (c) 2021 Project CHIP Authors 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 : 18 : #pragma once 19 : 20 : #include <app/AppConfig.h> 21 : #include <app/util/basic-types.h> 22 : #include <lib/core/CHIPCore.h> 23 : #include <lib/core/TLV.h> 24 : #include <lib/support/CodeUtils.h> 25 : #include <lib/support/logging/CHIPLogging.h> 26 : 27 : #include "ArrayBuilder.h" 28 : #include "ArrayParser.h" 29 : #include "CommandDataIB.h" 30 : 31 : namespace chip { 32 : namespace app { 33 : namespace InvokeRequests { 34 : class Parser : public ArrayParser 35 : { 36 : public: 37 : #if CHIP_CONFIG_IM_PRETTY_PRINT 38 : CHIP_ERROR PrettyPrint() const; 39 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT 40 : }; 41 : 42 : class Builder : public ArrayBuilder 43 : { 44 : public: 45 : /** 46 : * @brief Performs underlying StructBuilder::Init, but reserves memory need in 47 : * EndOfInvokeRequests() with underlying TLVWriter. 48 : */ 49 : CHIP_ERROR InitWithEndBufferReserved(TLV::TLVWriter * const apWriter, const uint8_t aContextTagToUse); 50 : 51 : /** 52 : * @brief Initialize a CommandDataIB::Builder for writing into the TLV stream 53 : * 54 : * @return A reference to CommandDataIB::Builder 55 : */ 56 : CommandDataIB::Builder & CreateCommandData(); 57 : 58 : /** 59 : * @return A reference to CommandDataIB::Builder 60 : */ 61 63 : CommandDataIB::Builder & GetCommandData() { return mCommandData; }; 62 : 63 : /** 64 : * @brief Mark the end of this InvokeRequests 65 : * 66 : * @return The builder's final status. 67 : */ 68 : CHIP_ERROR EndOfInvokeRequests(); 69 : 70 : /** 71 : * @brief Get number of bytes required in the buffer by EndOfInvokeRequests() 72 : * 73 : * @return Expected number of bytes required in the buffer by EndOfInvokeRequests() 74 : */ 75 : uint32_t GetSizeToEndInvokeRequests(); 76 : 77 : private: 78 : CommandDataIB::Builder mCommandData; 79 : bool mIsEndBufferReserved = false; 80 : }; 81 : } // namespace InvokeRequests 82 : } // namespace app 83 : } // namespace chip