xref: /aosp_15_r20/external/golang-protobuf/internal/testprotos/irregular/irregular.go (revision 1c12ee1efe575feb122dbf939ff15148a3b3e8f2)
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
5package irregular
6
7import (
8	"google.golang.org/protobuf/encoding/prototext"
9	"google.golang.org/protobuf/reflect/protodesc"
10	"google.golang.org/protobuf/reflect/protoreflect"
11	"google.golang.org/protobuf/runtime/protoiface"
12
13	"google.golang.org/protobuf/types/descriptorpb"
14)
15
16type IrregularMessage struct {
17	set   bool
18	value string
19}
20
21func (m *IrregularMessage) ProtoReflect() protoreflect.Message { return (*message)(m) }
22
23type message IrregularMessage
24
25type messageType struct{}
26
27func (messageType) New() protoreflect.Message                  { return &message{} }
28func (messageType) Zero() protoreflect.Message                 { return (*message)(nil) }
29func (messageType) Descriptor() protoreflect.MessageDescriptor { return fileDesc.Messages().Get(0) }
30
31func (m *message) New() protoreflect.Message                  { return &message{} }
32func (m *message) Descriptor() protoreflect.MessageDescriptor { return fileDesc.Messages().Get(0) }
33func (m *message) Type() protoreflect.MessageType             { return messageType{} }
34func (m *message) Interface() protoreflect.ProtoMessage       { return (*IrregularMessage)(m) }
35func (m *message) ProtoMethods() *protoiface.Methods          { return nil }
36
37var fieldDescS = fileDesc.Messages().Get(0).Fields().Get(0)
38
39func (m *message) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
40	if m.set {
41		f(fieldDescS, protoreflect.ValueOf(m.value))
42	}
43}
44
45func (m *message) Has(fd protoreflect.FieldDescriptor) bool {
46	if fd == fieldDescS {
47		return m.set
48	}
49	panic("invalid field descriptor")
50}
51
52func (m *message) Clear(fd protoreflect.FieldDescriptor) {
53	if fd == fieldDescS {
54		m.value = ""
55		m.set = false
56		return
57	}
58	panic("invalid field descriptor")
59}
60
61func (m *message) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
62	if fd == fieldDescS {
63		return protoreflect.ValueOf(m.value)
64	}
65	panic("invalid field descriptor")
66}
67
68func (m *message) Set(fd protoreflect.FieldDescriptor, v protoreflect.Value) {
69	if fd == fieldDescS {
70		m.value = v.String()
71		m.set = true
72		return
73	}
74	panic("invalid field descriptor")
75}
76
77func (m *message) Mutable(protoreflect.FieldDescriptor) protoreflect.Value {
78	panic("invalid field descriptor")
79}
80
81func (m *message) NewField(protoreflect.FieldDescriptor) protoreflect.Value {
82	panic("invalid field descriptor")
83}
84
85func (m *message) WhichOneof(protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
86	panic("invalid oneof descriptor")
87}
88
89func (m *message) GetUnknown() protoreflect.RawFields { return nil }
90func (m *message) SetUnknown(protoreflect.RawFields)  { return }
91
92func (m *message) IsValid() bool {
93	return m != nil
94}
95
96var fileDesc = func() protoreflect.FileDescriptor {
97	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
108func file_internal_testprotos_irregular_irregular_proto_init() { _ = fileDesc }
109
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`
127
128type AberrantMessage int
129
130func (m AberrantMessage) ProtoMessage()            {}
131func (m AberrantMessage) Reset()                   {}
132func (m AberrantMessage) String() string           { return "" }
133func (m AberrantMessage) Marshal() ([]byte, error) { return nil, nil }
134func (m AberrantMessage) Unmarshal([]byte) error   { return nil }
135