3 * Copyright (c) 2020 Project CHIP Authors
4 * 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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * This file defines builder in CHIP interaction model
26 #ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_BUILDER_H
27 #define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_BUILDER_H
29 #include <core/CHIPCore.h>
30 #include <core/CHIPTLV.h>
31 #include <support/CodeUtils.h>
32 #include <support/logging/CHIPLogging.h>
33 #include <util/basic-types.h>
41 * @brief Initialize the Builder object with TLVWriter and ContainerType
43 * @param [in] apWriter A pointer to a TLVWriter
44 * @param [in] aOuterContainerType outer container type
47 void Init(chip::TLV::TLVWriter * const apWriter, chip::TLV::TLVType aOuterContainerType);
50 * @brief Reset the Error
56 * @brief Reset the Error with particular aErr.
57 * @param [in] aErr the Error it would be reset with
60 void ResetError(CHIP_ERROR aErr);
63 * @brief Get current error
65 * @return #CHIP_NO_ERROR on success
67 CHIP_ERROR GetError() const { return mError; };
70 * @brief Get TLV Writer
72 * @return #Pointer to the TLVWriter
74 chip::TLV::TLVWriter * GetWriter() { return mpWriter; };
77 * Checkpoint the current tlv state into a TLVWriter
79 * @param[out] aPoint A writer to checkpoint the state of the TLV writer into.
80 * This writer must not outlive the builder
82 void Checkpoint(chip::TLV::TLVWriter & aPoint) { aPoint = *mpWriter; };
85 * Rollback the request state to the checkpointed TLVWriter
87 * @param[in] aPoint A that captured the state via Checkpoint() at some point in the past
89 void Rollback(const chip::TLV::TLVWriter & aPoint) { *mpWriter = aPoint; }
93 chip::TLV::TLVWriter * mpWriter;
94 chip::TLV::TLVType mOuterContainerType;
97 void EndOfContainer();
99 CHIP_ERROR InitAnonymousStructure(chip::TLV::TLVWriter * const apWriter);
104 #endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_BUILDER_H