Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Handle nullable attributes in TLV-to-attr-store interactions and Accessors #11666

Closed
wants to merge 5 commits into from

Conversation

restyled-io[bot]
Copy link
Contributor

@restyled-io restyled-io bot commented Nov 11, 2021

A duplicate of #11665 with additional commits that automatically address
incorrect style, created by Restyled.

⚠️ Even though this PR is not a Fork, it contains outside contributions.
Please review accordingly.

Since the original Pull Request was opened as a fork in a contributor's
repository, we are unable to create a Pull Request branching from it with only
the style fixes.

The following Restylers made fixes:

To incorporate these changes, you can either:

  1. Merge this Pull Request instead of the original, or

  2. Ask your contributor to locally incorporate these commits and push them to
    the original Pull Request

    Expand for example instructions
    ```console
    git remote add upstream https://github.com/project-chip/connectedhomeip.git
    git fetch upstream pull/<this PR number>/head
    git merge --ff-only FETCH_HEAD
    git push
    ```
    

NOTE: As work continues on the original Pull Request, this process will
re-run and update (force-push) this Pull Request with updated style fixes as
necessary. If the style is fixed manually at any point (i.e. this process finds
no fixes to make), this Pull Request will be closed automatically.

Sorry if this was unexpected. To disable it, see our documentation.

bzbarsky-apple and others added 5 commits November 10, 2021 17:18
…tten.

This implements the following semantics, for attributes we store in
the attribute store (integers, booleans, strings, octet strings):

Writes:

* An attempt to write TLV null for non-nullable attributes leads to an
  error.

* Writing TLV null to a nullable string or octet string sets its length
  to 0xFFFF or 0xFF depending on whether it's a long string or not.

* Writing TLV null to a nullable integer or boolean uses the "NaU" or
  "NaS" ZCL representation to represent it.

* Writing a TLV integer to an integer attribute makes a
  CanRepresentValue check and returns an error if it returns false.
  For now CanRepresentValue only disallows the NaU/NaS value for
  nullable attributes.

Reads:

* When reading a nullable integer or boolean, NaU/NaS is converted to TLV null.

* When reading an integer or boolean all other cases go through a
  CanRepresentValue check (in case the value in the attr store is not
  actually valid) and return error if it returns false.

* When reading a nullable string or octet string, length 0xFFFF/0xFF
  is converted to TLV null.

* When reading a non-nullable string or octet string, length
  0xFFFF/0xFF leads to an error.
For setters, the new behavior is:

* For non-string attributes when setting an integer or boolean value,
  do a CanRepresentValue check and fail if that fails.  For string
  attributes, ensure that strings with 0xFF or 0xFFFF as length cannot
  be passed in in practice.

* For nullable attributes add a SetNull method.

* For nullable attributes add a Set() method taking a Nullable<T> and
  calling either SetNull or the setter that expects a non-null value.

For getters, the new behavior is:

* When reading a nullable integer or boolean, NaU/NaS is converted to
  a null value stored in the Nullable.

* When reading a non-nullable integer or boolean, return error if
  CanRepresentValue returns false on the value from the attr store.

* When reading a nullable string or octet string, length 0xFFFF/0xFF
  is converted to a null value stored in the Nullable.

* When reading a non-nullable string or octet string, length
  0xFFFF/0xFF leads to an error.
@restyled-io restyled-io bot added the restyled label Nov 11, 2021
@restyled-io restyled-io bot closed this Nov 11, 2021
@restyled-io restyled-io bot deleted the restyled/nullable-attr-store branch November 11, 2021 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants