Skip to content

Commit

Permalink
zapTypeToDecodableClusterObjectType does not throw on ambiguous types
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and woody-apple committed Jan 26, 2022
1 parent 99c7249 commit 317ea68
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,38 @@ async function zapTypeToClusterObjectType(type, isDecodable, options)
const ns = options.hash.ns ? ('chip::app::Clusters::' + nsValueToNamespace(options.hash.ns) + '::') : '';
const typeChecker = async (method) => zclHelper[method](this.global.db, type, pkgId).then(zclType => zclType != 'unknown');

if (await typeChecker('isEnum')) {
const types = {
isEnum : await typeChecker('isEnum'),
isBitmap : await typeChecker('isBitmap'),
isEvent : await typeChecker('isEvent'),
isStruct : await typeChecker('isStruct'),
};

const typesCount = Object.values(types).filter(isType => isType).length;
if (typesCount > 1) {
let error = type + ' is ambiguous: \n';
Object.entries(types).forEach(([ key, value ]) => {
if (value) {
error += '\t' + key + ': ' + value + '\n';
}
});
throw error;
}

if (types.isEnum) {
return ns + type;
}

if (await typeChecker('isBitmap')) {
if (types.isBitmap) {
return 'chip::BitFlags<' + ns + type + '>';
}

if (await typeChecker('isStruct')) {
if (types.isStruct) {
passByReference = true;
return ns + 'Structs::' + type + '::' + (isDecodable ? 'DecodableType' : 'Type');
}

if (await typeChecker('isEvent')) {
if (types.isEvent) {
passByReference = true;
return ns + 'Events::' + type + '::' + (isDecodable ? 'DecodableType' : 'Type');
}
Expand Down

0 comments on commit 317ea68

Please sign in to comment.