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

proposal: encoding/asn1: add "enum" keyword for TagEnum #28873

Open
barlevd opened this Issue Nov 19, 2018 · 1 comment

Comments

Projects
None yet
4 participants
@barlevd
Copy link

barlevd commented Nov 19, 2018

Adding an "enum" tag option helps keeping the code clean.

for example:

the following code:

type tEnum int

const (
	tZero tEnum = iota
	tOne
)

type enumTest struct {
	A tEnum `asn1:"enum"`
}

func sampleTest(t *testing.T) {

	myTest := enumTest{A: tOne}

	buf, err := Marshal(myTest)
}

as compared to

type tEnum int

const (
	tZero tEnum = iota
	tOne
)

type enumTest struct {
	A tEnum
}
type enumStruct struct {
	A Enumerated
}

func sampleTest(t *testing.T) {

	myTest := enumTest{A: tOne}

	enum := enumStruct{A: Enumerated(int(myTest.A))}
	buf, err := Marshal(enum)
}

note the enumStruct is completely redundant and is used solely for getting an enum tag in the buffer

Same goes for Unmarshal, you need an intermediate structure if you want to have you own enumerated types.

@gopherbot gopherbot added this to the Proposal milestone Nov 19, 2018

@gopherbot gopherbot added the Proposal label Nov 19, 2018

@bcmills

This comment has been minimized.

Copy link
Member

bcmills commented Nov 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.