From 519dbee92094446623015c52935011a0dcecd270 Mon Sep 17 00:00:00 2001 From: Kevin J Walters Date: Wed, 12 Aug 2020 18:07:23 +0100 Subject: [PATCH 1/2] Changing the attribute data from a dict to an OrderedDict to enhance control over order to increase the utility of prefix matching. --- adafruit_ble/advertising/standard.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_ble/advertising/standard.py b/adafruit_ble/advertising/standard.py index 4259be0..bf4cc10 100644 --- a/adafruit_ble/advertising/standard.py +++ b/adafruit_ble/advertising/standard.py @@ -29,6 +29,7 @@ """ import struct +from collections import OrderedDict from . import ( Advertisement, @@ -220,7 +221,7 @@ def __init__( self._company_id = company_id self._adt = advertising_data_type - self.data = {} + self.data = OrderedDict() # makes field order match order they are set in self.company_id = company_id encoded_company = struct.pack(" Date: Wed, 12 Aug 2020 21:54:48 +0100 Subject: [PATCH 2/2] Documenting the effect of the new OrderedDict in ManufacturerData including what it benefits. --- adafruit_ble/advertising/standard.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_ble/advertising/standard.py b/adafruit_ble/advertising/standard.py index bf4cc10..0d1b5f7 100644 --- a/adafruit_ble/advertising/standard.py +++ b/adafruit_ble/advertising/standard.py @@ -212,7 +212,9 @@ def __init__(self, *services): class ManufacturerData(AdvertisingDataField): """Encapsulates manufacturer specific keyed data bytes. The manufacturer is identified by the company_id and the data is structured like an advertisement with a configurable key - format.""" + format. The order of the serialized data is determined by the order that the + `ManufacturerDataField` attributes are set in - this can be useful for + `match_prefixes` in an `Advertisement` sub-class.""" def __init__( self, obj, *, advertising_data_type=0xFF, company_id, key_encoding="B"