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

add Number method to enum #870

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
3 participants
@timestee
Copy link

commented Jun 17, 2019

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

This comment has been minimized.

Copy link
Collaborator

commented Jun 17, 2019

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

This comment has been minimized.

Copy link
Collaborator

commented Jun 17, 2019

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

commented Jun 17, 2019

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

@dsnet

This comment has been minimized.

Copy link
Member

commented Jun 17, 2019

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

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.