message_opaque_gen.go

  1// Copyright 2018 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
  5// Code generated by generate-types. DO NOT EDIT.
  6
  7package impl
  8
  9import (
 10	"reflect"
 11
 12	"google.golang.org/protobuf/reflect/protoreflect"
 13)
 14
 15func getterForOpaqueNullableScalar(mi *MessageInfo, index uint32, fd protoreflect.FieldDescriptor, fs reflect.StructField, conv Converter, fieldOffset offset) func(p pointer) protoreflect.Value {
 16	ft := fs.Type
 17	if ft.Kind() == reflect.Ptr {
 18		ft = ft.Elem()
 19	}
 20	if fd.Kind() == protoreflect.EnumKind {
 21		// Enums for nullable opaque types.
 22		return func(p pointer) protoreflect.Value {
 23			if p.IsNil() || !mi.present(p, index) {
 24				return conv.Zero()
 25			}
 26			rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
 27			return conv.PBValueOf(rv)
 28		}
 29	}
 30	switch ft.Kind() {
 31	case reflect.Bool:
 32		return func(p pointer) protoreflect.Value {
 33			if p.IsNil() || !mi.present(p, index) {
 34				return conv.Zero()
 35			}
 36			x := p.Apply(fieldOffset).Bool()
 37			return protoreflect.ValueOfBool(*x)
 38		}
 39	case reflect.Int32:
 40		return func(p pointer) protoreflect.Value {
 41			if p.IsNil() || !mi.present(p, index) {
 42				return conv.Zero()
 43			}
 44			x := p.Apply(fieldOffset).Int32()
 45			return protoreflect.ValueOfInt32(*x)
 46		}
 47	case reflect.Uint32:
 48		return func(p pointer) protoreflect.Value {
 49			if p.IsNil() || !mi.present(p, index) {
 50				return conv.Zero()
 51			}
 52			x := p.Apply(fieldOffset).Uint32()
 53			return protoreflect.ValueOfUint32(*x)
 54		}
 55	case reflect.Int64:
 56		return func(p pointer) protoreflect.Value {
 57			if p.IsNil() || !mi.present(p, index) {
 58				return conv.Zero()
 59			}
 60			x := p.Apply(fieldOffset).Int64()
 61			return protoreflect.ValueOfInt64(*x)
 62		}
 63	case reflect.Uint64:
 64		return func(p pointer) protoreflect.Value {
 65			if p.IsNil() || !mi.present(p, index) {
 66				return conv.Zero()
 67			}
 68			x := p.Apply(fieldOffset).Uint64()
 69			return protoreflect.ValueOfUint64(*x)
 70		}
 71	case reflect.Float32:
 72		return func(p pointer) protoreflect.Value {
 73			if p.IsNil() || !mi.present(p, index) {
 74				return conv.Zero()
 75			}
 76			x := p.Apply(fieldOffset).Float32()
 77			return protoreflect.ValueOfFloat32(*x)
 78		}
 79	case reflect.Float64:
 80		return func(p pointer) protoreflect.Value {
 81			if p.IsNil() || !mi.present(p, index) {
 82				return conv.Zero()
 83			}
 84			x := p.Apply(fieldOffset).Float64()
 85			return protoreflect.ValueOfFloat64(*x)
 86		}
 87	case reflect.String:
 88		if fd.Kind() == protoreflect.BytesKind {
 89			return func(p pointer) protoreflect.Value {
 90				if p.IsNil() || !mi.present(p, index) {
 91					return conv.Zero()
 92				}
 93				x := p.Apply(fieldOffset).StringPtr()
 94				if *x == nil {
 95					return conv.Zero()
 96				}
 97				if len(**x) == 0 {
 98					return protoreflect.ValueOfBytes(nil)
 99				}
100				return protoreflect.ValueOfBytes([]byte(**x))
101			}
102		}
103		return func(p pointer) protoreflect.Value {
104			if p.IsNil() || !mi.present(p, index) {
105				return conv.Zero()
106			}
107			x := p.Apply(fieldOffset).StringPtr()
108			if *x == nil {
109				return conv.Zero()
110			}
111			return protoreflect.ValueOfString(**x)
112		}
113	case reflect.Slice:
114		if fd.Kind() == protoreflect.StringKind {
115			return func(p pointer) protoreflect.Value {
116				if p.IsNil() || !mi.present(p, index) {
117					return conv.Zero()
118				}
119				x := p.Apply(fieldOffset).Bytes()
120				return protoreflect.ValueOfString(string(*x))
121			}
122		}
123		return func(p pointer) protoreflect.Value {
124			if p.IsNil() || !mi.present(p, index) {
125				return conv.Zero()
126			}
127			x := p.Apply(fieldOffset).Bytes()
128			return protoreflect.ValueOfBytes(*x)
129		}
130	}
131	panic("unexpected protobuf kind: " + ft.Kind().String())
132}