-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
encoding/binary: add AppendByteOrder #50601
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This proposal has been added to the active column of the proposals project |
Recently we've been doing things like ReadFileFS for FS with a ReadFile method. Otherwise seems reasonable, and it's nice that LittleEndian and BigEndian have unexported types so we can add the methods and use them directly. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/386017 mentions this issue: |
Change https://go.dev/cl/389636 mentions this issue: |
CL 386017 added new API for encoding/binary package. This file was accidentally not updated in the same CL. Updates #50601 Change-Id: Iefeb596ba04b8c6576cf0fe42030f658a5848832 Reviewed-on: https://go-review.googlesource.com/c/go/+/389636 Trust: Joseph Tsai <[email protected]> Run-TryBot: Joseph Tsai <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
A common operation when dealing with binary wire formats is the need to append a fixed-width integer.
Currently, a common way to do it is with:
This takes 3 lines and cannot be done as a expression.
I propose the addition of a new interface:
And that we document that
LittleEndian
andBigEndian
both implementByteOrder
andAppendableByteOrder
.Thus, the lines above can be simplified as:
In my work with various binary wire formats (e.g., tar, protobuf, etc.), an API like this would be more convenient than the existing
PutUintX
APIs.The
AppendableByteOrder
interface exists primarily for documentation purposes. It is not strictly needed.\cc @josharian
The text was updated successfully, but these errors were encountered: