-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[packet_transport] Make some arguments const #8700
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
Conversation
Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration ( |
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#8700
components: [packet_transport, uart, udp]
refresh: 1h (Added by the PR bot) |
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.
Pull Request Overview
This PR improves code quality by updating function signatures across UDP and UART packet transport components to use const reference parameters for data buffers, ensuring immutability where applicable.
- Update of send_packet functions to use const std::vector<uint8_t> & instead of non-const references.
- Consistent propagation of const correctness in both header and source files across UDP, UART, and packet transport modules.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
esphome/components/udp/udp_component.h | Updated send_packet to use a const vector argument. |
esphome/components/udp/packet_transport/udp_transport.h | Modified send_packet signature to const reference. |
esphome/components/udp/packet_transport/udp_transport.cpp | Updated send_packet call to match new const signature. |
esphome/components/uart/packet_transport/uart_transport.h | Updated send_packet signature to use const vector argument. |
esphome/components/uart/packet_transport/uart_transport.cpp | Updated send_packet call to match new const signature. |
esphome/components/packet_transport/packet_transport.h | Updated virtual send_packet and process_ methods to use const vector parameters. |
esphome/components/packet_transport/packet_transport.cpp | Updated process_ implementation to accept a const vector parameter. |
Comments suppressed due to low confidence (7)
esphome/components/udp/udp_component.h:33
- Updating send_packet to take a const reference improves clarity regarding immutability. Ensure that any callers relying on mutable data are updated accordingly.
void send_packet(const std::vector<uint8_t> &buf) { this->send_packet(buf.data(), buf.size()); }
esphome/components/udp/packet_transport/udp_transport.h:19
- Changing the parameter to a const reference enforces immutability and clarifies the interface contract. Confirm that this modification aligns with the expectations in the parent class.
void send_packet(const std::vector<uint8_t> &buf) const override;
esphome/components/udp/packet_transport/udp_transport.cpp:34
- The const correctness update here is appropriate; verify that the parent's send_packet accepts a const argument to avoid compatibility issues.
void UDPTransport::send_packet(const std::vector<uint8_t> &buf) const { this->parent_->send_packet(buf); }
esphome/components/uart/packet_transport/uart_transport.h:32
- Converting to a const reference in send_packet enhances code safety by ensuring the buffer remains unchanged. Confirm that all associated components reflect this change.
void send_packet(const std::vector<uint8_t> &buf) const override;
esphome/components/uart/packet_transport/uart_transport.cpp:77
- The const update here is consistent with the header declaration; ensure that the parent's method usage is compatible with this change.
void UARTTransport::send_packet(const std::vector<uint8_t> &buf) const {
esphome/components/packet_transport/packet_transport.h:109
- Changing process_ to accept a const vector reinforces immutability during data processing. Ensure that all calls to process_ are adjusted to reflect the const parameter requirement.
void process_(const std::vector<uint8_t> &data);
esphome/components/packet_transport/packet_transport.cpp:356
- Aligning the implementation with the header by using a const vector is a good consistency improvement. Verify that no in-place modifications of the data are expected within this function.
void PacketTransport::process_(const std::vector<uint8_t> &data) {
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #8700 +/- ##
==========================================
+ Coverage 53.70% 56.64% +2.93%
==========================================
Files 50 50
Lines 9408 9922 +514
Branches 1654 1340 -314
==========================================
+ Hits 5053 5620 +567
+ Misses 4056 3954 -102
- Partials 299 348 +49 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: clydeps <U5yx99dok9>
What does this implement/fix?
Change some function signatures to have const arguments since they aren't modified.
Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml
:# Example config.yaml
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: