Line data Source code
1 : /*
2 : * Copyright (c) 2025 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 : #include <app/data-model/StructDecodeIterator.h>
18 :
19 : namespace chip {
20 : namespace app {
21 : namespace Clusters {
22 : namespace detail {
23 :
24 11327 : CHIP_ERROR StructDecodeIterator::Next(uint8_t & context_tag)
25 : {
26 11327 : if (!mEntered)
27 : {
28 3391 : VerifyOrReturnError(TLV::kTLVType_Structure == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
29 3390 : ReturnErrorOnFailure(mReader.EnterContainer(mOuter));
30 3390 : mEntered = true;
31 : }
32 :
33 : while (true)
34 : {
35 11326 : CHIP_ERROR err = mReader.Next();
36 11326 : if (err != CHIP_NO_ERROR)
37 : {
38 11326 : VerifyOrReturnError(err == CHIP_ERROR_END_OF_TLV, err);
39 3388 : break;
40 : }
41 :
42 7938 : const TLV::Tag tag = mReader.GetTag();
43 7938 : if (!TLV::IsContextTag(tag))
44 : {
45 0 : continue;
46 : }
47 :
48 : // we know context tags are 8-bit
49 7938 : context_tag = static_cast<uint8_t>(TLV::TagNumFromTag(tag));
50 7938 : return CHIP_NO_ERROR;
51 0 : }
52 :
53 : // we get here IFF error is CHIP_ERROR_END_OF_TLV. We exit the container but
54 : // forward the the `end of tlv` as a final marker
55 3388 : ReturnErrorOnFailure(mReader.ExitContainer(mOuter));
56 3388 : return CHIP_ERROR_END_OF_TLV;
57 : }
58 :
59 : } // namespace detail
60 : } // namespace Clusters
61 : } // namespace app
62 : } // namespace chip
|