Skip to content

std.fmt: add # specifier to print raw bytes of the value (hex) #12313

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

Closed
Vexu opened this issue Aug 1, 2022 · 2 comments
Closed

std.fmt: add # specifier to print raw bytes of the value (hex) #12313

Vexu opened this issue Aug 1, 2022 · 2 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@Vexu
Copy link
Member

Vexu commented Aug 1, 2022

This was accepted as part of #1358 but never implemented. I'm opening this as a new proposal since it is of questionable usefulness:

(NOTE: do we need this? how often is it used?)

@Vexu Vexu added standard library This issue involves writing Zig code for the standard library. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. labels Aug 1, 2022
@Vexu Vexu added this to the 0.12.0 milestone Aug 1, 2022
@InKryption
Copy link
Contributor

InKryption commented Aug 1, 2022

I don't think it's necessary, if one wants they can use std.mem.asBytes -> std.fmt.fmtSliceHexLower/fmtSliceHexUpper.
Could even make a function in std.fmt like fmtAsBytesUpper, which does the same thing, if verbosity is an issue with that solution (ditto for fmtAsBytesLower).

@matu3ba
Copy link
Contributor

matu3ba commented Aug 5, 2022

I do agree with @InKryption that it is semantically not necessary and at first would be simpler to do without another flag to std.fmt

    1. However, it is poorly documented how to get the in-memory representation
    1. Printing the raw bytes is common on analyzing padding + alignment issues on overlapping types besides bit logic things like int, float, deterministic bigint stuff in buffers etc.
    1. If I want 5 values next to another like a csv table over time (say with file,line number + iteration), then writing those out will be annoying. How useful or common this is, would be the other question.

@Vexu Vexu closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2023
@andrewrk andrewrk modified the milestones: 0.14.0, 0.11.0 Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

4 participants