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 parser in CHIP interaction model
26 #ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_PARSER_H
27 #define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_PARSER_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 TLVReader and ContainerType
43 * @param [in] aReader TLVReader
44 * @param [in] aOuterContainerType outer container type
47 void Init(const chip::TLV::TLVReader & aReader, chip::TLV::TLVType aOuterContainerType);
50 * @brief Initialize a TLVReader to point to the beginning of any tagged element in this request
52 * @param [in] aTagToFind Tag to find in the request
53 * @param [out] apReader A pointer to TLVReader, which will be initialized at the specified TLV element
56 * @return #CHIP_NO_ERROR on success
58 CHIP_ERROR GetReaderOnTag(const uint64_t aTagToFind, chip::TLV::TLVReader * const apReader) const;
61 * @brief Get the TLV Reader
63 * @param [in] aReader A pointer to a TLVReader
66 void GetReader(chip::TLV::TLVReader * const apReader);
69 chip::TLV::TLVReader mReader;
70 chip::TLV::TLVType mOuterContainerType;
74 CHIP_ERROR GetUnsignedInteger(const uint8_t aContextTag, T * const apLValue) const
76 return GetSimpleValue(aContextTag, chip::TLV::kTLVType_UnsignedInteger, apLValue);
80 CHIP_ERROR GetSimpleValue(const uint8_t aContextTag, const chip::TLV::TLVType aTLVType, T * const apLValue) const
82 CHIP_ERROR err = CHIP_NO_ERROR;
83 chip::TLV::TLVReader reader;
87 err = mReader.FindElementWithTag(chip::TLV::ContextTag(aContextTag), reader);
90 VerifyOrExit(aTLVType == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE);
92 err = reader.Get(*apLValue);
96 ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err));
104 #endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_PARSER_H