MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / parsePermissions

Method parsePermissions

tools/bles2gatt.js:940–971  ·  view source on GitHub ↗
(permissions)

Source from the content-addressed store, hash-verified

938 return props.join('|');
939 }
940 parsePermissions(permissions) {
941 let perms = [];
942 let readPerms = 0;
943 let writePerms = 0;
944 permissions.forEach(p => {
945 switch(p.trim()) {
946 case "read":
947 ++readPerms;
948 perms.push("QAPI_BLE_GATT_ATTRIBUTE_FLAGS_READABLE");
949 break;
950 case "readEncrypted":
951 ++readPerms;
952 perms.push("QAPI_BLE_GATT_ATTRIBUTE_FLAGS_READABLE");
953 break;
954 case "write":
955 ++writePerms;
956 perms.push("QAPI_BLE_GATT_ATTRIBUTE_FLAGS_WRITABLE");
957 break;
958 case "writeEncrypted":
959 ++writePerms;
960 perms.push("QAPI_BLE_GATT_ATTRIBUTE_FLAGS_WRITABLE");
961 break;
962 default:
963 throw new Error("unsupported permission");
964 }
965 });
966 if (readPerms > 1)
967 throw new Error("only one of read/readEncrypted can be specified");
968 if (writePerms > 1)
969 throw new Error("only one of write/writeEncrypted can be specified");
970 return perms.join('|');
971 }
972 isEncrypted(characteristic) {
973 let encrypted = (-1 != characteristic.permissions.indexOf("readEncrypted") || -1 != characteristic.permissions.indexOf("writeEncrypted"));
974 return encrypted ? 1 : 0;

Callers 1

generateMethod · 0.95

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected