message_reflect_gen.go 7.6 KB

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