...

Source file src/google.golang.org/protobuf/internal/impl/message_reflect_gen.go

Documentation: google.golang.org/protobuf/internal/impl

     1  // Copyright 2018 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  // Code generated by generate-types. DO NOT EDIT.
     6  
     7  package impl
     8  
     9  import (
    10  	"google.golang.org/protobuf/reflect/protoreflect"
    11  	"google.golang.org/protobuf/runtime/protoiface"
    12  )
    13  
    14  func (m *messageState) Descriptor() protoreflect.MessageDescriptor {
    15  	return m.messageInfo().Desc
    16  }
    17  func (m *messageState) Type() protoreflect.MessageType {
    18  	return m.messageInfo()
    19  }
    20  func (m *messageState) New() protoreflect.Message {
    21  	return m.messageInfo().New()
    22  }
    23  func (m *messageState) Interface() protoreflect.ProtoMessage {
    24  	return m.protoUnwrap().(protoreflect.ProtoMessage)
    25  }
    26  func (m *messageState) protoUnwrap() interface{} {
    27  	return m.pointer().AsIfaceOf(m.messageInfo().GoReflectType.Elem())
    28  }
    29  func (m *messageState) ProtoMethods() *protoiface.Methods {
    30  	m.messageInfo().init()
    31  	return &m.messageInfo().methods
    32  }
    33  
    34  // ProtoMessageInfo is a pseudo-internal API for allowing the v1 code
    35  // to be able to retrieve a v2 MessageInfo struct.
    36  //
    37  // WARNING: This method is exempt from the compatibility promise and
    38  // may be removed in the future without warning.
    39  func (m *messageState) ProtoMessageInfo() *MessageInfo {
    40  	return m.messageInfo()
    41  }
    42  
    43  func (m *messageState) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
    44  	m.messageInfo().init()
    45  	for _, ri := range m.messageInfo().rangeInfos {
    46  		switch ri := ri.(type) {
    47  		case *fieldInfo:
    48  			if ri.has(m.pointer()) {
    49  				if !f(ri.fieldDesc, ri.get(m.pointer())) {
    50  					return
    51  				}
    52  			}
    53  		case *oneofInfo:
    54  			if n := ri.which(m.pointer()); n > 0 {
    55  				fi := m.messageInfo().fields[n]
    56  				if !f(fi.fieldDesc, fi.get(m.pointer())) {
    57  					return
    58  				}
    59  			}
    60  		}
    61  	}
    62  	m.messageInfo().extensionMap(m.pointer()).Range(f)
    63  }
    64  func (m *messageState) Has(fd protoreflect.FieldDescriptor) bool {
    65  	m.messageInfo().init()
    66  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
    67  		return fi.has(m.pointer())
    68  	} else {
    69  		return m.messageInfo().extensionMap(m.pointer()).Has(xt)
    70  	}
    71  }
    72  func (m *messageState) Clear(fd protoreflect.FieldDescriptor) {
    73  	m.messageInfo().init()
    74  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
    75  		fi.clear(m.pointer())
    76  	} else {
    77  		m.messageInfo().extensionMap(m.pointer()).Clear(xt)
    78  	}
    79  }
    80  func (m *messageState) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
    81  	m.messageInfo().init()
    82  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
    83  		return fi.get(m.pointer())
    84  	} else {
    85  		return m.messageInfo().extensionMap(m.pointer()).Get(xt)
    86  	}
    87  }
    88  func (m *messageState) Set(fd protoreflect.FieldDescriptor, v protoreflect.Value) {
    89  	m.messageInfo().init()
    90  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
    91  		fi.set(m.pointer(), v)
    92  	} else {
    93  		m.messageInfo().extensionMap(m.pointer()).Set(xt, v)
    94  	}
    95  }
    96  func (m *messageState) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
    97  	m.messageInfo().init()
    98  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
    99  		return fi.mutable(m.pointer())
   100  	} else {
   101  		return m.messageInfo().extensionMap(m.pointer()).Mutable(xt)
   102  	}
   103  }
   104  func (m *messageState) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value {
   105  	m.messageInfo().init()
   106  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
   107  		return fi.newField()
   108  	} else {
   109  		return xt.New()
   110  	}
   111  }
   112  func (m *messageState) WhichOneof(od protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
   113  	m.messageInfo().init()
   114  	if oi := m.messageInfo().oneofs[od.Name()]; oi != nil && oi.oneofDesc == od {
   115  		return od.Fields().ByNumber(oi.which(m.pointer()))
   116  	}
   117  	panic("invalid oneof descriptor " + string(od.FullName()) + " for message " + string(m.Descriptor().FullName()))
   118  }
   119  func (m *messageState) GetUnknown() protoreflect.RawFields {
   120  	m.messageInfo().init()
   121  	return m.messageInfo().getUnknown(m.pointer())
   122  }
   123  func (m *messageState) SetUnknown(b protoreflect.RawFields) {
   124  	m.messageInfo().init()
   125  	m.messageInfo().setUnknown(m.pointer(), b)
   126  }
   127  func (m *messageState) IsValid() bool {
   128  	return !m.pointer().IsNil()
   129  }
   130  
   131  func (m *messageReflectWrapper) Descriptor() protoreflect.MessageDescriptor {
   132  	return m.messageInfo().Desc
   133  }
   134  func (m *messageReflectWrapper) Type() protoreflect.MessageType {
   135  	return m.messageInfo()
   136  }
   137  func (m *messageReflectWrapper) New() protoreflect.Message {
   138  	return m.messageInfo().New()
   139  }
   140  func (m *messageReflectWrapper) Interface() protoreflect.ProtoMessage {
   141  	if m, ok := m.protoUnwrap().(protoreflect.ProtoMessage); ok {
   142  		return m
   143  	}
   144  	return (*messageIfaceWrapper)(m)
   145  }
   146  func (m *messageReflectWrapper) protoUnwrap() interface{} {
   147  	return m.pointer().AsIfaceOf(m.messageInfo().GoReflectType.Elem())
   148  }
   149  func (m *messageReflectWrapper) ProtoMethods() *protoiface.Methods {
   150  	m.messageInfo().init()
   151  	return &m.messageInfo().methods
   152  }
   153  
   154  // ProtoMessageInfo is a pseudo-internal API for allowing the v1 code
   155  // to be able to retrieve a v2 MessageInfo struct.
   156  //
   157  // WARNING: This method is exempt from the compatibility promise and
   158  // may be removed in the future without warning.
   159  func (m *messageReflectWrapper) ProtoMessageInfo() *MessageInfo {
   160  	return m.messageInfo()
   161  }
   162  
   163  func (m *messageReflectWrapper) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
   164  	m.messageInfo().init()
   165  	for _, ri := range m.messageInfo().rangeInfos {
   166  		switch ri := ri.(type) {
   167  		case *fieldInfo:
   168  			if ri.has(m.pointer()) {
   169  				if !f(ri.fieldDesc, ri.get(m.pointer())) {
   170  					return
   171  				}
   172  			}
   173  		case *oneofInfo:
   174  			if n := ri.which(m.pointer()); n > 0 {
   175  				fi := m.messageInfo().fields[n]
   176  				if !f(fi.fieldDesc, fi.get(m.pointer())) {
   177  					return
   178  				}
   179  			}
   180  		}
   181  	}
   182  	m.messageInfo().extensionMap(m.pointer()).Range(f)
   183  }
   184  func (m *messageReflectWrapper) Has(fd protoreflect.FieldDescriptor) bool {
   185  	m.messageInfo().init()
   186  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
   187  		return fi.has(m.pointer())
   188  	} else {
   189  		return m.messageInfo().extensionMap(m.pointer()).Has(xt)
   190  	}
   191  }
   192  func (m *messageReflectWrapper) Clear(fd protoreflect.FieldDescriptor) {
   193  	m.messageInfo().init()
   194  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
   195  		fi.clear(m.pointer())
   196  	} else {
   197  		m.messageInfo().extensionMap(m.pointer()).Clear(xt)
   198  	}
   199  }
   200  func (m *messageReflectWrapper) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
   201  	m.messageInfo().init()
   202  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
   203  		return fi.get(m.pointer())
   204  	} else {
   205  		return m.messageInfo().extensionMap(m.pointer()).Get(xt)
   206  	}
   207  }
   208  func (m *messageReflectWrapper) Set(fd protoreflect.FieldDescriptor, v protoreflect.Value) {
   209  	m.messageInfo().init()
   210  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
   211  		fi.set(m.pointer(), v)
   212  	} else {
   213  		m.messageInfo().extensionMap(m.pointer()).Set(xt, v)
   214  	}
   215  }
   216  func (m *messageReflectWrapper) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
   217  	m.messageInfo().init()
   218  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
   219  		return fi.mutable(m.pointer())
   220  	} else {
   221  		return m.messageInfo().extensionMap(m.pointer()).Mutable(xt)
   222  	}
   223  }
   224  func (m *messageReflectWrapper) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value {
   225  	m.messageInfo().init()
   226  	if fi, xt := m.messageInfo().checkField(fd); fi != nil {
   227  		return fi.newField()
   228  	} else {
   229  		return xt.New()
   230  	}
   231  }
   232  func (m *messageReflectWrapper) WhichOneof(od protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
   233  	m.messageInfo().init()
   234  	if oi := m.messageInfo().oneofs[od.Name()]; oi != nil && oi.oneofDesc == od {
   235  		return od.Fields().ByNumber(oi.which(m.pointer()))
   236  	}
   237  	panic("invalid oneof descriptor " + string(od.FullName()) + " for message " + string(m.Descriptor().FullName()))
   238  }
   239  func (m *messageReflectWrapper) GetUnknown() protoreflect.RawFields {
   240  	m.messageInfo().init()
   241  	return m.messageInfo().getUnknown(m.pointer())
   242  }
   243  func (m *messageReflectWrapper) SetUnknown(b protoreflect.RawFields) {
   244  	m.messageInfo().init()
   245  	m.messageInfo().setUnknown(m.pointer(), b)
   246  }
   247  func (m *messageReflectWrapper) IsValid() bool {
   248  	return !m.pointer().IsNil()
   249  }
   250  

View as plain text