aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/google.golang.org/protobuf/internal/impl/message_opaque_gen.go
blob: a69825699abf373a1a7d0b1c78e78afeb2b44fbe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Code generated by generate-types. DO NOT EDIT.

package impl

import (
	"reflect"

	"google.golang.org/protobuf/reflect/protoreflect"
)

func getterForOpaqueNullableScalar(mi *MessageInfo, index uint32, fd protoreflect.FieldDescriptor, fs reflect.StructField, conv Converter, fieldOffset offset) func(p pointer) protoreflect.Value {
	ft := fs.Type
	if ft.Kind() == reflect.Ptr {
		ft = ft.Elem()
	}
	if fd.Kind() == protoreflect.EnumKind {
		// Enums for nullable opaque types.
		return func(p pointer) protoreflect.Value {
			if p.IsNil() || !mi.present(p, index) {
				return conv.Zero()
			}
			rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
			return conv.PBValueOf(rv)
		}
	}
	switch ft.Kind() {
	case reflect.Bool:
		return func(p pointer) protoreflect.Value {
			if p.IsNil() || !mi.present(p, index) {
				return conv.Zero()
			}
			x := p.Apply(fieldOffset).Bool()
			return protoreflect.ValueOfBool(*x)
		}
	case reflect.Int32:
		return func(p pointer) protoreflect.Value {
			if p.IsNil() || !mi.present(p, index) {
				return conv.Zero()
			}
			x := p.Apply(fieldOffset).Int32()
			return protoreflect.ValueOfInt32(*x)
		}
	case reflect.Uint32:
		return func(p pointer) protoreflect.Value {
			if p.IsNil() || !mi.present(p, index) {
				return conv.Zero()
			}
			x := p.Apply(fieldOffset).Uint32()
			return protoreflect.ValueOfUint32(*x)
		}
	case reflect.Int64:
		return func(p pointer) protoreflect.Value {
			if p.IsNil() || !mi.present(p, index) {
				return conv.Zero()
			}
			x := p.Apply(fieldOffset).Int64()
			return protoreflect.ValueOfInt64(*x)
		}
	case reflect.Uint64:
		return func(p pointer) protoreflect.Value {
			if p.IsNil() || !mi.present(p, index) {
				return conv.Zero()
			}
			x := p.Apply(fieldOffset).Uint64()
			return protoreflect.ValueOfUint64(*x)
		}
	case reflect.Float32:
		return func(p pointer) protoreflect.Value {
			if p.IsNil() || !mi.present(p, index) {
				return conv.Zero()
			}
			x := p.Apply(fieldOffset).Float32()
			return protoreflect.ValueOfFloat32(*x)
		}
	case reflect.Float64:
		return func(p pointer) protoreflect.Value {
			if p.IsNil() || !mi.present(p, index) {
				return conv.Zero()
			}
			x := p.Apply(fieldOffset).Float64()
			return protoreflect.ValueOfFloat64(*x)
		}
	case reflect.String:
		if fd.Kind() == protoreflect.BytesKind {
			return func(p pointer) protoreflect.Value {
				if p.IsNil() || !mi.present(p, index) {
					return conv.Zero()
				}
				x := p.Apply(fieldOffset).StringPtr()
				if *x == nil {
					return conv.Zero()
				}
				if len(**x) == 0 {
					return protoreflect.ValueOfBytes(nil)
				}
				return protoreflect.ValueOfBytes([]byte(**x))
			}
		}
		return func(p pointer) protoreflect.Value {
			if p.IsNil() || !mi.present(p, index) {
				return conv.Zero()
			}
			x := p.Apply(fieldOffset).StringPtr()
			if *x == nil {
				return conv.Zero()
			}
			return protoreflect.ValueOfString(**x)
		}
	case reflect.Slice:
		if fd.Kind() == protoreflect.StringKind {
			return func(p pointer) protoreflect.Value {
				if p.IsNil() || !mi.present(p, index) {
					return conv.Zero()
				}
				x := p.Apply(fieldOffset).Bytes()
				return protoreflect.ValueOfString(string(*x))
			}
		}
		return func(p pointer) protoreflect.Value {
			if p.IsNil() || !mi.present(p, index) {
				return conv.Zero()
			}
			x := p.Apply(fieldOffset).Bytes()
			return protoreflect.ValueOfBytes(*x)
		}
	}
	panic("unexpected protobuf kind: " + ft.Kind().String())
}