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 AttributeDataVersionList parser and builder in CHIP interaction model
24 #include "AttributeDataVersionList.h"
26 #include "MessageDefHelper.h"
33 using namespace chip::TLV;
37 #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
38 CHIP_ERROR AttributeDataVersionList::Parser::CheckSchemaValidity() const
40 CHIP_ERROR err = CHIP_NO_ERROR;
41 chip::TLV::TLVReader reader;
42 chip::DataVersion version;
45 PRETTY_PRINT("AttributeDataVersionList = ");
50 while (CHIP_NO_ERROR == (err = reader.Next()))
52 VerifyOrExit(chip::TLV::AnonymousTag == reader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG);
54 switch (reader.GetType())
56 case chip::TLV::kTLVType_Null:
57 PRETTY_PRINT("\tNull,");
60 case chip::TLV::kTLVType_UnsignedInteger:
61 err = reader.Get(version);
64 PRETTY_PRINT("\t0x%" PRIx64 ",", version);
68 ExitNow(err = CHIP_ERROR_WRONG_TLV_TYPE);
77 if (CHIP_END_OF_TLV == err)
83 ChipLogFunctError(err);
87 #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
89 // 1) current element is anonymous
90 // 2) current element is either unsigned integer or NULL
91 bool AttributeDataVersionList::Parser::IsElementValid(void)
93 CHIP_ERROR err = CHIP_NO_ERROR;
96 VerifyOrExit(chip::TLV::AnonymousTag == mReader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG);
98 switch (mReader.GetType())
100 case chip::TLV::kTLVType_Null:
101 case chip::TLV::kTLVType_UnsignedInteger:
110 ChipLogFunctError(err);
115 bool AttributeDataVersionList::Parser::IsNull(void)
117 return (chip::TLV::kTLVType_Null == mReader.GetType());
120 CHIP_ERROR AttributeDataVersionList::Parser::GetVersion(chip::DataVersion * const apVersion)
122 CHIP_ERROR err = CHIP_NO_ERROR;
123 if (mReader.GetType() == kTLVType_Null)
126 ChipLogDetail(DataManagement, "Version is null in GetVersion");
130 err = mReader.Get(*apVersion);
135 AttributeDataVersionList::Builder & AttributeDataVersionList::Builder::AddVersion(const uint64_t aVersion)
137 // skip if error has already been set
138 SuccessOrExit(mError);
140 mError = mpWriter->Put(chip::TLV::AnonymousTag, aVersion);
141 ChipLogFunctError(mError);
147 AttributeDataVersionList::Builder & AttributeDataVersionList::Builder::AddNull(void)
149 // skip if error has already been set
150 SuccessOrExit(mError);
152 mError = mpWriter->PutNull(chip::TLV::AnonymousTag);
153 ChipLogFunctError(mError);
159 // Mark the end of this array and recover the type for outer container
160 AttributeDataVersionList::Builder & AttributeDataVersionList::Builder::EndOfAttributeDataVersionList(void)