...

Source file src/google.golang.org/protobuf/internal/testprotos/irregular/irregular.go

Documentation: google.golang.org/protobuf/internal/testprotos/irregular

     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  
     5  package irregular
     6  
     7  import (
     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  
    16  type IrregularMessage struct {
    17  	set   bool
    18  	value string
    19  }
    20  
    21  func (m *IrregularMessage) ProtoReflect() protoreflect.Message { return (*message)(m) }
    22  
    23  type message IrregularMessage
    24  
    25  type messageType struct{}
    26  
    27  func (messageType) New() protoreflect.Message                  { return &message{} }
    28  func (messageType) Zero() protoreflect.Message                 { return (*message)(nil) }
    29  func (messageType) Descriptor() protoreflect.MessageDescriptor { return fileDesc.Messages().Get(0) }
    30  
    31  func (m *message) New() protoreflect.Message                  { return &message{} }
    32  func (m *message) Descriptor() protoreflect.MessageDescriptor { return fileDesc.Messages().Get(0) }
    33  func (m *message) Type() protoreflect.MessageType             { return messageType{} }
    34  func (m *message) Interface() protoreflect.ProtoMessage       { return (*IrregularMessage)(m) }
    35  func (m *message) ProtoMethods() *protoiface.Methods          { return nil }
    36  
    37  var fieldDescS = fileDesc.Messages().Get(0).Fields().Get(0)
    38  
    39  func (m *message) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
    40  	if m.set {
    41  		f(fieldDescS, protoreflect.ValueOf(m.value))
    42  	}
    43  }
    44  
    45  func (m *message) Has(fd protoreflect.FieldDescriptor) bool {
    46  	if fd == fieldDescS {
    47  		return m.set
    48  	}
    49  	panic("invalid field descriptor")
    50  }
    51  
    52  func (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  
    61  func (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  
    68  func (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  
    77  func (m *message) Mutable(protoreflect.FieldDescriptor) protoreflect.Value {
    78  	panic("invalid field descriptor")
    79  }
    80  
    81  func (m *message) NewField(protoreflect.FieldDescriptor) protoreflect.Value {
    82  	panic("invalid field descriptor")
    83  }
    84  
    85  func (m *message) WhichOneof(protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
    86  	panic("invalid oneof descriptor")
    87  }
    88  
    89  func (m *message) GetUnknown() protoreflect.RawFields { return nil }
    90  func (m *message) SetUnknown(protoreflect.RawFields)  { return }
    91  
    92  func (m *message) IsValid() bool {
    93  	return m != nil
    94  }
    95  
    96  var 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  
   108  func file_internal_testprotos_irregular_irregular_proto_init() { _ = fileDesc }
   109  
   110  const 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  
   128  type AberrantMessage int
   129  
   130  func (m AberrantMessage) ProtoMessage()            {}
   131  func (m AberrantMessage) Reset()                   {}
   132  func (m AberrantMessage) String() string           { return "" }
   133  func (m AberrantMessage) Marshal() ([]byte, error) { return nil, nil }
   134  func (m AberrantMessage) Unmarshal([]byte) error   { return nil }
   135  

View as plain text