wrappers.go 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888
  1. // Protocol Buffers for Go with Gadgets
  2. //
  3. // Copyright (c) 2018, The GoGo Authors. All rights reserved.
  4. // http://github.com/gogo/protobuf
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are
  8. // met:
  9. //
  10. // * Redistributions of source code must retain the above copyright
  11. // notice, this list of conditions and the following disclaimer.
  12. // * Redistributions in binary form must reproduce the above
  13. // copyright notice, this list of conditions and the following disclaimer
  14. // in the documentation and/or other materials provided with the
  15. // distribution.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. package proto
  29. import (
  30. "io"
  31. "reflect"
  32. )
  33. func makeStdDoubleValueMarshaler(u *marshalInfo) (sizer, marshaler) {
  34. return func(ptr pointer, tagsize int) int {
  35. t := ptr.asPointerTo(u.typ).Interface().(*float64)
  36. v := &float64Value{*t}
  37. siz := Size(v)
  38. return tagsize + SizeVarint(uint64(siz)) + siz
  39. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  40. t := ptr.asPointerTo(u.typ).Interface().(*float64)
  41. v := &float64Value{*t}
  42. buf, err := Marshal(v)
  43. if err != nil {
  44. return nil, err
  45. }
  46. b = appendVarint(b, wiretag)
  47. b = appendVarint(b, uint64(len(buf)))
  48. b = append(b, buf...)
  49. return b, nil
  50. }
  51. }
  52. func makeStdDoubleValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) {
  53. return func(ptr pointer, tagsize int) int {
  54. if ptr.isNil() {
  55. return 0
  56. }
  57. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float64)
  58. v := &float64Value{*t}
  59. siz := Size(v)
  60. return tagsize + SizeVarint(uint64(siz)) + siz
  61. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  62. if ptr.isNil() {
  63. return b, nil
  64. }
  65. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float64)
  66. v := &float64Value{*t}
  67. buf, err := Marshal(v)
  68. if err != nil {
  69. return nil, err
  70. }
  71. b = appendVarint(b, wiretag)
  72. b = appendVarint(b, uint64(len(buf)))
  73. b = append(b, buf...)
  74. return b, nil
  75. }
  76. }
  77. func makeStdDoubleValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  78. return func(ptr pointer, tagsize int) int {
  79. s := ptr.getSlice(u.typ)
  80. n := 0
  81. for i := 0; i < s.Len(); i++ {
  82. elem := s.Index(i)
  83. t := elem.Interface().(float64)
  84. v := &float64Value{t}
  85. siz := Size(v)
  86. n += siz + SizeVarint(uint64(siz)) + tagsize
  87. }
  88. return n
  89. },
  90. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  91. s := ptr.getSlice(u.typ)
  92. for i := 0; i < s.Len(); i++ {
  93. elem := s.Index(i)
  94. t := elem.Interface().(float64)
  95. v := &float64Value{t}
  96. siz := Size(v)
  97. buf, err := Marshal(v)
  98. if err != nil {
  99. return nil, err
  100. }
  101. b = appendVarint(b, wiretag)
  102. b = appendVarint(b, uint64(siz))
  103. b = append(b, buf...)
  104. }
  105. return b, nil
  106. }
  107. }
  108. func makeStdDoubleValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  109. return func(ptr pointer, tagsize int) int {
  110. s := ptr.getSlice(reflect.PtrTo(u.typ))
  111. n := 0
  112. for i := 0; i < s.Len(); i++ {
  113. elem := s.Index(i)
  114. t := elem.Interface().(*float64)
  115. v := &float64Value{*t}
  116. siz := Size(v)
  117. n += siz + SizeVarint(uint64(siz)) + tagsize
  118. }
  119. return n
  120. },
  121. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  122. s := ptr.getSlice(reflect.PtrTo(u.typ))
  123. for i := 0; i < s.Len(); i++ {
  124. elem := s.Index(i)
  125. t := elem.Interface().(*float64)
  126. v := &float64Value{*t}
  127. siz := Size(v)
  128. buf, err := Marshal(v)
  129. if err != nil {
  130. return nil, err
  131. }
  132. b = appendVarint(b, wiretag)
  133. b = appendVarint(b, uint64(siz))
  134. b = append(b, buf...)
  135. }
  136. return b, nil
  137. }
  138. }
  139. func makeStdDoubleValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  140. return func(b []byte, f pointer, w int) ([]byte, error) {
  141. if w != WireBytes {
  142. return nil, errInternalBadWireType
  143. }
  144. x, n := decodeVarint(b)
  145. if n == 0 {
  146. return nil, io.ErrUnexpectedEOF
  147. }
  148. b = b[n:]
  149. if x > uint64(len(b)) {
  150. return nil, io.ErrUnexpectedEOF
  151. }
  152. m := &float64Value{}
  153. if err := Unmarshal(b[:x], m); err != nil {
  154. return nil, err
  155. }
  156. s := f.asPointerTo(sub.typ).Elem()
  157. s.Set(reflect.ValueOf(m.Value))
  158. return b[x:], nil
  159. }
  160. }
  161. func makeStdDoubleValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  162. return func(b []byte, f pointer, w int) ([]byte, error) {
  163. if w != WireBytes {
  164. return nil, errInternalBadWireType
  165. }
  166. x, n := decodeVarint(b)
  167. if n == 0 {
  168. return nil, io.ErrUnexpectedEOF
  169. }
  170. b = b[n:]
  171. if x > uint64(len(b)) {
  172. return nil, io.ErrUnexpectedEOF
  173. }
  174. m := &float64Value{}
  175. if err := Unmarshal(b[:x], m); err != nil {
  176. return nil, err
  177. }
  178. s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem()
  179. s.Set(reflect.ValueOf(&m.Value))
  180. return b[x:], nil
  181. }
  182. }
  183. func makeStdDoubleValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  184. return func(b []byte, f pointer, w int) ([]byte, error) {
  185. if w != WireBytes {
  186. return nil, errInternalBadWireType
  187. }
  188. x, n := decodeVarint(b)
  189. if n == 0 {
  190. return nil, io.ErrUnexpectedEOF
  191. }
  192. b = b[n:]
  193. if x > uint64(len(b)) {
  194. return nil, io.ErrUnexpectedEOF
  195. }
  196. m := &float64Value{}
  197. if err := Unmarshal(b[:x], m); err != nil {
  198. return nil, err
  199. }
  200. slice := f.getSlice(reflect.PtrTo(sub.typ))
  201. newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value))
  202. slice.Set(newSlice)
  203. return b[x:], nil
  204. }
  205. }
  206. func makeStdDoubleValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  207. return func(b []byte, f pointer, w int) ([]byte, error) {
  208. if w != WireBytes {
  209. return nil, errInternalBadWireType
  210. }
  211. x, n := decodeVarint(b)
  212. if n == 0 {
  213. return nil, io.ErrUnexpectedEOF
  214. }
  215. b = b[n:]
  216. if x > uint64(len(b)) {
  217. return nil, io.ErrUnexpectedEOF
  218. }
  219. m := &float64Value{}
  220. if err := Unmarshal(b[:x], m); err != nil {
  221. return nil, err
  222. }
  223. slice := f.getSlice(sub.typ)
  224. newSlice := reflect.Append(slice, reflect.ValueOf(m.Value))
  225. slice.Set(newSlice)
  226. return b[x:], nil
  227. }
  228. }
  229. func makeStdFloatValueMarshaler(u *marshalInfo) (sizer, marshaler) {
  230. return func(ptr pointer, tagsize int) int {
  231. t := ptr.asPointerTo(u.typ).Interface().(*float32)
  232. v := &float32Value{*t}
  233. siz := Size(v)
  234. return tagsize + SizeVarint(uint64(siz)) + siz
  235. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  236. t := ptr.asPointerTo(u.typ).Interface().(*float32)
  237. v := &float32Value{*t}
  238. buf, err := Marshal(v)
  239. if err != nil {
  240. return nil, err
  241. }
  242. b = appendVarint(b, wiretag)
  243. b = appendVarint(b, uint64(len(buf)))
  244. b = append(b, buf...)
  245. return b, nil
  246. }
  247. }
  248. func makeStdFloatValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) {
  249. return func(ptr pointer, tagsize int) int {
  250. if ptr.isNil() {
  251. return 0
  252. }
  253. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float32)
  254. v := &float32Value{*t}
  255. siz := Size(v)
  256. return tagsize + SizeVarint(uint64(siz)) + siz
  257. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  258. if ptr.isNil() {
  259. return b, nil
  260. }
  261. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float32)
  262. v := &float32Value{*t}
  263. buf, err := Marshal(v)
  264. if err != nil {
  265. return nil, err
  266. }
  267. b = appendVarint(b, wiretag)
  268. b = appendVarint(b, uint64(len(buf)))
  269. b = append(b, buf...)
  270. return b, nil
  271. }
  272. }
  273. func makeStdFloatValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  274. return func(ptr pointer, tagsize int) int {
  275. s := ptr.getSlice(u.typ)
  276. n := 0
  277. for i := 0; i < s.Len(); i++ {
  278. elem := s.Index(i)
  279. t := elem.Interface().(float32)
  280. v := &float32Value{t}
  281. siz := Size(v)
  282. n += siz + SizeVarint(uint64(siz)) + tagsize
  283. }
  284. return n
  285. },
  286. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  287. s := ptr.getSlice(u.typ)
  288. for i := 0; i < s.Len(); i++ {
  289. elem := s.Index(i)
  290. t := elem.Interface().(float32)
  291. v := &float32Value{t}
  292. siz := Size(v)
  293. buf, err := Marshal(v)
  294. if err != nil {
  295. return nil, err
  296. }
  297. b = appendVarint(b, wiretag)
  298. b = appendVarint(b, uint64(siz))
  299. b = append(b, buf...)
  300. }
  301. return b, nil
  302. }
  303. }
  304. func makeStdFloatValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  305. return func(ptr pointer, tagsize int) int {
  306. s := ptr.getSlice(reflect.PtrTo(u.typ))
  307. n := 0
  308. for i := 0; i < s.Len(); i++ {
  309. elem := s.Index(i)
  310. t := elem.Interface().(*float32)
  311. v := &float32Value{*t}
  312. siz := Size(v)
  313. n += siz + SizeVarint(uint64(siz)) + tagsize
  314. }
  315. return n
  316. },
  317. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  318. s := ptr.getSlice(reflect.PtrTo(u.typ))
  319. for i := 0; i < s.Len(); i++ {
  320. elem := s.Index(i)
  321. t := elem.Interface().(*float32)
  322. v := &float32Value{*t}
  323. siz := Size(v)
  324. buf, err := Marshal(v)
  325. if err != nil {
  326. return nil, err
  327. }
  328. b = appendVarint(b, wiretag)
  329. b = appendVarint(b, uint64(siz))
  330. b = append(b, buf...)
  331. }
  332. return b, nil
  333. }
  334. }
  335. func makeStdFloatValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  336. return func(b []byte, f pointer, w int) ([]byte, error) {
  337. if w != WireBytes {
  338. return nil, errInternalBadWireType
  339. }
  340. x, n := decodeVarint(b)
  341. if n == 0 {
  342. return nil, io.ErrUnexpectedEOF
  343. }
  344. b = b[n:]
  345. if x > uint64(len(b)) {
  346. return nil, io.ErrUnexpectedEOF
  347. }
  348. m := &float32Value{}
  349. if err := Unmarshal(b[:x], m); err != nil {
  350. return nil, err
  351. }
  352. s := f.asPointerTo(sub.typ).Elem()
  353. s.Set(reflect.ValueOf(m.Value))
  354. return b[x:], nil
  355. }
  356. }
  357. func makeStdFloatValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  358. return func(b []byte, f pointer, w int) ([]byte, error) {
  359. if w != WireBytes {
  360. return nil, errInternalBadWireType
  361. }
  362. x, n := decodeVarint(b)
  363. if n == 0 {
  364. return nil, io.ErrUnexpectedEOF
  365. }
  366. b = b[n:]
  367. if x > uint64(len(b)) {
  368. return nil, io.ErrUnexpectedEOF
  369. }
  370. m := &float32Value{}
  371. if err := Unmarshal(b[:x], m); err != nil {
  372. return nil, err
  373. }
  374. s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem()
  375. s.Set(reflect.ValueOf(&m.Value))
  376. return b[x:], nil
  377. }
  378. }
  379. func makeStdFloatValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  380. return func(b []byte, f pointer, w int) ([]byte, error) {
  381. if w != WireBytes {
  382. return nil, errInternalBadWireType
  383. }
  384. x, n := decodeVarint(b)
  385. if n == 0 {
  386. return nil, io.ErrUnexpectedEOF
  387. }
  388. b = b[n:]
  389. if x > uint64(len(b)) {
  390. return nil, io.ErrUnexpectedEOF
  391. }
  392. m := &float32Value{}
  393. if err := Unmarshal(b[:x], m); err != nil {
  394. return nil, err
  395. }
  396. slice := f.getSlice(reflect.PtrTo(sub.typ))
  397. newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value))
  398. slice.Set(newSlice)
  399. return b[x:], nil
  400. }
  401. }
  402. func makeStdFloatValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  403. return func(b []byte, f pointer, w int) ([]byte, error) {
  404. if w != WireBytes {
  405. return nil, errInternalBadWireType
  406. }
  407. x, n := decodeVarint(b)
  408. if n == 0 {
  409. return nil, io.ErrUnexpectedEOF
  410. }
  411. b = b[n:]
  412. if x > uint64(len(b)) {
  413. return nil, io.ErrUnexpectedEOF
  414. }
  415. m := &float32Value{}
  416. if err := Unmarshal(b[:x], m); err != nil {
  417. return nil, err
  418. }
  419. slice := f.getSlice(sub.typ)
  420. newSlice := reflect.Append(slice, reflect.ValueOf(m.Value))
  421. slice.Set(newSlice)
  422. return b[x:], nil
  423. }
  424. }
  425. func makeStdInt64ValueMarshaler(u *marshalInfo) (sizer, marshaler) {
  426. return func(ptr pointer, tagsize int) int {
  427. t := ptr.asPointerTo(u.typ).Interface().(*int64)
  428. v := &int64Value{*t}
  429. siz := Size(v)
  430. return tagsize + SizeVarint(uint64(siz)) + siz
  431. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  432. t := ptr.asPointerTo(u.typ).Interface().(*int64)
  433. v := &int64Value{*t}
  434. buf, err := Marshal(v)
  435. if err != nil {
  436. return nil, err
  437. }
  438. b = appendVarint(b, wiretag)
  439. b = appendVarint(b, uint64(len(buf)))
  440. b = append(b, buf...)
  441. return b, nil
  442. }
  443. }
  444. func makeStdInt64ValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) {
  445. return func(ptr pointer, tagsize int) int {
  446. if ptr.isNil() {
  447. return 0
  448. }
  449. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int64)
  450. v := &int64Value{*t}
  451. siz := Size(v)
  452. return tagsize + SizeVarint(uint64(siz)) + siz
  453. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  454. if ptr.isNil() {
  455. return b, nil
  456. }
  457. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int64)
  458. v := &int64Value{*t}
  459. buf, err := Marshal(v)
  460. if err != nil {
  461. return nil, err
  462. }
  463. b = appendVarint(b, wiretag)
  464. b = appendVarint(b, uint64(len(buf)))
  465. b = append(b, buf...)
  466. return b, nil
  467. }
  468. }
  469. func makeStdInt64ValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  470. return func(ptr pointer, tagsize int) int {
  471. s := ptr.getSlice(u.typ)
  472. n := 0
  473. for i := 0; i < s.Len(); i++ {
  474. elem := s.Index(i)
  475. t := elem.Interface().(int64)
  476. v := &int64Value{t}
  477. siz := Size(v)
  478. n += siz + SizeVarint(uint64(siz)) + tagsize
  479. }
  480. return n
  481. },
  482. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  483. s := ptr.getSlice(u.typ)
  484. for i := 0; i < s.Len(); i++ {
  485. elem := s.Index(i)
  486. t := elem.Interface().(int64)
  487. v := &int64Value{t}
  488. siz := Size(v)
  489. buf, err := Marshal(v)
  490. if err != nil {
  491. return nil, err
  492. }
  493. b = appendVarint(b, wiretag)
  494. b = appendVarint(b, uint64(siz))
  495. b = append(b, buf...)
  496. }
  497. return b, nil
  498. }
  499. }
  500. func makeStdInt64ValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  501. return func(ptr pointer, tagsize int) int {
  502. s := ptr.getSlice(reflect.PtrTo(u.typ))
  503. n := 0
  504. for i := 0; i < s.Len(); i++ {
  505. elem := s.Index(i)
  506. t := elem.Interface().(*int64)
  507. v := &int64Value{*t}
  508. siz := Size(v)
  509. n += siz + SizeVarint(uint64(siz)) + tagsize
  510. }
  511. return n
  512. },
  513. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  514. s := ptr.getSlice(reflect.PtrTo(u.typ))
  515. for i := 0; i < s.Len(); i++ {
  516. elem := s.Index(i)
  517. t := elem.Interface().(*int64)
  518. v := &int64Value{*t}
  519. siz := Size(v)
  520. buf, err := Marshal(v)
  521. if err != nil {
  522. return nil, err
  523. }
  524. b = appendVarint(b, wiretag)
  525. b = appendVarint(b, uint64(siz))
  526. b = append(b, buf...)
  527. }
  528. return b, nil
  529. }
  530. }
  531. func makeStdInt64ValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  532. return func(b []byte, f pointer, w int) ([]byte, error) {
  533. if w != WireBytes {
  534. return nil, errInternalBadWireType
  535. }
  536. x, n := decodeVarint(b)
  537. if n == 0 {
  538. return nil, io.ErrUnexpectedEOF
  539. }
  540. b = b[n:]
  541. if x > uint64(len(b)) {
  542. return nil, io.ErrUnexpectedEOF
  543. }
  544. m := &int64Value{}
  545. if err := Unmarshal(b[:x], m); err != nil {
  546. return nil, err
  547. }
  548. s := f.asPointerTo(sub.typ).Elem()
  549. s.Set(reflect.ValueOf(m.Value))
  550. return b[x:], nil
  551. }
  552. }
  553. func makeStdInt64ValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  554. return func(b []byte, f pointer, w int) ([]byte, error) {
  555. if w != WireBytes {
  556. return nil, errInternalBadWireType
  557. }
  558. x, n := decodeVarint(b)
  559. if n == 0 {
  560. return nil, io.ErrUnexpectedEOF
  561. }
  562. b = b[n:]
  563. if x > uint64(len(b)) {
  564. return nil, io.ErrUnexpectedEOF
  565. }
  566. m := &int64Value{}
  567. if err := Unmarshal(b[:x], m); err != nil {
  568. return nil, err
  569. }
  570. s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem()
  571. s.Set(reflect.ValueOf(&m.Value))
  572. return b[x:], nil
  573. }
  574. }
  575. func makeStdInt64ValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  576. return func(b []byte, f pointer, w int) ([]byte, error) {
  577. if w != WireBytes {
  578. return nil, errInternalBadWireType
  579. }
  580. x, n := decodeVarint(b)
  581. if n == 0 {
  582. return nil, io.ErrUnexpectedEOF
  583. }
  584. b = b[n:]
  585. if x > uint64(len(b)) {
  586. return nil, io.ErrUnexpectedEOF
  587. }
  588. m := &int64Value{}
  589. if err := Unmarshal(b[:x], m); err != nil {
  590. return nil, err
  591. }
  592. slice := f.getSlice(reflect.PtrTo(sub.typ))
  593. newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value))
  594. slice.Set(newSlice)
  595. return b[x:], nil
  596. }
  597. }
  598. func makeStdInt64ValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  599. return func(b []byte, f pointer, w int) ([]byte, error) {
  600. if w != WireBytes {
  601. return nil, errInternalBadWireType
  602. }
  603. x, n := decodeVarint(b)
  604. if n == 0 {
  605. return nil, io.ErrUnexpectedEOF
  606. }
  607. b = b[n:]
  608. if x > uint64(len(b)) {
  609. return nil, io.ErrUnexpectedEOF
  610. }
  611. m := &int64Value{}
  612. if err := Unmarshal(b[:x], m); err != nil {
  613. return nil, err
  614. }
  615. slice := f.getSlice(sub.typ)
  616. newSlice := reflect.Append(slice, reflect.ValueOf(m.Value))
  617. slice.Set(newSlice)
  618. return b[x:], nil
  619. }
  620. }
  621. func makeStdUInt64ValueMarshaler(u *marshalInfo) (sizer, marshaler) {
  622. return func(ptr pointer, tagsize int) int {
  623. t := ptr.asPointerTo(u.typ).Interface().(*uint64)
  624. v := &uint64Value{*t}
  625. siz := Size(v)
  626. return tagsize + SizeVarint(uint64(siz)) + siz
  627. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  628. t := ptr.asPointerTo(u.typ).Interface().(*uint64)
  629. v := &uint64Value{*t}
  630. buf, err := Marshal(v)
  631. if err != nil {
  632. return nil, err
  633. }
  634. b = appendVarint(b, wiretag)
  635. b = appendVarint(b, uint64(len(buf)))
  636. b = append(b, buf...)
  637. return b, nil
  638. }
  639. }
  640. func makeStdUInt64ValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) {
  641. return func(ptr pointer, tagsize int) int {
  642. if ptr.isNil() {
  643. return 0
  644. }
  645. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint64)
  646. v := &uint64Value{*t}
  647. siz := Size(v)
  648. return tagsize + SizeVarint(uint64(siz)) + siz
  649. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  650. if ptr.isNil() {
  651. return b, nil
  652. }
  653. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint64)
  654. v := &uint64Value{*t}
  655. buf, err := Marshal(v)
  656. if err != nil {
  657. return nil, err
  658. }
  659. b = appendVarint(b, wiretag)
  660. b = appendVarint(b, uint64(len(buf)))
  661. b = append(b, buf...)
  662. return b, nil
  663. }
  664. }
  665. func makeStdUInt64ValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  666. return func(ptr pointer, tagsize int) int {
  667. s := ptr.getSlice(u.typ)
  668. n := 0
  669. for i := 0; i < s.Len(); i++ {
  670. elem := s.Index(i)
  671. t := elem.Interface().(uint64)
  672. v := &uint64Value{t}
  673. siz := Size(v)
  674. n += siz + SizeVarint(uint64(siz)) + tagsize
  675. }
  676. return n
  677. },
  678. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  679. s := ptr.getSlice(u.typ)
  680. for i := 0; i < s.Len(); i++ {
  681. elem := s.Index(i)
  682. t := elem.Interface().(uint64)
  683. v := &uint64Value{t}
  684. siz := Size(v)
  685. buf, err := Marshal(v)
  686. if err != nil {
  687. return nil, err
  688. }
  689. b = appendVarint(b, wiretag)
  690. b = appendVarint(b, uint64(siz))
  691. b = append(b, buf...)
  692. }
  693. return b, nil
  694. }
  695. }
  696. func makeStdUInt64ValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  697. return func(ptr pointer, tagsize int) int {
  698. s := ptr.getSlice(reflect.PtrTo(u.typ))
  699. n := 0
  700. for i := 0; i < s.Len(); i++ {
  701. elem := s.Index(i)
  702. t := elem.Interface().(*uint64)
  703. v := &uint64Value{*t}
  704. siz := Size(v)
  705. n += siz + SizeVarint(uint64(siz)) + tagsize
  706. }
  707. return n
  708. },
  709. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  710. s := ptr.getSlice(reflect.PtrTo(u.typ))
  711. for i := 0; i < s.Len(); i++ {
  712. elem := s.Index(i)
  713. t := elem.Interface().(*uint64)
  714. v := &uint64Value{*t}
  715. siz := Size(v)
  716. buf, err := Marshal(v)
  717. if err != nil {
  718. return nil, err
  719. }
  720. b = appendVarint(b, wiretag)
  721. b = appendVarint(b, uint64(siz))
  722. b = append(b, buf...)
  723. }
  724. return b, nil
  725. }
  726. }
  727. func makeStdUInt64ValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  728. return func(b []byte, f pointer, w int) ([]byte, error) {
  729. if w != WireBytes {
  730. return nil, errInternalBadWireType
  731. }
  732. x, n := decodeVarint(b)
  733. if n == 0 {
  734. return nil, io.ErrUnexpectedEOF
  735. }
  736. b = b[n:]
  737. if x > uint64(len(b)) {
  738. return nil, io.ErrUnexpectedEOF
  739. }
  740. m := &uint64Value{}
  741. if err := Unmarshal(b[:x], m); err != nil {
  742. return nil, err
  743. }
  744. s := f.asPointerTo(sub.typ).Elem()
  745. s.Set(reflect.ValueOf(m.Value))
  746. return b[x:], nil
  747. }
  748. }
  749. func makeStdUInt64ValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  750. return func(b []byte, f pointer, w int) ([]byte, error) {
  751. if w != WireBytes {
  752. return nil, errInternalBadWireType
  753. }
  754. x, n := decodeVarint(b)
  755. if n == 0 {
  756. return nil, io.ErrUnexpectedEOF
  757. }
  758. b = b[n:]
  759. if x > uint64(len(b)) {
  760. return nil, io.ErrUnexpectedEOF
  761. }
  762. m := &uint64Value{}
  763. if err := Unmarshal(b[:x], m); err != nil {
  764. return nil, err
  765. }
  766. s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem()
  767. s.Set(reflect.ValueOf(&m.Value))
  768. return b[x:], nil
  769. }
  770. }
  771. func makeStdUInt64ValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  772. return func(b []byte, f pointer, w int) ([]byte, error) {
  773. if w != WireBytes {
  774. return nil, errInternalBadWireType
  775. }
  776. x, n := decodeVarint(b)
  777. if n == 0 {
  778. return nil, io.ErrUnexpectedEOF
  779. }
  780. b = b[n:]
  781. if x > uint64(len(b)) {
  782. return nil, io.ErrUnexpectedEOF
  783. }
  784. m := &uint64Value{}
  785. if err := Unmarshal(b[:x], m); err != nil {
  786. return nil, err
  787. }
  788. slice := f.getSlice(reflect.PtrTo(sub.typ))
  789. newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value))
  790. slice.Set(newSlice)
  791. return b[x:], nil
  792. }
  793. }
  794. func makeStdUInt64ValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  795. return func(b []byte, f pointer, w int) ([]byte, error) {
  796. if w != WireBytes {
  797. return nil, errInternalBadWireType
  798. }
  799. x, n := decodeVarint(b)
  800. if n == 0 {
  801. return nil, io.ErrUnexpectedEOF
  802. }
  803. b = b[n:]
  804. if x > uint64(len(b)) {
  805. return nil, io.ErrUnexpectedEOF
  806. }
  807. m := &uint64Value{}
  808. if err := Unmarshal(b[:x], m); err != nil {
  809. return nil, err
  810. }
  811. slice := f.getSlice(sub.typ)
  812. newSlice := reflect.Append(slice, reflect.ValueOf(m.Value))
  813. slice.Set(newSlice)
  814. return b[x:], nil
  815. }
  816. }
  817. func makeStdInt32ValueMarshaler(u *marshalInfo) (sizer, marshaler) {
  818. return func(ptr pointer, tagsize int) int {
  819. t := ptr.asPointerTo(u.typ).Interface().(*int32)
  820. v := &int32Value{*t}
  821. siz := Size(v)
  822. return tagsize + SizeVarint(uint64(siz)) + siz
  823. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  824. t := ptr.asPointerTo(u.typ).Interface().(*int32)
  825. v := &int32Value{*t}
  826. buf, err := Marshal(v)
  827. if err != nil {
  828. return nil, err
  829. }
  830. b = appendVarint(b, wiretag)
  831. b = appendVarint(b, uint64(len(buf)))
  832. b = append(b, buf...)
  833. return b, nil
  834. }
  835. }
  836. func makeStdInt32ValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) {
  837. return func(ptr pointer, tagsize int) int {
  838. if ptr.isNil() {
  839. return 0
  840. }
  841. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int32)
  842. v := &int32Value{*t}
  843. siz := Size(v)
  844. return tagsize + SizeVarint(uint64(siz)) + siz
  845. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  846. if ptr.isNil() {
  847. return b, nil
  848. }
  849. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int32)
  850. v := &int32Value{*t}
  851. buf, err := Marshal(v)
  852. if err != nil {
  853. return nil, err
  854. }
  855. b = appendVarint(b, wiretag)
  856. b = appendVarint(b, uint64(len(buf)))
  857. b = append(b, buf...)
  858. return b, nil
  859. }
  860. }
  861. func makeStdInt32ValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  862. return func(ptr pointer, tagsize int) int {
  863. s := ptr.getSlice(u.typ)
  864. n := 0
  865. for i := 0; i < s.Len(); i++ {
  866. elem := s.Index(i)
  867. t := elem.Interface().(int32)
  868. v := &int32Value{t}
  869. siz := Size(v)
  870. n += siz + SizeVarint(uint64(siz)) + tagsize
  871. }
  872. return n
  873. },
  874. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  875. s := ptr.getSlice(u.typ)
  876. for i := 0; i < s.Len(); i++ {
  877. elem := s.Index(i)
  878. t := elem.Interface().(int32)
  879. v := &int32Value{t}
  880. siz := Size(v)
  881. buf, err := Marshal(v)
  882. if err != nil {
  883. return nil, err
  884. }
  885. b = appendVarint(b, wiretag)
  886. b = appendVarint(b, uint64(siz))
  887. b = append(b, buf...)
  888. }
  889. return b, nil
  890. }
  891. }
  892. func makeStdInt32ValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  893. return func(ptr pointer, tagsize int) int {
  894. s := ptr.getSlice(reflect.PtrTo(u.typ))
  895. n := 0
  896. for i := 0; i < s.Len(); i++ {
  897. elem := s.Index(i)
  898. t := elem.Interface().(*int32)
  899. v := &int32Value{*t}
  900. siz := Size(v)
  901. n += siz + SizeVarint(uint64(siz)) + tagsize
  902. }
  903. return n
  904. },
  905. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  906. s := ptr.getSlice(reflect.PtrTo(u.typ))
  907. for i := 0; i < s.Len(); i++ {
  908. elem := s.Index(i)
  909. t := elem.Interface().(*int32)
  910. v := &int32Value{*t}
  911. siz := Size(v)
  912. buf, err := Marshal(v)
  913. if err != nil {
  914. return nil, err
  915. }
  916. b = appendVarint(b, wiretag)
  917. b = appendVarint(b, uint64(siz))
  918. b = append(b, buf...)
  919. }
  920. return b, nil
  921. }
  922. }
  923. func makeStdInt32ValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  924. return func(b []byte, f pointer, w int) ([]byte, error) {
  925. if w != WireBytes {
  926. return nil, errInternalBadWireType
  927. }
  928. x, n := decodeVarint(b)
  929. if n == 0 {
  930. return nil, io.ErrUnexpectedEOF
  931. }
  932. b = b[n:]
  933. if x > uint64(len(b)) {
  934. return nil, io.ErrUnexpectedEOF
  935. }
  936. m := &int32Value{}
  937. if err := Unmarshal(b[:x], m); err != nil {
  938. return nil, err
  939. }
  940. s := f.asPointerTo(sub.typ).Elem()
  941. s.Set(reflect.ValueOf(m.Value))
  942. return b[x:], nil
  943. }
  944. }
  945. func makeStdInt32ValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  946. return func(b []byte, f pointer, w int) ([]byte, error) {
  947. if w != WireBytes {
  948. return nil, errInternalBadWireType
  949. }
  950. x, n := decodeVarint(b)
  951. if n == 0 {
  952. return nil, io.ErrUnexpectedEOF
  953. }
  954. b = b[n:]
  955. if x > uint64(len(b)) {
  956. return nil, io.ErrUnexpectedEOF
  957. }
  958. m := &int32Value{}
  959. if err := Unmarshal(b[:x], m); err != nil {
  960. return nil, err
  961. }
  962. s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem()
  963. s.Set(reflect.ValueOf(&m.Value))
  964. return b[x:], nil
  965. }
  966. }
  967. func makeStdInt32ValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  968. return func(b []byte, f pointer, w int) ([]byte, error) {
  969. if w != WireBytes {
  970. return nil, errInternalBadWireType
  971. }
  972. x, n := decodeVarint(b)
  973. if n == 0 {
  974. return nil, io.ErrUnexpectedEOF
  975. }
  976. b = b[n:]
  977. if x > uint64(len(b)) {
  978. return nil, io.ErrUnexpectedEOF
  979. }
  980. m := &int32Value{}
  981. if err := Unmarshal(b[:x], m); err != nil {
  982. return nil, err
  983. }
  984. slice := f.getSlice(reflect.PtrTo(sub.typ))
  985. newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value))
  986. slice.Set(newSlice)
  987. return b[x:], nil
  988. }
  989. }
  990. func makeStdInt32ValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  991. return func(b []byte, f pointer, w int) ([]byte, error) {
  992. if w != WireBytes {
  993. return nil, errInternalBadWireType
  994. }
  995. x, n := decodeVarint(b)
  996. if n == 0 {
  997. return nil, io.ErrUnexpectedEOF
  998. }
  999. b = b[n:]
  1000. if x > uint64(len(b)) {
  1001. return nil, io.ErrUnexpectedEOF
  1002. }
  1003. m := &int32Value{}
  1004. if err := Unmarshal(b[:x], m); err != nil {
  1005. return nil, err
  1006. }
  1007. slice := f.getSlice(sub.typ)
  1008. newSlice := reflect.Append(slice, reflect.ValueOf(m.Value))
  1009. slice.Set(newSlice)
  1010. return b[x:], nil
  1011. }
  1012. }
  1013. func makeStdUInt32ValueMarshaler(u *marshalInfo) (sizer, marshaler) {
  1014. return func(ptr pointer, tagsize int) int {
  1015. t := ptr.asPointerTo(u.typ).Interface().(*uint32)
  1016. v := &uint32Value{*t}
  1017. siz := Size(v)
  1018. return tagsize + SizeVarint(uint64(siz)) + siz
  1019. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1020. t := ptr.asPointerTo(u.typ).Interface().(*uint32)
  1021. v := &uint32Value{*t}
  1022. buf, err := Marshal(v)
  1023. if err != nil {
  1024. return nil, err
  1025. }
  1026. b = appendVarint(b, wiretag)
  1027. b = appendVarint(b, uint64(len(buf)))
  1028. b = append(b, buf...)
  1029. return b, nil
  1030. }
  1031. }
  1032. func makeStdUInt32ValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) {
  1033. return func(ptr pointer, tagsize int) int {
  1034. if ptr.isNil() {
  1035. return 0
  1036. }
  1037. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint32)
  1038. v := &uint32Value{*t}
  1039. siz := Size(v)
  1040. return tagsize + SizeVarint(uint64(siz)) + siz
  1041. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1042. if ptr.isNil() {
  1043. return b, nil
  1044. }
  1045. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint32)
  1046. v := &uint32Value{*t}
  1047. buf, err := Marshal(v)
  1048. if err != nil {
  1049. return nil, err
  1050. }
  1051. b = appendVarint(b, wiretag)
  1052. b = appendVarint(b, uint64(len(buf)))
  1053. b = append(b, buf...)
  1054. return b, nil
  1055. }
  1056. }
  1057. func makeStdUInt32ValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  1058. return func(ptr pointer, tagsize int) int {
  1059. s := ptr.getSlice(u.typ)
  1060. n := 0
  1061. for i := 0; i < s.Len(); i++ {
  1062. elem := s.Index(i)
  1063. t := elem.Interface().(uint32)
  1064. v := &uint32Value{t}
  1065. siz := Size(v)
  1066. n += siz + SizeVarint(uint64(siz)) + tagsize
  1067. }
  1068. return n
  1069. },
  1070. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1071. s := ptr.getSlice(u.typ)
  1072. for i := 0; i < s.Len(); i++ {
  1073. elem := s.Index(i)
  1074. t := elem.Interface().(uint32)
  1075. v := &uint32Value{t}
  1076. siz := Size(v)
  1077. buf, err := Marshal(v)
  1078. if err != nil {
  1079. return nil, err
  1080. }
  1081. b = appendVarint(b, wiretag)
  1082. b = appendVarint(b, uint64(siz))
  1083. b = append(b, buf...)
  1084. }
  1085. return b, nil
  1086. }
  1087. }
  1088. func makeStdUInt32ValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  1089. return func(ptr pointer, tagsize int) int {
  1090. s := ptr.getSlice(reflect.PtrTo(u.typ))
  1091. n := 0
  1092. for i := 0; i < s.Len(); i++ {
  1093. elem := s.Index(i)
  1094. t := elem.Interface().(*uint32)
  1095. v := &uint32Value{*t}
  1096. siz := Size(v)
  1097. n += siz + SizeVarint(uint64(siz)) + tagsize
  1098. }
  1099. return n
  1100. },
  1101. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1102. s := ptr.getSlice(reflect.PtrTo(u.typ))
  1103. for i := 0; i < s.Len(); i++ {
  1104. elem := s.Index(i)
  1105. t := elem.Interface().(*uint32)
  1106. v := &uint32Value{*t}
  1107. siz := Size(v)
  1108. buf, err := Marshal(v)
  1109. if err != nil {
  1110. return nil, err
  1111. }
  1112. b = appendVarint(b, wiretag)
  1113. b = appendVarint(b, uint64(siz))
  1114. b = append(b, buf...)
  1115. }
  1116. return b, nil
  1117. }
  1118. }
  1119. func makeStdUInt32ValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1120. return func(b []byte, f pointer, w int) ([]byte, error) {
  1121. if w != WireBytes {
  1122. return nil, errInternalBadWireType
  1123. }
  1124. x, n := decodeVarint(b)
  1125. if n == 0 {
  1126. return nil, io.ErrUnexpectedEOF
  1127. }
  1128. b = b[n:]
  1129. if x > uint64(len(b)) {
  1130. return nil, io.ErrUnexpectedEOF
  1131. }
  1132. m := &uint32Value{}
  1133. if err := Unmarshal(b[:x], m); err != nil {
  1134. return nil, err
  1135. }
  1136. s := f.asPointerTo(sub.typ).Elem()
  1137. s.Set(reflect.ValueOf(m.Value))
  1138. return b[x:], nil
  1139. }
  1140. }
  1141. func makeStdUInt32ValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1142. return func(b []byte, f pointer, w int) ([]byte, error) {
  1143. if w != WireBytes {
  1144. return nil, errInternalBadWireType
  1145. }
  1146. x, n := decodeVarint(b)
  1147. if n == 0 {
  1148. return nil, io.ErrUnexpectedEOF
  1149. }
  1150. b = b[n:]
  1151. if x > uint64(len(b)) {
  1152. return nil, io.ErrUnexpectedEOF
  1153. }
  1154. m := &uint32Value{}
  1155. if err := Unmarshal(b[:x], m); err != nil {
  1156. return nil, err
  1157. }
  1158. s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem()
  1159. s.Set(reflect.ValueOf(&m.Value))
  1160. return b[x:], nil
  1161. }
  1162. }
  1163. func makeStdUInt32ValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1164. return func(b []byte, f pointer, w int) ([]byte, error) {
  1165. if w != WireBytes {
  1166. return nil, errInternalBadWireType
  1167. }
  1168. x, n := decodeVarint(b)
  1169. if n == 0 {
  1170. return nil, io.ErrUnexpectedEOF
  1171. }
  1172. b = b[n:]
  1173. if x > uint64(len(b)) {
  1174. return nil, io.ErrUnexpectedEOF
  1175. }
  1176. m := &uint32Value{}
  1177. if err := Unmarshal(b[:x], m); err != nil {
  1178. return nil, err
  1179. }
  1180. slice := f.getSlice(reflect.PtrTo(sub.typ))
  1181. newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value))
  1182. slice.Set(newSlice)
  1183. return b[x:], nil
  1184. }
  1185. }
  1186. func makeStdUInt32ValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1187. return func(b []byte, f pointer, w int) ([]byte, error) {
  1188. if w != WireBytes {
  1189. return nil, errInternalBadWireType
  1190. }
  1191. x, n := decodeVarint(b)
  1192. if n == 0 {
  1193. return nil, io.ErrUnexpectedEOF
  1194. }
  1195. b = b[n:]
  1196. if x > uint64(len(b)) {
  1197. return nil, io.ErrUnexpectedEOF
  1198. }
  1199. m := &uint32Value{}
  1200. if err := Unmarshal(b[:x], m); err != nil {
  1201. return nil, err
  1202. }
  1203. slice := f.getSlice(sub.typ)
  1204. newSlice := reflect.Append(slice, reflect.ValueOf(m.Value))
  1205. slice.Set(newSlice)
  1206. return b[x:], nil
  1207. }
  1208. }
  1209. func makeStdBoolValueMarshaler(u *marshalInfo) (sizer, marshaler) {
  1210. return func(ptr pointer, tagsize int) int {
  1211. t := ptr.asPointerTo(u.typ).Interface().(*bool)
  1212. v := &boolValue{*t}
  1213. siz := Size(v)
  1214. return tagsize + SizeVarint(uint64(siz)) + siz
  1215. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1216. t := ptr.asPointerTo(u.typ).Interface().(*bool)
  1217. v := &boolValue{*t}
  1218. buf, err := Marshal(v)
  1219. if err != nil {
  1220. return nil, err
  1221. }
  1222. b = appendVarint(b, wiretag)
  1223. b = appendVarint(b, uint64(len(buf)))
  1224. b = append(b, buf...)
  1225. return b, nil
  1226. }
  1227. }
  1228. func makeStdBoolValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) {
  1229. return func(ptr pointer, tagsize int) int {
  1230. if ptr.isNil() {
  1231. return 0
  1232. }
  1233. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*bool)
  1234. v := &boolValue{*t}
  1235. siz := Size(v)
  1236. return tagsize + SizeVarint(uint64(siz)) + siz
  1237. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1238. if ptr.isNil() {
  1239. return b, nil
  1240. }
  1241. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*bool)
  1242. v := &boolValue{*t}
  1243. buf, err := Marshal(v)
  1244. if err != nil {
  1245. return nil, err
  1246. }
  1247. b = appendVarint(b, wiretag)
  1248. b = appendVarint(b, uint64(len(buf)))
  1249. b = append(b, buf...)
  1250. return b, nil
  1251. }
  1252. }
  1253. func makeStdBoolValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  1254. return func(ptr pointer, tagsize int) int {
  1255. s := ptr.getSlice(u.typ)
  1256. n := 0
  1257. for i := 0; i < s.Len(); i++ {
  1258. elem := s.Index(i)
  1259. t := elem.Interface().(bool)
  1260. v := &boolValue{t}
  1261. siz := Size(v)
  1262. n += siz + SizeVarint(uint64(siz)) + tagsize
  1263. }
  1264. return n
  1265. },
  1266. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1267. s := ptr.getSlice(u.typ)
  1268. for i := 0; i < s.Len(); i++ {
  1269. elem := s.Index(i)
  1270. t := elem.Interface().(bool)
  1271. v := &boolValue{t}
  1272. siz := Size(v)
  1273. buf, err := Marshal(v)
  1274. if err != nil {
  1275. return nil, err
  1276. }
  1277. b = appendVarint(b, wiretag)
  1278. b = appendVarint(b, uint64(siz))
  1279. b = append(b, buf...)
  1280. }
  1281. return b, nil
  1282. }
  1283. }
  1284. func makeStdBoolValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  1285. return func(ptr pointer, tagsize int) int {
  1286. s := ptr.getSlice(reflect.PtrTo(u.typ))
  1287. n := 0
  1288. for i := 0; i < s.Len(); i++ {
  1289. elem := s.Index(i)
  1290. t := elem.Interface().(*bool)
  1291. v := &boolValue{*t}
  1292. siz := Size(v)
  1293. n += siz + SizeVarint(uint64(siz)) + tagsize
  1294. }
  1295. return n
  1296. },
  1297. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1298. s := ptr.getSlice(reflect.PtrTo(u.typ))
  1299. for i := 0; i < s.Len(); i++ {
  1300. elem := s.Index(i)
  1301. t := elem.Interface().(*bool)
  1302. v := &boolValue{*t}
  1303. siz := Size(v)
  1304. buf, err := Marshal(v)
  1305. if err != nil {
  1306. return nil, err
  1307. }
  1308. b = appendVarint(b, wiretag)
  1309. b = appendVarint(b, uint64(siz))
  1310. b = append(b, buf...)
  1311. }
  1312. return b, nil
  1313. }
  1314. }
  1315. func makeStdBoolValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1316. return func(b []byte, f pointer, w int) ([]byte, error) {
  1317. if w != WireBytes {
  1318. return nil, errInternalBadWireType
  1319. }
  1320. x, n := decodeVarint(b)
  1321. if n == 0 {
  1322. return nil, io.ErrUnexpectedEOF
  1323. }
  1324. b = b[n:]
  1325. if x > uint64(len(b)) {
  1326. return nil, io.ErrUnexpectedEOF
  1327. }
  1328. m := &boolValue{}
  1329. if err := Unmarshal(b[:x], m); err != nil {
  1330. return nil, err
  1331. }
  1332. s := f.asPointerTo(sub.typ).Elem()
  1333. s.Set(reflect.ValueOf(m.Value))
  1334. return b[x:], nil
  1335. }
  1336. }
  1337. func makeStdBoolValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1338. return func(b []byte, f pointer, w int) ([]byte, error) {
  1339. if w != WireBytes {
  1340. return nil, errInternalBadWireType
  1341. }
  1342. x, n := decodeVarint(b)
  1343. if n == 0 {
  1344. return nil, io.ErrUnexpectedEOF
  1345. }
  1346. b = b[n:]
  1347. if x > uint64(len(b)) {
  1348. return nil, io.ErrUnexpectedEOF
  1349. }
  1350. m := &boolValue{}
  1351. if err := Unmarshal(b[:x], m); err != nil {
  1352. return nil, err
  1353. }
  1354. s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem()
  1355. s.Set(reflect.ValueOf(&m.Value))
  1356. return b[x:], nil
  1357. }
  1358. }
  1359. func makeStdBoolValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1360. return func(b []byte, f pointer, w int) ([]byte, error) {
  1361. if w != WireBytes {
  1362. return nil, errInternalBadWireType
  1363. }
  1364. x, n := decodeVarint(b)
  1365. if n == 0 {
  1366. return nil, io.ErrUnexpectedEOF
  1367. }
  1368. b = b[n:]
  1369. if x > uint64(len(b)) {
  1370. return nil, io.ErrUnexpectedEOF
  1371. }
  1372. m := &boolValue{}
  1373. if err := Unmarshal(b[:x], m); err != nil {
  1374. return nil, err
  1375. }
  1376. slice := f.getSlice(reflect.PtrTo(sub.typ))
  1377. newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value))
  1378. slice.Set(newSlice)
  1379. return b[x:], nil
  1380. }
  1381. }
  1382. func makeStdBoolValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1383. return func(b []byte, f pointer, w int) ([]byte, error) {
  1384. if w != WireBytes {
  1385. return nil, errInternalBadWireType
  1386. }
  1387. x, n := decodeVarint(b)
  1388. if n == 0 {
  1389. return nil, io.ErrUnexpectedEOF
  1390. }
  1391. b = b[n:]
  1392. if x > uint64(len(b)) {
  1393. return nil, io.ErrUnexpectedEOF
  1394. }
  1395. m := &boolValue{}
  1396. if err := Unmarshal(b[:x], m); err != nil {
  1397. return nil, err
  1398. }
  1399. slice := f.getSlice(sub.typ)
  1400. newSlice := reflect.Append(slice, reflect.ValueOf(m.Value))
  1401. slice.Set(newSlice)
  1402. return b[x:], nil
  1403. }
  1404. }
  1405. func makeStdStringValueMarshaler(u *marshalInfo) (sizer, marshaler) {
  1406. return func(ptr pointer, tagsize int) int {
  1407. t := ptr.asPointerTo(u.typ).Interface().(*string)
  1408. v := &stringValue{*t}
  1409. siz := Size(v)
  1410. return tagsize + SizeVarint(uint64(siz)) + siz
  1411. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1412. t := ptr.asPointerTo(u.typ).Interface().(*string)
  1413. v := &stringValue{*t}
  1414. buf, err := Marshal(v)
  1415. if err != nil {
  1416. return nil, err
  1417. }
  1418. b = appendVarint(b, wiretag)
  1419. b = appendVarint(b, uint64(len(buf)))
  1420. b = append(b, buf...)
  1421. return b, nil
  1422. }
  1423. }
  1424. func makeStdStringValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) {
  1425. return func(ptr pointer, tagsize int) int {
  1426. if ptr.isNil() {
  1427. return 0
  1428. }
  1429. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*string)
  1430. v := &stringValue{*t}
  1431. siz := Size(v)
  1432. return tagsize + SizeVarint(uint64(siz)) + siz
  1433. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1434. if ptr.isNil() {
  1435. return b, nil
  1436. }
  1437. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*string)
  1438. v := &stringValue{*t}
  1439. buf, err := Marshal(v)
  1440. if err != nil {
  1441. return nil, err
  1442. }
  1443. b = appendVarint(b, wiretag)
  1444. b = appendVarint(b, uint64(len(buf)))
  1445. b = append(b, buf...)
  1446. return b, nil
  1447. }
  1448. }
  1449. func makeStdStringValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  1450. return func(ptr pointer, tagsize int) int {
  1451. s := ptr.getSlice(u.typ)
  1452. n := 0
  1453. for i := 0; i < s.Len(); i++ {
  1454. elem := s.Index(i)
  1455. t := elem.Interface().(string)
  1456. v := &stringValue{t}
  1457. siz := Size(v)
  1458. n += siz + SizeVarint(uint64(siz)) + tagsize
  1459. }
  1460. return n
  1461. },
  1462. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1463. s := ptr.getSlice(u.typ)
  1464. for i := 0; i < s.Len(); i++ {
  1465. elem := s.Index(i)
  1466. t := elem.Interface().(string)
  1467. v := &stringValue{t}
  1468. siz := Size(v)
  1469. buf, err := Marshal(v)
  1470. if err != nil {
  1471. return nil, err
  1472. }
  1473. b = appendVarint(b, wiretag)
  1474. b = appendVarint(b, uint64(siz))
  1475. b = append(b, buf...)
  1476. }
  1477. return b, nil
  1478. }
  1479. }
  1480. func makeStdStringValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  1481. return func(ptr pointer, tagsize int) int {
  1482. s := ptr.getSlice(reflect.PtrTo(u.typ))
  1483. n := 0
  1484. for i := 0; i < s.Len(); i++ {
  1485. elem := s.Index(i)
  1486. t := elem.Interface().(*string)
  1487. v := &stringValue{*t}
  1488. siz := Size(v)
  1489. n += siz + SizeVarint(uint64(siz)) + tagsize
  1490. }
  1491. return n
  1492. },
  1493. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1494. s := ptr.getSlice(reflect.PtrTo(u.typ))
  1495. for i := 0; i < s.Len(); i++ {
  1496. elem := s.Index(i)
  1497. t := elem.Interface().(*string)
  1498. v := &stringValue{*t}
  1499. siz := Size(v)
  1500. buf, err := Marshal(v)
  1501. if err != nil {
  1502. return nil, err
  1503. }
  1504. b = appendVarint(b, wiretag)
  1505. b = appendVarint(b, uint64(siz))
  1506. b = append(b, buf...)
  1507. }
  1508. return b, nil
  1509. }
  1510. }
  1511. func makeStdStringValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1512. return func(b []byte, f pointer, w int) ([]byte, error) {
  1513. if w != WireBytes {
  1514. return nil, errInternalBadWireType
  1515. }
  1516. x, n := decodeVarint(b)
  1517. if n == 0 {
  1518. return nil, io.ErrUnexpectedEOF
  1519. }
  1520. b = b[n:]
  1521. if x > uint64(len(b)) {
  1522. return nil, io.ErrUnexpectedEOF
  1523. }
  1524. m := &stringValue{}
  1525. if err := Unmarshal(b[:x], m); err != nil {
  1526. return nil, err
  1527. }
  1528. s := f.asPointerTo(sub.typ).Elem()
  1529. s.Set(reflect.ValueOf(m.Value))
  1530. return b[x:], nil
  1531. }
  1532. }
  1533. func makeStdStringValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1534. return func(b []byte, f pointer, w int) ([]byte, error) {
  1535. if w != WireBytes {
  1536. return nil, errInternalBadWireType
  1537. }
  1538. x, n := decodeVarint(b)
  1539. if n == 0 {
  1540. return nil, io.ErrUnexpectedEOF
  1541. }
  1542. b = b[n:]
  1543. if x > uint64(len(b)) {
  1544. return nil, io.ErrUnexpectedEOF
  1545. }
  1546. m := &stringValue{}
  1547. if err := Unmarshal(b[:x], m); err != nil {
  1548. return nil, err
  1549. }
  1550. s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem()
  1551. s.Set(reflect.ValueOf(&m.Value))
  1552. return b[x:], nil
  1553. }
  1554. }
  1555. func makeStdStringValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1556. return func(b []byte, f pointer, w int) ([]byte, error) {
  1557. if w != WireBytes {
  1558. return nil, errInternalBadWireType
  1559. }
  1560. x, n := decodeVarint(b)
  1561. if n == 0 {
  1562. return nil, io.ErrUnexpectedEOF
  1563. }
  1564. b = b[n:]
  1565. if x > uint64(len(b)) {
  1566. return nil, io.ErrUnexpectedEOF
  1567. }
  1568. m := &stringValue{}
  1569. if err := Unmarshal(b[:x], m); err != nil {
  1570. return nil, err
  1571. }
  1572. slice := f.getSlice(reflect.PtrTo(sub.typ))
  1573. newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value))
  1574. slice.Set(newSlice)
  1575. return b[x:], nil
  1576. }
  1577. }
  1578. func makeStdStringValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1579. return func(b []byte, f pointer, w int) ([]byte, error) {
  1580. if w != WireBytes {
  1581. return nil, errInternalBadWireType
  1582. }
  1583. x, n := decodeVarint(b)
  1584. if n == 0 {
  1585. return nil, io.ErrUnexpectedEOF
  1586. }
  1587. b = b[n:]
  1588. if x > uint64(len(b)) {
  1589. return nil, io.ErrUnexpectedEOF
  1590. }
  1591. m := &stringValue{}
  1592. if err := Unmarshal(b[:x], m); err != nil {
  1593. return nil, err
  1594. }
  1595. slice := f.getSlice(sub.typ)
  1596. newSlice := reflect.Append(slice, reflect.ValueOf(m.Value))
  1597. slice.Set(newSlice)
  1598. return b[x:], nil
  1599. }
  1600. }
  1601. func makeStdBytesValueMarshaler(u *marshalInfo) (sizer, marshaler) {
  1602. return func(ptr pointer, tagsize int) int {
  1603. t := ptr.asPointerTo(u.typ).Interface().(*[]byte)
  1604. v := &bytesValue{*t}
  1605. siz := Size(v)
  1606. return tagsize + SizeVarint(uint64(siz)) + siz
  1607. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1608. t := ptr.asPointerTo(u.typ).Interface().(*[]byte)
  1609. v := &bytesValue{*t}
  1610. buf, err := Marshal(v)
  1611. if err != nil {
  1612. return nil, err
  1613. }
  1614. b = appendVarint(b, wiretag)
  1615. b = appendVarint(b, uint64(len(buf)))
  1616. b = append(b, buf...)
  1617. return b, nil
  1618. }
  1619. }
  1620. func makeStdBytesValuePtrMarshaler(u *marshalInfo) (sizer, marshaler) {
  1621. return func(ptr pointer, tagsize int) int {
  1622. if ptr.isNil() {
  1623. return 0
  1624. }
  1625. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*[]byte)
  1626. v := &bytesValue{*t}
  1627. siz := Size(v)
  1628. return tagsize + SizeVarint(uint64(siz)) + siz
  1629. }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1630. if ptr.isNil() {
  1631. return b, nil
  1632. }
  1633. t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*[]byte)
  1634. v := &bytesValue{*t}
  1635. buf, err := Marshal(v)
  1636. if err != nil {
  1637. return nil, err
  1638. }
  1639. b = appendVarint(b, wiretag)
  1640. b = appendVarint(b, uint64(len(buf)))
  1641. b = append(b, buf...)
  1642. return b, nil
  1643. }
  1644. }
  1645. func makeStdBytesValueSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  1646. return func(ptr pointer, tagsize int) int {
  1647. s := ptr.getSlice(u.typ)
  1648. n := 0
  1649. for i := 0; i < s.Len(); i++ {
  1650. elem := s.Index(i)
  1651. t := elem.Interface().([]byte)
  1652. v := &bytesValue{t}
  1653. siz := Size(v)
  1654. n += siz + SizeVarint(uint64(siz)) + tagsize
  1655. }
  1656. return n
  1657. },
  1658. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1659. s := ptr.getSlice(u.typ)
  1660. for i := 0; i < s.Len(); i++ {
  1661. elem := s.Index(i)
  1662. t := elem.Interface().([]byte)
  1663. v := &bytesValue{t}
  1664. siz := Size(v)
  1665. buf, err := Marshal(v)
  1666. if err != nil {
  1667. return nil, err
  1668. }
  1669. b = appendVarint(b, wiretag)
  1670. b = appendVarint(b, uint64(siz))
  1671. b = append(b, buf...)
  1672. }
  1673. return b, nil
  1674. }
  1675. }
  1676. func makeStdBytesValuePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
  1677. return func(ptr pointer, tagsize int) int {
  1678. s := ptr.getSlice(reflect.PtrTo(u.typ))
  1679. n := 0
  1680. for i := 0; i < s.Len(); i++ {
  1681. elem := s.Index(i)
  1682. t := elem.Interface().(*[]byte)
  1683. v := &bytesValue{*t}
  1684. siz := Size(v)
  1685. n += siz + SizeVarint(uint64(siz)) + tagsize
  1686. }
  1687. return n
  1688. },
  1689. func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
  1690. s := ptr.getSlice(reflect.PtrTo(u.typ))
  1691. for i := 0; i < s.Len(); i++ {
  1692. elem := s.Index(i)
  1693. t := elem.Interface().(*[]byte)
  1694. v := &bytesValue{*t}
  1695. siz := Size(v)
  1696. buf, err := Marshal(v)
  1697. if err != nil {
  1698. return nil, err
  1699. }
  1700. b = appendVarint(b, wiretag)
  1701. b = appendVarint(b, uint64(siz))
  1702. b = append(b, buf...)
  1703. }
  1704. return b, nil
  1705. }
  1706. }
  1707. func makeStdBytesValueUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1708. return func(b []byte, f pointer, w int) ([]byte, error) {
  1709. if w != WireBytes {
  1710. return nil, errInternalBadWireType
  1711. }
  1712. x, n := decodeVarint(b)
  1713. if n == 0 {
  1714. return nil, io.ErrUnexpectedEOF
  1715. }
  1716. b = b[n:]
  1717. if x > uint64(len(b)) {
  1718. return nil, io.ErrUnexpectedEOF
  1719. }
  1720. m := &bytesValue{}
  1721. if err := Unmarshal(b[:x], m); err != nil {
  1722. return nil, err
  1723. }
  1724. s := f.asPointerTo(sub.typ).Elem()
  1725. s.Set(reflect.ValueOf(m.Value))
  1726. return b[x:], nil
  1727. }
  1728. }
  1729. func makeStdBytesValuePtrUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1730. return func(b []byte, f pointer, w int) ([]byte, error) {
  1731. if w != WireBytes {
  1732. return nil, errInternalBadWireType
  1733. }
  1734. x, n := decodeVarint(b)
  1735. if n == 0 {
  1736. return nil, io.ErrUnexpectedEOF
  1737. }
  1738. b = b[n:]
  1739. if x > uint64(len(b)) {
  1740. return nil, io.ErrUnexpectedEOF
  1741. }
  1742. m := &bytesValue{}
  1743. if err := Unmarshal(b[:x], m); err != nil {
  1744. return nil, err
  1745. }
  1746. s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem()
  1747. s.Set(reflect.ValueOf(&m.Value))
  1748. return b[x:], nil
  1749. }
  1750. }
  1751. func makeStdBytesValuePtrSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1752. return func(b []byte, f pointer, w int) ([]byte, error) {
  1753. if w != WireBytes {
  1754. return nil, errInternalBadWireType
  1755. }
  1756. x, n := decodeVarint(b)
  1757. if n == 0 {
  1758. return nil, io.ErrUnexpectedEOF
  1759. }
  1760. b = b[n:]
  1761. if x > uint64(len(b)) {
  1762. return nil, io.ErrUnexpectedEOF
  1763. }
  1764. m := &bytesValue{}
  1765. if err := Unmarshal(b[:x], m); err != nil {
  1766. return nil, err
  1767. }
  1768. slice := f.getSlice(reflect.PtrTo(sub.typ))
  1769. newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value))
  1770. slice.Set(newSlice)
  1771. return b[x:], nil
  1772. }
  1773. }
  1774. func makeStdBytesValueSliceUnmarshaler(sub *unmarshalInfo, name string) unmarshaler {
  1775. return func(b []byte, f pointer, w int) ([]byte, error) {
  1776. if w != WireBytes {
  1777. return nil, errInternalBadWireType
  1778. }
  1779. x, n := decodeVarint(b)
  1780. if n == 0 {
  1781. return nil, io.ErrUnexpectedEOF
  1782. }
  1783. b = b[n:]
  1784. if x > uint64(len(b)) {
  1785. return nil, io.ErrUnexpectedEOF
  1786. }
  1787. m := &bytesValue{}
  1788. if err := Unmarshal(b[:x], m); err != nil {
  1789. return nil, err
  1790. }
  1791. slice := f.getSlice(sub.typ)
  1792. newSlice := reflect.Append(slice, reflect.ValueOf(m.Value))
  1793. slice.Set(newSlice)
  1794. return b[x:], nil
  1795. }
  1796. }