You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

604 lines
15 KiB

  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 proto
  6. import (
  7. "math"
  8. "unicode/utf8"
  9. "google.golang.org/protobuf/encoding/protowire"
  10. "google.golang.org/protobuf/internal/errors"
  11. "google.golang.org/protobuf/internal/strs"
  12. "google.golang.org/protobuf/reflect/protoreflect"
  13. )
  14. // unmarshalScalar decodes a value of the given kind.
  15. //
  16. // Message values are decoded into a []byte which aliases the input data.
  17. func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd protoreflect.FieldDescriptor) (val protoreflect.Value, n int, err error) {
  18. switch fd.Kind() {
  19. case protoreflect.BoolKind:
  20. if wtyp != protowire.VarintType {
  21. return val, 0, errUnknown
  22. }
  23. v, n := protowire.ConsumeVarint(b)
  24. if n < 0 {
  25. return val, 0, errDecode
  26. }
  27. return protoreflect.ValueOfBool(protowire.DecodeBool(v)), n, nil
  28. case protoreflect.EnumKind:
  29. if wtyp != protowire.VarintType {
  30. return val, 0, errUnknown
  31. }
  32. v, n := protowire.ConsumeVarint(b)
  33. if n < 0 {
  34. return val, 0, errDecode
  35. }
  36. return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), n, nil
  37. case protoreflect.Int32Kind:
  38. if wtyp != protowire.VarintType {
  39. return val, 0, errUnknown
  40. }
  41. v, n := protowire.ConsumeVarint(b)
  42. if n < 0 {
  43. return val, 0, errDecode
  44. }
  45. return protoreflect.ValueOfInt32(int32(v)), n, nil
  46. case protoreflect.Sint32Kind:
  47. if wtyp != protowire.VarintType {
  48. return val, 0, errUnknown
  49. }
  50. v, n := protowire.ConsumeVarint(b)
  51. if n < 0 {
  52. return val, 0, errDecode
  53. }
  54. return protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))), n, nil
  55. case protoreflect.Uint32Kind:
  56. if wtyp != protowire.VarintType {
  57. return val, 0, errUnknown
  58. }
  59. v, n := protowire.ConsumeVarint(b)
  60. if n < 0 {
  61. return val, 0, errDecode
  62. }
  63. return protoreflect.ValueOfUint32(uint32(v)), n, nil
  64. case protoreflect.Int64Kind:
  65. if wtyp != protowire.VarintType {
  66. return val, 0, errUnknown
  67. }
  68. v, n := protowire.ConsumeVarint(b)
  69. if n < 0 {
  70. return val, 0, errDecode
  71. }
  72. return protoreflect.ValueOfInt64(int64(v)), n, nil
  73. case protoreflect.Sint64Kind:
  74. if wtyp != protowire.VarintType {
  75. return val, 0, errUnknown
  76. }
  77. v, n := protowire.ConsumeVarint(b)
  78. if n < 0 {
  79. return val, 0, errDecode
  80. }
  81. return protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)), n, nil
  82. case protoreflect.Uint64Kind:
  83. if wtyp != protowire.VarintType {
  84. return val, 0, errUnknown
  85. }
  86. v, n := protowire.ConsumeVarint(b)
  87. if n < 0 {
  88. return val, 0, errDecode
  89. }
  90. return protoreflect.ValueOfUint64(v), n, nil
  91. case protoreflect.Sfixed32Kind:
  92. if wtyp != protowire.Fixed32Type {
  93. return val, 0, errUnknown
  94. }
  95. v, n := protowire.ConsumeFixed32(b)
  96. if n < 0 {
  97. return val, 0, errDecode
  98. }
  99. return protoreflect.ValueOfInt32(int32(v)), n, nil
  100. case protoreflect.Fixed32Kind:
  101. if wtyp != protowire.Fixed32Type {
  102. return val, 0, errUnknown
  103. }
  104. v, n := protowire.ConsumeFixed32(b)
  105. if n < 0 {
  106. return val, 0, errDecode
  107. }
  108. return protoreflect.ValueOfUint32(uint32(v)), n, nil
  109. case protoreflect.FloatKind:
  110. if wtyp != protowire.Fixed32Type {
  111. return val, 0, errUnknown
  112. }
  113. v, n := protowire.ConsumeFixed32(b)
  114. if n < 0 {
  115. return val, 0, errDecode
  116. }
  117. return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), n, nil
  118. case protoreflect.Sfixed64Kind:
  119. if wtyp != protowire.Fixed64Type {
  120. return val, 0, errUnknown
  121. }
  122. v, n := protowire.ConsumeFixed64(b)
  123. if n < 0 {
  124. return val, 0, errDecode
  125. }
  126. return protoreflect.ValueOfInt64(int64(v)), n, nil
  127. case protoreflect.Fixed64Kind:
  128. if wtyp != protowire.Fixed64Type {
  129. return val, 0, errUnknown
  130. }
  131. v, n := protowire.ConsumeFixed64(b)
  132. if n < 0 {
  133. return val, 0, errDecode
  134. }
  135. return protoreflect.ValueOfUint64(v), n, nil
  136. case protoreflect.DoubleKind:
  137. if wtyp != protowire.Fixed64Type {
  138. return val, 0, errUnknown
  139. }
  140. v, n := protowire.ConsumeFixed64(b)
  141. if n < 0 {
  142. return val, 0, errDecode
  143. }
  144. return protoreflect.ValueOfFloat64(math.Float64frombits(v)), n, nil
  145. case protoreflect.StringKind:
  146. if wtyp != protowire.BytesType {
  147. return val, 0, errUnknown
  148. }
  149. v, n := protowire.ConsumeBytes(b)
  150. if n < 0 {
  151. return val, 0, errDecode
  152. }
  153. if strs.EnforceUTF8(fd) && !utf8.Valid(v) {
  154. return protoreflect.Value{}, 0, errors.InvalidUTF8(string(fd.FullName()))
  155. }
  156. return protoreflect.ValueOfString(string(v)), n, nil
  157. case protoreflect.BytesKind:
  158. if wtyp != protowire.BytesType {
  159. return val, 0, errUnknown
  160. }
  161. v, n := protowire.ConsumeBytes(b)
  162. if n < 0 {
  163. return val, 0, errDecode
  164. }
  165. return protoreflect.ValueOfBytes(append(emptyBuf[:], v...)), n, nil
  166. case protoreflect.MessageKind:
  167. if wtyp != protowire.BytesType {
  168. return val, 0, errUnknown
  169. }
  170. v, n := protowire.ConsumeBytes(b)
  171. if n < 0 {
  172. return val, 0, errDecode
  173. }
  174. return protoreflect.ValueOfBytes(v), n, nil
  175. case protoreflect.GroupKind:
  176. if wtyp != protowire.StartGroupType {
  177. return val, 0, errUnknown
  178. }
  179. v, n := protowire.ConsumeGroup(fd.Number(), b)
  180. if n < 0 {
  181. return val, 0, errDecode
  182. }
  183. return protoreflect.ValueOfBytes(v), n, nil
  184. default:
  185. return val, 0, errUnknown
  186. }
  187. }
  188. func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list protoreflect.List, fd protoreflect.FieldDescriptor) (n int, err error) {
  189. switch fd.Kind() {
  190. case protoreflect.BoolKind:
  191. if wtyp == protowire.BytesType {
  192. buf, n := protowire.ConsumeBytes(b)
  193. if n < 0 {
  194. return 0, errDecode
  195. }
  196. for len(buf) > 0 {
  197. v, n := protowire.ConsumeVarint(buf)
  198. if n < 0 {
  199. return 0, errDecode
  200. }
  201. buf = buf[n:]
  202. list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v)))
  203. }
  204. return n, nil
  205. }
  206. if wtyp != protowire.VarintType {
  207. return 0, errUnknown
  208. }
  209. v, n := protowire.ConsumeVarint(b)
  210. if n < 0 {
  211. return 0, errDecode
  212. }
  213. list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v)))
  214. return n, nil
  215. case protoreflect.EnumKind:
  216. if wtyp == protowire.BytesType {
  217. buf, n := protowire.ConsumeBytes(b)
  218. if n < 0 {
  219. return 0, errDecode
  220. }
  221. for len(buf) > 0 {
  222. v, n := protowire.ConsumeVarint(buf)
  223. if n < 0 {
  224. return 0, errDecode
  225. }
  226. buf = buf[n:]
  227. list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
  228. }
  229. return n, nil
  230. }
  231. if wtyp != protowire.VarintType {
  232. return 0, errUnknown
  233. }
  234. v, n := protowire.ConsumeVarint(b)
  235. if n < 0 {
  236. return 0, errDecode
  237. }
  238. list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
  239. return n, nil
  240. case protoreflect.Int32Kind:
  241. if wtyp == protowire.BytesType {
  242. buf, n := protowire.ConsumeBytes(b)
  243. if n < 0 {
  244. return 0, errDecode
  245. }
  246. for len(buf) > 0 {
  247. v, n := protowire.ConsumeVarint(buf)
  248. if n < 0 {
  249. return 0, errDecode
  250. }
  251. buf = buf[n:]
  252. list.Append(protoreflect.ValueOfInt32(int32(v)))
  253. }
  254. return n, nil
  255. }
  256. if wtyp != protowire.VarintType {
  257. return 0, errUnknown
  258. }
  259. v, n := protowire.ConsumeVarint(b)
  260. if n < 0 {
  261. return 0, errDecode
  262. }
  263. list.Append(protoreflect.ValueOfInt32(int32(v)))
  264. return n, nil
  265. case protoreflect.Sint32Kind:
  266. if wtyp == protowire.BytesType {
  267. buf, n := protowire.ConsumeBytes(b)
  268. if n < 0 {
  269. return 0, errDecode
  270. }
  271. for len(buf) > 0 {
  272. v, n := protowire.ConsumeVarint(buf)
  273. if n < 0 {
  274. return 0, errDecode
  275. }
  276. buf = buf[n:]
  277. list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))))
  278. }
  279. return n, nil
  280. }
  281. if wtyp != protowire.VarintType {
  282. return 0, errUnknown
  283. }
  284. v, n := protowire.ConsumeVarint(b)
  285. if n < 0 {
  286. return 0, errDecode
  287. }
  288. list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))))
  289. return n, nil
  290. case protoreflect.Uint32Kind:
  291. if wtyp == protowire.BytesType {
  292. buf, n := protowire.ConsumeBytes(b)
  293. if n < 0 {
  294. return 0, errDecode
  295. }
  296. for len(buf) > 0 {
  297. v, n := protowire.ConsumeVarint(buf)
  298. if n < 0 {
  299. return 0, errDecode
  300. }
  301. buf = buf[n:]
  302. list.Append(protoreflect.ValueOfUint32(uint32(v)))
  303. }
  304. return n, nil
  305. }
  306. if wtyp != protowire.VarintType {
  307. return 0, errUnknown
  308. }
  309. v, n := protowire.ConsumeVarint(b)
  310. if n < 0 {
  311. return 0, errDecode
  312. }
  313. list.Append(protoreflect.ValueOfUint32(uint32(v)))
  314. return n, nil
  315. case protoreflect.Int64Kind:
  316. if wtyp == protowire.BytesType {
  317. buf, n := protowire.ConsumeBytes(b)
  318. if n < 0 {
  319. return 0, errDecode
  320. }
  321. for len(buf) > 0 {
  322. v, n := protowire.ConsumeVarint(buf)
  323. if n < 0 {
  324. return 0, errDecode
  325. }
  326. buf = buf[n:]
  327. list.Append(protoreflect.ValueOfInt64(int64(v)))
  328. }
  329. return n, nil
  330. }
  331. if wtyp != protowire.VarintType {
  332. return 0, errUnknown
  333. }
  334. v, n := protowire.ConsumeVarint(b)
  335. if n < 0 {
  336. return 0, errDecode
  337. }
  338. list.Append(protoreflect.ValueOfInt64(int64(v)))
  339. return n, nil
  340. case protoreflect.Sint64Kind:
  341. if wtyp == protowire.BytesType {
  342. buf, n := protowire.ConsumeBytes(b)
  343. if n < 0 {
  344. return 0, errDecode
  345. }
  346. for len(buf) > 0 {
  347. v, n := protowire.ConsumeVarint(buf)
  348. if n < 0 {
  349. return 0, errDecode
  350. }
  351. buf = buf[n:]
  352. list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)))
  353. }
  354. return n, nil
  355. }
  356. if wtyp != protowire.VarintType {
  357. return 0, errUnknown
  358. }
  359. v, n := protowire.ConsumeVarint(b)
  360. if n < 0 {
  361. return 0, errDecode
  362. }
  363. list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)))
  364. return n, nil
  365. case protoreflect.Uint64Kind:
  366. if wtyp == protowire.BytesType {
  367. buf, n := protowire.ConsumeBytes(b)
  368. if n < 0 {
  369. return 0, errDecode
  370. }
  371. for len(buf) > 0 {
  372. v, n := protowire.ConsumeVarint(buf)
  373. if n < 0 {
  374. return 0, errDecode
  375. }
  376. buf = buf[n:]
  377. list.Append(protoreflect.ValueOfUint64(v))
  378. }
  379. return n, nil
  380. }
  381. if wtyp != protowire.VarintType {
  382. return 0, errUnknown
  383. }
  384. v, n := protowire.ConsumeVarint(b)
  385. if n < 0 {
  386. return 0, errDecode
  387. }
  388. list.Append(protoreflect.ValueOfUint64(v))
  389. return n, nil
  390. case protoreflect.Sfixed32Kind:
  391. if wtyp == protowire.BytesType {
  392. buf, n := protowire.ConsumeBytes(b)
  393. if n < 0 {
  394. return 0, errDecode
  395. }
  396. for len(buf) > 0 {
  397. v, n := protowire.ConsumeFixed32(buf)
  398. if n < 0 {
  399. return 0, errDecode
  400. }
  401. buf = buf[n:]
  402. list.Append(protoreflect.ValueOfInt32(int32(v)))
  403. }
  404. return n, nil
  405. }
  406. if wtyp != protowire.Fixed32Type {
  407. return 0, errUnknown
  408. }
  409. v, n := protowire.ConsumeFixed32(b)
  410. if n < 0 {
  411. return 0, errDecode
  412. }
  413. list.Append(protoreflect.ValueOfInt32(int32(v)))
  414. return n, nil
  415. case protoreflect.Fixed32Kind:
  416. if wtyp == protowire.BytesType {
  417. buf, n := protowire.ConsumeBytes(b)
  418. if n < 0 {
  419. return 0, errDecode
  420. }
  421. for len(buf) > 0 {
  422. v, n := protowire.ConsumeFixed32(buf)
  423. if n < 0 {
  424. return 0, errDecode
  425. }
  426. buf = buf[n:]
  427. list.Append(protoreflect.ValueOfUint32(uint32(v)))
  428. }
  429. return n, nil
  430. }
  431. if wtyp != protowire.Fixed32Type {
  432. return 0, errUnknown
  433. }
  434. v, n := protowire.ConsumeFixed32(b)
  435. if n < 0 {
  436. return 0, errDecode
  437. }
  438. list.Append(protoreflect.ValueOfUint32(uint32(v)))
  439. return n, nil
  440. case protoreflect.FloatKind:
  441. if wtyp == protowire.BytesType {
  442. buf, n := protowire.ConsumeBytes(b)
  443. if n < 0 {
  444. return 0, errDecode
  445. }
  446. for len(buf) > 0 {
  447. v, n := protowire.ConsumeFixed32(buf)
  448. if n < 0 {
  449. return 0, errDecode
  450. }
  451. buf = buf[n:]
  452. list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
  453. }
  454. return n, nil
  455. }
  456. if wtyp != protowire.Fixed32Type {
  457. return 0, errUnknown
  458. }
  459. v, n := protowire.ConsumeFixed32(b)
  460. if n < 0 {
  461. return 0, errDecode
  462. }
  463. list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
  464. return n, nil
  465. case protoreflect.Sfixed64Kind:
  466. if wtyp == protowire.BytesType {
  467. buf, n := protowire.ConsumeBytes(b)
  468. if n < 0 {
  469. return 0, errDecode
  470. }
  471. for len(buf) > 0 {
  472. v, n := protowire.ConsumeFixed64(buf)
  473. if n < 0 {
  474. return 0, errDecode
  475. }
  476. buf = buf[n:]
  477. list.Append(protoreflect.ValueOfInt64(int64(v)))
  478. }
  479. return n, nil
  480. }
  481. if wtyp != protowire.Fixed64Type {
  482. return 0, errUnknown
  483. }
  484. v, n := protowire.ConsumeFixed64(b)
  485. if n < 0 {
  486. return 0, errDecode
  487. }
  488. list.Append(protoreflect.ValueOfInt64(int64(v)))
  489. return n, nil
  490. case protoreflect.Fixed64Kind:
  491. if wtyp == protowire.BytesType {
  492. buf, n := protowire.ConsumeBytes(b)
  493. if n < 0 {
  494. return 0, errDecode
  495. }
  496. for len(buf) > 0 {
  497. v, n := protowire.ConsumeFixed64(buf)
  498. if n < 0 {
  499. return 0, errDecode
  500. }
  501. buf = buf[n:]
  502. list.Append(protoreflect.ValueOfUint64(v))
  503. }
  504. return n, nil
  505. }
  506. if wtyp != protowire.Fixed64Type {
  507. return 0, errUnknown
  508. }
  509. v, n := protowire.ConsumeFixed64(b)
  510. if n < 0 {
  511. return 0, errDecode
  512. }
  513. list.Append(protoreflect.ValueOfUint64(v))
  514. return n, nil
  515. case protoreflect.DoubleKind:
  516. if wtyp == protowire.BytesType {
  517. buf, n := protowire.ConsumeBytes(b)
  518. if n < 0 {
  519. return 0, errDecode
  520. }
  521. for len(buf) > 0 {
  522. v, n := protowire.ConsumeFixed64(buf)
  523. if n < 0 {
  524. return 0, errDecode
  525. }
  526. buf = buf[n:]
  527. list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
  528. }
  529. return n, nil
  530. }
  531. if wtyp != protowire.Fixed64Type {
  532. return 0, errUnknown
  533. }
  534. v, n := protowire.ConsumeFixed64(b)
  535. if n < 0 {
  536. return 0, errDecode
  537. }
  538. list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
  539. return n, nil
  540. case protoreflect.StringKind:
  541. if wtyp != protowire.BytesType {
  542. return 0, errUnknown
  543. }
  544. v, n := protowire.ConsumeBytes(b)
  545. if n < 0 {
  546. return 0, errDecode
  547. }
  548. if strs.EnforceUTF8(fd) && !utf8.Valid(v) {
  549. return 0, errors.InvalidUTF8(string(fd.FullName()))
  550. }
  551. list.Append(protoreflect.ValueOfString(string(v)))
  552. return n, nil
  553. case protoreflect.BytesKind:
  554. if wtyp != protowire.BytesType {
  555. return 0, errUnknown
  556. }
  557. v, n := protowire.ConsumeBytes(b)
  558. if n < 0 {
  559. return 0, errDecode
  560. }
  561. list.Append(protoreflect.ValueOfBytes(append(emptyBuf[:], v...)))
  562. return n, nil
  563. case protoreflect.MessageKind:
  564. if wtyp != protowire.BytesType {
  565. return 0, errUnknown
  566. }
  567. v, n := protowire.ConsumeBytes(b)
  568. if n < 0 {
  569. return 0, errDecode
  570. }
  571. m := list.NewElement()
  572. if err := o.unmarshalMessage(v, m.Message()); err != nil {
  573. return 0, err
  574. }
  575. list.Append(m)
  576. return n, nil
  577. case protoreflect.GroupKind:
  578. if wtyp != protowire.StartGroupType {
  579. return 0, errUnknown
  580. }
  581. v, n := protowire.ConsumeGroup(fd.Number(), b)
  582. if n < 0 {
  583. return 0, errDecode
  584. }
  585. m := list.NewElement()
  586. if err := o.unmarshalMessage(v, m.Message()); err != nil {
  587. return 0, err
  588. }
  589. list.Append(m)
  590. return n, nil
  591. default:
  592. return 0, errUnknown
  593. }
  594. }
  595. // We append to an empty array rather than a nil []byte to get non-nil zero-length byte slices.
  596. var emptyBuf [0]byte