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

[util] Create ByteSpan class for holding OCTET_STRING type values in ZCL encoder #5122

Merged
merged 4 commits into from
Mar 5, 2021

Conversation

erjiaqing
Copy link
Contributor

@erjiaqing erjiaqing commented Mar 3, 2021

Problem

The ZCL codegen does not support OCTET_STRING for strings which is not expected to be non-null terminated. This is a critical issue for codegen on the encoder side, which cannot encode OCTET_STRING correctly.

Summary of Changes

This PR introduces the BytesData type for holding OCTET_STRING type in ZCL without the ownership of the data.

#4503

examples/chip-tool/commands/clusters/Commands.h Outdated Show resolved Hide resolved
src/app/encoder.cpp Outdated Show resolved Hide resolved
src/app/encoder.cpp Outdated Show resolved Hide resolved
src/app/encoder.cpp Outdated Show resolved Hide resolved
src/app/util/bytes-data.h Outdated Show resolved Hide resolved
src/app/zap-templates/templates/chip/CHIPClusters-src.zapt Outdated Show resolved Hide resolved
src/app/zap-templates/templates/chip/encoder-src.zapt Outdated Show resolved Hide resolved
src/controller/CHIPClusters.cpp Outdated Show resolved Hide resolved
src/controller/CHIPClusters.cpp Outdated Show resolved Hide resolved
src/controller/CHIPClusters.cpp Outdated Show resolved Hide resolved
@erjiaqing erjiaqing requested a review from andy31415 March 4, 2021 15:33
@erjiaqing erjiaqing changed the title [codegen] Create BytesData class for holding OCTET_STRING type values in ZCL [codegen] Create ByteSpan class for holding OCTET_STRING type values in ZCL Mar 4, 2021
@erjiaqing erjiaqing changed the title [codegen] Create ByteSpan class for holding OCTET_STRING type values in ZCL [util] Create ByteSpan class for holding OCTET_STRING type values in ZCL Mar 4, 2021
examples/chip-tool/commands/clusters/Commands.h Outdated Show resolved Hide resolved
examples/chip-tool/commands/clusters/Commands.h Outdated Show resolved Hide resolved
examples/chip-tool/gen/CHIPClustersObjc.mm Outdated Show resolved Hide resolved
examples/chip-tool/templates/commands.zapt Outdated Show resolved Hide resolved
@@ -117,7 +128,7 @@ public:

chip::Controller::{{asCamelCased parent.name false}}Cluster cluster;
cluster.Associate(device, endpointId);
return cluster.{{asCamelCased name false}}(onSuccessCallback->Cancel(), onFailureCallback->Cancel(){{#chip_server_cluster_command_arguments}}, {{#if (isByteString type)}} reinterpret_cast<uint8_t*>(m{{asCamelCased label false}}), static_cast<uint32_t>(strlen(m{{asCamelCased label false}})){{else}}m{{asCamelCased label false}}{{/if}}{{/chip_server_cluster_command_arguments}});
return cluster.{{asCamelCased name false}}(onSuccessCallback->Cancel(), onFailureCallback->Cancel(){{#chip_server_cluster_command_arguments}}, {{#if (isByteString type)}} chip::ByteSpan(reinterpret_cast<uint8_t *>(m{{asCamelCased label false}}), strlen(m{{asCamelCased label false}})){{else}}m{{asCamelCased label false}}{{/if}}{{/chip_server_cluster_command_arguments}});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return cluster.{{asCamelCased name false}}(onSuccessCallback->Cancel(), onFailureCallback->Cancel(){{#chip_server_cluster_command_arguments}}, {{#if (isByteString type)}} chip::ByteSpan(reinterpret_cast<uint8_t *>(m{{asCamelCased label false}}), strlen(m{{asCamelCased label false}})){{else}}m{{asCamelCased label false}}{{/if}}{{/chip_server_cluster_command_arguments}});
return cluster.{{asCamelCased name false}}(onSuccessCallback->Cancel(), onFailureCallback->Cancel(){{#chip_server_cluster_command_arguments}}, {{#if (isByteString type)}} chip::ByteSpan(chip::chip::Uint8::from_char(m{{asCamelCased label false}}), strlen(m{{asCamelCased label false}})){{else}}m{{asCamelCased label false}}{{/if}}{{/chip_server_cluster_command_arguments}});

I assume there will be a followup at some point to store a ByteSpan in the member, right?

src/lib/support/Span.h Outdated Show resolved Hide resolved
@@ -378,8 +378,8 @@ NS_ASSUME_NONNULL_BEGIN
timeoutMs:(uint32_t)timeoutMs
completionHandler:(ResponseHandler)completionHandler;
- (void)commissioningComplete:(ResponseHandler)completionHandler;
- (void)setFabric:(char *)fabricId
fabricSecret:(char *)fabricSecret
- (void)setFabric:(NSString)fabricId
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't compile, should be NSString *

examples/chip-tool/gen/CHIPClustersObjc.h Outdated Show resolved Hide resolved
Copy link
Contributor

@bzbarsky-apple bzbarsky-apple left a comment

Choose a reason for hiding this comment

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

Looks good with the NSByte typo fixed.

@erjiaqing erjiaqing changed the title [util] Create ByteSpan class for holding OCTET_STRING type values in ZCL [util] Create ByteSpan class for holding OCTET_STRING type values in ZCL encoder Mar 5, 2021
@erjiaqing
Copy link
Contributor Author

Updated title of this PR, will submit another PR for decoder / handler side.

@erjiaqing
Copy link
Contributor Author

@msandstedt PTAL
@vivien-apple any more comments?

@andy31415 andy31415 merged commit fc666df into project-chip:master Mar 5, 2021
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.

8 participants