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
A format specifier for bytes #6429
Comments
Comment author: @gasche I have no idea of what a good syntax would be. My only idea would be to reuse "%#s" (currently considered as "%s", but planning-to-be-outlawed in 4.02 as it doesn't mean anything), and it's mediocre at best. |
Comment author: @whitequark Well, you could disambiguate the conflict with %b/%B by using the second letter: %y/%Y, in the same way as e.g. options for Unix tools are disambiguated. This is what I would expect, at least. |
Comment author: @gasche Note that in the meantime, we could make sure that "%a" Bytes.print by works (by adding the relevant functions if need be for some *printf function), which would already have reasonable readability. |
Comment author: @damiendoligez While we decide which letter to use, you should use this for debugging without too much pain: let (!!) = Bytes.unsafe_to_string;; For the letter, I think Y is a good candidate. My first idea was Z but we might want to use that for bignums at some point in the future. As for %#s, that would make the type depend on the format's flags rather than the letter. A very bad idea. |
Comment author: @gasche I considered implementing this, but I'm not happy with having both %y and %Y. The problem is that the usual semantics of the big-letter version is "as written in OCaml source code", so it would seem natural that whichever output syntax is chosen for %Y also produces valid OCaml literals; but we have no literal syntax for bytes. On the other hand, the escaped-printing behavior of %S is certainly more useful than the non-escaped behavior of %s for bytes, for the "byte sequences" applications that have no reason to stay in the printable ASCII range; so if we had only one formatter for bytes, it should probably have the semantics of %S. |
Comment author: @damiendoligez I think the parallel with %s/%S is quite natural, so if you want to implement only one, it should be %Y... |
Comment author: @whitequark I think implementing just %Y is a good idea. |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
I believe this is still a relevant feature request. Thinking about it again, it is not clear that there is no value for a |
Marking this as "newcomer job advanced": the Format machinery uses advanced types, one has to be familiar with GADTs to work on them, but then it is doable for a newcomer to add support for a new conversion by imitating the existing code. |
This would actually be quite useful. |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Okay I went through the whole conversation and since the feature felt
sensible to me, I removed the Stale label and assigned it to myself,
without knowing precisely when I will be able to work on it.
I also agree with @gasche that being able to do litteral printing would
be helpful, especially if the purpose is to output binary files,
although I assume there are already other ways to achieve this.
To make this job really doable for newcomers, would it be possible /
easy to provide a few hints on which steps to folllow / which files to
modify to implement the feature, as @gasche had so nicely done in an
issue or PR about adding extension points to let operators or something
like that? Sorry for not being able to be more precise on that, locating
issues and PRs is at the moment not that easy for me but I'm sure
somebody will see what I mean, at least @gasche himself!
|
Just a food for thought, for debugging the sparse hexadecimal format might be more useful, at least it's quite useful for the reverse engineering tasks:
The first is the "normal" hex, the second is the sparse "hexII" format invented by Ange Albertini. See more information at https://speakerdeck.com/ange/no-more-dumb-hex |
Original bug ID: 6429
Reporter: @whitequark
Status: confirmed (set by @damiendoligez on 2014-05-21T15:32:19Z)
Resolution: open
Priority: normal
Severity: feature
Target version: undecided
Category: standard library
Monitored by: braibant @diml
Bug description
Without a %S-like format specifier for Bytes, debugging becomes extremely annoying--the code is littered with bogus conversions everywhere. Perhaps it's possible to provide one?
It also makes sense to provide its non-escaped equivalent as well ("%s").
The text was updated successfully, but these errors were encountered: