Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / MessageDef / ListParser.cpp
1 /**
2  *
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18 /**
19  *    @file
20  *     This file defines List parser in CHIP interaction model
21  *
22  */
23
24 #include "ListParser.h"
25
26 #include <inttypes.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29
30 using namespace chip;
31 using namespace chip::TLV;
32
33 namespace chip {
34 namespace app {
35 ListParser::ListParser() {}
36
37 CHIP_ERROR ListParser::Init(const chip::TLV::TLVReader & aReader)
38 {
39     CHIP_ERROR err = CHIP_NO_ERROR;
40
41     // make a copy of the reader here
42     mReader.Init(aReader);
43
44     VerifyOrExit(chip::TLV::kTLVType_Array == mReader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE);
45
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);
49
50 exit:
51     ChipLogFunctError(err);
52
53     return err;
54 }
55
56 CHIP_ERROR ListParser::InitIfPresent(const chip::TLV::TLVReader & aReader, const uint8_t aContextTagToFind)
57 {
58     CHIP_ERROR err = CHIP_NO_ERROR;
59     chip::TLV::TLVReader reader;
60
61     err = mReader.FindElementWithTag(chip::TLV::ContextTag(aContextTagToFind), reader);
62     SuccessOrExit(err);
63
64     err = Init(reader);
65     SuccessOrExit(err);
66
67 exit:
68     ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err));
69
70     return err;
71 }
72
73 CHIP_ERROR ListParser::Next()
74 {
75     CHIP_ERROR err = mReader.Next();
76
77     ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err));
78
79     return err;
80 }
81 }; // namespace app
82 }; // namespace chip