Skip to content

add Number method to enum #870

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

Closed
wants to merge 1 commit into from
Closed

add Number method to enum #870

wants to merge 1 commit into from

Conversation

timestee
Copy link

related issue: protocolbuffers/protobuf#6104 (comment)

if enum has Number method. Though we define ErrorCode in different proto files. We could solve the problem like this:

type ProtoEnum interface {
	fmt.Stringer
	Number() int32
	EnumDescriptor() ([]byte, []int)
}

func Errorf(v ProtoEnum) error {
   // now we could get the code and message desc.
}

@googlebot
Copy link
Collaborator

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link
Collaborator

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@dsnet
Copy link
Member

dsnet commented Jun 17, 2019

This is fixed in v2 with the new protoreflect.Enum interface where the Number method returns a protoreflect.EnumNumber.

@dsnet dsnet closed this Jun 17, 2019
@timestee
Copy link
Author

thanks @dsnet v2 is stable now ? could use it in production?

@dsnet
Copy link
Member

dsnet commented Jun 17, 2019

It is not stable. If you're interested in tracking breaking changes, subscribe to #867.

@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants