| {{#if header}} |
| namespace {{asUpperCamelCase name}} { |
| enum class Fields : uint8_t { |
| {{#zcl_struct_items}} |
| k{{asUpperCamelCase label}} = {{fieldIdentifier}}, |
| {{/zcl_struct_items}} |
| }; |
| |
| struct Type { |
| public: |
| {{#zcl_struct_items}} |
| {{zapTypeToEncodableClusterObjectType type}} {{asLowerCamelCase label}}{{> cluster_objects_field_init}}; |
| {{/zcl_struct_items}} |
| |
| {{#unless struct_contains_array}} |
| CHIP_ERROR Decode(TLV::TLVReader &reader); |
| {{/unless}} |
| |
| static constexpr bool kIsFabricScoped = {{isFabricScoped}}; |
| |
| {{#if isFabricScoped}} |
| auto GetFabricIndex() const { |
| return fabricIndex; |
| } |
| |
| void SetFabricIndex(chip::FabricIndex fabricIndex_) { |
| fabricIndex = fabricIndex_; |
| } |
| |
| CHIP_ERROR EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; |
| CHIP_ERROR EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIndex aAccessingFabricIndex) const; |
| |
| private: |
| CHIP_ERROR DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional<FabricIndex> & aAccessingFabricIndex) const; |
| {{else}} |
| CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; |
| {{/if}} |
| }; |
| |
| {{#if struct_contains_array}} |
| struct DecodableType { |
| public: |
| {{#zcl_struct_items}} |
| {{zapTypeToDecodableClusterObjectType type}} {{asLowerCamelCase label}}{{> cluster_objects_field_init}}; |
| {{/zcl_struct_items}} |
| |
| CHIP_ERROR Decode(TLV::TLVReader &reader); |
| |
| static constexpr bool kIsFabricScoped = {{isFabricScoped}}; |
| |
| {{#if isFabricScoped}} |
| auto GetFabricIndex() const { |
| return fabricIndex; |
| } |
| |
| void SetFabricIndex(chip::FabricIndex fabricIndex_) { |
| fabricIndex = fabricIndex_; |
| } |
| {{/if}} |
| }; |
| {{else}} |
| using DecodableType = Type; |
| {{/if}} |
| |
| } // namespace {{asUpperCamelCase name}} |
| {{else}} |
| namespace {{asUpperCamelCase name}} { |
| {{#if isFabricScoped}} |
| CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const |
| { |
| return DoEncode(aWriter, aTag, NullOptional); |
| } |
| |
| CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIndex aAccessingFabricIndex) const |
| { |
| return DoEncode(aWriter, aTag, MakeOptional(aAccessingFabricIndex)); |
| } |
| |
| CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional<FabricIndex> & aAccessingFabricIndex) const |
| { |
| {{#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)); |
| {{#zcl_struct_items}} |
| {{#if (is_num_equal fieldIdentifier 254)}} |
| if (aAccessingFabricIndex.HasValue()) { |
| ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}})); |
| } |
| {{else if isFabricSensitive}} |
| if (includeSensitive) { |
| ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}})); |
| } |
| {{else}} |
| ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}})); |
| {{/if}} |
| {{/zcl_struct_items}} |
| ReturnErrorOnFailure(aWriter.EndContainer(outer)); |
| return CHIP_NO_ERROR; |
| } |
| {{else}} |
| CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const |
| { |
| TLV::TLVType outer; |
| ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); |
| {{#zcl_struct_items}} |
| ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}})); |
| {{/zcl_struct_items}} |
| ReturnErrorOnFailure(aWriter.EndContainer(outer)); |
| return CHIP_NO_ERROR; |
| } |
| {{/if}} |
| |
| CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) { |
| CHIP_ERROR err = CHIP_NO_ERROR; |
| TLV::TLVType outer; |
| VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); |
| err = reader.EnterContainer(outer); |
| ReturnErrorOnFailure(err); |
| while ((err = reader.Next()) == CHIP_NO_ERROR) { |
| if (!TLV::IsContextTag(reader.GetTag())) |
| { |
| continue; |
| } |
| switch (TLV::TagNumFromTag(reader.GetTag())) |
| { |
| {{#zcl_struct_items}} |
| case to_underlying(Fields::k{{asUpperCamelCase label}}): |
| ReturnErrorOnFailure(DataModel::Decode(reader, {{asLowerCamelCase label}})); |
| break; |
| {{/zcl_struct_items}} |
| default: |
| break; |
| } |
| } |
| |
| VerifyOrReturnError(err == CHIP_END_OF_TLV, err); |
| ReturnErrorOnFailure(reader.ExitContainer(outer)); |
| |
| return CHIP_NO_ERROR; |
| } |
| |
| } // namespace {{asUpperCamelCase name}} |
| {{/if}} |