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

Open
bangzek opened this issue Dec 21, 2024 · 2 comments
Open

Feature Request: LitHex, LitBit, LitOct #119

bangzek opened this issue Dec 21, 2024 · 2 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.

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