enum.go 559 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. pref "google.golang.org/protobuf/reflect/protoreflect"
  8. )
  9. type EnumInfo struct {
  10. GoReflectType reflect.Type // int32 kind
  11. Desc pref.EnumDescriptor
  12. }
  13. func (t *EnumInfo) New(n pref.EnumNumber) pref.Enum {
  14. return reflect.ValueOf(n).Convert(t.GoReflectType).Interface().(pref.Enum)
  15. }
  16. func (t *EnumInfo) Descriptor() pref.EnumDescriptor { return t.Desc }