diff --git a/src/app/data-model/WrappedStructEncoder.h b/src/app/data-model/WrappedStructEncoder.h new file mode 100644 index 00000000000000..7c5e77912ca5fe --- /dev/null +++ b/src/app/data-model/WrappedStructEncoder.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include +#include +#include + +#include + +namespace chip { +namespace app { +namespace DataModel { + +class WrappedStructEncoder +{ +public: + WrappedStructEncoder(TLV::TLVWriter & writer, TLV::Tag outerTag) : mWriter(writer) + { + mLastError = mWriter.StartContainer(outerTag, TLV::kTLVType_Structure, mOuter); + } + + template + void Encode(uint8_t contextTag, Args &&... args) + { + VerifyOrReturn(mLastError == CHIP_NO_ERROR); + mLastError = DataModel::Encode(mWriter, TLV::ContextTag(contextTag), std::forward(args)...); + } + + CHIP_ERROR Finalize() + { + if (mLastError == CHIP_NO_ERROR) + { + mLastError = mWriter.EndContainer(mOuter); + } + return mLastError; + } + +private: + TLV::TLVWriter & mWriter; + CHIP_ERROR mLastError = CHIP_NO_ERROR; + TLV::TLVType mOuter; +}; + +} // namespace DataModel +} // namespace app +} // namespace chip diff --git a/src/app/zap-templates/partials/cluster-objects-struct.zapt b/src/app/zap-templates/partials/cluster-objects-struct.zapt index ad39d631a515cb..020f38f13a56dc 100644 --- a/src/app/zap-templates/partials/cluster-objects-struct.zapt +++ b/src/app/zap-templates/partials/cluster-objects-struct.zapt @@ -64,6 +64,7 @@ namespace {{asUpperCamelCase name}} { } // namespace {{asUpperCamelCase name}} {{else}} + namespace {{asUpperCamelCase name}} { {{#if isFabricScoped}} CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const @@ -81,34 +82,33 @@ CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optiona {{#if struct_has_fabric_sensitive_fields}} bool includeSensitive = !aAccessingFabricIndex.HasValue() || (aAccessingFabricIndex.Value() == fabricIndex); {{/if}} - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + + DataModel::WrappedStructEncoder encoder{aWriter, aTag}; + {{#zcl_struct_items}} {{#if (is_num_equal fieldIdentifier 254)}} if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}})); + encoder.Encode(to_underlying(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}}); } {{else if isFabricSensitive}} if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}})); + encoder.Encode(to_underlying(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}}); } {{else}} - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}})); + encoder.Encode(to_underlying(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}}); {{/if}} {{/zcl_struct_items}} - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } {{else}} CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + DataModel::WrappedStructEncoder encoder{aWriter, aTag}; {{#zcl_struct_items}} - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}})); + encoder.Encode(to_underlying(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}}); {{/zcl_struct_items}} - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + return encoder.Finalize(); } {{/if}} diff --git a/src/app/zap-templates/templates/app/cluster-objects-src.zapt b/src/app/zap-templates/templates/app/cluster-objects-src.zapt index 6bdbf3cb4f8674..50bd812be31521 100644 --- a/src/app/zap-templates/templates/app/cluster-objects-src.zapt +++ b/src/app/zap-templates/templates/app/cluster-objects-src.zapt @@ -1,6 +1,8 @@ {{> header}} +#include #include + #include namespace chip { @@ -80,12 +82,11 @@ namespace Commands { {{#zcl_commands}} namespace {{asUpperCamelCase name}} { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const{ - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + DataModel::WrappedStructEncoder encoder{aWriter, aTag}; {{#zcl_command_arguments}} - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}})); + encoder.Encode(to_underlying(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}}); {{/zcl_command_arguments}} - return aWriter.EndContainer(outer); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) { diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp index 263a23b1dc9200..8b7b6784ad0283 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp @@ -18,6 +18,8 @@ // THIS FILE IS GENERATED BY ZAP #include +#include + #include namespace chip { @@ -77,15 +79,14 @@ class StructDecodeIterator // Structs shared across multiple clusters. namespace Structs { + namespace ModeTagStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMfgCode), mfgCode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValue), value)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMfgCode), mfgCode); + encoder.Encode(to_underlying(Fields::kValue), value); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -119,16 +120,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace ModeTagStruct + namespace ModeOptionStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLabel), label)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMode), mode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kModeTags), modeTags)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kLabel), label); + encoder.Encode(to_underlying(Fields::kMode), mode); + encoder.Encode(to_underlying(Fields::kModeTags), modeTags); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -166,15 +166,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace ModeOptionStruct + namespace ApplicationStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCatalogVendorID), catalogVendorID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kApplicationID), applicationID)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCatalogVendorID), catalogVendorID); + encoder.Encode(to_underlying(Fields::kApplicationID), applicationID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -208,16 +207,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace ApplicationStruct + namespace ErrorStateStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kErrorStateID), errorStateID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kErrorStateLabel), errorStateLabel)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kErrorStateDetails), errorStateDetails)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kErrorStateID), errorStateID); + encoder.Encode(to_underlying(Fields::kErrorStateLabel), errorStateLabel); + encoder.Encode(to_underlying(Fields::kErrorStateDetails), errorStateDetails); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -255,15 +253,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace ErrorStateStruct + namespace LabelStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLabel), label)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValue), value)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kLabel), label); + encoder.Encode(to_underlying(Fields::kValue), value); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -297,15 +294,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace LabelStruct + namespace OperationalStateStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOperationalStateID), operationalStateID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOperationalStateLabel), operationalStateLabel)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOperationalStateID), operationalStateID); + encoder.Encode(to_underlying(Fields::kOperationalStateLabel), operationalStateLabel); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -348,10 +344,9 @@ namespace Commands { namespace Identify { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIdentifyTime), identifyTime)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kIdentifyTime), identifyTime); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -383,11 +378,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TriggerEffect { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEffectIdentifier), effectIdentifier)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEffectVariant), effectVariant)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kEffectIdentifier), effectIdentifier); + encoder.Encode(to_underlying(Fields::kEffectVariant), effectVariant); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -458,11 +452,10 @@ namespace Commands { namespace AddGroup { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupName), groupName)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kGroupName), groupName); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -498,11 +491,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace AddGroupResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -538,10 +530,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ViewGroup { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -573,12 +564,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ViewGroupResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupName), groupName)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kGroupName), groupName); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -618,10 +608,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetGroupMembership { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupList), groupList)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupList), groupList); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -653,11 +642,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetGroupMembershipResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCapacity), capacity)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupList), groupList)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCapacity), capacity); + encoder.Encode(to_underlying(Fields::kGroupList), groupList); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -693,10 +681,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RemoveGroup { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -728,11 +715,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RemoveGroupResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -768,9 +754,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RemoveAllGroups { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -789,11 +774,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace AddGroupIfIdentifying { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupName), groupName)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kGroupName), groupName); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -858,15 +842,14 @@ namespace Events {} // namespace Events } // namespace Groups namespace Scenes { namespace Structs { + namespace AttributeValuePair { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAttributeID), attributeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAttributeValue), attributeValue)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kAttributeID), attributeID); + encoder.Encode(to_underlying(Fields::kAttributeValue), attributeValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -900,15 +883,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace AttributeValuePair + namespace ExtensionFieldSet { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kClusterID), clusterID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAttributeValueList), attributeValueList)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kClusterID), clusterID); + encoder.Encode(to_underlying(Fields::kAttributeValueList), attributeValueList); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -948,14 +930,13 @@ namespace Commands { namespace AddScene { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneName), sceneName)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExtensionFieldSets), extensionFieldSets)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kSceneName), sceneName); + encoder.Encode(to_underlying(Fields::kExtensionFieldSets), extensionFieldSets); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1003,12 +984,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace AddSceneResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1048,11 +1028,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ViewScene { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1088,15 +1067,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ViewSceneResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneName), sceneName)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExtensionFieldSets), extensionFieldSets)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kSceneName), sceneName); + encoder.Encode(to_underlying(Fields::kExtensionFieldSets), extensionFieldSets); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1148,11 +1126,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RemoveScene { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1188,12 +1165,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RemoveSceneResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1233,10 +1209,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RemoveAllScenes { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1268,11 +1243,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RemoveAllScenesResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1308,11 +1282,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StoreScene { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1348,12 +1321,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StoreSceneResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1393,12 +1365,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RecallScene { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1438,10 +1409,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetSceneMembership { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1473,13 +1443,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetSceneMembershipResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCapacity), capacity)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneList), sceneList)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kCapacity), capacity); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneList), sceneList); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1523,14 +1492,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace EnhancedAddScene { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneName), sceneName)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExtensionFieldSets), extensionFieldSets)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kSceneName), sceneName); + encoder.Encode(to_underlying(Fields::kExtensionFieldSets), extensionFieldSets); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1578,12 +1546,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace EnhancedAddSceneResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1623,11 +1590,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace EnhancedViewScene { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1663,15 +1629,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace EnhancedViewSceneResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupID), groupID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneID), sceneID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneName), sceneName)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExtensionFieldSets), extensionFieldSets)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupID), groupID); + encoder.Encode(to_underlying(Fields::kSceneID), sceneID); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kSceneName), sceneName); + encoder.Encode(to_underlying(Fields::kExtensionFieldSets), extensionFieldSets); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1723,14 +1688,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace CopyScene { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMode), mode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupIdentifierFrom), groupIdentifierFrom)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneIdentifierFrom), sceneIdentifierFrom)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupIdentifierTo), groupIdentifierTo)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneIdentifierTo), sceneIdentifierTo)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMode), mode); + encoder.Encode(to_underlying(Fields::kGroupIdentifierFrom), groupIdentifierFrom); + encoder.Encode(to_underlying(Fields::kSceneIdentifierFrom), sceneIdentifierFrom); + encoder.Encode(to_underlying(Fields::kGroupIdentifierTo), groupIdentifierTo); + encoder.Encode(to_underlying(Fields::kSceneIdentifierTo), sceneIdentifierTo); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1778,12 +1742,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace CopySceneResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupIdentifierFrom), groupIdentifierFrom)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSceneIdentifierFrom), sceneIdentifierFrom)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kGroupIdentifierFrom), groupIdentifierFrom); + encoder.Encode(to_underlying(Fields::kSceneIdentifierFrom), sceneIdentifierFrom); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1870,9 +1833,8 @@ namespace Commands { namespace Off { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1891,9 +1853,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace On { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1912,9 +1873,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Toggle { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1933,11 +1893,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace OffWithEffect { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEffectIdentifier), effectIdentifier)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEffectVariant), effectVariant)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kEffectIdentifier), effectIdentifier); + encoder.Encode(to_underlying(Fields::kEffectVariant), effectVariant); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1973,9 +1932,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace OnWithRecallGlobalScene { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -1994,12 +1952,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace OnWithTimedOff { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOnOffControl), onOffControl)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOnTime), onTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOffWaitTime), offWaitTime)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOnOffControl), onOffControl); + encoder.Encode(to_underlying(Fields::kOnTime), onTime); + encoder.Encode(to_underlying(Fields::kOffWaitTime), offWaitTime); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2114,13 +2071,12 @@ namespace Commands { namespace MoveToLevel { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLevel), level)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kLevel), level); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2164,13 +2120,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Move { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMoveMode), moveMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRate), rate)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMoveMode), moveMode); + encoder.Encode(to_underlying(Fields::kRate), rate); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2214,14 +2169,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Step { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepMode), stepMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepSize), stepSize)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStepMode), stepMode); + encoder.Encode(to_underlying(Fields::kStepSize), stepSize); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2269,11 +2223,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Stop { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2309,13 +2262,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveToLevelWithOnOff { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLevel), level)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kLevel), level); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2359,13 +2311,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveWithOnOff { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMoveMode), moveMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRate), rate)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMoveMode), moveMode); + encoder.Encode(to_underlying(Fields::kRate), rate); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2409,14 +2360,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StepWithOnOff { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepMode), stepMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepSize), stepSize)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStepMode), stepMode); + encoder.Encode(to_underlying(Fields::kStepSize), stepSize); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2464,11 +2414,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StopWithOnOff { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2504,10 +2453,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveToClosestFrequency { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFrequency), frequency)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kFrequency), frequency); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2672,15 +2620,14 @@ namespace Events {} // namespace Events } // namespace PulseWidthModulation namespace Descriptor { namespace Structs { + namespace DeviceTypeStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDeviceType), deviceType)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRevision), revision)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kDeviceType), deviceType); + encoder.Encode(to_underlying(Fields::kRevision), revision); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2714,17 +2661,16 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace DeviceTypeStruct + namespace SemanticTagStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMfgCode), mfgCode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNamespaceID), namespaceID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTag), tag)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLabel), label)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMfgCode), mfgCode); + encoder.Encode(to_underlying(Fields::kNamespaceID), namespaceID); + encoder.Encode(to_underlying(Fields::kTag), tag); + encoder.Encode(to_underlying(Fields::kLabel), label); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2808,6 +2754,7 @@ namespace Events {} // namespace Events } // namespace Descriptor namespace Binding { namespace Structs { + namespace TargetStruct { CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -2821,18 +2768,19 @@ CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIn CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional & aAccessingFabricIndex) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNode), node)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroup), group)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpoint), endpoint)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCluster), cluster)); + + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + + encoder.Encode(to_underlying(Fields::kNode), node); + encoder.Encode(to_underlying(Fields::kGroup), group); + encoder.Encode(to_underlying(Fields::kEndpoint), endpoint); + encoder.Encode(to_underlying(Fields::kCluster), cluster); if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); } - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2912,16 +2860,15 @@ namespace Events {} // namespace Events } // namespace Binding namespace AccessControl { namespace Structs { + namespace AccessControlTargetStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCluster), cluster)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpoint), endpoint)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDeviceType), deviceType)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCluster), cluster); + encoder.Encode(to_underlying(Fields::kEndpoint), endpoint); + encoder.Encode(to_underlying(Fields::kDeviceType), deviceType); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -2959,6 +2906,7 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace AccessControlTargetStruct + namespace AccessControlEntryStruct { CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -2973,30 +2921,31 @@ CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIn CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional & aAccessingFabricIndex) const { bool includeSensitive = !aAccessingFabricIndex.HasValue() || (aAccessingFabricIndex.Value() == fabricIndex); - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPrivilege), privilege)); + encoder.Encode(to_underlying(Fields::kPrivilege), privilege); } if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAuthMode), authMode)); + encoder.Encode(to_underlying(Fields::kAuthMode), authMode); } if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSubjects), subjects)); + encoder.Encode(to_underlying(Fields::kSubjects), subjects); } if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTargets), targets)); + encoder.Encode(to_underlying(Fields::kTargets), targets); } if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); } - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3042,6 +2991,7 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace AccessControlEntryStruct + namespace AccessControlExtensionStruct { CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -3056,18 +3006,19 @@ CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIn CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional & aAccessingFabricIndex) const { bool includeSensitive = !aAccessingFabricIndex.HasValue() || (aAccessingFabricIndex.Value() == fabricIndex); - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kData), data)); + encoder.Encode(to_underlying(Fields::kData), data); } if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); } - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3254,19 +3205,18 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace AccessControl namespace Actions { namespace Structs { + namespace ActionStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kType), type)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpointListID), endpointListID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSupportedCommands), supportedCommands)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kState), state)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kName), name); + encoder.Encode(to_underlying(Fields::kType), type); + encoder.Encode(to_underlying(Fields::kEndpointListID), endpointListID); + encoder.Encode(to_underlying(Fields::kSupportedCommands), supportedCommands); + encoder.Encode(to_underlying(Fields::kState), state); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3316,17 +3266,16 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace ActionStruct + namespace EndpointListStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpointListID), endpointListID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kType), type)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpoints), endpoints)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kEndpointListID), endpointListID); + encoder.Encode(to_underlying(Fields::kName), name); + encoder.Encode(to_underlying(Fields::kType), type); + encoder.Encode(to_underlying(Fields::kEndpoints), endpoints); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3374,11 +3323,10 @@ namespace Commands { namespace InstantAction { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3414,12 +3362,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace InstantActionWithTransition { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3459,11 +3406,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StartAction { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3499,12 +3445,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StartActionWithDuration { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDuration), duration)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + encoder.Encode(to_underlying(Fields::kDuration), duration); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3544,11 +3489,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StopAction { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3584,11 +3528,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace PauseAction { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3624,12 +3567,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace PauseActionWithDuration { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDuration), duration)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + encoder.Encode(to_underlying(Fields::kDuration), duration); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3669,11 +3611,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ResumeAction { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3709,11 +3650,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace EnableAction { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3749,12 +3689,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace EnableActionWithDuration { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDuration), duration)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + encoder.Encode(to_underlying(Fields::kDuration), duration); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3794,11 +3733,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace DisableAction { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -3834,12 +3772,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace DisableActionWithDuration { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActionID), actionID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInvokeID), invokeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDuration), duration)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActionID), actionID); + encoder.Encode(to_underlying(Fields::kInvokeID), invokeID); + encoder.Encode(to_underlying(Fields::kDuration), duration); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -4008,15 +3945,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace Actions namespace BasicInformation { namespace Structs { + namespace CapabilityMinimaStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCaseSessionsPerFabric), caseSessionsPerFabric)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSubscriptionsPerFabric), subscriptionsPerFabric)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCaseSessionsPerFabric), caseSessionsPerFabric); + encoder.Encode(to_underlying(Fields::kSubscriptionsPerFabric), subscriptionsPerFabric); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -4050,15 +3986,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace CapabilityMinimaStruct + namespace ProductAppearanceStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFinish), finish)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPrimaryColor), primaryColor)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kFinish), finish); + encoder.Encode(to_underlying(Fields::kPrimaryColor), primaryColor); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -4098,9 +4033,8 @@ namespace Commands { namespace MfgSpecificPing { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -4319,17 +4253,16 @@ namespace Commands { namespace QueryImage { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kVendorID), vendorID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProductID), productID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSoftwareVersion), softwareVersion)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProtocolsSupported), protocolsSupported)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kHardwareVersion), hardwareVersion)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLocation), location)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRequestorCanConsent), requestorCanConsent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMetadataForProvider), metadataForProvider)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kVendorID), vendorID); + encoder.Encode(to_underlying(Fields::kProductID), productID); + encoder.Encode(to_underlying(Fields::kSoftwareVersion), softwareVersion); + encoder.Encode(to_underlying(Fields::kProtocolsSupported), protocolsSupported); + encoder.Encode(to_underlying(Fields::kHardwareVersion), hardwareVersion); + encoder.Encode(to_underlying(Fields::kLocation), location); + encoder.Encode(to_underlying(Fields::kRequestorCanConsent), requestorCanConsent); + encoder.Encode(to_underlying(Fields::kMetadataForProvider), metadataForProvider); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -4389,17 +4322,16 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace QueryImageResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDelayedActionTime), delayedActionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kImageURI), imageURI)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSoftwareVersion), softwareVersion)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSoftwareVersionString), softwareVersionString)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUpdateToken), updateToken)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserConsentNeeded), userConsentNeeded)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMetadataForRequestor), metadataForRequestor)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kDelayedActionTime), delayedActionTime); + encoder.Encode(to_underlying(Fields::kImageURI), imageURI); + encoder.Encode(to_underlying(Fields::kSoftwareVersion), softwareVersion); + encoder.Encode(to_underlying(Fields::kSoftwareVersionString), softwareVersionString); + encoder.Encode(to_underlying(Fields::kUpdateToken), updateToken); + encoder.Encode(to_underlying(Fields::kUserConsentNeeded), userConsentNeeded); + encoder.Encode(to_underlying(Fields::kMetadataForRequestor), metadataForRequestor); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -4459,11 +4391,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ApplyUpdateRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUpdateToken), updateToken)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNewVersion), newVersion)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kUpdateToken), updateToken); + encoder.Encode(to_underlying(Fields::kNewVersion), newVersion); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -4499,11 +4430,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ApplyUpdateResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAction), action)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDelayedActionTime), delayedActionTime)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kAction), action); + encoder.Encode(to_underlying(Fields::kDelayedActionTime), delayedActionTime); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -4539,11 +4469,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace NotifyUpdateApplied { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUpdateToken), updateToken)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSoftwareVersion), softwareVersion)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kUpdateToken), updateToken); + encoder.Encode(to_underlying(Fields::kSoftwareVersion), softwareVersion); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -4606,6 +4535,7 @@ namespace Events {} // namespace Events } // namespace OtaSoftwareUpdateProvider namespace OtaSoftwareUpdateRequestor { namespace Structs { + namespace ProviderLocation { CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -4619,16 +4549,17 @@ CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIn CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional & aAccessingFabricIndex) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProviderNodeID), providerNodeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpoint), endpoint)); + + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + + encoder.Encode(to_underlying(Fields::kProviderNodeID), providerNodeID); + encoder.Encode(to_underlying(Fields::kEndpoint), endpoint); if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); } - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -4672,14 +4603,13 @@ namespace Commands { namespace AnnounceOTAProvider { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProviderNodeID), providerNodeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kVendorID), vendorID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAnnouncementReason), announcementReason)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMetadataForNode), metadataForNode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpoint), endpoint)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kProviderNodeID), providerNodeID); + encoder.Encode(to_underlying(Fields::kVendorID), vendorID); + encoder.Encode(to_underlying(Fields::kAnnouncementReason), announcementReason); + encoder.Encode(to_underlying(Fields::kMetadataForNode), metadataForNode); + encoder.Encode(to_underlying(Fields::kEndpoint), endpoint); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5037,15 +4967,14 @@ namespace Events {} // namespace Events } // namespace PowerSourceConfiguration namespace PowerSource { namespace Structs { + namespace BatChargeFaultChangeType { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCurrent), current)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPrevious), previous)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCurrent), current); + encoder.Encode(to_underlying(Fields::kPrevious), previous); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5079,15 +5008,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace BatChargeFaultChangeType + namespace BatFaultChangeType { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCurrent), current)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPrevious), previous)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCurrent), current); + encoder.Encode(to_underlying(Fields::kPrevious), previous); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5121,15 +5049,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace BatFaultChangeType + namespace WiredFaultChangeType { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCurrent), current)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPrevious), previous)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCurrent), current); + encoder.Encode(to_underlying(Fields::kPrevious), previous); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5380,17 +5307,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace PowerSource namespace GeneralCommissioning { namespace Structs { + namespace BasicCommissioningInfo { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFailSafeExpiryLengthSeconds), failSafeExpiryLengthSeconds)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMaxCumulativeFailsafeSeconds), maxCumulativeFailsafeSeconds)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kFailSafeExpiryLengthSeconds), failSafeExpiryLengthSeconds); + encoder.Encode(to_underlying(Fields::kMaxCumulativeFailsafeSeconds), maxCumulativeFailsafeSeconds); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5430,11 +5354,10 @@ namespace Commands { namespace ArmFailSafe { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExpiryLengthSeconds), expiryLengthSeconds)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBreadcrumb), breadcrumb)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kExpiryLengthSeconds), expiryLengthSeconds); + encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5470,11 +5393,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ArmFailSafeResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kErrorCode), errorCode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDebugText), debugText)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kErrorCode), errorCode); + encoder.Encode(to_underlying(Fields::kDebugText), debugText); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5510,12 +5432,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetRegulatoryConfig { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNewRegulatoryConfig), newRegulatoryConfig)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCountryCode), countryCode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBreadcrumb), breadcrumb)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNewRegulatoryConfig), newRegulatoryConfig); + encoder.Encode(to_underlying(Fields::kCountryCode), countryCode); + encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5555,11 +5476,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetRegulatoryConfigResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kErrorCode), errorCode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDebugText), debugText)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kErrorCode), errorCode); + encoder.Encode(to_underlying(Fields::kDebugText), debugText); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5595,9 +5515,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace CommissioningComplete { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5616,11 +5535,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace CommissioningCompleteResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kErrorCode), errorCode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDebugText), debugText)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kErrorCode), errorCode); + encoder.Encode(to_underlying(Fields::kDebugText), debugText); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5693,15 +5611,14 @@ namespace Events {} // namespace Events } // namespace GeneralCommissioning namespace NetworkCommissioning { namespace Structs { + namespace NetworkInfoStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkID), networkID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kConnected), connected)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNetworkID), networkID); + encoder.Encode(to_underlying(Fields::kConnected), connected); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5735,21 +5652,20 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace NetworkInfoStruct + namespace ThreadInterfaceScanResultStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPanId), panId)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExtendedPanId), extendedPanId)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkName), networkName)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kChannel), channel)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kVersion), version)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExtendedAddress), extendedAddress)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRssi), rssi)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLqi), lqi)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kPanId), panId); + encoder.Encode(to_underlying(Fields::kExtendedPanId), extendedPanId); + encoder.Encode(to_underlying(Fields::kNetworkName), networkName); + encoder.Encode(to_underlying(Fields::kChannel), channel); + encoder.Encode(to_underlying(Fields::kVersion), version); + encoder.Encode(to_underlying(Fields::kExtendedAddress), extendedAddress); + encoder.Encode(to_underlying(Fields::kRssi), rssi); + encoder.Encode(to_underlying(Fields::kLqi), lqi); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5807,19 +5723,18 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace ThreadInterfaceScanResultStruct + namespace WiFiInterfaceScanResultStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSecurity), security)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSsid), ssid)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBssid), bssid)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kChannel), channel)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWiFiBand), wiFiBand)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRssi), rssi)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kSecurity), security); + encoder.Encode(to_underlying(Fields::kSsid), ssid); + encoder.Encode(to_underlying(Fields::kBssid), bssid); + encoder.Encode(to_underlying(Fields::kChannel), channel); + encoder.Encode(to_underlying(Fields::kWiFiBand), wiFiBand); + encoder.Encode(to_underlying(Fields::kRssi), rssi); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5875,11 +5790,10 @@ namespace Commands { namespace ScanNetworks { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSsid), ssid)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBreadcrumb), breadcrumb)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kSsid), ssid); + encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5915,13 +5829,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ScanNetworksResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkingStatus), networkingStatus)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDebugText), debugText)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWiFiScanResults), wiFiScanResults)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kThreadScanResults), threadScanResults)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNetworkingStatus), networkingStatus); + encoder.Encode(to_underlying(Fields::kDebugText), debugText); + encoder.Encode(to_underlying(Fields::kWiFiScanResults), wiFiScanResults); + encoder.Encode(to_underlying(Fields::kThreadScanResults), threadScanResults); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -5965,12 +5878,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace AddOrUpdateWiFiNetwork { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSsid), ssid)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredentials), credentials)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBreadcrumb), breadcrumb)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kSsid), ssid); + encoder.Encode(to_underlying(Fields::kCredentials), credentials); + encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6010,11 +5922,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace AddOrUpdateThreadNetwork { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOperationalDataset), operationalDataset)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBreadcrumb), breadcrumb)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOperationalDataset), operationalDataset); + encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6050,11 +5961,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RemoveNetwork { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkID), networkID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBreadcrumb), breadcrumb)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNetworkID), networkID); + encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6090,12 +6000,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace NetworkConfigResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkingStatus), networkingStatus)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDebugText), debugText)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkIndex), networkIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNetworkingStatus), networkingStatus); + encoder.Encode(to_underlying(Fields::kDebugText), debugText); + encoder.Encode(to_underlying(Fields::kNetworkIndex), networkIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6135,11 +6044,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ConnectNetwork { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkID), networkID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBreadcrumb), breadcrumb)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNetworkID), networkID); + encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6175,12 +6083,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ConnectNetworkResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkingStatus), networkingStatus)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDebugText), debugText)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kErrorValue), errorValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNetworkingStatus), networkingStatus); + encoder.Encode(to_underlying(Fields::kDebugText), debugText); + encoder.Encode(to_underlying(Fields::kErrorValue), errorValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6220,12 +6127,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ReorderNetwork { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkID), networkID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkIndex), networkIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBreadcrumb), breadcrumb)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNetworkID), networkID); + encoder.Encode(to_underlying(Fields::kNetworkIndex), networkIndex); + encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6312,12 +6218,11 @@ namespace Commands { namespace RetrieveLogsRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIntent), intent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRequestedProtocol), requestedProtocol)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransferFileDesignator), transferFileDesignator)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kIntent), intent); + encoder.Encode(to_underlying(Fields::kRequestedProtocol), requestedProtocol); + encoder.Encode(to_underlying(Fields::kTransferFileDesignator), transferFileDesignator); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6357,13 +6262,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RetrieveLogsResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLogContent), logContent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUTCTimeStamp), UTCTimeStamp)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTimeSinceBoot), timeSinceBoot)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kLogContent), logContent); + encoder.Encode(to_underlying(Fields::kUTCTimeStamp), UTCTimeStamp); + encoder.Encode(to_underlying(Fields::kTimeSinceBoot), timeSinceBoot); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6434,23 +6338,20 @@ namespace Events {} // namespace Events } // namespace DiagnosticLogs namespace GeneralDiagnostics { namespace Structs { + namespace NetworkInterface { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIsOperational), isOperational)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOffPremiseServicesReachableIPv4), offPremiseServicesReachableIPv4)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOffPremiseServicesReachableIPv6), offPremiseServicesReachableIPv6)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kHardwareAddress), hardwareAddress)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIPv4Addresses), IPv4Addresses)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIPv6Addresses), IPv6Addresses)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kType), type)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kName), name); + encoder.Encode(to_underlying(Fields::kIsOperational), isOperational); + encoder.Encode(to_underlying(Fields::kOffPremiseServicesReachableIPv4), offPremiseServicesReachableIPv4); + encoder.Encode(to_underlying(Fields::kOffPremiseServicesReachableIPv6), offPremiseServicesReachableIPv6); + encoder.Encode(to_underlying(Fields::kHardwareAddress), hardwareAddress); + encoder.Encode(to_underlying(Fields::kIPv4Addresses), IPv4Addresses); + encoder.Encode(to_underlying(Fields::kIPv6Addresses), IPv6Addresses); + encoder.Encode(to_underlying(Fields::kType), type); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6514,11 +6415,10 @@ namespace Commands { namespace TestEventTrigger { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEnableKey), enableKey)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEventTrigger), eventTrigger)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kEnableKey), enableKey); + encoder.Encode(to_underlying(Fields::kEventTrigger), eventTrigger); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6757,18 +6657,17 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace GeneralDiagnostics namespace SoftwareDiagnostics { namespace Structs { + namespace ThreadMetricsStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kId), id)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStackFreeCurrent), stackFreeCurrent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStackFreeMinimum), stackFreeMinimum)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStackSize), stackSize)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kId), id); + encoder.Encode(to_underlying(Fields::kName), name); + encoder.Encode(to_underlying(Fields::kStackFreeCurrent), stackFreeCurrent); + encoder.Encode(to_underlying(Fields::kStackFreeMinimum), stackFreeMinimum); + encoder.Encode(to_underlying(Fields::kStackSize), stackSize); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6820,9 +6719,8 @@ namespace Commands { namespace ResetWatermarks { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -6922,27 +6820,26 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace SoftwareDiagnostics namespace ThreadNetworkDiagnostics { namespace Structs { + namespace NeighborTableStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExtAddress), extAddress)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAge), age)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRloc16), rloc16)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLinkFrameCounter), linkFrameCounter)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMleFrameCounter), mleFrameCounter)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLqi), lqi)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAverageRssi), averageRssi)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLastRssi), lastRssi)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFrameErrorRate), frameErrorRate)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMessageErrorRate), messageErrorRate)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRxOnWhenIdle), rxOnWhenIdle)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFullThreadDevice), fullThreadDevice)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFullNetworkData), fullNetworkData)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIsChild), isChild)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kExtAddress), extAddress); + encoder.Encode(to_underlying(Fields::kAge), age); + encoder.Encode(to_underlying(Fields::kRloc16), rloc16); + encoder.Encode(to_underlying(Fields::kLinkFrameCounter), linkFrameCounter); + encoder.Encode(to_underlying(Fields::kMleFrameCounter), mleFrameCounter); + encoder.Encode(to_underlying(Fields::kLqi), lqi); + encoder.Encode(to_underlying(Fields::kAverageRssi), averageRssi); + encoder.Encode(to_underlying(Fields::kLastRssi), lastRssi); + encoder.Encode(to_underlying(Fields::kFrameErrorRate), frameErrorRate); + encoder.Encode(to_underlying(Fields::kMessageErrorRate), messageErrorRate); + encoder.Encode(to_underlying(Fields::kRxOnWhenIdle), rxOnWhenIdle); + encoder.Encode(to_underlying(Fields::kFullThreadDevice), fullThreadDevice); + encoder.Encode(to_underlying(Fields::kFullNetworkData), fullNetworkData); + encoder.Encode(to_underlying(Fields::kIsChild), isChild); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7024,25 +6921,24 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace NeighborTableStruct + namespace OperationalDatasetComponents { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kActiveTimestampPresent), activeTimestampPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPendingTimestampPresent), pendingTimestampPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMasterKeyPresent), masterKeyPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNetworkNamePresent), networkNamePresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExtendedPanIdPresent), extendedPanIdPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMeshLocalPrefixPresent), meshLocalPrefixPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDelayPresent), delayPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPanIdPresent), panIdPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kChannelPresent), channelPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPskcPresent), pskcPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSecurityPolicyPresent), securityPolicyPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kChannelMaskPresent), channelMaskPresent)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kActiveTimestampPresent), activeTimestampPresent); + encoder.Encode(to_underlying(Fields::kPendingTimestampPresent), pendingTimestampPresent); + encoder.Encode(to_underlying(Fields::kMasterKeyPresent), masterKeyPresent); + encoder.Encode(to_underlying(Fields::kNetworkNamePresent), networkNamePresent); + encoder.Encode(to_underlying(Fields::kExtendedPanIdPresent), extendedPanIdPresent); + encoder.Encode(to_underlying(Fields::kMeshLocalPrefixPresent), meshLocalPrefixPresent); + encoder.Encode(to_underlying(Fields::kDelayPresent), delayPresent); + encoder.Encode(to_underlying(Fields::kPanIdPresent), panIdPresent); + encoder.Encode(to_underlying(Fields::kChannelPresent), channelPresent); + encoder.Encode(to_underlying(Fields::kPskcPresent), pskcPresent); + encoder.Encode(to_underlying(Fields::kSecurityPolicyPresent), securityPolicyPresent); + encoder.Encode(to_underlying(Fields::kChannelMaskPresent), channelMaskPresent); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7116,23 +7012,22 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace OperationalDatasetComponents + namespace RouteTableStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExtAddress), extAddress)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRloc16), rloc16)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRouterId), routerId)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNextHop), nextHop)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPathCost), pathCost)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLQIIn), LQIIn)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLQIOut), LQIOut)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAge), age)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAllocated), allocated)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLinkEstablished), linkEstablished)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kExtAddress), extAddress); + encoder.Encode(to_underlying(Fields::kRloc16), rloc16); + encoder.Encode(to_underlying(Fields::kRouterId), routerId); + encoder.Encode(to_underlying(Fields::kNextHop), nextHop); + encoder.Encode(to_underlying(Fields::kPathCost), pathCost); + encoder.Encode(to_underlying(Fields::kLQIIn), LQIIn); + encoder.Encode(to_underlying(Fields::kLQIOut), LQIOut); + encoder.Encode(to_underlying(Fields::kAge), age); + encoder.Encode(to_underlying(Fields::kAllocated), allocated); + encoder.Encode(to_underlying(Fields::kLinkEstablished), linkEstablished); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7198,15 +7093,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace RouteTableStruct + namespace SecurityPolicy { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRotationTime), rotationTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFlags), flags)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kRotationTime), rotationTime); + encoder.Encode(to_underlying(Fields::kFlags), flags); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7246,9 +7140,8 @@ namespace Commands { namespace ResetCounts { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7500,9 +7393,8 @@ namespace Commands { namespace ResetCounts { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7689,9 +7581,8 @@ namespace Commands { namespace ResetCounts { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7755,16 +7646,15 @@ namespace Events {} // namespace Events } // namespace EthernetNetworkDiagnostics namespace TimeSynchronization { namespace Structs { + namespace DSTOffsetStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOffset), offset)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValidStarting), validStarting)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValidUntil), validUntil)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOffset), offset); + encoder.Encode(to_underlying(Fields::kValidStarting), validStarting); + encoder.Encode(to_underlying(Fields::kValidUntil), validUntil); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7802,15 +7692,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace DSTOffsetStruct + namespace FabricScopedTrustedTimeSourceStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNodeID), nodeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpoint), endpoint)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNodeID), nodeID); + encoder.Encode(to_underlying(Fields::kEndpoint), endpoint); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7844,16 +7733,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace FabricScopedTrustedTimeSourceStruct + namespace TimeZoneStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOffset), offset)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValidAt), validAt)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOffset), offset); + encoder.Encode(to_underlying(Fields::kValidAt), validAt); + encoder.Encode(to_underlying(Fields::kName), name); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7891,16 +7779,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace TimeZoneStruct + namespace TrustedTimeSourceStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNodeID), nodeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpoint), endpoint)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); + encoder.Encode(to_underlying(Fields::kNodeID), nodeID); + encoder.Encode(to_underlying(Fields::kEndpoint), endpoint); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7944,12 +7831,11 @@ namespace Commands { namespace SetUTCTime { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUTCTime), UTCTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGranularity), granularity)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTimeSource), timeSource)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kUTCTime), UTCTime); + encoder.Encode(to_underlying(Fields::kGranularity), granularity); + encoder.Encode(to_underlying(Fields::kTimeSource), timeSource); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -7989,10 +7875,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetTrustedTimeSource { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTrustedTimeSource), trustedTimeSource)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kTrustedTimeSource), trustedTimeSource); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -8024,10 +7909,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetTimeZone { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTimeZone), timeZone)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kTimeZone), timeZone); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -8059,10 +7943,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetTimeZoneResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDSTOffsetRequired), DSTOffsetRequired)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kDSTOffsetRequired), DSTOffsetRequired); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -8094,10 +7977,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetDSTOffset { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDSTOffset), DSTOffset)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kDSTOffset), DSTOffset); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -8129,10 +8011,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetDefaultNTP { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDefaultNTP), defaultNTP)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kDefaultNTP), defaultNTP); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -8356,15 +8237,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace TimeSynchronization namespace BridgedDeviceBasicInformation { namespace Structs { + namespace ProductAppearanceStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFinish), finish)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPrimaryColor), primaryColor)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kFinish), finish); + encoder.Encode(to_underlying(Fields::kPrimaryColor), primaryColor); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -8873,14 +8753,13 @@ namespace Commands { namespace OpenCommissioningWindow { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCommissioningTimeout), commissioningTimeout)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPAKEPasscodeVerifier), PAKEPasscodeVerifier)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDiscriminator), discriminator)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIterations), iterations)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSalt), salt)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCommissioningTimeout), commissioningTimeout); + encoder.Encode(to_underlying(Fields::kPAKEPasscodeVerifier), PAKEPasscodeVerifier); + encoder.Encode(to_underlying(Fields::kDiscriminator), discriminator); + encoder.Encode(to_underlying(Fields::kIterations), iterations); + encoder.Encode(to_underlying(Fields::kSalt), salt); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -8928,10 +8807,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace OpenBasicCommissioningWindow { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCommissioningTimeout), commissioningTimeout)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCommissioningTimeout), commissioningTimeout); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -8963,9 +8841,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RevokeCommissioning { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9017,6 +8894,7 @@ namespace Events {} // namespace Events } // namespace AdministratorCommissioning namespace OperationalCredentials { namespace Structs { + namespace FabricDescriptorStruct { CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -9030,19 +8908,20 @@ CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIn CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional & aAccessingFabricIndex) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRootPublicKey), rootPublicKey)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kVendorID), vendorID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricID), fabricID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNodeID), nodeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLabel), label)); + + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + + encoder.Encode(to_underlying(Fields::kRootPublicKey), rootPublicKey); + encoder.Encode(to_underlying(Fields::kVendorID), vendorID); + encoder.Encode(to_underlying(Fields::kFabricID), fabricID); + encoder.Encode(to_underlying(Fields::kNodeID), nodeID); + encoder.Encode(to_underlying(Fields::kLabel), label); if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); } - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9092,6 +8971,7 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace FabricDescriptorStruct + namespace NOCStruct { CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -9106,22 +8986,23 @@ CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIn CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional & aAccessingFabricIndex) const { bool includeSensitive = !aAccessingFabricIndex.HasValue() || (aAccessingFabricIndex.Value() == fabricIndex); - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNoc), noc)); + encoder.Encode(to_underlying(Fields::kNoc), noc); } if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIcac), icac)); + encoder.Encode(to_underlying(Fields::kIcac), icac); } if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); } - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9165,10 +9046,9 @@ namespace Commands { namespace AttestationRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAttestationNonce), attestationNonce)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kAttestationNonce), attestationNonce); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9200,11 +9080,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace AttestationResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAttestationElements), attestationElements)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAttestationSignature), attestationSignature)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kAttestationElements), attestationElements); + encoder.Encode(to_underlying(Fields::kAttestationSignature), attestationSignature); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9240,10 +9119,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace CertificateChainRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCertificateType), certificateType)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCertificateType), certificateType); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9275,10 +9153,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace CertificateChainResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCertificate), certificate)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCertificate), certificate); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9310,11 +9187,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace CSRRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCSRNonce), CSRNonce)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIsForUpdateNOC), isForUpdateNOC)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCSRNonce), CSRNonce); + encoder.Encode(to_underlying(Fields::kIsForUpdateNOC), isForUpdateNOC); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9350,11 +9226,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace CSRResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNOCSRElements), NOCSRElements)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAttestationSignature), attestationSignature)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNOCSRElements), NOCSRElements); + encoder.Encode(to_underlying(Fields::kAttestationSignature), attestationSignature); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9390,14 +9265,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace AddNOC { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNOCValue), NOCValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kICACValue), ICACValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIPKValue), IPKValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCaseAdminSubject), caseAdminSubject)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAdminVendorId), adminVendorId)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNOCValue), NOCValue); + encoder.Encode(to_underlying(Fields::kICACValue), ICACValue); + encoder.Encode(to_underlying(Fields::kIPKValue), IPKValue); + encoder.Encode(to_underlying(Fields::kCaseAdminSubject), caseAdminSubject); + encoder.Encode(to_underlying(Fields::kAdminVendorId), adminVendorId); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9445,11 +9319,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace UpdateNOC { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNOCValue), NOCValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kICACValue), ICACValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNOCValue), NOCValue); + encoder.Encode(to_underlying(Fields::kICACValue), ICACValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9485,12 +9358,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace NOCResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatusCode), statusCode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDebugText), debugText)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatusCode), statusCode); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); + encoder.Encode(to_underlying(Fields::kDebugText), debugText); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9530,10 +9402,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace UpdateFabricLabel { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLabel), label)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kLabel), label); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9565,10 +9436,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RemoveFabric { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9600,10 +9470,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace AddTrustedRootCertificate { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRootCACertificate), rootCACertificate)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kRootCACertificate), rootCACertificate); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9674,6 +9543,7 @@ namespace Events {} // namespace Events } // namespace OperationalCredentials namespace GroupKeyManagement { namespace Structs { + namespace GroupInfoMapStruct { CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -9687,17 +9557,18 @@ CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIn CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional & aAccessingFabricIndex) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupId), groupId)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpoints), endpoints)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupName), groupName)); + + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + + encoder.Encode(to_underlying(Fields::kGroupId), groupId); + encoder.Encode(to_underlying(Fields::kEndpoints), endpoints); + encoder.Encode(to_underlying(Fields::kGroupName), groupName); if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); } - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9739,6 +9610,7 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace GroupInfoMapStruct + namespace GroupKeyMapStruct { CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -9752,16 +9624,17 @@ CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIn CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional & aAccessingFabricIndex) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupId), groupId)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupKeySetID), groupKeySetID)); + + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + + encoder.Encode(to_underlying(Fields::kGroupId), groupId); + encoder.Encode(to_underlying(Fields::kGroupKeySetID), groupKeySetID); if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); } - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9799,21 +9672,20 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace GroupKeyMapStruct + namespace GroupKeySetStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupKeySetID), groupKeySetID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupKeySecurityPolicy), groupKeySecurityPolicy)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEpochKey0), epochKey0)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEpochStartTime0), epochStartTime0)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEpochKey1), epochKey1)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEpochStartTime1), epochStartTime1)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEpochKey2), epochKey2)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEpochStartTime2), epochStartTime2)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupKeySetID), groupKeySetID); + encoder.Encode(to_underlying(Fields::kGroupKeySecurityPolicy), groupKeySecurityPolicy); + encoder.Encode(to_underlying(Fields::kEpochKey0), epochKey0); + encoder.Encode(to_underlying(Fields::kEpochStartTime0), epochStartTime0); + encoder.Encode(to_underlying(Fields::kEpochKey1), epochKey1); + encoder.Encode(to_underlying(Fields::kEpochStartTime1), epochStartTime1); + encoder.Encode(to_underlying(Fields::kEpochKey2), epochKey2); + encoder.Encode(to_underlying(Fields::kEpochStartTime2), epochStartTime2); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9877,10 +9749,9 @@ namespace Commands { namespace KeySetWrite { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupKeySet), groupKeySet)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupKeySet), groupKeySet); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9912,10 +9783,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace KeySetRead { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupKeySetID), groupKeySetID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupKeySetID), groupKeySetID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9947,10 +9817,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace KeySetReadResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupKeySet), groupKeySet)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupKeySet), groupKeySet); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -9982,10 +9851,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace KeySetRemove { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupKeySetID), groupKeySetID)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupKeySetID), groupKeySetID); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10017,9 +9885,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace KeySetReadAllIndices { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10038,10 +9905,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace KeySetReadAllIndicesResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kGroupKeySetIDs), groupKeySetIDs)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kGroupKeySetIDs), groupKeySetIDs); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10332,6 +10198,7 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace BooleanState namespace IcdManagement { namespace Structs { + namespace MonitoringRegistrationStruct { CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -10346,22 +10213,23 @@ CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIn CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional & aAccessingFabricIndex) const { bool includeSensitive = !aAccessingFabricIndex.HasValue() || (aAccessingFabricIndex.Value() == fabricIndex); - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCheckInNodeID), checkInNodeID)); + encoder.Encode(to_underlying(Fields::kCheckInNodeID), checkInNodeID); } if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMonitoredSubject), monitoredSubject)); + encoder.Encode(to_underlying(Fields::kMonitoredSubject), monitoredSubject); } if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); } - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10405,13 +10273,12 @@ namespace Commands { namespace RegisterClient { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCheckInNodeID), checkInNodeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMonitoredSubject), monitoredSubject)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kKey), key)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kVerificationKey), verificationKey)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCheckInNodeID), checkInNodeID); + encoder.Encode(to_underlying(Fields::kMonitoredSubject), monitoredSubject); + encoder.Encode(to_underlying(Fields::kKey), key); + encoder.Encode(to_underlying(Fields::kVerificationKey), verificationKey); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10455,10 +10322,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RegisterClientResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kICDCounter), ICDCounter)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kICDCounter), ICDCounter); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10490,11 +10356,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace UnregisterClient { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCheckInNodeID), checkInNodeID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kVerificationKey), verificationKey)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCheckInNodeID), checkInNodeID); + encoder.Encode(to_underlying(Fields::kVerificationKey), verificationKey); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10530,9 +10395,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StayActiveRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10590,15 +10454,14 @@ namespace Events {} // namespace Events } // namespace IcdManagement namespace ModeSelect { namespace Structs { + namespace SemanticTagStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMfgCode), mfgCode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValue), value)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMfgCode), mfgCode); + encoder.Encode(to_underlying(Fields::kValue), value); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10632,16 +10495,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace SemanticTagStruct + namespace ModeOptionStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLabel), label)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMode), mode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSemanticTags), semanticTags)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kLabel), label); + encoder.Encode(to_underlying(Fields::kMode), mode); + encoder.Encode(to_underlying(Fields::kSemanticTags), semanticTags); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10685,10 +10547,9 @@ namespace Commands { namespace ChangeToMode { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNewMode), newMode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNewMode), newMode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10764,10 +10625,9 @@ namespace Commands { namespace ChangeToMode { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNewMode), newMode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNewMode), newMode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10799,11 +10659,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ChangeToModeResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatusText), statusText)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kStatusText), statusText); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10879,10 +10738,9 @@ namespace Commands { namespace ChangeToMode { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNewMode), newMode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNewMode), newMode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -10914,11 +10772,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ChangeToModeResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatusText), statusText)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kStatusText), statusText); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -11032,10 +10889,9 @@ namespace Commands { namespace ChangeToMode { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNewMode), newMode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNewMode), newMode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -11067,11 +10923,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ChangeToModeResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatusText), statusText)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kStatusText), statusText); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -11147,10 +11002,9 @@ namespace Commands { namespace ChangeToMode { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNewMode), newMode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNewMode), newMode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -11182,11 +11036,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ChangeToModeResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatusText), statusText)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kStatusText), statusText); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -11261,11 +11114,10 @@ namespace Commands { namespace SetTemperature { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTargetTemperature), targetTemperature)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTargetTemperatureLevel), targetTemperatureLevel)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kTargetTemperature), targetTemperature); + encoder.Encode(to_underlying(Fields::kTargetTemperatureLevel), targetTemperatureLevel); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -11432,10 +11284,9 @@ namespace Commands { namespace ChangeToMode { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNewMode), newMode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNewMode), newMode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -11467,11 +11318,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ChangeToModeResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatusText), statusText)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kStatusText), statusText); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -11578,9 +11428,8 @@ namespace Commands { namespace SelfTestRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -11958,10 +11807,9 @@ namespace Commands { namespace Reset { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAlarms), alarms)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kAlarms), alarms); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -11993,10 +11841,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ModifyEnabledAlarms { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMask), mask)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMask), mask); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12119,9 +11966,8 @@ namespace Commands { namespace Pause { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12140,9 +11986,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Stop { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12161,9 +12006,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Start { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12182,9 +12026,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Resume { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12203,10 +12046,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace OperationalCommandResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCommandResponseState), commandResponseState)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCommandResponseState), commandResponseState); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12363,9 +12205,8 @@ namespace Commands { namespace Pause { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12384,9 +12225,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Stop { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12405,9 +12245,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Start { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12426,9 +12265,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Resume { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12447,10 +12285,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace OperationalCommandResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCommandResponseState), commandResponseState)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCommandResponseState), commandResponseState); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12602,15 +12439,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace RvcOperationalState namespace HepaFilterMonitoring { namespace Structs { + namespace ReplacementProductStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProductIdentifierType), productIdentifierType)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProductIdentifierValue), productIdentifierValue)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kProductIdentifierType), productIdentifierType); + encoder.Encode(to_underlying(Fields::kProductIdentifierValue), productIdentifierValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12650,9 +12486,8 @@ namespace Commands { namespace ResetCondition { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12710,15 +12545,14 @@ namespace Events {} // namespace Events } // namespace HepaFilterMonitoring namespace ActivatedCarbonFilterMonitoring { namespace Structs { + namespace ReplacementProductStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProductIdentifierType), productIdentifierType)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProductIdentifierValue), productIdentifierValue)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kProductIdentifierType), productIdentifierType); + encoder.Encode(to_underlying(Fields::kProductIdentifierValue), productIdentifierValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12758,9 +12592,8 @@ namespace Commands { namespace ResetCondition { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12818,15 +12651,14 @@ namespace Events {} // namespace Events } // namespace ActivatedCarbonFilterMonitoring namespace DoorLock { namespace Structs { + namespace CredentialStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredentialType), credentialType)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredentialIndex), credentialIndex)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCredentialType), credentialType); + encoder.Encode(to_underlying(Fields::kCredentialIndex), credentialIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12866,10 +12698,9 @@ namespace Commands { namespace LockDoor { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPINCode), PINCode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kPINCode), PINCode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12901,10 +12732,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace UnlockDoor { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPINCode), PINCode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kPINCode), PINCode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12936,11 +12766,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace UnlockWithTimeout { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTimeout), timeout)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPINCode), PINCode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kTimeout), timeout); + encoder.Encode(to_underlying(Fields::kPINCode), PINCode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -12976,16 +12805,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetWeekDaySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWeekDayIndex), weekDayIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDaysMask), daysMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStartHour), startHour)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStartMinute), startMinute)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndHour), endHour)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndMinute), endMinute)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kWeekDayIndex), weekDayIndex); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + encoder.Encode(to_underlying(Fields::kDaysMask), daysMask); + encoder.Encode(to_underlying(Fields::kStartHour), startHour); + encoder.Encode(to_underlying(Fields::kStartMinute), startMinute); + encoder.Encode(to_underlying(Fields::kEndHour), endHour); + encoder.Encode(to_underlying(Fields::kEndMinute), endMinute); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13041,11 +12869,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetWeekDaySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWeekDayIndex), weekDayIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kWeekDayIndex), weekDayIndex); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13081,17 +12908,16 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetWeekDayScheduleResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWeekDayIndex), weekDayIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDaysMask), daysMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStartHour), startHour)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStartMinute), startMinute)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndHour), endHour)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndMinute), endMinute)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kWeekDayIndex), weekDayIndex); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kDaysMask), daysMask); + encoder.Encode(to_underlying(Fields::kStartHour), startHour); + encoder.Encode(to_underlying(Fields::kStartMinute), startMinute); + encoder.Encode(to_underlying(Fields::kEndHour), endHour); + encoder.Encode(to_underlying(Fields::kEndMinute), endMinute); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13151,11 +12977,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ClearWeekDaySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWeekDayIndex), weekDayIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kWeekDayIndex), weekDayIndex); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13191,13 +13016,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetYearDaySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kYearDayIndex), yearDayIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLocalStartTime), localStartTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLocalEndTime), localEndTime)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kYearDayIndex), yearDayIndex); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + encoder.Encode(to_underlying(Fields::kLocalStartTime), localStartTime); + encoder.Encode(to_underlying(Fields::kLocalEndTime), localEndTime); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13241,11 +13065,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetYearDaySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kYearDayIndex), yearDayIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kYearDayIndex), yearDayIndex); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13281,14 +13104,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetYearDayScheduleResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kYearDayIndex), yearDayIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLocalStartTime), localStartTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLocalEndTime), localEndTime)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kYearDayIndex), yearDayIndex); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kLocalStartTime), localStartTime); + encoder.Encode(to_underlying(Fields::kLocalEndTime), localEndTime); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13336,11 +13158,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ClearYearDaySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kYearDayIndex), yearDayIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kYearDayIndex), yearDayIndex); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13376,13 +13197,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetHolidaySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kHolidayIndex), holidayIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLocalStartTime), localStartTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLocalEndTime), localEndTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOperatingMode), operatingMode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kHolidayIndex), holidayIndex); + encoder.Encode(to_underlying(Fields::kLocalStartTime), localStartTime); + encoder.Encode(to_underlying(Fields::kLocalEndTime), localEndTime); + encoder.Encode(to_underlying(Fields::kOperatingMode), operatingMode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13426,10 +13246,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetHolidaySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kHolidayIndex), holidayIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kHolidayIndex), holidayIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13461,14 +13280,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetHolidayScheduleResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kHolidayIndex), holidayIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLocalStartTime), localStartTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLocalEndTime), localEndTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOperatingMode), operatingMode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kHolidayIndex), holidayIndex); + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kLocalStartTime), localStartTime); + encoder.Encode(to_underlying(Fields::kLocalEndTime), localEndTime); + encoder.Encode(to_underlying(Fields::kOperatingMode), operatingMode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13516,10 +13334,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ClearHolidaySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kHolidayIndex), holidayIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kHolidayIndex), holidayIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13551,16 +13368,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetUser { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOperationType), operationType)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserName), userName)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserUniqueID), userUniqueID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserStatus), userStatus)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserType), userType)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredentialRule), credentialRule)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOperationType), operationType); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + encoder.Encode(to_underlying(Fields::kUserName), userName); + encoder.Encode(to_underlying(Fields::kUserUniqueID), userUniqueID); + encoder.Encode(to_underlying(Fields::kUserStatus), userStatus); + encoder.Encode(to_underlying(Fields::kUserType), userType); + encoder.Encode(to_underlying(Fields::kCredentialRule), credentialRule); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13616,10 +13432,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetUser { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13651,19 +13466,18 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetUserResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserName), userName)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserUniqueID), userUniqueID)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserStatus), userStatus)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserType), userType)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredentialRule), credentialRule)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredentials), credentials)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCreatorFabricIndex), creatorFabricIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLastModifiedFabricIndex), lastModifiedFabricIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNextUserIndex), nextUserIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + encoder.Encode(to_underlying(Fields::kUserName), userName); + encoder.Encode(to_underlying(Fields::kUserUniqueID), userUniqueID); + encoder.Encode(to_underlying(Fields::kUserStatus), userStatus); + encoder.Encode(to_underlying(Fields::kUserType), userType); + encoder.Encode(to_underlying(Fields::kCredentialRule), credentialRule); + encoder.Encode(to_underlying(Fields::kCredentials), credentials); + encoder.Encode(to_underlying(Fields::kCreatorFabricIndex), creatorFabricIndex); + encoder.Encode(to_underlying(Fields::kLastModifiedFabricIndex), lastModifiedFabricIndex); + encoder.Encode(to_underlying(Fields::kNextUserIndex), nextUserIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13731,10 +13545,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ClearUser { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13766,15 +13579,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetCredential { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOperationType), operationType)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredential), credential)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredentialData), credentialData)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserStatus), userStatus)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserType), userType)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOperationType), operationType); + encoder.Encode(to_underlying(Fields::kCredential), credential); + encoder.Encode(to_underlying(Fields::kCredentialData), credentialData); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + encoder.Encode(to_underlying(Fields::kUserStatus), userStatus); + encoder.Encode(to_underlying(Fields::kUserType), userType); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13826,12 +13638,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetCredentialResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNextCredentialIndex), nextCredentialIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + encoder.Encode(to_underlying(Fields::kNextCredentialIndex), nextCredentialIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13871,10 +13682,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetCredentialStatus { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredential), credential)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCredential), credential); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13906,14 +13716,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetCredentialStatusResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredentialExists), credentialExists)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCreatorFabricIndex), creatorFabricIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLastModifiedFabricIndex), lastModifiedFabricIndex)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNextCredentialIndex), nextCredentialIndex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCredentialExists), credentialExists); + encoder.Encode(to_underlying(Fields::kUserIndex), userIndex); + encoder.Encode(to_underlying(Fields::kCreatorFabricIndex), creatorFabricIndex); + encoder.Encode(to_underlying(Fields::kLastModifiedFabricIndex), lastModifiedFabricIndex); + encoder.Encode(to_underlying(Fields::kNextCredentialIndex), nextCredentialIndex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13961,10 +13770,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ClearCredential { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCredential), credential)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCredential), credential); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -13996,10 +13804,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace UnboltDoor { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPINCode), PINCode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kPINCode), PINCode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -14395,9 +14202,8 @@ namespace Commands { namespace UpOrOpen { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -14416,9 +14222,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace DownOrClose { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -14437,9 +14242,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StopMotion { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -14458,10 +14262,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GoToLiftValue { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLiftValue), liftValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kLiftValue), liftValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -14493,10 +14296,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GoToLiftPercentage { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLiftPercent100thsValue), liftPercent100thsValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kLiftPercent100thsValue), liftPercent100thsValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -14528,10 +14330,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GoToTiltValue { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTiltValue), tiltValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kTiltValue), tiltValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -14563,10 +14364,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GoToTiltPercentage { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTiltPercent100thsValue), tiltPercent100thsValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kTiltPercent100thsValue), tiltPercent100thsValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -14673,10 +14473,9 @@ namespace Commands { namespace BarrierControlGoToPercent { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPercentOpen), percentOpen)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kPercentOpen), percentOpen); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -14708,9 +14507,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace BarrierControlStop { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15210,16 +15008,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace PumpConfigurationAndControl namespace Thermostat { namespace Structs { + namespace ThermostatScheduleTransition { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kHeatSetpoint), heatSetpoint)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCoolSetpoint), coolSetpoint)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kHeatSetpoint), heatSetpoint); + encoder.Encode(to_underlying(Fields::kCoolSetpoint), coolSetpoint); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15263,11 +15060,10 @@ namespace Commands { namespace SetpointRaiseLower { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMode), mode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAmount), amount)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMode), mode); + encoder.Encode(to_underlying(Fields::kAmount), amount); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15303,14 +15099,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetWeeklyScheduleResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNumberOfTransitionsForSequence), numberOfTransitionsForSequence)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDayOfWeekForSequence), dayOfWeekForSequence)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kModeForSequence), modeForSequence)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitions), transitions)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNumberOfTransitionsForSequence), numberOfTransitionsForSequence); + encoder.Encode(to_underlying(Fields::kDayOfWeekForSequence), dayOfWeekForSequence); + encoder.Encode(to_underlying(Fields::kModeForSequence), modeForSequence); + encoder.Encode(to_underlying(Fields::kTransitions), transitions); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15354,14 +15148,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SetWeeklySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNumberOfTransitionsForSequence), numberOfTransitionsForSequence)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDayOfWeekForSequence), dayOfWeekForSequence)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kModeForSequence), modeForSequence)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitions), transitions)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNumberOfTransitionsForSequence), numberOfTransitionsForSequence); + encoder.Encode(to_underlying(Fields::kDayOfWeekForSequence), dayOfWeekForSequence); + encoder.Encode(to_underlying(Fields::kModeForSequence), modeForSequence); + encoder.Encode(to_underlying(Fields::kTransitions), transitions); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15405,11 +15197,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetWeeklySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDaysToReturn), daysToReturn)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kModeToReturn), modeToReturn)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kDaysToReturn), daysToReturn); + encoder.Encode(to_underlying(Fields::kModeToReturn), modeToReturn); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15445,9 +15236,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ClearWeeklySchedule { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15595,12 +15385,11 @@ namespace Commands { namespace Step { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDirection), direction)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWrap), wrap)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLowestOff), lowestOff)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kDirection), direction); + encoder.Encode(to_underlying(Fields::kWrap), wrap); + encoder.Encode(to_underlying(Fields::kLowestOff), lowestOff); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15731,14 +15520,13 @@ namespace Commands { namespace MoveToHue { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kHue), hue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDirection), direction)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kHue), hue); + encoder.Encode(to_underlying(Fields::kDirection), direction); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15786,13 +15574,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveHue { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMoveMode), moveMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRate), rate)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMoveMode), moveMode); + encoder.Encode(to_underlying(Fields::kRate), rate); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15836,14 +15623,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StepHue { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepMode), stepMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepSize), stepSize)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStepMode), stepMode); + encoder.Encode(to_underlying(Fields::kStepSize), stepSize); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15891,13 +15677,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveToSaturation { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSaturation), saturation)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kSaturation), saturation); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15941,13 +15726,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveSaturation { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMoveMode), moveMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRate), rate)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMoveMode), moveMode); + encoder.Encode(to_underlying(Fields::kRate), rate); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -15991,14 +15775,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StepSaturation { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepMode), stepMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepSize), stepSize)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStepMode), stepMode); + encoder.Encode(to_underlying(Fields::kStepSize), stepSize); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16046,14 +15829,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveToHueAndSaturation { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kHue), hue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSaturation), saturation)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kHue), hue); + encoder.Encode(to_underlying(Fields::kSaturation), saturation); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16101,14 +15883,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveToColor { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kColorX), colorX)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kColorY), colorY)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kColorX), colorX); + encoder.Encode(to_underlying(Fields::kColorY), colorY); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16156,13 +15937,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveColor { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRateX), rateX)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRateY), rateY)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kRateX), rateX); + encoder.Encode(to_underlying(Fields::kRateY), rateY); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16206,14 +15986,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StepColor { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepX), stepX)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepY), stepY)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStepX), stepX); + encoder.Encode(to_underlying(Fields::kStepY), stepY); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16261,13 +16040,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveToColorTemperature { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kColorTemperatureMireds), colorTemperatureMireds)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kColorTemperatureMireds), colorTemperatureMireds); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16311,14 +16089,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace EnhancedMoveToHue { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEnhancedHue), enhancedHue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDirection), direction)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kEnhancedHue), enhancedHue); + encoder.Encode(to_underlying(Fields::kDirection), direction); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16366,13 +16143,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace EnhancedMoveHue { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMoveMode), moveMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRate), rate)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMoveMode), moveMode); + encoder.Encode(to_underlying(Fields::kRate), rate); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16416,14 +16192,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace EnhancedStepHue { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepMode), stepMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepSize), stepSize)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStepMode), stepMode); + encoder.Encode(to_underlying(Fields::kStepSize), stepSize); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16471,14 +16246,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace EnhancedMoveToHueAndSaturation { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEnhancedHue), enhancedHue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSaturation), saturation)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kEnhancedHue), enhancedHue); + encoder.Encode(to_underlying(Fields::kSaturation), saturation); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16526,16 +16300,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ColorLoopSet { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUpdateFlags), updateFlags)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAction), action)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDirection), direction)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTime), time)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStartHue), startHue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kUpdateFlags), updateFlags); + encoder.Encode(to_underlying(Fields::kAction), action); + encoder.Encode(to_underlying(Fields::kDirection), direction); + encoder.Encode(to_underlying(Fields::kTime), time); + encoder.Encode(to_underlying(Fields::kStartHue), startHue); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16591,11 +16364,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StopMoveStep { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16631,17 +16403,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace MoveColorTemperature { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMoveMode), moveMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kRate), rate)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kColorTemperatureMinimumMireds), colorTemperatureMinimumMireds)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kColorTemperatureMaximumMireds), colorTemperatureMaximumMireds)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMoveMode), moveMode); + encoder.Encode(to_underlying(Fields::kRate), rate); + encoder.Encode(to_underlying(Fields::kColorTemperatureMinimumMireds), colorTemperatureMinimumMireds); + encoder.Encode(to_underlying(Fields::kColorTemperatureMaximumMireds), colorTemperatureMaximumMireds); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -16693,18 +16462,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StepColorTemperature { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepMode), stepMode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStepSize), stepSize)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTransitionTime), transitionTime)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kColorTemperatureMinimumMireds), colorTemperatureMinimumMireds)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kColorTemperatureMaximumMireds), colorTemperatureMaximumMireds)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsMask), optionsMask)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionsOverride), optionsOverride)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStepMode), stepMode); + encoder.Encode(to_underlying(Fields::kStepSize), stepSize); + encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime); + encoder.Encode(to_underlying(Fields::kColorTemperatureMinimumMireds), colorTemperatureMinimumMireds); + encoder.Encode(to_underlying(Fields::kColorTemperatureMaximumMireds), colorTemperatureMaximumMireds); + encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask); + encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -17757,18 +17523,17 @@ namespace Events {} // namespace Events } // namespace WakeOnLan namespace Channel { namespace Structs { + namespace ChannelInfoStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMajorNumber), majorNumber)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMinorNumber), minorNumber)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCallSign), callSign)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAffiliateCallSign), affiliateCallSign)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMajorNumber), majorNumber); + encoder.Encode(to_underlying(Fields::kMinorNumber), minorNumber); + encoder.Encode(to_underlying(Fields::kName), name); + encoder.Encode(to_underlying(Fields::kCallSign), callSign); + encoder.Encode(to_underlying(Fields::kAffiliateCallSign), affiliateCallSign); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -17814,17 +17579,16 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace ChannelInfoStruct + namespace LineupInfoStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOperatorName), operatorName)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLineupName), lineupName)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPostalCode), postalCode)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLineupInfoType), lineupInfoType)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kOperatorName), operatorName); + encoder.Encode(to_underlying(Fields::kLineupName), lineupName); + encoder.Encode(to_underlying(Fields::kPostalCode), postalCode); + encoder.Encode(to_underlying(Fields::kLineupInfoType), lineupInfoType); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -17872,10 +17636,9 @@ namespace Commands { namespace ChangeChannel { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMatch), match)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMatch), match); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -17907,11 +17670,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ChangeChannelResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kData), data)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kData), data); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -17947,11 +17709,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ChangeChannelByNumber { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMajorNumber), majorNumber)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMinorNumber), minorNumber)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMajorNumber), majorNumber); + encoder.Encode(to_underlying(Fields::kMinorNumber), minorNumber); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -17987,10 +17748,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SkipChannel { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kCount), count)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kCount), count); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18055,15 +17815,14 @@ namespace Events {} // namespace Events } // namespace Channel namespace TargetNavigator { namespace Structs { + namespace TargetInfoStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIdentifier), identifier)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kIdentifier), identifier); + encoder.Encode(to_underlying(Fields::kName), name); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18103,11 +17862,10 @@ namespace Commands { namespace NavigateTarget { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTarget), target)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kData), data)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kTarget), target); + encoder.Encode(to_underlying(Fields::kData), data); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18143,11 +17901,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace NavigateTargetResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kData), data)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kData), data); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18214,15 +17971,14 @@ namespace Events {} // namespace Events } // namespace TargetNavigator namespace MediaPlayback { namespace Structs { + namespace PlaybackPositionStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kUpdatedAt), updatedAt)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPosition), position)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kUpdatedAt), updatedAt); + encoder.Encode(to_underlying(Fields::kPosition), position); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18262,9 +18018,8 @@ namespace Commands { namespace Play { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18283,9 +18038,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Pause { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18304,9 +18058,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Stop { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18325,9 +18078,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StartOver { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18346,9 +18098,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Previous { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18367,9 +18118,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Next { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18388,9 +18138,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Rewind { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18409,9 +18158,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace FastForward { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18430,11 +18178,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SkipForward { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDeltaPositionMilliseconds), deltaPositionMilliseconds)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kDeltaPositionMilliseconds), deltaPositionMilliseconds); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18466,11 +18212,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SkipBackward { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDeltaPositionMilliseconds), deltaPositionMilliseconds)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kDeltaPositionMilliseconds), deltaPositionMilliseconds); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18502,11 +18246,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace PlaybackResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kData), data)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kData), data); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18542,10 +18285,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Seek { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPosition), position)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kPosition), position); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18618,17 +18360,16 @@ namespace Events {} // namespace Events } // namespace MediaPlayback namespace MediaInput { namespace Structs { + namespace InputInfoStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIndex), index)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kInputType), inputType)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDescription), description)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kIndex), index); + encoder.Encode(to_underlying(Fields::kInputType), inputType); + encoder.Encode(to_underlying(Fields::kName), name); + encoder.Encode(to_underlying(Fields::kDescription), description); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18676,10 +18417,9 @@ namespace Commands { namespace SelectInput { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIndex), index)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kIndex), index); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18711,9 +18451,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace ShowInputStatus { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18732,9 +18471,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace HideInputStatus { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18753,11 +18491,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RenameInput { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIndex), index)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kIndex), index); + encoder.Encode(to_underlying(Fields::kName), name); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18828,9 +18565,8 @@ namespace Commands { namespace Sleep { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18880,10 +18616,9 @@ namespace Commands { namespace SendKey { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kKeyCode), keyCode)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kKeyCode), keyCode); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18915,10 +18650,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SendKeyResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -18977,16 +18711,15 @@ namespace Events {} // namespace Events } // namespace KeypadInput namespace ContentLauncher { namespace Structs { + namespace DimensionStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWidth), width)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kHeight), height)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMetric), metric)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kWidth), width); + encoder.Encode(to_underlying(Fields::kHeight), height); + encoder.Encode(to_underlying(Fields::kMetric), metric); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19024,15 +18757,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace DimensionStruct + namespace AdditionalInfoStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValue), value)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kName), name); + encoder.Encode(to_underlying(Fields::kValue), value); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19066,16 +18798,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace AdditionalInfoStruct + namespace ParameterStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kType), type)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValue), value)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kExternalIDList), externalIDList)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kType), type); + encoder.Encode(to_underlying(Fields::kValue), value); + encoder.Encode(to_underlying(Fields::kExternalIDList), externalIDList); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19113,14 +18844,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace ParameterStruct + namespace ContentSearchStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kParameterList), parameterList)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kParameterList), parameterList); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19150,16 +18880,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace ContentSearchStruct + namespace StyleInformationStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kImageURL), imageURL)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kColor), color)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSize), size)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kImageURL), imageURL); + encoder.Encode(to_underlying(Fields::kColor), color); + encoder.Encode(to_underlying(Fields::kSize), size); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19197,19 +18926,18 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace StyleInformationStruct + namespace BrandingInformationStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProviderName), providerName)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBackground), background)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kLogo), logo)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProgressBar), progressBar)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSplash), splash)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWaterMark), waterMark)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kProviderName), providerName); + encoder.Encode(to_underlying(Fields::kBackground), background); + encoder.Encode(to_underlying(Fields::kLogo), logo); + encoder.Encode(to_underlying(Fields::kProgressBar), progressBar); + encoder.Encode(to_underlying(Fields::kSplash), splash); + encoder.Encode(to_underlying(Fields::kWaterMark), waterMark); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19265,12 +18993,11 @@ namespace Commands { namespace LaunchContent { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSearch), search)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAutoPlay), autoPlay)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kData), data)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kSearch), search); + encoder.Encode(to_underlying(Fields::kAutoPlay), autoPlay); + encoder.Encode(to_underlying(Fields::kData), data); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19310,12 +19037,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace LaunchURL { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kContentURL), contentURL)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kDisplayString), displayString)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kBrandingInformation), brandingInformation)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kContentURL), contentURL); + encoder.Encode(to_underlying(Fields::kDisplayString), displayString); + encoder.Encode(to_underlying(Fields::kBrandingInformation), brandingInformation); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19355,11 +19081,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace LauncherResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kData), data)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kData), data); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19426,16 +19151,15 @@ namespace Events {} // namespace Events } // namespace ContentLauncher namespace AudioOutput { namespace Structs { + namespace OutputInfoStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIndex), index)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOutputType), outputType)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kIndex), index); + encoder.Encode(to_underlying(Fields::kOutputType), outputType); + encoder.Encode(to_underlying(Fields::kName), name); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19479,10 +19203,9 @@ namespace Commands { namespace SelectOutput { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIndex), index)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kIndex), index); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19514,11 +19237,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace RenameOutput { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIndex), index)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kName), name)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kIndex), index); + encoder.Encode(to_underlying(Fields::kName), name); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19585,15 +19307,14 @@ namespace Events {} // namespace Events } // namespace AudioOutput namespace ApplicationLauncher { namespace Structs { + namespace ApplicationEPStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kApplication), application)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kEndpoint), endpoint)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kApplication), application); + encoder.Encode(to_underlying(Fields::kEndpoint), endpoint); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19633,11 +19354,10 @@ namespace Commands { namespace LaunchApp { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kApplication), application)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kData), data)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kApplication), application); + encoder.Encode(to_underlying(Fields::kData), data); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19673,10 +19393,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace StopApp { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kApplication), application)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kApplication), application); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19708,10 +19427,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace HideApp { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kApplication), application)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kApplication), application); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19743,11 +19461,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace LauncherResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kData), data)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kData), data); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19865,10 +19582,9 @@ namespace Commands { namespace GetSetupPIN { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTempAccountIdentifier), tempAccountIdentifier)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kTempAccountIdentifier), tempAccountIdentifier); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19900,10 +19616,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetSetupPINResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSetupPIN), setupPIN)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kSetupPIN), setupPIN); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19935,11 +19650,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Login { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTempAccountIdentifier), tempAccountIdentifier)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kSetupPIN), setupPIN)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kTempAccountIdentifier), tempAccountIdentifier); + encoder.Encode(to_underlying(Fields::kSetupPIN), setupPIN); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -19975,9 +19689,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace Logout { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20027,13 +19740,12 @@ namespace Commands { namespace GetProfileInfoResponseCommand { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProfileCount), profileCount)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProfileIntervalPeriod), profileIntervalPeriod)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMaxNumberOfIntervals), maxNumberOfIntervals)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kListOfAttributes), listOfAttributes)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kProfileCount), profileCount); + encoder.Encode(to_underlying(Fields::kProfileIntervalPeriod), profileIntervalPeriod); + encoder.Encode(to_underlying(Fields::kMaxNumberOfIntervals), maxNumberOfIntervals); + encoder.Encode(to_underlying(Fields::kListOfAttributes), listOfAttributes); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20077,9 +19789,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetProfileInfoCommand { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20098,16 +19809,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetMeasurementProfileResponseCommand { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStartTime), startTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStatus), status)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kProfileIntervalPeriod), profileIntervalPeriod)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNumberOfIntervalsDelivered), numberOfIntervalsDelivered)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAttributeId), attributeId)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kIntervals), intervals)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kStartTime), startTime); + encoder.Encode(to_underlying(Fields::kStatus), status); + encoder.Encode(to_underlying(Fields::kProfileIntervalPeriod), profileIntervalPeriod); + encoder.Encode(to_underlying(Fields::kNumberOfIntervalsDelivered), numberOfIntervalsDelivered); + encoder.Encode(to_underlying(Fields::kAttributeId), attributeId); + encoder.Encode(to_underlying(Fields::kIntervals), intervals); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20159,12 +19868,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace GetMeasurementProfileCommand { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kAttributeId), attributeId)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kStartTime), startTime)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNumberOfIntervals), numberOfIntervals)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kAttributeId), attributeId); + encoder.Encode(to_underlying(Fields::kStartTime), startTime); + encoder.Encode(to_underlying(Fields::kNumberOfIntervals), numberOfIntervals); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20487,21 +20195,20 @@ namespace Events {} // namespace Events } // namespace ElectricalMeasurement namespace UnitTesting { namespace Structs { + namespace SimpleStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kA), a)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kB), b)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kC), c)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kD), d)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kE), e)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kF), f)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kG), g)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kH), h)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kA), a); + encoder.Encode(to_underlying(Fields::kB), b); + encoder.Encode(to_underlying(Fields::kC), c); + encoder.Encode(to_underlying(Fields::kD), d); + encoder.Encode(to_underlying(Fields::kE), e); + encoder.Encode(to_underlying(Fields::kF), f); + encoder.Encode(to_underlying(Fields::kG), g); + encoder.Encode(to_underlying(Fields::kH), h); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20559,6 +20266,7 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace SimpleStruct + namespace TestFabricScoped { CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -20573,47 +20281,43 @@ CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIn CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional & aAccessingFabricIndex) const { bool includeSensitive = !aAccessingFabricIndex.HasValue() || (aAccessingFabricIndex.Value() == fabricIndex); - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricSensitiveInt8u), fabricSensitiveInt8u)); + encoder.Encode(to_underlying(Fields::kFabricSensitiveInt8u), fabricSensitiveInt8u); } if (includeSensitive) { - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalFabricSensitiveInt8u), optionalFabricSensitiveInt8u)); + encoder.Encode(to_underlying(Fields::kOptionalFabricSensitiveInt8u), optionalFabricSensitiveInt8u); } if (includeSensitive) { - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableFabricSensitiveInt8u), nullableFabricSensitiveInt8u)); + encoder.Encode(to_underlying(Fields::kNullableFabricSensitiveInt8u), nullableFabricSensitiveInt8u); } if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalFabricSensitiveInt8u), - nullableOptionalFabricSensitiveInt8u)); + encoder.Encode(to_underlying(Fields::kNullableOptionalFabricSensitiveInt8u), nullableOptionalFabricSensitiveInt8u); } if (includeSensitive) { - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricSensitiveCharString), fabricSensitiveCharString)); + encoder.Encode(to_underlying(Fields::kFabricSensitiveCharString), fabricSensitiveCharString); } if (includeSensitive) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricSensitiveStruct), fabricSensitiveStruct)); + encoder.Encode(to_underlying(Fields::kFabricSensitiveStruct), fabricSensitiveStruct); } if (includeSensitive) { - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricSensitiveInt8uList), fabricSensitiveInt8uList)); + encoder.Encode(to_underlying(Fields::kFabricSensitiveInt8uList), fabricSensitiveInt8uList); } if (aAccessingFabricIndex.HasValue()) { - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex)); + encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex); } - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20671,25 +20375,24 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace TestFabricScoped + namespace NullablesAndOptionalsStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableInt), nullableInt)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalInt), optionalInt)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalInt), nullableOptionalInt)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableString), nullableString)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalString), optionalString)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalString), nullableOptionalString)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableStruct), nullableStruct)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalStruct), optionalStruct)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalStruct), nullableOptionalStruct)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableList), nullableList)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalList), optionalList)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalList), nullableOptionalList)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNullableInt), nullableInt); + encoder.Encode(to_underlying(Fields::kOptionalInt), optionalInt); + encoder.Encode(to_underlying(Fields::kNullableOptionalInt), nullableOptionalInt); + encoder.Encode(to_underlying(Fields::kNullableString), nullableString); + encoder.Encode(to_underlying(Fields::kOptionalString), optionalString); + encoder.Encode(to_underlying(Fields::kNullableOptionalString), nullableOptionalString); + encoder.Encode(to_underlying(Fields::kNullableStruct), nullableStruct); + encoder.Encode(to_underlying(Fields::kOptionalStruct), optionalStruct); + encoder.Encode(to_underlying(Fields::kNullableOptionalStruct), nullableOptionalStruct); + encoder.Encode(to_underlying(Fields::kNullableList), nullableList); + encoder.Encode(to_underlying(Fields::kOptionalList), optionalList); + encoder.Encode(to_underlying(Fields::kNullableOptionalList), nullableOptionalList); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20763,16 +20466,15 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace NullablesAndOptionalsStruct + namespace NestedStruct { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kA), a)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kB), b)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kC), c)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kA), a); + encoder.Encode(to_underlying(Fields::kB), b); + encoder.Encode(to_underlying(Fields::kC), c); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20810,20 +20512,19 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace NestedStruct + namespace NestedStructList { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kA), a)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kB), b)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kC), c)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kD), d)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kE), e)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kF), f)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kG), g)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kA), a); + encoder.Encode(to_underlying(Fields::kB), b); + encoder.Encode(to_underlying(Fields::kC), c); + encoder.Encode(to_underlying(Fields::kD), d); + encoder.Encode(to_underlying(Fields::kE), e); + encoder.Encode(to_underlying(Fields::kF), f); + encoder.Encode(to_underlying(Fields::kG), g); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20877,14 +20578,13 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace NestedStructList + namespace DoubleNestedStructList { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kA), a)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kA), a); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20914,15 +20614,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } // namespace DoubleNestedStructList + namespace TestListStructOctet { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMember1), member1)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMember2), member2)); - ReturnErrorOnFailure(aWriter.EndContainer(outer)); - return CHIP_NO_ERROR; + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMember1), member1); + encoder.Encode(to_underlying(Fields::kMember2), member2); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20962,9 +20661,8 @@ namespace Commands { namespace Test { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -20983,10 +20681,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestSpecificResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kReturnValue), returnValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kReturnValue), returnValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21018,9 +20715,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestNotHandled { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21039,10 +20735,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestAddArgumentsResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kReturnValue), returnValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kReturnValue), returnValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21074,9 +20769,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestSpecific { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21095,10 +20789,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestSimpleArgumentResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kReturnValue), returnValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kReturnValue), returnValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21130,9 +20823,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestUnknownCommand { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21151,15 +20843,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestStructArrayArgumentResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg2), arg2)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg3), arg3)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg4), arg4)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg5), arg5)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg6), arg6)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + encoder.Encode(to_underlying(Fields::kArg2), arg2); + encoder.Encode(to_underlying(Fields::kArg3), arg3); + encoder.Encode(to_underlying(Fields::kArg4), arg4); + encoder.Encode(to_underlying(Fields::kArg5), arg5); + encoder.Encode(to_underlying(Fields::kArg6), arg6); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21211,11 +20902,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestAddArguments { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg2), arg2)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + encoder.Encode(to_underlying(Fields::kArg2), arg2); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21251,10 +20941,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestListInt8UReverseResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21286,10 +20975,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestSimpleArgumentRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21321,11 +21009,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestEnumsResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg2), arg2)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + encoder.Encode(to_underlying(Fields::kArg2), arg2); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21361,15 +21048,14 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestStructArrayArgumentRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg2), arg2)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg3), arg3)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg4), arg4)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg5), arg5)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg6), arg6)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + encoder.Encode(to_underlying(Fields::kArg2), arg2); + encoder.Encode(to_underlying(Fields::kArg3), arg3); + encoder.Encode(to_underlying(Fields::kArg4), arg4); + encoder.Encode(to_underlying(Fields::kArg5), arg5); + encoder.Encode(to_underlying(Fields::kArg6), arg6); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21421,13 +21107,12 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestNullableOptionalResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWasPresent), wasPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kWasNull), wasNull)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValue), value)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOriginalValue), originalValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kWasPresent), wasPresent); + encoder.Encode(to_underlying(Fields::kWasNull), wasNull); + encoder.Encode(to_underlying(Fields::kValue), value); + encoder.Encode(to_underlying(Fields::kOriginalValue), originalValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21471,10 +21156,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestStructArgumentRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21506,48 +21190,36 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestComplexNullableOptionalResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableIntWasNull), nullableIntWasNull)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableIntValue), nullableIntValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalIntWasPresent), optionalIntWasPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalIntValue), optionalIntValue)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalIntWasPresent), nullableOptionalIntWasPresent)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalIntWasNull), nullableOptionalIntWasNull)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalIntValue), nullableOptionalIntValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableStringWasNull), nullableStringWasNull)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableStringValue), nullableStringValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalStringWasPresent), optionalStringWasPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalStringValue), optionalStringValue)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalStringWasPresent), nullableOptionalStringWasPresent)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalStringWasNull), nullableOptionalStringWasNull)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalStringValue), nullableOptionalStringValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableStructWasNull), nullableStructWasNull)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableStructValue), nullableStructValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalStructWasPresent), optionalStructWasPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalStructValue), optionalStructValue)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalStructWasPresent), nullableOptionalStructWasPresent)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalStructWasNull), nullableOptionalStructWasNull)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalStructValue), nullableOptionalStructValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableListWasNull), nullableListWasNull)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableListValue), nullableListValue)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalListWasPresent), optionalListWasPresent)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalListValue), optionalListValue)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalListWasPresent), nullableOptionalListWasPresent)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalListWasNull), nullableOptionalListWasNull)); - ReturnErrorOnFailure( - DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalListValue), nullableOptionalListValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNullableIntWasNull), nullableIntWasNull); + encoder.Encode(to_underlying(Fields::kNullableIntValue), nullableIntValue); + encoder.Encode(to_underlying(Fields::kOptionalIntWasPresent), optionalIntWasPresent); + encoder.Encode(to_underlying(Fields::kOptionalIntValue), optionalIntValue); + encoder.Encode(to_underlying(Fields::kNullableOptionalIntWasPresent), nullableOptionalIntWasPresent); + encoder.Encode(to_underlying(Fields::kNullableOptionalIntWasNull), nullableOptionalIntWasNull); + encoder.Encode(to_underlying(Fields::kNullableOptionalIntValue), nullableOptionalIntValue); + encoder.Encode(to_underlying(Fields::kNullableStringWasNull), nullableStringWasNull); + encoder.Encode(to_underlying(Fields::kNullableStringValue), nullableStringValue); + encoder.Encode(to_underlying(Fields::kOptionalStringWasPresent), optionalStringWasPresent); + encoder.Encode(to_underlying(Fields::kOptionalStringValue), optionalStringValue); + encoder.Encode(to_underlying(Fields::kNullableOptionalStringWasPresent), nullableOptionalStringWasPresent); + encoder.Encode(to_underlying(Fields::kNullableOptionalStringWasNull), nullableOptionalStringWasNull); + encoder.Encode(to_underlying(Fields::kNullableOptionalStringValue), nullableOptionalStringValue); + encoder.Encode(to_underlying(Fields::kNullableStructWasNull), nullableStructWasNull); + encoder.Encode(to_underlying(Fields::kNullableStructValue), nullableStructValue); + encoder.Encode(to_underlying(Fields::kOptionalStructWasPresent), optionalStructWasPresent); + encoder.Encode(to_underlying(Fields::kOptionalStructValue), optionalStructValue); + encoder.Encode(to_underlying(Fields::kNullableOptionalStructWasPresent), nullableOptionalStructWasPresent); + encoder.Encode(to_underlying(Fields::kNullableOptionalStructWasNull), nullableOptionalStructWasNull); + encoder.Encode(to_underlying(Fields::kNullableOptionalStructValue), nullableOptionalStructValue); + encoder.Encode(to_underlying(Fields::kNullableListWasNull), nullableListWasNull); + encoder.Encode(to_underlying(Fields::kNullableListValue), nullableListValue); + encoder.Encode(to_underlying(Fields::kOptionalListWasPresent), optionalListWasPresent); + encoder.Encode(to_underlying(Fields::kOptionalListValue), optionalListValue); + encoder.Encode(to_underlying(Fields::kNullableOptionalListWasPresent), nullableOptionalListWasPresent); + encoder.Encode(to_underlying(Fields::kNullableOptionalListWasNull), nullableOptionalListWasNull); + encoder.Encode(to_underlying(Fields::kNullableOptionalListValue), nullableOptionalListValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21687,10 +21359,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestNestedStructArgumentRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21722,10 +21393,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace BooleanResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValue), value)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kValue), value); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21757,10 +21427,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestListStructArgumentRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21792,10 +21461,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SimpleStructResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21827,10 +21495,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestListInt8UArgumentRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21862,10 +21529,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestEmitTestEventResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValue), value)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kValue), value); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21897,10 +21563,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestNestedStructListArgumentRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21932,10 +21597,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestEmitTestFabricScopedEventResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kValue), value)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kValue), value); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -21967,10 +21631,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestListNestedStructListArgumentRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22002,10 +21665,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestListInt8UReverseRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22037,11 +21699,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestEnumsRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg2), arg2)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + encoder.Encode(to_underlying(Fields::kArg2), arg2); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22077,10 +21738,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestNullableOptionalRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22112,21 +21772,20 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestComplexNullableOptionalRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableInt), nullableInt)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalInt), optionalInt)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalInt), nullableOptionalInt)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableString), nullableString)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalString), optionalString)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalString), nullableOptionalString)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableStruct), nullableStruct)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalStruct), optionalStruct)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalStruct), nullableOptionalStruct)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableList), nullableList)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kOptionalList), optionalList)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNullableOptionalList), nullableOptionalList)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kNullableInt), nullableInt); + encoder.Encode(to_underlying(Fields::kOptionalInt), optionalInt); + encoder.Encode(to_underlying(Fields::kNullableOptionalInt), nullableOptionalInt); + encoder.Encode(to_underlying(Fields::kNullableString), nullableString); + encoder.Encode(to_underlying(Fields::kOptionalString), optionalString); + encoder.Encode(to_underlying(Fields::kNullableOptionalString), nullableOptionalString); + encoder.Encode(to_underlying(Fields::kNullableStruct), nullableStruct); + encoder.Encode(to_underlying(Fields::kOptionalStruct), optionalStruct); + encoder.Encode(to_underlying(Fields::kNullableOptionalStruct), nullableOptionalStruct); + encoder.Encode(to_underlying(Fields::kNullableList), nullableList); + encoder.Encode(to_underlying(Fields::kOptionalList), optionalList); + encoder.Encode(to_underlying(Fields::kNullableOptionalList), nullableOptionalList); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22202,10 +21861,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace SimpleStructEchoRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22237,9 +21895,8 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TimedInvokeRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22258,10 +21915,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestSimpleOptionalArgumentRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22293,12 +21949,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestEmitTestEventRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg2), arg2)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg3), arg3)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + encoder.Encode(to_underlying(Fields::kArg2), arg2); + encoder.Encode(to_underlying(Fields::kArg3), arg3); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22338,10 +21993,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace TestEmitTestFabricScopedEventRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22664,14 +22318,13 @@ namespace Commands { namespace FailAtFault { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kType), type)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kId), id)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNumCallsToSkip), numCallsToSkip)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNumCallsToFail), numCallsToFail)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kTakeMutex), takeMutex)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kType), type); + encoder.Encode(to_underlying(Fields::kId), id); + encoder.Encode(to_underlying(Fields::kNumCallsToSkip), numCallsToSkip); + encoder.Encode(to_underlying(Fields::kNumCallsToFail), numCallsToFail); + encoder.Encode(to_underlying(Fields::kTakeMutex), takeMutex); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22719,12 +22372,11 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace FailRandomlyAtFault { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kType), type)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kId), id)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kPercentage), percentage)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kType), type); + encoder.Encode(to_underlying(Fields::kId), id); + encoder.Encode(to_underlying(Fields::kPercentage), percentage); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22795,9 +22447,8 @@ namespace Commands { namespace Ping { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22816,10 +22467,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace AddArgumentsResponse { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kReturnValue), returnValue)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kReturnValue), returnValue); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) @@ -22851,11 +22501,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) namespace AddArguments { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { - TLV::TLVType outer; - ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg1), arg1)); - ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kArg2), arg2)); - return aWriter.EndContainer(outer); + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kArg1), arg1); + encoder.Encode(to_underlying(Fields::kArg2), arg2); + return encoder.Finalize(); } CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)