3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2018 Google LLC.
5 * 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 List parser in CHIP interaction model
24 #include "ListParser.h"
31 using namespace chip::TLV;
35 ListParser::ListParser() {}
37 CHIP_ERROR ListParser::Init(const chip::TLV::TLVReader & aReader)
39 CHIP_ERROR err = CHIP_NO_ERROR;
41 // make a copy of the reader here
42 mReader.Init(aReader);
44 VerifyOrExit(chip::TLV::kTLVType_Array == mReader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE);
46 // This is just a dummy, as we're not going to exit this container ever
47 chip::TLV::TLVType OuterContainerType;
48 err = mReader.EnterContainer(OuterContainerType);
51 ChipLogFunctError(err);
56 CHIP_ERROR ListParser::InitIfPresent(const chip::TLV::TLVReader & aReader, const uint8_t aContextTagToFind)
58 CHIP_ERROR err = CHIP_NO_ERROR;
59 chip::TLV::TLVReader reader;
61 err = mReader.FindElementWithTag(chip::TLV::ContextTag(aContextTagToFind), reader);
68 ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err));
73 CHIP_ERROR ListParser::Next()
75 CHIP_ERROR err = mReader.Next();
77 ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err));