Skip to content

Use sequence instead of map for data filters - #545

Merged
beaufortfrancois merged 2 commits into
mainfrom
data-filter
Apr 29, 2021
Merged

Use sequence instead of map for data filters#545
beaufortfrancois merged 2 commits into
mainfrom
data-filter

Conversation

@beaufortfrancois

@beaufortfrancois beaufortfrancois commented Apr 27, 2021

Copy link
Copy Markdown
Member

The more I'm playing with manufacturer data filters, the more I think we should go with a sequence instead of a map in BluetoothLEScanFilterInit for both manufacturerData and serviceData.

Because users can have different strings to express the same uint16 ('0' and '00' for instance), we'll have to check for the unicity of the key which is what we're doing already with a sequence.
Moreover, having a required companyIdentifier dictionary key seems more readable than a simple object key.

I've added some code samples below to give you an idea of what I'm experiencing.

// It's not easy to understand what we're filtering on at first glance and the
// empty object isn't nice to read as well.
let manufacturerData = { 0x00e0: {} };
navigator.bluetooth.requestDevice({ filters: [{ manufacturerData }] });

// And with the base-10 serialization of a uint16, it's not much better.
// We would have to handle the `0x` case among others or let developers do it.
let manufacturerData = { "224": {} };
navigator.bluetooth.requestDevice({ filters: [{ manufacturerData }] });

And here's what I'm proposing:

// [NEW] Simplest form.
let manufacturerData = [{ companyIdentifier: 0x00e0 }];
navigator.bluetooth.requestDevice({ filters: [{ manufacturerData }] });

// [NEW] Full filtering on manufacturer data.
let manufacturerData = [
  {
    companyIdentifier: 0x00e0,
    dataPrefix: new Uint8Array([0x01, 0x02, 0x03, 0x04]),
    mask: new Uint8Array([0xff, 0xff, 0xff, 0x00]),
  },
];
navigator.bluetooth.requestDevice({ filters: [{ manufacturerData }] });

@reillyeon What do you think?


Preview | Diff

@beaufortfrancois

Copy link
Copy Markdown
Member Author

