blob: 6685e432ff8b6426cb61080d8793097c3878f4ed [file] [log] [blame]
Damien Neil5b6d0472019-06-14 11:54:07 -07001// 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
5package irregular
6
7import (
8 "google.golang.org/protobuf/encoding/prototext"
9 "google.golang.org/protobuf/reflect/protodesc"
10 pref "google.golang.org/protobuf/reflect/protoreflect"
11 "google.golang.org/protobuf/types/descriptorpb"
12)
13
14type IrregularMessage struct {
15 set bool
16 value string
17}
18
19func (m *IrregularMessage) ProtoReflect() pref.Message { return (*message)(m) }
20
21type message IrregularMessage
22
23func (m *message) Descriptor() pref.MessageDescriptor { return descriptor.Messages().Get(0) }
Damien Neil5b6d0472019-06-14 11:54:07 -070024func (m *message) New() pref.Message { return &message{} }
25func (m *message) Interface() pref.ProtoMessage { return (*IrregularMessage)(m) }
26
Joe Tsai378c1322019-04-25 23:48:08 -070027var fieldDescS = descriptor.Messages().Get(0).Fields().Get(0)
Damien Neil5b6d0472019-06-14 11:54:07 -070028
Joe Tsai378c1322019-04-25 23:48:08 -070029func (m *message) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
30 if m.set {
31 f(fieldDescS, pref.ValueOf(m.value))
32 }
33}
34
35func (m *message) Has(fd pref.FieldDescriptor) bool {
36 if fd == fieldDescS {
Damien Neil5b6d0472019-06-14 11:54:07 -070037 return m.set
38 }
Joe Tsai378c1322019-04-25 23:48:08 -070039 panic("invalid field descriptor")
Damien Neil5b6d0472019-06-14 11:54:07 -070040}
41
Joe Tsai378c1322019-04-25 23:48:08 -070042func (m *message) Clear(fd pref.FieldDescriptor) {
43 if fd == fieldDescS {
Damien Neil5b6d0472019-06-14 11:54:07 -070044 m.value = ""
45 m.set = false
Joe Tsai378c1322019-04-25 23:48:08 -070046 return
Damien Neil5b6d0472019-06-14 11:54:07 -070047 }
Joe Tsai378c1322019-04-25 23:48:08 -070048 panic("invalid field descriptor")
Damien Neil5b6d0472019-06-14 11:54:07 -070049}
50
Joe Tsai378c1322019-04-25 23:48:08 -070051func (m *message) Get(fd pref.FieldDescriptor) pref.Value {
52 if fd == fieldDescS {
53 return pref.ValueOf(m.value)
Damien Neil5b6d0472019-06-14 11:54:07 -070054 }
Joe Tsai378c1322019-04-25 23:48:08 -070055 panic("invalid field descriptor")
Damien Neil5b6d0472019-06-14 11:54:07 -070056}
57
Joe Tsai378c1322019-04-25 23:48:08 -070058func (m *message) Set(fd pref.FieldDescriptor, v pref.Value) {
59 if fd == fieldDescS {
60 m.value = v.String()
61 m.set = true
62 return
63 }
64 panic("invalid field descriptor")
Damien Neil5b6d0472019-06-14 11:54:07 -070065}
66
Joe Tsai378c1322019-04-25 23:48:08 -070067func (m *message) Mutable(pref.FieldDescriptor) pref.Value {
68 panic("invalid field descriptor")
Damien Neil5b6d0472019-06-14 11:54:07 -070069}
70
Joe Tsai378c1322019-04-25 23:48:08 -070071func (m *message) NewMessage(pref.FieldDescriptor) pref.Message {
72 panic("invalid field descriptor")
73}
Damien Neil5b6d0472019-06-14 11:54:07 -070074
Joe Tsai378c1322019-04-25 23:48:08 -070075func (m *message) WhichOneof(pref.OneofDescriptor) pref.FieldDescriptor {
76 panic("invalid oneof descriptor")
77}
Damien Neil5b6d0472019-06-14 11:54:07 -070078
Joe Tsai378c1322019-04-25 23:48:08 -070079func (m *message) GetUnknown() pref.RawFields { return nil }
80func (m *message) SetUnknown(pref.RawFields) { return }
Damien Neil5b6d0472019-06-14 11:54:07 -070081
82var descriptor = func() pref.FileDescriptor {
83 p := &descriptorpb.FileDescriptorProto{}
84 if err := prototext.Unmarshal([]byte(descriptorText), p); err != nil {
85 panic(err)
86 }
87 file, err := protodesc.NewFile(p, nil)
88 if err != nil {
89 panic(err)
90 }
91 return file
92}()
93
94func file_irregular_irregular_proto_init() { _ = descriptor }
95
96const descriptorText = `
97 name: "internal/testprotos/irregular/irregular.proto"
98 package: "goproto.proto.thirdparty"
99 message_type {
100 name: "IrregularMessage"
101 field {
102 name: "s"
103 number: 1
104 label: LABEL_OPTIONAL
105 type: TYPE_STRING
106 json_name: "s"
107 }
108 }
109 options {
110 go_package: "google.golang.org/protobuf/internal/testprotos/irregular"
111 }
112`