-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Use custom ember-buffer decode on codegen data model Read as well. #36229
Use custom ember-buffer decode on codegen data model Read as well. #36229
Conversation
Review changes with SemanticDiff. |
PR #36229: Size comparison from 515bc3b to 91d5458 Full report (68 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
bool isSigned = (mAttributeType == ZCL_INT8S_ATTRIBUTE_TYPE) // | ||
|| (mAttributeType == ZCL_INT16S_ATTRIBUTE_TYPE) // | ||
|| (mAttributeType == ZCL_INT24S_ATTRIBUTE_TYPE) // | ||
|| (mAttributeType == ZCL_INT32S_ATTRIBUTE_TYPE) // | ||
|| (mAttributeType == ZCL_INT40S_ATTRIBUTE_TYPE) // | ||
|| (mAttributeType == ZCL_INT48S_ATTRIBUTE_TYPE) // | ||
|| (mAttributeType == ZCL_INT56S_ATTRIBUTE_TYPE) // | ||
|| (mAttributeType == ZCL_INT64S_ATTRIBUTE_TYPE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we are reinventing chip::app::IsSignedAttributeType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably me not knowing all the functions we have ... will update it.
|
||
if (mIsNullable && (value.uint_value == nullValue)) | ||
{ | ||
// MaxValue is used for NULL setting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment does not make sense for signed types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will re-write it. It does rely that we have a union and we store the null value as a uint64_t ... so we are looking at a static u64 cast on both sides here ...
case ZCL_INT8U_ATTRIBUTE_TYPE: // Unsigned 8-bit integer | ||
return writer.Put(tag, static_cast<uint8_t>(value.uint_value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we doing this? Assuming the value is in range at all, we can just Put()
as a 64-bit signed/unsigned respectively depending on isSigned and don't need this whole big switch and the casting.
case 0xFF: | ||
return writer.PutNull(tag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will incorrectly encode null even if !mIsNullable
, instead of correctly erroring out.
} | ||
if (NumericAttributeTraits<float>::IsNullValue(value.value)) | ||
{ | ||
return writer.PutNull(tag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this needs to check mIsNullable!
} | ||
if (NumericAttributeTraits<double>::IsNullValue(value.value)) | ||
{ | ||
return writer.PutNull(tag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to check mIsNullable.
@@ -73,6 +85,10 @@ class EmberAttributeDataBuffer | |||
/// Takes into account internal mIsNullable. | |||
CHIP_ERROR DecodeSignedInteger(chip::TLV::TLVReader & reader, EndianWriter & writer); | |||
|
|||
/// Encodes the UNSIGNED integer into `writer`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is not just for unsigned. What is this comment talking about?
…roject-chip#36229) * Use EmberAttributeDataBuffer for codegen provider _Read * Fix comments * Restyled by clang-format --------- Co-authored-by: Andrei Litvin <[email protected]> Co-authored-by: Restyled.io <[email protected]>
This saves about 1KB of flash compared to the alternative (more template-heavy) approach.