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

Feature Request: LitHex, LitBit, LitOct #119

Closed
bangzek opened this issue Dec 21, 2024 · 3 comments
Closed

Feature Request: LitHex, LitBit, LitOct #119

bangzek opened this issue Dec 21, 2024 · 3 comments

Comments

@bangzek
Copy link

bangzek commented Dec 21, 2024

I work on low level binary protocol stuff and need to generate file using jen. I wish there's LitHex and LitBit so my generated code could use 0xFF and 0b1111_0000 literal.

@dave
Copy link
Owner

dave commented Dec 21, 2024

Can you give me examples of this syntax used in code?

@bangzek
Copy link
Author

bangzek commented Dec 23, 2024

Take this code:

	f := NewFile("util")
	f.Func().Id("positive").Params(Id("b").Byte()).Bool().Block(
		Return(Id("b").Op("&").Lit(0x80).Op("==").Lit(0x00)),
	)
	fmt.Printf("%#v", f)

which will generate:

package util

func positive(b byte) bool {
	return b&128 == 0
}

I want to change the output b&128 to b&0x80 so it would be clear to human why it using that magic number.

I hope it clear to you.

@dave
Copy link
Owner

dave commented Jan 15, 2025

Aaah ok I see... I think unfortunately this will have to be a no... Jennifer is concerned with outputting code that compiles correctly, not code that is pretty or easy to read... The API is already rather cluttered already, and adding more methods to tweak the formatting or readability of the output code is an deep rabbit hole!

@dave dave closed this as completed Jan 15, 2025
@dave dave reopened this Jan 15, 2025
@dave dave closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
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

No branches or pull requests

2 participants