message_reflect_gen.go 7.8 KB

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