Skip to content
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

Support both little and big endian dump #189

Merged
merged 12 commits into from
Apr 25, 2023
Merged

Conversation

RinHizakura
Copy link
Contributor

In #170, we solve a part of the demand for #104, which provided the option to group bytes. In this patch, I am trying to complete the remaining requirement for endianness.

src/bin/hexyl.rs Outdated
Comment on lines 207 to 214
.arg(
Arg::new("little_endian_dump")
.short('e')
.action(ArgAction::SetTrue)
.help(
"Print out the data in little endian format. Otherwise the data will be showed \
in big endian format by default.",
),
Copy link
Owner

Choose a reason for hiding this comment

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

Is this only usable with --group-size? If so, we should specify that using https://docs.rs/clap/latest/clap/struct.Arg.html#method.requires.

Also, should we maybe introduce a --endianness=little/big option instead (where we can still discuss what the default should be)? We could potentially still have -e as an alias for --endianness=little if we choose big as the default.

Copy link
Contributor Author

@RinHizakura RinHizakura Apr 22, 2023

Choose a reason for hiding this comment

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

I think this option doesn't have to be depending on --group-size. Because if we don't specify the group size in the option, we'll default it to one. In other words, hexyl -g 1 file and hexyl file are the same.

For another question, the reason that I choose to use big-endian as default is because of the design of xxd:

$ xxd --help
...
Options:
    -e          little-endian dump (incompatible with -ps,-i,-r).

However, it would be fine if hexyl want to have a different design for the dump of endianness. Please tell me which you would prefer.

Copy link
Owner

Choose a reason for hiding this comment

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

I think this option doesn't have to be depending on --group-size. Because if we don't specify the group size in the option, we'll default it to one. In other words, hexyl -g 1 file and hexyl file are the same.

yes. But Endianness won't have any effect if the group size is 1, right?

However, it would be fine if hexyl want to have a different design for the dump of endianness. Please tell me which you would prefer.

Let's follow xxd here for now, but I would still prefer a --endianness=little/big option instead of a --little-endian-dump flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But Endianness won't have any effect if the group size is 1, right?

Sure. If we want to inform the user that this would be no effect, let's use the requires method.

Let's follow xxd here for now, but I would still prefer a --endianness=little/big option instead of a --little-endian-dump flag.

I change the command line option to --endianness=little/big now.

Copy link
Owner

Choose a reason for hiding this comment

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

I thought about it again and now think that your initial version was actually better (sorry). Because not using requires allows someone to set an alias like alias hexyl="hexyl --endianness=little", and use that even if -g is not present.

Instead, we can mention that it only has an effect if group size > 1.

I'll make the necessary adjustments.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
tests/integration_tests.rs Outdated Show resolved Hide resolved
Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you very much! This looks good.

src/bin/hexyl.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@sharkdp sharkdp merged commit 816779e into sharkdp:master Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants