Skip to content

Document put_be and put_le helpers for writing integers into byte buffers - #318

Merged
J. Nick Koston (bdraco) merged 5 commits into
mainfrom
put-be-le-helpers
Nov 5, 2026
Merged

J. Nick Koston (bdraco) merged 5 commits into
mainfrom
put-be-le-helpers

Conversation

@bdraco

Copy link
Copy Markdown
Member

Description

Documents put_be16(), put_be24(), put_be32(), put_le16() and put_le32() from esphome/core/helpers.h, which write an integer into an existing byte buffer and return the pointer past it, in the "Helpers for raw device data" section next to the checksum helpers.

Pull request in esphome this documents (if applicable):

@netlify

netlify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for esphome-dev-docs ready!

Name Link
🔨 Latest commit e0ee04a
🔍 Latest deploy log https://app.netlify.com/projects/esphome-dev-docs/deploys/6aeb52619daffdcc65a7abc8
😎 Deploy Preview https://deploy-preview-318--esphome-dev-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the integer-to-buffer helper documentation update.

No open issues 🎉

What changed in this PR

Documents the integer-to-buffer helpers introduced in esphome/esphome#22211, adding guidance alongside the existing raw device data helpers.

Changes:

  • Describes the five big- and little-endian write helpers with a before-and-after example.
  • Explains pointer chaining, fixed write widths, signed values, and alignment requirements, and points to helpers for decoding bytes.
File Description
src/​content/​docs/​contributing/​code.md Adds a section on writing integers into existing byte buffers.

Review effort: Balanced

@bdraco

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@bdraco

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@bdraco

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@bdraco
J. Nick Koston (bdraco) marked this pull request as ready for review November 3, 2026 18:44
@esphbot

ESPHome Bot (esphbot) commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Previous review — superseded by a newer review below.

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tip

No blocking issues found — ready to merge.

@bdraco

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@esphbot

Copy link
Copy Markdown
Contributor

PR Review — Document put_be and put_le helpers for writing integers into byte buffers

Approve: the one finding from the last review is fixed, and nothing new came up.

What works well:

  • The section opens with why the helpers exist: byte order is easy to get wrong when the shifts are written by hand. This matches how the checksum section before it is framed.
  • The before/after example is a realistic register-address frame, and p = put_be16(p, length); shows how the returned pointer is used.
  • The fixed-width paragraph (lines 450–455) now says plainly that each helper writes the width in its name and drops any higher bits. It gives both the int-promotion case (x >> 8) and the put_be24() top-byte case. This fixes the earlier finding that the sentence only covered the 16-bit helpers.
  • It covers two's complement for signed values and says the buffer does not need to be aligned.
  • It points to the decode helpers (encode_uint16, encode_value<T>, encode_value_le<T>), using the names the i2c architecture docs already use.
  • The section sits between Checksums and Signed values, and its heading level and style match both.

No open issues.



Checklist

  • Matches PR description (documents put_be16/24/32, put_le16/32 in raw device data section)
  • Prior finding (fixed-width wording) resolved
  • Referenced helper names consistent with existing docs
  • No hardcoded secrets

Automated review by Kōan (Claude) HEAD=e0ee04a 20s

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tip

No blocking issues found — ready to merge.

@bdraco
J. Nick Koston (bdraco) merged commit 3bb1773 into main Nov 5, 2026
10 checks passed
@bdraco
J. Nick Koston (bdraco) deleted the put-be-le-helpers branch November 5, 2026 22:31
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.

3 participants