enum.go 594 B

123456789101112131415161718192021
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package impl
  5. import (
  6. "reflect"
  7. "google.golang.org/protobuf/reflect/protoreflect"
  8. )
  9. type EnumInfo struct {
  10. GoReflectType reflect.Type // int32 kind
  11. Desc protoreflect.EnumDescriptor
  12. }
  13. func (t *EnumInfo) New(n protoreflect.EnumNumber) protoreflect.Enum {
  14. return reflect.ValueOf(n).Convert(t.GoReflectType).Interface().(protoreflect.Enum)
  15. }
  16. func (t *EnumInfo) Descriptor() protoreflect.EnumDescriptor { return t.Desc }