2019-06-14 11:54:07 -07:00
|
|
|
// Copyright 2019 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.
|
|
|
|
|
|
|
|
package irregular
|
|
|
|
|
|
|
|
import (
|
|
|
|
"google.golang.org/protobuf/encoding/prototext"
|
|
|
|
"google.golang.org/protobuf/reflect/protodesc"
|
|
|
|
pref "google.golang.org/protobuf/reflect/protoreflect"
|
2020-01-21 11:27:51 -08:00
|
|
|
"google.golang.org/protobuf/runtime/protoiface"
|
2019-07-02 14:58:02 -07:00
|
|
|
|
2019-06-14 11:54:07 -07:00
|
|
|
"google.golang.org/protobuf/types/descriptorpb"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IrregularMessage struct {
|
|
|
|
set bool
|
|
|
|
value string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *IrregularMessage) ProtoReflect() pref.Message { return (*message)(m) }
|
|
|
|
|
|
|
|
type message IrregularMessage
|
|
|
|
|
2019-08-06 15:43:25 -07:00
|
|
|
func (m *message) Descriptor() pref.MessageDescriptor { return fileDesc.Messages().Get(0) }
|
|
|
|
func (m *message) Type() pref.MessageType { return m }
|
2019-06-14 11:54:07 -07:00
|
|
|
func (m *message) New() pref.Message { return &message{} }
|
2019-08-06 15:43:25 -07:00
|
|
|
func (m *message) Zero() pref.Message { return (*message)(nil) }
|
2019-06-14 11:54:07 -07:00
|
|
|
func (m *message) Interface() pref.ProtoMessage { return (*IrregularMessage)(m) }
|
2020-01-21 11:27:51 -08:00
|
|
|
func (m *message) ProtoMethods() *protoiface.Methods { return nil }
|
2019-06-14 11:54:07 -07:00
|
|
|
|
2019-07-02 14:58:02 -07:00
|
|
|
var fieldDescS = fileDesc.Messages().Get(0).Fields().Get(0)
|
2019-06-14 11:54:07 -07:00
|
|
|
|
2019-04-25 23:48:08 -07:00
|
|
|
func (m *message) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
|
|
|
|
if m.set {
|
|
|
|
f(fieldDescS, pref.ValueOf(m.value))
|
2019-06-14 11:54:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-25 23:48:08 -07:00
|
|
|
func (m *message) Has(fd pref.FieldDescriptor) bool {
|
|
|
|
if fd == fieldDescS {
|
|
|
|
return m.set
|
2019-06-14 11:54:07 -07:00
|
|
|
}
|
2019-04-25 23:48:08 -07:00
|
|
|
panic("invalid field descriptor")
|
2019-06-14 11:54:07 -07:00
|
|
|
}
|
|
|
|
|
2019-04-25 23:48:08 -07:00
|
|
|
func (m *message) Clear(fd pref.FieldDescriptor) {
|
|
|
|
if fd == fieldDescS {
|
2019-06-14 11:54:07 -07:00
|
|
|
m.value = ""
|
|
|
|
m.set = false
|
2019-04-25 23:48:08 -07:00
|
|
|
return
|
2019-06-14 11:54:07 -07:00
|
|
|
}
|
2019-04-25 23:48:08 -07:00
|
|
|
panic("invalid field descriptor")
|
2019-06-14 11:54:07 -07:00
|
|
|
}
|
|
|
|
|
2019-04-25 23:48:08 -07:00
|
|
|
func (m *message) Get(fd pref.FieldDescriptor) pref.Value {
|
|
|
|
if fd == fieldDescS {
|
|
|
|
return pref.ValueOf(m.value)
|
|
|
|
}
|
|
|
|
panic("invalid field descriptor")
|
2019-06-14 11:54:07 -07:00
|
|
|
}
|
|
|
|
|
2019-04-25 23:48:08 -07:00
|
|
|
func (m *message) Set(fd pref.FieldDescriptor, v pref.Value) {
|
|
|
|
if fd == fieldDescS {
|
|
|
|
m.value = v.String()
|
|
|
|
m.set = true
|
|
|
|
return
|
2019-06-14 11:54:07 -07:00
|
|
|
}
|
2019-04-25 23:48:08 -07:00
|
|
|
panic("invalid field descriptor")
|
2019-06-14 11:54:07 -07:00
|
|
|
}
|
|
|
|
|
2019-04-25 23:48:08 -07:00
|
|
|
func (m *message) Mutable(pref.FieldDescriptor) pref.Value {
|
|
|
|
panic("invalid field descriptor")
|
2019-06-14 11:54:07 -07:00
|
|
|
}
|
|
|
|
|
all: add NewField, NewElement, NewValue
Add methods to protoreflect.{Message,List,Map} to constrict values
assignable to a message field, list element, or map value. These
methods return the default value for scalar fields, the zero value for
scalar list elements and map values, and an empty, mutable value for
messages, lists, and maps.
Deprecate the NewMessage methods on these types, which are superseded.
Updates golang/protobuf#879
Change-Id: I0f064f60c89a239330ccea81523f559f14fd2c4f
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/188997
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-08-05 10:48:38 -07:00
|
|
|
func (m *message) NewField(pref.FieldDescriptor) pref.Value {
|
|
|
|
panic("invalid field descriptor")
|
|
|
|
}
|
|
|
|
|
2019-04-25 23:48:08 -07:00
|
|
|
func (m *message) WhichOneof(pref.OneofDescriptor) pref.FieldDescriptor {
|
|
|
|
panic("invalid oneof descriptor")
|
|
|
|
}
|
2019-06-14 11:54:07 -07:00
|
|
|
|
2019-04-25 23:48:08 -07:00
|
|
|
func (m *message) GetUnknown() pref.RawFields { return nil }
|
|
|
|
func (m *message) SetUnknown(pref.RawFields) { return }
|
2019-06-14 11:54:07 -07:00
|
|
|
|
2019-11-26 13:27:24 -08:00
|
|
|
func (m *message) IsValid() bool {
|
|
|
|
return m != nil
|
|
|
|
}
|
|
|
|
|
2019-07-02 14:58:02 -07:00
|
|
|
var fileDesc = func() pref.FileDescriptor {
|
2019-06-14 11:54:07 -07:00
|
|
|
p := &descriptorpb.FileDescriptorProto{}
|
|
|
|
if err := prototext.Unmarshal([]byte(descriptorText), p); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
file, err := protodesc.NewFile(p, nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return file
|
|
|
|
}()
|
|
|
|
|
2020-02-04 15:03:30 -08:00
|
|
|
func file_internal_testprotos_irregular_irregular_proto_init() { _ = fileDesc }
|
2019-06-14 11:54:07 -07:00
|
|
|
|
|
|
|
const descriptorText = `
|
|
|
|
name: "internal/testprotos/irregular/irregular.proto"
|
|
|
|
package: "goproto.proto.thirdparty"
|
|
|
|
message_type {
|
|
|
|
name: "IrregularMessage"
|
|
|
|
field {
|
|
|
|
name: "s"
|
|
|
|
number: 1
|
|
|
|
label: LABEL_OPTIONAL
|
|
|
|
type: TYPE_STRING
|
|
|
|
json_name: "s"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
options {
|
|
|
|
go_package: "google.golang.org/protobuf/internal/testprotos/irregular"
|
|
|
|
}
|
|
|
|
`
|
2019-09-30 15:34:27 -07:00
|
|
|
|
|
|
|
type AberrantMessage int
|
|
|
|
|
|
|
|
func (m AberrantMessage) ProtoMessage() {}
|
|
|
|
func (m AberrantMessage) Reset() {}
|
|
|
|
func (m AberrantMessage) String() string { return "" }
|
|
|
|
func (m AberrantMessage) Marshal() ([]byte, error) { return nil, nil }
|
|
|
|
func (m AberrantMessage) Unmarshal([]byte) error { return nil }
|