Note that CI should succeed once #546 is merged.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 27, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Comment thread index.bs Outdated
1. Let |canonicalizedDataFilter| be the result of <a
for="BluetoothDataFilterInit">canonicalizing</a> |dataFilter|,
present and
<code>|filter|.{{BluetoothLEScanFilterInit/manufacturerData}}.length === 0</code>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit, as was pointed out to me on the most recent specifications I worked on, the correct syntax for referring to a member of a dictionary is filter["manufacturerData"] rather than filter.manufacturerData. We should do a pass to fix this over the whole specification but might as well avoid introducing new examples of the old style.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
[
{
manufacturerData: [
{ companyIdentifier: 17, dataPrefix: new Uint8Array([1, 2, 3]) },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put companyIdentifier and dataPrefix on separate lines in this and the next two examples to avoid this table column becoming too wide.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
1. For each |manufacturerData| in
<code>|filter|.{{BluetoothLEScanFilterInit/manufacturerData}}</code>, do the following sub-steps:
1. If <code>|manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}}</code>
is present in |canonicalizedFilter|.manufacturerData,

@reillyeon reillyeon Apr 27, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably be more specific about what "present" means here. Something like, "If there exists a object |existing| in |canonicalizedFilter|["manufacturerData"] where |existing|["companyIdentifier"] === |manufacturerData|["companyIdentifier"], throw..."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
for="BluetoothDataFilterInit">canonicalizing</a> |manufacturerData|,
<a>converted to an ECMAScript value</a>. If this throws an exception,
propagate that exception and abort these steps.
1. Call <a abstract-op>CreateDataProperty</a>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since canonicalizedFilter["manufacturerData"] is now a sequence rather than an object we can append to it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
@@ -1400,51 +1431,42 @@ returned from the following steps:
<code><var>filter</var>.namePrefix</code>.
1. Set <code>|canonicalizedFilter|.manufacturerData</code> to `{}`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize canonicalizedFilter["manufacturerData"] to an empty array rather than an empty object.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
(|canonicalizedFilter|.manufacturerData,
<code>|manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}}</code>,
|canonicalizedManufacturerDataFilter|).
1. Set <code>|canonicalizedFilter|.serviceData</code> to `{}`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
<a>converted to an ECMAScript value</a>. If this throws an exception,
propagate that exception and abort these steps.
1. Call <a
abstract-op>CreateDataProperty</a>(|canonicalizedFilter|.serviceData,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread scanning.bs Outdated
type:enum-value; for:PermissionName; text:"bluetooth"
spec: permissions-1
type: enum-value
text: "bluetooth"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #546 you only removed the conflicting enum value above. Is this change also necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not anymore. Thanks for catching!

@beaufortfrancois beaufortfrancois left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

Comment thread index.bs Outdated
[
{
manufacturerData: [
{ companyIdentifier: 17, dataPrefix: new Uint8Array([1, 2, 3]) },

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
1. Let |canonicalizedDataFilter| be the result of <a
for="BluetoothDataFilterInit">canonicalizing</a> |dataFilter|,
present and
<code>|filter|.{{BluetoothLEScanFilterInit/manufacturerData}}.length === 0</code>,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
1. For each |manufacturerData| in
<code>|filter|.{{BluetoothLEScanFilterInit/manufacturerData}}</code>, do the following sub-steps:
1. If <code>|manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}}</code>
is present in |canonicalizedFilter|.manufacturerData,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread scanning.bs Outdated
type:enum-value; for:PermissionName; text:"bluetooth"
spec: permissions-1
type: enum-value
text: "bluetooth"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not anymore. Thanks for catching!

Comment thread index.bs Outdated
for="BluetoothDataFilterInit">canonicalizing</a> |manufacturerData|,
<a>converted to an ECMAScript value</a>. If this throws an exception,
propagate that exception and abort these steps.
1. Call <a abstract-op>CreateDataProperty</a>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
(|canonicalizedFilter|.manufacturerData,
<code>|manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}}</code>,
|canonicalizedManufacturerDataFilter|).
1. Set <code>|canonicalizedFilter|.serviceData</code> to `{}`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
<a>converted to an ECMAScript value</a>. If this throws an exception,
propagate that exception and abort these steps.
1. Call <a
abstract-op>CreateDataProperty</a>(|canonicalizedFilter|.serviceData,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread index.bs Outdated
@@ -1400,51 +1431,42 @@ returned from the following steps:
<code><var>filter</var>.namePrefix</code>.
1. Set <code>|canonicalizedFilter|.manufacturerData</code> to `{}`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 28, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 28, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
@beaufortfrancois
beaufortfrancois merged commit d9eeae5 into main Apr 29, 2021
@beaufortfrancois
beaufortfrancois deleted the data-filter branch April 29, 2021 07:23
github-actions Bot added a commit that referenced this pull request Apr 29, 2021
SHA: d9eeae5
Reason: push, by @beaufortfrancois

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Apr 29, 2021
SHA: d9eeae5
Reason: push, by @beaufortfrancois

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Apr 29, 2021
SHA: d9eeae5
Reason: push, by @beaufortfrancois

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Apr 29, 2021
SHA: d9eeae5
Reason: push, by @beaufortfrancois

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 29, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 30, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 30, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 30, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 3, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 4, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 4, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 4, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 5, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 5, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 5, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830933
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879284}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 5, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830933
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879284}
blueboxd pushed a commit to blueboxd/chromium-legacy that referenced this pull request May 5, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830933
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879284}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request May 8, 2021
…ilter when requesting device, a=testonly

Automatic update from web-platform-tests
[Web Bluetooth] Add `manufacturerData` filter when requesting device

This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830933
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879284}

--

wpt-commits: d50983bfca33b58be57894725b190b8c1a011ddc
wpt-pr: 28718
jwidar pushed a commit to jwidar/LatencyZeroGithub that referenced this pull request Sep 16, 2025
…ilter when requesting device, a=testonly

Automatic update from web-platform-tests
[Web Bluetooth] Add `manufacturerData` filter when requesting device

This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830933
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879284}

--

wpt-commits: d50983bfca33b58be57894725b190b8c1a011ddc
wpt-pr: 28718
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants