blob: ec4458982ed5e1f2447b2eecff8f5fe585dbcc1b [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"
Joe Tsaid4211502019-07-02 14:58:02 -070011 "google.golang.org/protobuf/reflect/prototype"
12
Damien Neil5b6d0472019-06-14 11:54:07 -070013 "google.golang.org/protobuf/types/descriptorpb"
14)
15
16type IrregularMessage struct {
17 set bool
18 value string
19}
20
21func (m *IrregularMessage) ProtoReflect() pref.Message { return (*message)(m) }
22
23type message IrregularMessage
24
Joe Tsaid4211502019-07-02 14:58:02 -070025var messageType = &prototype.Message{
26 MessageDescriptor: fileDesc.Messages().Get(0),
27 NewMessage: func() pref.Message {
28 return &message{}
29 },
30}
31
32func (m *message) Descriptor() pref.MessageDescriptor { return messageType.Descriptor() }
33func (m *message) Type() pref.MessageType { return messageType }
Damien Neil5b6d0472019-06-14 11:54:07 -070034func (m *message) New() pref.Message { return &message{} }
35func (m *message) Interface() pref.ProtoMessage { return (*IrregularMessage)(m) }
36
Joe Tsaid4211502019-07-02 14:58:02 -070037var fieldDescS = fileDesc.Messages().Get(0).Fields().Get(0)
Damien Neil5b6d0472019-06-14 11:54:07 -070038
Joe Tsai378c1322019-04-25 23:48:08 -070039func (m *message) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
40 if m.set {
41 f(fieldDescS, pref.ValueOf(m.value))
42 }
43}
44
45func (m *message) Has(fd pref.FieldDescriptor) bool {
46 if fd == fieldDescS {
Damien Neil5b6d0472019-06-14 11:54:07 -070047 return m.set
48 }
Joe Tsai378c1322019-04-25 23:48:08 -070049 panic("invalid field descriptor")
Damien Neil5b6d0472019-06-14 11:54:07 -070050}
51
Joe Tsai378c1322019-04-25 23:48:08 -070052func (m *message) Clear(fd pref.FieldDescriptor) {
53 if fd == fieldDescS {
Damien Neil5b6d0472019-06-14 11:54:07 -070054 m.value = ""
55 m.set = false
Joe Tsai378c1322019-04-25 23:48:08 -070056 return
Damien Neil5b6d0472019-06-14 11:54:07 -070057 }
Joe Tsai378c1322019-04-25 23:48:08 -070058 panic("invalid field descriptor")
Damien Neil5b6d0472019-06-14 11:54:07 -070059}
60
Joe Tsai378c1322019-04-25 23:48:08 -070061func (m *message) Get(fd pref.FieldDescriptor) pref.Value {
62 if fd == fieldDescS {
63 return pref.ValueOf(m.value)
Damien Neil5b6d0472019-06-14 11:54:07 -070064 }
Joe Tsai378c1322019-04-25 23:48:08 -070065 panic("invalid field descriptor")
Damien Neil5b6d0472019-06-14 11:54:07 -070066}
67
Joe Tsai378c1322019-04-25 23:48:08 -070068func (m *message) Set(fd pref.FieldDescriptor, v pref.Value) {
69 if fd == fieldDescS {
70 m.value = v.String()
71 m.set = true
72 return
73 }
74 panic("invalid field descriptor")
Damien Neil5b6d0472019-06-14 11:54:07 -070075}
76
Joe Tsai378c1322019-04-25 23:48:08 -070077func (m *message) Mutable(pref.FieldDescriptor) pref.Value {
78 panic("invalid field descriptor")
Damien Neil5b6d0472019-06-14 11:54:07 -070079}
80
Joe Tsai378c1322019-04-25 23:48:08 -070081func (m *message) NewMessage(pref.FieldDescriptor) pref.Message {
82 panic("invalid field descriptor")
83}
Damien Neil5b6d0472019-06-14 11:54:07 -070084
Damien Neilf5274512019-08-05 10:48:38 -070085func (m *message) NewField(pref.FieldDescriptor) pref.Value {
86 panic("invalid field descriptor")
87}
88
Joe Tsai378c1322019-04-25 23:48:08 -070089func (m *message) WhichOneof(pref.OneofDescriptor) pref.FieldDescriptor {
90 panic("invalid oneof descriptor")
91}
Damien Neil5b6d0472019-06-14 11:54:07 -070092
Joe Tsai378c1322019-04-25 23:48:08 -070093func (m *message) GetUnknown() pref.RawFields { return nil }
94func (m *message) SetUnknown(pref.RawFields) { return }
Damien Neil5b6d0472019-06-14 11:54:07 -070095
Joe Tsaid4211502019-07-02 14:58:02 -070096var fileDesc = func() pref.FileDescriptor {
Damien Neil5b6d0472019-06-14 11:54:07 -070097 p := &descriptorpb.FileDescriptorProto{}
98 if err := prototext.Unmarshal([]byte(descriptorText), p); err != nil {
99 panic(err)
100 }
101 file, err := protodesc.NewFile(p, nil)
102 if err != nil {
103 panic(err)
104 }
105 return file
106}()
107
Joe Tsaid4211502019-07-02 14:58:02 -0700108func file_irregular_irregular_proto_init() { _ = fileDesc }
Damien Neil5b6d0472019-06-14 11:54:07 -0700109
110const descriptorText = `
111 name: "internal/testprotos/irregular/irregular.proto"
112 package: "goproto.proto.thirdparty"
113 message_type {
114 name: "IrregularMessage"
115 field {
116 name: "s"
117 number: 1
118 label: LABEL_OPTIONAL
119 type: TYPE_STRING
120 json_name: "s"
121 }
122 }
123 options {
124 go_package: "google.golang.org/protobuf/internal/testprotos/irregular"
125 }
126`