codec_gen.go 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637
  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. "math"
  8. "unicode/utf8"
  9. "google.golang.org/protobuf/encoding/protowire"
  10. "google.golang.org/protobuf/reflect/protoreflect"
  11. )
  12. // sizeBool returns the size of wire encoding a bool pointer as a Bool.
  13. func sizeBool(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  14. v := *p.Bool()
  15. return f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v))
  16. }
  17. // appendBool wire encodes a bool pointer as a Bool.
  18. func appendBool(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  19. v := *p.Bool()
  20. b = protowire.AppendVarint(b, f.wiretag)
  21. b = protowire.AppendVarint(b, protowire.EncodeBool(v))
  22. return b, nil
  23. }
  24. // consumeBool wire decodes a bool pointer as a Bool.
  25. func consumeBool(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  26. if wtyp != protowire.VarintType {
  27. return out, errUnknown
  28. }
  29. var v uint64
  30. var n int
  31. if len(b) >= 1 && b[0] < 0x80 {
  32. v = uint64(b[0])
  33. n = 1
  34. } else if len(b) >= 2 && b[1] < 128 {
  35. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  36. n = 2
  37. } else {
  38. v, n = protowire.ConsumeVarint(b)
  39. }
  40. if n < 0 {
  41. return out, errDecode
  42. }
  43. *p.Bool() = protowire.DecodeBool(v)
  44. out.n = n
  45. return out, nil
  46. }
  47. var coderBool = pointerCoderFuncs{
  48. size: sizeBool,
  49. marshal: appendBool,
  50. unmarshal: consumeBool,
  51. merge: mergeBool,
  52. }
  53. // sizeBoolNoZero returns the size of wire encoding a bool pointer as a Bool.
  54. // The zero value is not encoded.
  55. func sizeBoolNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  56. v := *p.Bool()
  57. if v == false {
  58. return 0
  59. }
  60. return f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v))
  61. }
  62. // appendBoolNoZero wire encodes a bool pointer as a Bool.
  63. // The zero value is not encoded.
  64. func appendBoolNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  65. v := *p.Bool()
  66. if v == false {
  67. return b, nil
  68. }
  69. b = protowire.AppendVarint(b, f.wiretag)
  70. b = protowire.AppendVarint(b, protowire.EncodeBool(v))
  71. return b, nil
  72. }
  73. var coderBoolNoZero = pointerCoderFuncs{
  74. size: sizeBoolNoZero,
  75. marshal: appendBoolNoZero,
  76. unmarshal: consumeBool,
  77. merge: mergeBoolNoZero,
  78. }
  79. // sizeBoolPtr returns the size of wire encoding a *bool pointer as a Bool.
  80. // It panics if the pointer is nil.
  81. func sizeBoolPtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  82. v := **p.BoolPtr()
  83. return f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v))
  84. }
  85. // appendBoolPtr wire encodes a *bool pointer as a Bool.
  86. // It panics if the pointer is nil.
  87. func appendBoolPtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  88. v := **p.BoolPtr()
  89. b = protowire.AppendVarint(b, f.wiretag)
  90. b = protowire.AppendVarint(b, protowire.EncodeBool(v))
  91. return b, nil
  92. }
  93. // consumeBoolPtr wire decodes a *bool pointer as a Bool.
  94. func consumeBoolPtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  95. if wtyp != protowire.VarintType {
  96. return out, errUnknown
  97. }
  98. var v uint64
  99. var n int
  100. if len(b) >= 1 && b[0] < 0x80 {
  101. v = uint64(b[0])
  102. n = 1
  103. } else if len(b) >= 2 && b[1] < 128 {
  104. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  105. n = 2
  106. } else {
  107. v, n = protowire.ConsumeVarint(b)
  108. }
  109. if n < 0 {
  110. return out, errDecode
  111. }
  112. vp := p.BoolPtr()
  113. if *vp == nil {
  114. *vp = new(bool)
  115. }
  116. **vp = protowire.DecodeBool(v)
  117. out.n = n
  118. return out, nil
  119. }
  120. var coderBoolPtr = pointerCoderFuncs{
  121. size: sizeBoolPtr,
  122. marshal: appendBoolPtr,
  123. unmarshal: consumeBoolPtr,
  124. merge: mergeBoolPtr,
  125. }
  126. // sizeBoolSlice returns the size of wire encoding a []bool pointer as a repeated Bool.
  127. func sizeBoolSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  128. s := *p.BoolSlice()
  129. for _, v := range s {
  130. size += f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v))
  131. }
  132. return size
  133. }
  134. // appendBoolSlice encodes a []bool pointer as a repeated Bool.
  135. func appendBoolSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  136. s := *p.BoolSlice()
  137. for _, v := range s {
  138. b = protowire.AppendVarint(b, f.wiretag)
  139. b = protowire.AppendVarint(b, protowire.EncodeBool(v))
  140. }
  141. return b, nil
  142. }
  143. // consumeBoolSlice wire decodes a []bool pointer as a repeated Bool.
  144. func consumeBoolSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  145. sp := p.BoolSlice()
  146. if wtyp == protowire.BytesType {
  147. s := *sp
  148. b, n := protowire.ConsumeBytes(b)
  149. if n < 0 {
  150. return out, errDecode
  151. }
  152. for len(b) > 0 {
  153. var v uint64
  154. var n int
  155. if len(b) >= 1 && b[0] < 0x80 {
  156. v = uint64(b[0])
  157. n = 1
  158. } else if len(b) >= 2 && b[1] < 128 {
  159. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  160. n = 2
  161. } else {
  162. v, n = protowire.ConsumeVarint(b)
  163. }
  164. if n < 0 {
  165. return out, errDecode
  166. }
  167. s = append(s, protowire.DecodeBool(v))
  168. b = b[n:]
  169. }
  170. *sp = s
  171. out.n = n
  172. return out, nil
  173. }
  174. if wtyp != protowire.VarintType {
  175. return out, errUnknown
  176. }
  177. var v uint64
  178. var n int
  179. if len(b) >= 1 && b[0] < 0x80 {
  180. v = uint64(b[0])
  181. n = 1
  182. } else if len(b) >= 2 && b[1] < 128 {
  183. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  184. n = 2
  185. } else {
  186. v, n = protowire.ConsumeVarint(b)
  187. }
  188. if n < 0 {
  189. return out, errDecode
  190. }
  191. *sp = append(*sp, protowire.DecodeBool(v))
  192. out.n = n
  193. return out, nil
  194. }
  195. var coderBoolSlice = pointerCoderFuncs{
  196. size: sizeBoolSlice,
  197. marshal: appendBoolSlice,
  198. unmarshal: consumeBoolSlice,
  199. merge: mergeBoolSlice,
  200. }
  201. // sizeBoolPackedSlice returns the size of wire encoding a []bool pointer as a packed repeated Bool.
  202. func sizeBoolPackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  203. s := *p.BoolSlice()
  204. if len(s) == 0 {
  205. return 0
  206. }
  207. n := 0
  208. for _, v := range s {
  209. n += protowire.SizeVarint(protowire.EncodeBool(v))
  210. }
  211. return f.tagsize + protowire.SizeBytes(n)
  212. }
  213. // appendBoolPackedSlice encodes a []bool pointer as a packed repeated Bool.
  214. func appendBoolPackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  215. s := *p.BoolSlice()
  216. if len(s) == 0 {
  217. return b, nil
  218. }
  219. b = protowire.AppendVarint(b, f.wiretag)
  220. n := 0
  221. for _, v := range s {
  222. n += protowire.SizeVarint(protowire.EncodeBool(v))
  223. }
  224. b = protowire.AppendVarint(b, uint64(n))
  225. for _, v := range s {
  226. b = protowire.AppendVarint(b, protowire.EncodeBool(v))
  227. }
  228. return b, nil
  229. }
  230. var coderBoolPackedSlice = pointerCoderFuncs{
  231. size: sizeBoolPackedSlice,
  232. marshal: appendBoolPackedSlice,
  233. unmarshal: consumeBoolSlice,
  234. merge: mergeBoolSlice,
  235. }
  236. // sizeBoolValue returns the size of wire encoding a bool value as a Bool.
  237. func sizeBoolValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  238. return tagsize + protowire.SizeVarint(protowire.EncodeBool(v.Bool()))
  239. }
  240. // appendBoolValue encodes a bool value as a Bool.
  241. func appendBoolValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  242. b = protowire.AppendVarint(b, wiretag)
  243. b = protowire.AppendVarint(b, protowire.EncodeBool(v.Bool()))
  244. return b, nil
  245. }
  246. // consumeBoolValue decodes a bool value as a Bool.
  247. func consumeBoolValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  248. if wtyp != protowire.VarintType {
  249. return protoreflect.Value{}, out, errUnknown
  250. }
  251. var v uint64
  252. var n int
  253. if len(b) >= 1 && b[0] < 0x80 {
  254. v = uint64(b[0])
  255. n = 1
  256. } else if len(b) >= 2 && b[1] < 128 {
  257. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  258. n = 2
  259. } else {
  260. v, n = protowire.ConsumeVarint(b)
  261. }
  262. if n < 0 {
  263. return protoreflect.Value{}, out, errDecode
  264. }
  265. out.n = n
  266. return protoreflect.ValueOfBool(protowire.DecodeBool(v)), out, nil
  267. }
  268. var coderBoolValue = valueCoderFuncs{
  269. size: sizeBoolValue,
  270. marshal: appendBoolValue,
  271. unmarshal: consumeBoolValue,
  272. merge: mergeScalarValue,
  273. }
  274. // sizeBoolSliceValue returns the size of wire encoding a []bool value as a repeated Bool.
  275. func sizeBoolSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  276. list := listv.List()
  277. for i, llen := 0, list.Len(); i < llen; i++ {
  278. v := list.Get(i)
  279. size += tagsize + protowire.SizeVarint(protowire.EncodeBool(v.Bool()))
  280. }
  281. return size
  282. }
  283. // appendBoolSliceValue encodes a []bool value as a repeated Bool.
  284. func appendBoolSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  285. list := listv.List()
  286. for i, llen := 0, list.Len(); i < llen; i++ {
  287. v := list.Get(i)
  288. b = protowire.AppendVarint(b, wiretag)
  289. b = protowire.AppendVarint(b, protowire.EncodeBool(v.Bool()))
  290. }
  291. return b, nil
  292. }
  293. // consumeBoolSliceValue wire decodes a []bool value as a repeated Bool.
  294. func consumeBoolSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  295. list := listv.List()
  296. if wtyp == protowire.BytesType {
  297. b, n := protowire.ConsumeBytes(b)
  298. if n < 0 {
  299. return protoreflect.Value{}, out, errDecode
  300. }
  301. for len(b) > 0 {
  302. var v uint64
  303. var n int
  304. if len(b) >= 1 && b[0] < 0x80 {
  305. v = uint64(b[0])
  306. n = 1
  307. } else if len(b) >= 2 && b[1] < 128 {
  308. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  309. n = 2
  310. } else {
  311. v, n = protowire.ConsumeVarint(b)
  312. }
  313. if n < 0 {
  314. return protoreflect.Value{}, out, errDecode
  315. }
  316. list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v)))
  317. b = b[n:]
  318. }
  319. out.n = n
  320. return listv, out, nil
  321. }
  322. if wtyp != protowire.VarintType {
  323. return protoreflect.Value{}, out, errUnknown
  324. }
  325. var v uint64
  326. var n int
  327. if len(b) >= 1 && b[0] < 0x80 {
  328. v = uint64(b[0])
  329. n = 1
  330. } else if len(b) >= 2 && b[1] < 128 {
  331. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  332. n = 2
  333. } else {
  334. v, n = protowire.ConsumeVarint(b)
  335. }
  336. if n < 0 {
  337. return protoreflect.Value{}, out, errDecode
  338. }
  339. list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v)))
  340. out.n = n
  341. return listv, out, nil
  342. }
  343. var coderBoolSliceValue = valueCoderFuncs{
  344. size: sizeBoolSliceValue,
  345. marshal: appendBoolSliceValue,
  346. unmarshal: consumeBoolSliceValue,
  347. merge: mergeListValue,
  348. }
  349. // sizeBoolPackedSliceValue returns the size of wire encoding a []bool value as a packed repeated Bool.
  350. func sizeBoolPackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  351. list := listv.List()
  352. llen := list.Len()
  353. if llen == 0 {
  354. return 0
  355. }
  356. n := 0
  357. for i, llen := 0, llen; i < llen; i++ {
  358. v := list.Get(i)
  359. n += protowire.SizeVarint(protowire.EncodeBool(v.Bool()))
  360. }
  361. return tagsize + protowire.SizeBytes(n)
  362. }
  363. // appendBoolPackedSliceValue encodes a []bool value as a packed repeated Bool.
  364. func appendBoolPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  365. list := listv.List()
  366. llen := list.Len()
  367. if llen == 0 {
  368. return b, nil
  369. }
  370. b = protowire.AppendVarint(b, wiretag)
  371. n := 0
  372. for i := 0; i < llen; i++ {
  373. v := list.Get(i)
  374. n += protowire.SizeVarint(protowire.EncodeBool(v.Bool()))
  375. }
  376. b = protowire.AppendVarint(b, uint64(n))
  377. for i := 0; i < llen; i++ {
  378. v := list.Get(i)
  379. b = protowire.AppendVarint(b, protowire.EncodeBool(v.Bool()))
  380. }
  381. return b, nil
  382. }
  383. var coderBoolPackedSliceValue = valueCoderFuncs{
  384. size: sizeBoolPackedSliceValue,
  385. marshal: appendBoolPackedSliceValue,
  386. unmarshal: consumeBoolSliceValue,
  387. merge: mergeListValue,
  388. }
  389. // sizeEnumValue returns the size of wire encoding a value as a Enum.
  390. func sizeEnumValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  391. return tagsize + protowire.SizeVarint(uint64(v.Enum()))
  392. }
  393. // appendEnumValue encodes a value as a Enum.
  394. func appendEnumValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  395. b = protowire.AppendVarint(b, wiretag)
  396. b = protowire.AppendVarint(b, uint64(v.Enum()))
  397. return b, nil
  398. }
  399. // consumeEnumValue decodes a value as a Enum.
  400. func consumeEnumValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  401. if wtyp != protowire.VarintType {
  402. return protoreflect.Value{}, out, errUnknown
  403. }
  404. var v uint64
  405. var n int
  406. if len(b) >= 1 && b[0] < 0x80 {
  407. v = uint64(b[0])
  408. n = 1
  409. } else if len(b) >= 2 && b[1] < 128 {
  410. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  411. n = 2
  412. } else {
  413. v, n = protowire.ConsumeVarint(b)
  414. }
  415. if n < 0 {
  416. return protoreflect.Value{}, out, errDecode
  417. }
  418. out.n = n
  419. return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), out, nil
  420. }
  421. var coderEnumValue = valueCoderFuncs{
  422. size: sizeEnumValue,
  423. marshal: appendEnumValue,
  424. unmarshal: consumeEnumValue,
  425. merge: mergeScalarValue,
  426. }
  427. // sizeEnumSliceValue returns the size of wire encoding a [] value as a repeated Enum.
  428. func sizeEnumSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  429. list := listv.List()
  430. for i, llen := 0, list.Len(); i < llen; i++ {
  431. v := list.Get(i)
  432. size += tagsize + protowire.SizeVarint(uint64(v.Enum()))
  433. }
  434. return size
  435. }
  436. // appendEnumSliceValue encodes a [] value as a repeated Enum.
  437. func appendEnumSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  438. list := listv.List()
  439. for i, llen := 0, list.Len(); i < llen; i++ {
  440. v := list.Get(i)
  441. b = protowire.AppendVarint(b, wiretag)
  442. b = protowire.AppendVarint(b, uint64(v.Enum()))
  443. }
  444. return b, nil
  445. }
  446. // consumeEnumSliceValue wire decodes a [] value as a repeated Enum.
  447. func consumeEnumSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  448. list := listv.List()
  449. if wtyp == protowire.BytesType {
  450. b, n := protowire.ConsumeBytes(b)
  451. if n < 0 {
  452. return protoreflect.Value{}, out, errDecode
  453. }
  454. for len(b) > 0 {
  455. var v uint64
  456. var n int
  457. if len(b) >= 1 && b[0] < 0x80 {
  458. v = uint64(b[0])
  459. n = 1
  460. } else if len(b) >= 2 && b[1] < 128 {
  461. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  462. n = 2
  463. } else {
  464. v, n = protowire.ConsumeVarint(b)
  465. }
  466. if n < 0 {
  467. return protoreflect.Value{}, out, errDecode
  468. }
  469. list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
  470. b = b[n:]
  471. }
  472. out.n = n
  473. return listv, out, nil
  474. }
  475. if wtyp != protowire.VarintType {
  476. return protoreflect.Value{}, out, errUnknown
  477. }
  478. var v uint64
  479. var n int
  480. if len(b) >= 1 && b[0] < 0x80 {
  481. v = uint64(b[0])
  482. n = 1
  483. } else if len(b) >= 2 && b[1] < 128 {
  484. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  485. n = 2
  486. } else {
  487. v, n = protowire.ConsumeVarint(b)
  488. }
  489. if n < 0 {
  490. return protoreflect.Value{}, out, errDecode
  491. }
  492. list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
  493. out.n = n
  494. return listv, out, nil
  495. }
  496. var coderEnumSliceValue = valueCoderFuncs{
  497. size: sizeEnumSliceValue,
  498. marshal: appendEnumSliceValue,
  499. unmarshal: consumeEnumSliceValue,
  500. merge: mergeListValue,
  501. }
  502. // sizeEnumPackedSliceValue returns the size of wire encoding a [] value as a packed repeated Enum.
  503. func sizeEnumPackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  504. list := listv.List()
  505. llen := list.Len()
  506. if llen == 0 {
  507. return 0
  508. }
  509. n := 0
  510. for i, llen := 0, llen; i < llen; i++ {
  511. v := list.Get(i)
  512. n += protowire.SizeVarint(uint64(v.Enum()))
  513. }
  514. return tagsize + protowire.SizeBytes(n)
  515. }
  516. // appendEnumPackedSliceValue encodes a [] value as a packed repeated Enum.
  517. func appendEnumPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  518. list := listv.List()
  519. llen := list.Len()
  520. if llen == 0 {
  521. return b, nil
  522. }
  523. b = protowire.AppendVarint(b, wiretag)
  524. n := 0
  525. for i := 0; i < llen; i++ {
  526. v := list.Get(i)
  527. n += protowire.SizeVarint(uint64(v.Enum()))
  528. }
  529. b = protowire.AppendVarint(b, uint64(n))
  530. for i := 0; i < llen; i++ {
  531. v := list.Get(i)
  532. b = protowire.AppendVarint(b, uint64(v.Enum()))
  533. }
  534. return b, nil
  535. }
  536. var coderEnumPackedSliceValue = valueCoderFuncs{
  537. size: sizeEnumPackedSliceValue,
  538. marshal: appendEnumPackedSliceValue,
  539. unmarshal: consumeEnumSliceValue,
  540. merge: mergeListValue,
  541. }
  542. // sizeInt32 returns the size of wire encoding a int32 pointer as a Int32.
  543. func sizeInt32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  544. v := *p.Int32()
  545. return f.tagsize + protowire.SizeVarint(uint64(v))
  546. }
  547. // appendInt32 wire encodes a int32 pointer as a Int32.
  548. func appendInt32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  549. v := *p.Int32()
  550. b = protowire.AppendVarint(b, f.wiretag)
  551. b = protowire.AppendVarint(b, uint64(v))
  552. return b, nil
  553. }
  554. // consumeInt32 wire decodes a int32 pointer as a Int32.
  555. func consumeInt32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  556. if wtyp != protowire.VarintType {
  557. return out, errUnknown
  558. }
  559. var v uint64
  560. var n int
  561. if len(b) >= 1 && b[0] < 0x80 {
  562. v = uint64(b[0])
  563. n = 1
  564. } else if len(b) >= 2 && b[1] < 128 {
  565. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  566. n = 2
  567. } else {
  568. v, n = protowire.ConsumeVarint(b)
  569. }
  570. if n < 0 {
  571. return out, errDecode
  572. }
  573. *p.Int32() = int32(v)
  574. out.n = n
  575. return out, nil
  576. }
  577. var coderInt32 = pointerCoderFuncs{
  578. size: sizeInt32,
  579. marshal: appendInt32,
  580. unmarshal: consumeInt32,
  581. merge: mergeInt32,
  582. }
  583. // sizeInt32NoZero returns the size of wire encoding a int32 pointer as a Int32.
  584. // The zero value is not encoded.
  585. func sizeInt32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  586. v := *p.Int32()
  587. if v == 0 {
  588. return 0
  589. }
  590. return f.tagsize + protowire.SizeVarint(uint64(v))
  591. }
  592. // appendInt32NoZero wire encodes a int32 pointer as a Int32.
  593. // The zero value is not encoded.
  594. func appendInt32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  595. v := *p.Int32()
  596. if v == 0 {
  597. return b, nil
  598. }
  599. b = protowire.AppendVarint(b, f.wiretag)
  600. b = protowire.AppendVarint(b, uint64(v))
  601. return b, nil
  602. }
  603. var coderInt32NoZero = pointerCoderFuncs{
  604. size: sizeInt32NoZero,
  605. marshal: appendInt32NoZero,
  606. unmarshal: consumeInt32,
  607. merge: mergeInt32NoZero,
  608. }
  609. // sizeInt32Ptr returns the size of wire encoding a *int32 pointer as a Int32.
  610. // It panics if the pointer is nil.
  611. func sizeInt32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  612. v := **p.Int32Ptr()
  613. return f.tagsize + protowire.SizeVarint(uint64(v))
  614. }
  615. // appendInt32Ptr wire encodes a *int32 pointer as a Int32.
  616. // It panics if the pointer is nil.
  617. func appendInt32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  618. v := **p.Int32Ptr()
  619. b = protowire.AppendVarint(b, f.wiretag)
  620. b = protowire.AppendVarint(b, uint64(v))
  621. return b, nil
  622. }
  623. // consumeInt32Ptr wire decodes a *int32 pointer as a Int32.
  624. func consumeInt32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  625. if wtyp != protowire.VarintType {
  626. return out, errUnknown
  627. }
  628. var v uint64
  629. var n int
  630. if len(b) >= 1 && b[0] < 0x80 {
  631. v = uint64(b[0])
  632. n = 1
  633. } else if len(b) >= 2 && b[1] < 128 {
  634. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  635. n = 2
  636. } else {
  637. v, n = protowire.ConsumeVarint(b)
  638. }
  639. if n < 0 {
  640. return out, errDecode
  641. }
  642. vp := p.Int32Ptr()
  643. if *vp == nil {
  644. *vp = new(int32)
  645. }
  646. **vp = int32(v)
  647. out.n = n
  648. return out, nil
  649. }
  650. var coderInt32Ptr = pointerCoderFuncs{
  651. size: sizeInt32Ptr,
  652. marshal: appendInt32Ptr,
  653. unmarshal: consumeInt32Ptr,
  654. merge: mergeInt32Ptr,
  655. }
  656. // sizeInt32Slice returns the size of wire encoding a []int32 pointer as a repeated Int32.
  657. func sizeInt32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  658. s := *p.Int32Slice()
  659. for _, v := range s {
  660. size += f.tagsize + protowire.SizeVarint(uint64(v))
  661. }
  662. return size
  663. }
  664. // appendInt32Slice encodes a []int32 pointer as a repeated Int32.
  665. func appendInt32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  666. s := *p.Int32Slice()
  667. for _, v := range s {
  668. b = protowire.AppendVarint(b, f.wiretag)
  669. b = protowire.AppendVarint(b, uint64(v))
  670. }
  671. return b, nil
  672. }
  673. // consumeInt32Slice wire decodes a []int32 pointer as a repeated Int32.
  674. func consumeInt32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  675. sp := p.Int32Slice()
  676. if wtyp == protowire.BytesType {
  677. s := *sp
  678. b, n := protowire.ConsumeBytes(b)
  679. if n < 0 {
  680. return out, errDecode
  681. }
  682. for len(b) > 0 {
  683. var v uint64
  684. var n int
  685. if len(b) >= 1 && b[0] < 0x80 {
  686. v = uint64(b[0])
  687. n = 1
  688. } else if len(b) >= 2 && b[1] < 128 {
  689. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  690. n = 2
  691. } else {
  692. v, n = protowire.ConsumeVarint(b)
  693. }
  694. if n < 0 {
  695. return out, errDecode
  696. }
  697. s = append(s, int32(v))
  698. b = b[n:]
  699. }
  700. *sp = s
  701. out.n = n
  702. return out, nil
  703. }
  704. if wtyp != protowire.VarintType {
  705. return out, errUnknown
  706. }
  707. var v uint64
  708. var n int
  709. if len(b) >= 1 && b[0] < 0x80 {
  710. v = uint64(b[0])
  711. n = 1
  712. } else if len(b) >= 2 && b[1] < 128 {
  713. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  714. n = 2
  715. } else {
  716. v, n = protowire.ConsumeVarint(b)
  717. }
  718. if n < 0 {
  719. return out, errDecode
  720. }
  721. *sp = append(*sp, int32(v))
  722. out.n = n
  723. return out, nil
  724. }
  725. var coderInt32Slice = pointerCoderFuncs{
  726. size: sizeInt32Slice,
  727. marshal: appendInt32Slice,
  728. unmarshal: consumeInt32Slice,
  729. merge: mergeInt32Slice,
  730. }
  731. // sizeInt32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Int32.
  732. func sizeInt32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  733. s := *p.Int32Slice()
  734. if len(s) == 0 {
  735. return 0
  736. }
  737. n := 0
  738. for _, v := range s {
  739. n += protowire.SizeVarint(uint64(v))
  740. }
  741. return f.tagsize + protowire.SizeBytes(n)
  742. }
  743. // appendInt32PackedSlice encodes a []int32 pointer as a packed repeated Int32.
  744. func appendInt32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  745. s := *p.Int32Slice()
  746. if len(s) == 0 {
  747. return b, nil
  748. }
  749. b = protowire.AppendVarint(b, f.wiretag)
  750. n := 0
  751. for _, v := range s {
  752. n += protowire.SizeVarint(uint64(v))
  753. }
  754. b = protowire.AppendVarint(b, uint64(n))
  755. for _, v := range s {
  756. b = protowire.AppendVarint(b, uint64(v))
  757. }
  758. return b, nil
  759. }
  760. var coderInt32PackedSlice = pointerCoderFuncs{
  761. size: sizeInt32PackedSlice,
  762. marshal: appendInt32PackedSlice,
  763. unmarshal: consumeInt32Slice,
  764. merge: mergeInt32Slice,
  765. }
  766. // sizeInt32Value returns the size of wire encoding a int32 value as a Int32.
  767. func sizeInt32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  768. return tagsize + protowire.SizeVarint(uint64(int32(v.Int())))
  769. }
  770. // appendInt32Value encodes a int32 value as a Int32.
  771. func appendInt32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  772. b = protowire.AppendVarint(b, wiretag)
  773. b = protowire.AppendVarint(b, uint64(int32(v.Int())))
  774. return b, nil
  775. }
  776. // consumeInt32Value decodes a int32 value as a Int32.
  777. func consumeInt32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  778. if wtyp != protowire.VarintType {
  779. return protoreflect.Value{}, out, errUnknown
  780. }
  781. var v uint64
  782. var n int
  783. if len(b) >= 1 && b[0] < 0x80 {
  784. v = uint64(b[0])
  785. n = 1
  786. } else if len(b) >= 2 && b[1] < 128 {
  787. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  788. n = 2
  789. } else {
  790. v, n = protowire.ConsumeVarint(b)
  791. }
  792. if n < 0 {
  793. return protoreflect.Value{}, out, errDecode
  794. }
  795. out.n = n
  796. return protoreflect.ValueOfInt32(int32(v)), out, nil
  797. }
  798. var coderInt32Value = valueCoderFuncs{
  799. size: sizeInt32Value,
  800. marshal: appendInt32Value,
  801. unmarshal: consumeInt32Value,
  802. merge: mergeScalarValue,
  803. }
  804. // sizeInt32SliceValue returns the size of wire encoding a []int32 value as a repeated Int32.
  805. func sizeInt32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  806. list := listv.List()
  807. for i, llen := 0, list.Len(); i < llen; i++ {
  808. v := list.Get(i)
  809. size += tagsize + protowire.SizeVarint(uint64(int32(v.Int())))
  810. }
  811. return size
  812. }
  813. // appendInt32SliceValue encodes a []int32 value as a repeated Int32.
  814. func appendInt32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  815. list := listv.List()
  816. for i, llen := 0, list.Len(); i < llen; i++ {
  817. v := list.Get(i)
  818. b = protowire.AppendVarint(b, wiretag)
  819. b = protowire.AppendVarint(b, uint64(int32(v.Int())))
  820. }
  821. return b, nil
  822. }
  823. // consumeInt32SliceValue wire decodes a []int32 value as a repeated Int32.
  824. func consumeInt32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  825. list := listv.List()
  826. if wtyp == protowire.BytesType {
  827. b, n := protowire.ConsumeBytes(b)
  828. if n < 0 {
  829. return protoreflect.Value{}, out, errDecode
  830. }
  831. for len(b) > 0 {
  832. var v uint64
  833. var n int
  834. if len(b) >= 1 && b[0] < 0x80 {
  835. v = uint64(b[0])
  836. n = 1
  837. } else if len(b) >= 2 && b[1] < 128 {
  838. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  839. n = 2
  840. } else {
  841. v, n = protowire.ConsumeVarint(b)
  842. }
  843. if n < 0 {
  844. return protoreflect.Value{}, out, errDecode
  845. }
  846. list.Append(protoreflect.ValueOfInt32(int32(v)))
  847. b = b[n:]
  848. }
  849. out.n = n
  850. return listv, out, nil
  851. }
  852. if wtyp != protowire.VarintType {
  853. return protoreflect.Value{}, out, errUnknown
  854. }
  855. var v uint64
  856. var n int
  857. if len(b) >= 1 && b[0] < 0x80 {
  858. v = uint64(b[0])
  859. n = 1
  860. } else if len(b) >= 2 && b[1] < 128 {
  861. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  862. n = 2
  863. } else {
  864. v, n = protowire.ConsumeVarint(b)
  865. }
  866. if n < 0 {
  867. return protoreflect.Value{}, out, errDecode
  868. }
  869. list.Append(protoreflect.ValueOfInt32(int32(v)))
  870. out.n = n
  871. return listv, out, nil
  872. }
  873. var coderInt32SliceValue = valueCoderFuncs{
  874. size: sizeInt32SliceValue,
  875. marshal: appendInt32SliceValue,
  876. unmarshal: consumeInt32SliceValue,
  877. merge: mergeListValue,
  878. }
  879. // sizeInt32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Int32.
  880. func sizeInt32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  881. list := listv.List()
  882. llen := list.Len()
  883. if llen == 0 {
  884. return 0
  885. }
  886. n := 0
  887. for i, llen := 0, llen; i < llen; i++ {
  888. v := list.Get(i)
  889. n += protowire.SizeVarint(uint64(int32(v.Int())))
  890. }
  891. return tagsize + protowire.SizeBytes(n)
  892. }
  893. // appendInt32PackedSliceValue encodes a []int32 value as a packed repeated Int32.
  894. func appendInt32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  895. list := listv.List()
  896. llen := list.Len()
  897. if llen == 0 {
  898. return b, nil
  899. }
  900. b = protowire.AppendVarint(b, wiretag)
  901. n := 0
  902. for i := 0; i < llen; i++ {
  903. v := list.Get(i)
  904. n += protowire.SizeVarint(uint64(int32(v.Int())))
  905. }
  906. b = protowire.AppendVarint(b, uint64(n))
  907. for i := 0; i < llen; i++ {
  908. v := list.Get(i)
  909. b = protowire.AppendVarint(b, uint64(int32(v.Int())))
  910. }
  911. return b, nil
  912. }
  913. var coderInt32PackedSliceValue = valueCoderFuncs{
  914. size: sizeInt32PackedSliceValue,
  915. marshal: appendInt32PackedSliceValue,
  916. unmarshal: consumeInt32SliceValue,
  917. merge: mergeListValue,
  918. }
  919. // sizeSint32 returns the size of wire encoding a int32 pointer as a Sint32.
  920. func sizeSint32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  921. v := *p.Int32()
  922. return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
  923. }
  924. // appendSint32 wire encodes a int32 pointer as a Sint32.
  925. func appendSint32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  926. v := *p.Int32()
  927. b = protowire.AppendVarint(b, f.wiretag)
  928. b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v)))
  929. return b, nil
  930. }
  931. // consumeSint32 wire decodes a int32 pointer as a Sint32.
  932. func consumeSint32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  933. if wtyp != protowire.VarintType {
  934. return out, errUnknown
  935. }
  936. var v uint64
  937. var n int
  938. if len(b) >= 1 && b[0] < 0x80 {
  939. v = uint64(b[0])
  940. n = 1
  941. } else if len(b) >= 2 && b[1] < 128 {
  942. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  943. n = 2
  944. } else {
  945. v, n = protowire.ConsumeVarint(b)
  946. }
  947. if n < 0 {
  948. return out, errDecode
  949. }
  950. *p.Int32() = int32(protowire.DecodeZigZag(v & math.MaxUint32))
  951. out.n = n
  952. return out, nil
  953. }
  954. var coderSint32 = pointerCoderFuncs{
  955. size: sizeSint32,
  956. marshal: appendSint32,
  957. unmarshal: consumeSint32,
  958. merge: mergeInt32,
  959. }
  960. // sizeSint32NoZero returns the size of wire encoding a int32 pointer as a Sint32.
  961. // The zero value is not encoded.
  962. func sizeSint32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  963. v := *p.Int32()
  964. if v == 0 {
  965. return 0
  966. }
  967. return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
  968. }
  969. // appendSint32NoZero wire encodes a int32 pointer as a Sint32.
  970. // The zero value is not encoded.
  971. func appendSint32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  972. v := *p.Int32()
  973. if v == 0 {
  974. return b, nil
  975. }
  976. b = protowire.AppendVarint(b, f.wiretag)
  977. b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v)))
  978. return b, nil
  979. }
  980. var coderSint32NoZero = pointerCoderFuncs{
  981. size: sizeSint32NoZero,
  982. marshal: appendSint32NoZero,
  983. unmarshal: consumeSint32,
  984. merge: mergeInt32NoZero,
  985. }
  986. // sizeSint32Ptr returns the size of wire encoding a *int32 pointer as a Sint32.
  987. // It panics if the pointer is nil.
  988. func sizeSint32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  989. v := **p.Int32Ptr()
  990. return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
  991. }
  992. // appendSint32Ptr wire encodes a *int32 pointer as a Sint32.
  993. // It panics if the pointer is nil.
  994. func appendSint32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  995. v := **p.Int32Ptr()
  996. b = protowire.AppendVarint(b, f.wiretag)
  997. b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v)))
  998. return b, nil
  999. }
  1000. // consumeSint32Ptr wire decodes a *int32 pointer as a Sint32.
  1001. func consumeSint32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  1002. if wtyp != protowire.VarintType {
  1003. return out, errUnknown
  1004. }
  1005. var v uint64
  1006. var n int
  1007. if len(b) >= 1 && b[0] < 0x80 {
  1008. v = uint64(b[0])
  1009. n = 1
  1010. } else if len(b) >= 2 && b[1] < 128 {
  1011. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1012. n = 2
  1013. } else {
  1014. v, n = protowire.ConsumeVarint(b)
  1015. }
  1016. if n < 0 {
  1017. return out, errDecode
  1018. }
  1019. vp := p.Int32Ptr()
  1020. if *vp == nil {
  1021. *vp = new(int32)
  1022. }
  1023. **vp = int32(protowire.DecodeZigZag(v & math.MaxUint32))
  1024. out.n = n
  1025. return out, nil
  1026. }
  1027. var coderSint32Ptr = pointerCoderFuncs{
  1028. size: sizeSint32Ptr,
  1029. marshal: appendSint32Ptr,
  1030. unmarshal: consumeSint32Ptr,
  1031. merge: mergeInt32Ptr,
  1032. }
  1033. // sizeSint32Slice returns the size of wire encoding a []int32 pointer as a repeated Sint32.
  1034. func sizeSint32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1035. s := *p.Int32Slice()
  1036. for _, v := range s {
  1037. size += f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
  1038. }
  1039. return size
  1040. }
  1041. // appendSint32Slice encodes a []int32 pointer as a repeated Sint32.
  1042. func appendSint32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1043. s := *p.Int32Slice()
  1044. for _, v := range s {
  1045. b = protowire.AppendVarint(b, f.wiretag)
  1046. b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v)))
  1047. }
  1048. return b, nil
  1049. }
  1050. // consumeSint32Slice wire decodes a []int32 pointer as a repeated Sint32.
  1051. func consumeSint32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  1052. sp := p.Int32Slice()
  1053. if wtyp == protowire.BytesType {
  1054. s := *sp
  1055. b, n := protowire.ConsumeBytes(b)
  1056. if n < 0 {
  1057. return out, errDecode
  1058. }
  1059. for len(b) > 0 {
  1060. var v uint64
  1061. var n int
  1062. if len(b) >= 1 && b[0] < 0x80 {
  1063. v = uint64(b[0])
  1064. n = 1
  1065. } else if len(b) >= 2 && b[1] < 128 {
  1066. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1067. n = 2
  1068. } else {
  1069. v, n = protowire.ConsumeVarint(b)
  1070. }
  1071. if n < 0 {
  1072. return out, errDecode
  1073. }
  1074. s = append(s, int32(protowire.DecodeZigZag(v&math.MaxUint32)))
  1075. b = b[n:]
  1076. }
  1077. *sp = s
  1078. out.n = n
  1079. return out, nil
  1080. }
  1081. if wtyp != protowire.VarintType {
  1082. return out, errUnknown
  1083. }
  1084. var v uint64
  1085. var n int
  1086. if len(b) >= 1 && b[0] < 0x80 {
  1087. v = uint64(b[0])
  1088. n = 1
  1089. } else if len(b) >= 2 && b[1] < 128 {
  1090. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1091. n = 2
  1092. } else {
  1093. v, n = protowire.ConsumeVarint(b)
  1094. }
  1095. if n < 0 {
  1096. return out, errDecode
  1097. }
  1098. *sp = append(*sp, int32(protowire.DecodeZigZag(v&math.MaxUint32)))
  1099. out.n = n
  1100. return out, nil
  1101. }
  1102. var coderSint32Slice = pointerCoderFuncs{
  1103. size: sizeSint32Slice,
  1104. marshal: appendSint32Slice,
  1105. unmarshal: consumeSint32Slice,
  1106. merge: mergeInt32Slice,
  1107. }
  1108. // sizeSint32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sint32.
  1109. func sizeSint32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1110. s := *p.Int32Slice()
  1111. if len(s) == 0 {
  1112. return 0
  1113. }
  1114. n := 0
  1115. for _, v := range s {
  1116. n += protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
  1117. }
  1118. return f.tagsize + protowire.SizeBytes(n)
  1119. }
  1120. // appendSint32PackedSlice encodes a []int32 pointer as a packed repeated Sint32.
  1121. func appendSint32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1122. s := *p.Int32Slice()
  1123. if len(s) == 0 {
  1124. return b, nil
  1125. }
  1126. b = protowire.AppendVarint(b, f.wiretag)
  1127. n := 0
  1128. for _, v := range s {
  1129. n += protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
  1130. }
  1131. b = protowire.AppendVarint(b, uint64(n))
  1132. for _, v := range s {
  1133. b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v)))
  1134. }
  1135. return b, nil
  1136. }
  1137. var coderSint32PackedSlice = pointerCoderFuncs{
  1138. size: sizeSint32PackedSlice,
  1139. marshal: appendSint32PackedSlice,
  1140. unmarshal: consumeSint32Slice,
  1141. merge: mergeInt32Slice,
  1142. }
  1143. // sizeSint32Value returns the size of wire encoding a int32 value as a Sint32.
  1144. func sizeSint32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  1145. return tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int()))))
  1146. }
  1147. // appendSint32Value encodes a int32 value as a Sint32.
  1148. func appendSint32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  1149. b = protowire.AppendVarint(b, wiretag)
  1150. b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(int32(v.Int()))))
  1151. return b, nil
  1152. }
  1153. // consumeSint32Value decodes a int32 value as a Sint32.
  1154. func consumeSint32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  1155. if wtyp != protowire.VarintType {
  1156. return protoreflect.Value{}, out, errUnknown
  1157. }
  1158. var v uint64
  1159. var n int
  1160. if len(b) >= 1 && b[0] < 0x80 {
  1161. v = uint64(b[0])
  1162. n = 1
  1163. } else if len(b) >= 2 && b[1] < 128 {
  1164. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1165. n = 2
  1166. } else {
  1167. v, n = protowire.ConsumeVarint(b)
  1168. }
  1169. if n < 0 {
  1170. return protoreflect.Value{}, out, errDecode
  1171. }
  1172. out.n = n
  1173. return protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))), out, nil
  1174. }
  1175. var coderSint32Value = valueCoderFuncs{
  1176. size: sizeSint32Value,
  1177. marshal: appendSint32Value,
  1178. unmarshal: consumeSint32Value,
  1179. merge: mergeScalarValue,
  1180. }
  1181. // sizeSint32SliceValue returns the size of wire encoding a []int32 value as a repeated Sint32.
  1182. func sizeSint32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  1183. list := listv.List()
  1184. for i, llen := 0, list.Len(); i < llen; i++ {
  1185. v := list.Get(i)
  1186. size += tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int()))))
  1187. }
  1188. return size
  1189. }
  1190. // appendSint32SliceValue encodes a []int32 value as a repeated Sint32.
  1191. func appendSint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  1192. list := listv.List()
  1193. for i, llen := 0, list.Len(); i < llen; i++ {
  1194. v := list.Get(i)
  1195. b = protowire.AppendVarint(b, wiretag)
  1196. b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(int32(v.Int()))))
  1197. }
  1198. return b, nil
  1199. }
  1200. // consumeSint32SliceValue wire decodes a []int32 value as a repeated Sint32.
  1201. func consumeSint32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  1202. list := listv.List()
  1203. if wtyp == protowire.BytesType {
  1204. b, n := protowire.ConsumeBytes(b)
  1205. if n < 0 {
  1206. return protoreflect.Value{}, out, errDecode
  1207. }
  1208. for len(b) > 0 {
  1209. var v uint64
  1210. var n int
  1211. if len(b) >= 1 && b[0] < 0x80 {
  1212. v = uint64(b[0])
  1213. n = 1
  1214. } else if len(b) >= 2 && b[1] < 128 {
  1215. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1216. n = 2
  1217. } else {
  1218. v, n = protowire.ConsumeVarint(b)
  1219. }
  1220. if n < 0 {
  1221. return protoreflect.Value{}, out, errDecode
  1222. }
  1223. list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))))
  1224. b = b[n:]
  1225. }
  1226. out.n = n
  1227. return listv, out, nil
  1228. }
  1229. if wtyp != protowire.VarintType {
  1230. return protoreflect.Value{}, out, errUnknown
  1231. }
  1232. var v uint64
  1233. var n int
  1234. if len(b) >= 1 && b[0] < 0x80 {
  1235. v = uint64(b[0])
  1236. n = 1
  1237. } else if len(b) >= 2 && b[1] < 128 {
  1238. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1239. n = 2
  1240. } else {
  1241. v, n = protowire.ConsumeVarint(b)
  1242. }
  1243. if n < 0 {
  1244. return protoreflect.Value{}, out, errDecode
  1245. }
  1246. list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))))
  1247. out.n = n
  1248. return listv, out, nil
  1249. }
  1250. var coderSint32SliceValue = valueCoderFuncs{
  1251. size: sizeSint32SliceValue,
  1252. marshal: appendSint32SliceValue,
  1253. unmarshal: consumeSint32SliceValue,
  1254. merge: mergeListValue,
  1255. }
  1256. // sizeSint32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sint32.
  1257. func sizeSint32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  1258. list := listv.List()
  1259. llen := list.Len()
  1260. if llen == 0 {
  1261. return 0
  1262. }
  1263. n := 0
  1264. for i, llen := 0, llen; i < llen; i++ {
  1265. v := list.Get(i)
  1266. n += protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int()))))
  1267. }
  1268. return tagsize + protowire.SizeBytes(n)
  1269. }
  1270. // appendSint32PackedSliceValue encodes a []int32 value as a packed repeated Sint32.
  1271. func appendSint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  1272. list := listv.List()
  1273. llen := list.Len()
  1274. if llen == 0 {
  1275. return b, nil
  1276. }
  1277. b = protowire.AppendVarint(b, wiretag)
  1278. n := 0
  1279. for i := 0; i < llen; i++ {
  1280. v := list.Get(i)
  1281. n += protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int()))))
  1282. }
  1283. b = protowire.AppendVarint(b, uint64(n))
  1284. for i := 0; i < llen; i++ {
  1285. v := list.Get(i)
  1286. b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(int32(v.Int()))))
  1287. }
  1288. return b, nil
  1289. }
  1290. var coderSint32PackedSliceValue = valueCoderFuncs{
  1291. size: sizeSint32PackedSliceValue,
  1292. marshal: appendSint32PackedSliceValue,
  1293. unmarshal: consumeSint32SliceValue,
  1294. merge: mergeListValue,
  1295. }
  1296. // sizeUint32 returns the size of wire encoding a uint32 pointer as a Uint32.
  1297. func sizeUint32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1298. v := *p.Uint32()
  1299. return f.tagsize + protowire.SizeVarint(uint64(v))
  1300. }
  1301. // appendUint32 wire encodes a uint32 pointer as a Uint32.
  1302. func appendUint32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1303. v := *p.Uint32()
  1304. b = protowire.AppendVarint(b, f.wiretag)
  1305. b = protowire.AppendVarint(b, uint64(v))
  1306. return b, nil
  1307. }
  1308. // consumeUint32 wire decodes a uint32 pointer as a Uint32.
  1309. func consumeUint32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  1310. if wtyp != protowire.VarintType {
  1311. return out, errUnknown
  1312. }
  1313. var v uint64
  1314. var n int
  1315. if len(b) >= 1 && b[0] < 0x80 {
  1316. v = uint64(b[0])
  1317. n = 1
  1318. } else if len(b) >= 2 && b[1] < 128 {
  1319. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1320. n = 2
  1321. } else {
  1322. v, n = protowire.ConsumeVarint(b)
  1323. }
  1324. if n < 0 {
  1325. return out, errDecode
  1326. }
  1327. *p.Uint32() = uint32(v)
  1328. out.n = n
  1329. return out, nil
  1330. }
  1331. var coderUint32 = pointerCoderFuncs{
  1332. size: sizeUint32,
  1333. marshal: appendUint32,
  1334. unmarshal: consumeUint32,
  1335. merge: mergeUint32,
  1336. }
  1337. // sizeUint32NoZero returns the size of wire encoding a uint32 pointer as a Uint32.
  1338. // The zero value is not encoded.
  1339. func sizeUint32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1340. v := *p.Uint32()
  1341. if v == 0 {
  1342. return 0
  1343. }
  1344. return f.tagsize + protowire.SizeVarint(uint64(v))
  1345. }
  1346. // appendUint32NoZero wire encodes a uint32 pointer as a Uint32.
  1347. // The zero value is not encoded.
  1348. func appendUint32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1349. v := *p.Uint32()
  1350. if v == 0 {
  1351. return b, nil
  1352. }
  1353. b = protowire.AppendVarint(b, f.wiretag)
  1354. b = protowire.AppendVarint(b, uint64(v))
  1355. return b, nil
  1356. }
  1357. var coderUint32NoZero = pointerCoderFuncs{
  1358. size: sizeUint32NoZero,
  1359. marshal: appendUint32NoZero,
  1360. unmarshal: consumeUint32,
  1361. merge: mergeUint32NoZero,
  1362. }
  1363. // sizeUint32Ptr returns the size of wire encoding a *uint32 pointer as a Uint32.
  1364. // It panics if the pointer is nil.
  1365. func sizeUint32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1366. v := **p.Uint32Ptr()
  1367. return f.tagsize + protowire.SizeVarint(uint64(v))
  1368. }
  1369. // appendUint32Ptr wire encodes a *uint32 pointer as a Uint32.
  1370. // It panics if the pointer is nil.
  1371. func appendUint32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1372. v := **p.Uint32Ptr()
  1373. b = protowire.AppendVarint(b, f.wiretag)
  1374. b = protowire.AppendVarint(b, uint64(v))
  1375. return b, nil
  1376. }
  1377. // consumeUint32Ptr wire decodes a *uint32 pointer as a Uint32.
  1378. func consumeUint32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  1379. if wtyp != protowire.VarintType {
  1380. return out, errUnknown
  1381. }
  1382. var v uint64
  1383. var n int
  1384. if len(b) >= 1 && b[0] < 0x80 {
  1385. v = uint64(b[0])
  1386. n = 1
  1387. } else if len(b) >= 2 && b[1] < 128 {
  1388. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1389. n = 2
  1390. } else {
  1391. v, n = protowire.ConsumeVarint(b)
  1392. }
  1393. if n < 0 {
  1394. return out, errDecode
  1395. }
  1396. vp := p.Uint32Ptr()
  1397. if *vp == nil {
  1398. *vp = new(uint32)
  1399. }
  1400. **vp = uint32(v)
  1401. out.n = n
  1402. return out, nil
  1403. }
  1404. var coderUint32Ptr = pointerCoderFuncs{
  1405. size: sizeUint32Ptr,
  1406. marshal: appendUint32Ptr,
  1407. unmarshal: consumeUint32Ptr,
  1408. merge: mergeUint32Ptr,
  1409. }
  1410. // sizeUint32Slice returns the size of wire encoding a []uint32 pointer as a repeated Uint32.
  1411. func sizeUint32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1412. s := *p.Uint32Slice()
  1413. for _, v := range s {
  1414. size += f.tagsize + protowire.SizeVarint(uint64(v))
  1415. }
  1416. return size
  1417. }
  1418. // appendUint32Slice encodes a []uint32 pointer as a repeated Uint32.
  1419. func appendUint32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1420. s := *p.Uint32Slice()
  1421. for _, v := range s {
  1422. b = protowire.AppendVarint(b, f.wiretag)
  1423. b = protowire.AppendVarint(b, uint64(v))
  1424. }
  1425. return b, nil
  1426. }
  1427. // consumeUint32Slice wire decodes a []uint32 pointer as a repeated Uint32.
  1428. func consumeUint32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  1429. sp := p.Uint32Slice()
  1430. if wtyp == protowire.BytesType {
  1431. s := *sp
  1432. b, n := protowire.ConsumeBytes(b)
  1433. if n < 0 {
  1434. return out, errDecode
  1435. }
  1436. for len(b) > 0 {
  1437. var v uint64
  1438. var n int
  1439. if len(b) >= 1 && b[0] < 0x80 {
  1440. v = uint64(b[0])
  1441. n = 1
  1442. } else if len(b) >= 2 && b[1] < 128 {
  1443. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1444. n = 2
  1445. } else {
  1446. v, n = protowire.ConsumeVarint(b)
  1447. }
  1448. if n < 0 {
  1449. return out, errDecode
  1450. }
  1451. s = append(s, uint32(v))
  1452. b = b[n:]
  1453. }
  1454. *sp = s
  1455. out.n = n
  1456. return out, nil
  1457. }
  1458. if wtyp != protowire.VarintType {
  1459. return out, errUnknown
  1460. }
  1461. var v uint64
  1462. var n int
  1463. if len(b) >= 1 && b[0] < 0x80 {
  1464. v = uint64(b[0])
  1465. n = 1
  1466. } else if len(b) >= 2 && b[1] < 128 {
  1467. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1468. n = 2
  1469. } else {
  1470. v, n = protowire.ConsumeVarint(b)
  1471. }
  1472. if n < 0 {
  1473. return out, errDecode
  1474. }
  1475. *sp = append(*sp, uint32(v))
  1476. out.n = n
  1477. return out, nil
  1478. }
  1479. var coderUint32Slice = pointerCoderFuncs{
  1480. size: sizeUint32Slice,
  1481. marshal: appendUint32Slice,
  1482. unmarshal: consumeUint32Slice,
  1483. merge: mergeUint32Slice,
  1484. }
  1485. // sizeUint32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Uint32.
  1486. func sizeUint32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1487. s := *p.Uint32Slice()
  1488. if len(s) == 0 {
  1489. return 0
  1490. }
  1491. n := 0
  1492. for _, v := range s {
  1493. n += protowire.SizeVarint(uint64(v))
  1494. }
  1495. return f.tagsize + protowire.SizeBytes(n)
  1496. }
  1497. // appendUint32PackedSlice encodes a []uint32 pointer as a packed repeated Uint32.
  1498. func appendUint32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1499. s := *p.Uint32Slice()
  1500. if len(s) == 0 {
  1501. return b, nil
  1502. }
  1503. b = protowire.AppendVarint(b, f.wiretag)
  1504. n := 0
  1505. for _, v := range s {
  1506. n += protowire.SizeVarint(uint64(v))
  1507. }
  1508. b = protowire.AppendVarint(b, uint64(n))
  1509. for _, v := range s {
  1510. b = protowire.AppendVarint(b, uint64(v))
  1511. }
  1512. return b, nil
  1513. }
  1514. var coderUint32PackedSlice = pointerCoderFuncs{
  1515. size: sizeUint32PackedSlice,
  1516. marshal: appendUint32PackedSlice,
  1517. unmarshal: consumeUint32Slice,
  1518. merge: mergeUint32Slice,
  1519. }
  1520. // sizeUint32Value returns the size of wire encoding a uint32 value as a Uint32.
  1521. func sizeUint32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  1522. return tagsize + protowire.SizeVarint(uint64(uint32(v.Uint())))
  1523. }
  1524. // appendUint32Value encodes a uint32 value as a Uint32.
  1525. func appendUint32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  1526. b = protowire.AppendVarint(b, wiretag)
  1527. b = protowire.AppendVarint(b, uint64(uint32(v.Uint())))
  1528. return b, nil
  1529. }
  1530. // consumeUint32Value decodes a uint32 value as a Uint32.
  1531. func consumeUint32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  1532. if wtyp != protowire.VarintType {
  1533. return protoreflect.Value{}, out, errUnknown
  1534. }
  1535. var v uint64
  1536. var n int
  1537. if len(b) >= 1 && b[0] < 0x80 {
  1538. v = uint64(b[0])
  1539. n = 1
  1540. } else if len(b) >= 2 && b[1] < 128 {
  1541. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1542. n = 2
  1543. } else {
  1544. v, n = protowire.ConsumeVarint(b)
  1545. }
  1546. if n < 0 {
  1547. return protoreflect.Value{}, out, errDecode
  1548. }
  1549. out.n = n
  1550. return protoreflect.ValueOfUint32(uint32(v)), out, nil
  1551. }
  1552. var coderUint32Value = valueCoderFuncs{
  1553. size: sizeUint32Value,
  1554. marshal: appendUint32Value,
  1555. unmarshal: consumeUint32Value,
  1556. merge: mergeScalarValue,
  1557. }
  1558. // sizeUint32SliceValue returns the size of wire encoding a []uint32 value as a repeated Uint32.
  1559. func sizeUint32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  1560. list := listv.List()
  1561. for i, llen := 0, list.Len(); i < llen; i++ {
  1562. v := list.Get(i)
  1563. size += tagsize + protowire.SizeVarint(uint64(uint32(v.Uint())))
  1564. }
  1565. return size
  1566. }
  1567. // appendUint32SliceValue encodes a []uint32 value as a repeated Uint32.
  1568. func appendUint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  1569. list := listv.List()
  1570. for i, llen := 0, list.Len(); i < llen; i++ {
  1571. v := list.Get(i)
  1572. b = protowire.AppendVarint(b, wiretag)
  1573. b = protowire.AppendVarint(b, uint64(uint32(v.Uint())))
  1574. }
  1575. return b, nil
  1576. }
  1577. // consumeUint32SliceValue wire decodes a []uint32 value as a repeated Uint32.
  1578. func consumeUint32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  1579. list := listv.List()
  1580. if wtyp == protowire.BytesType {
  1581. b, n := protowire.ConsumeBytes(b)
  1582. if n < 0 {
  1583. return protoreflect.Value{}, out, errDecode
  1584. }
  1585. for len(b) > 0 {
  1586. var v uint64
  1587. var n int
  1588. if len(b) >= 1 && b[0] < 0x80 {
  1589. v = uint64(b[0])
  1590. n = 1
  1591. } else if len(b) >= 2 && b[1] < 128 {
  1592. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1593. n = 2
  1594. } else {
  1595. v, n = protowire.ConsumeVarint(b)
  1596. }
  1597. if n < 0 {
  1598. return protoreflect.Value{}, out, errDecode
  1599. }
  1600. list.Append(protoreflect.ValueOfUint32(uint32(v)))
  1601. b = b[n:]
  1602. }
  1603. out.n = n
  1604. return listv, out, nil
  1605. }
  1606. if wtyp != protowire.VarintType {
  1607. return protoreflect.Value{}, out, errUnknown
  1608. }
  1609. var v uint64
  1610. var n int
  1611. if len(b) >= 1 && b[0] < 0x80 {
  1612. v = uint64(b[0])
  1613. n = 1
  1614. } else if len(b) >= 2 && b[1] < 128 {
  1615. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1616. n = 2
  1617. } else {
  1618. v, n = protowire.ConsumeVarint(b)
  1619. }
  1620. if n < 0 {
  1621. return protoreflect.Value{}, out, errDecode
  1622. }
  1623. list.Append(protoreflect.ValueOfUint32(uint32(v)))
  1624. out.n = n
  1625. return listv, out, nil
  1626. }
  1627. var coderUint32SliceValue = valueCoderFuncs{
  1628. size: sizeUint32SliceValue,
  1629. marshal: appendUint32SliceValue,
  1630. unmarshal: consumeUint32SliceValue,
  1631. merge: mergeListValue,
  1632. }
  1633. // sizeUint32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Uint32.
  1634. func sizeUint32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  1635. list := listv.List()
  1636. llen := list.Len()
  1637. if llen == 0 {
  1638. return 0
  1639. }
  1640. n := 0
  1641. for i, llen := 0, llen; i < llen; i++ {
  1642. v := list.Get(i)
  1643. n += protowire.SizeVarint(uint64(uint32(v.Uint())))
  1644. }
  1645. return tagsize + protowire.SizeBytes(n)
  1646. }
  1647. // appendUint32PackedSliceValue encodes a []uint32 value as a packed repeated Uint32.
  1648. func appendUint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  1649. list := listv.List()
  1650. llen := list.Len()
  1651. if llen == 0 {
  1652. return b, nil
  1653. }
  1654. b = protowire.AppendVarint(b, wiretag)
  1655. n := 0
  1656. for i := 0; i < llen; i++ {
  1657. v := list.Get(i)
  1658. n += protowire.SizeVarint(uint64(uint32(v.Uint())))
  1659. }
  1660. b = protowire.AppendVarint(b, uint64(n))
  1661. for i := 0; i < llen; i++ {
  1662. v := list.Get(i)
  1663. b = protowire.AppendVarint(b, uint64(uint32(v.Uint())))
  1664. }
  1665. return b, nil
  1666. }
  1667. var coderUint32PackedSliceValue = valueCoderFuncs{
  1668. size: sizeUint32PackedSliceValue,
  1669. marshal: appendUint32PackedSliceValue,
  1670. unmarshal: consumeUint32SliceValue,
  1671. merge: mergeListValue,
  1672. }
  1673. // sizeInt64 returns the size of wire encoding a int64 pointer as a Int64.
  1674. func sizeInt64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1675. v := *p.Int64()
  1676. return f.tagsize + protowire.SizeVarint(uint64(v))
  1677. }
  1678. // appendInt64 wire encodes a int64 pointer as a Int64.
  1679. func appendInt64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1680. v := *p.Int64()
  1681. b = protowire.AppendVarint(b, f.wiretag)
  1682. b = protowire.AppendVarint(b, uint64(v))
  1683. return b, nil
  1684. }
  1685. // consumeInt64 wire decodes a int64 pointer as a Int64.
  1686. func consumeInt64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  1687. if wtyp != protowire.VarintType {
  1688. return out, errUnknown
  1689. }
  1690. var v uint64
  1691. var n int
  1692. if len(b) >= 1 && b[0] < 0x80 {
  1693. v = uint64(b[0])
  1694. n = 1
  1695. } else if len(b) >= 2 && b[1] < 128 {
  1696. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1697. n = 2
  1698. } else {
  1699. v, n = protowire.ConsumeVarint(b)
  1700. }
  1701. if n < 0 {
  1702. return out, errDecode
  1703. }
  1704. *p.Int64() = int64(v)
  1705. out.n = n
  1706. return out, nil
  1707. }
  1708. var coderInt64 = pointerCoderFuncs{
  1709. size: sizeInt64,
  1710. marshal: appendInt64,
  1711. unmarshal: consumeInt64,
  1712. merge: mergeInt64,
  1713. }
  1714. // sizeInt64NoZero returns the size of wire encoding a int64 pointer as a Int64.
  1715. // The zero value is not encoded.
  1716. func sizeInt64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1717. v := *p.Int64()
  1718. if v == 0 {
  1719. return 0
  1720. }
  1721. return f.tagsize + protowire.SizeVarint(uint64(v))
  1722. }
  1723. // appendInt64NoZero wire encodes a int64 pointer as a Int64.
  1724. // The zero value is not encoded.
  1725. func appendInt64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1726. v := *p.Int64()
  1727. if v == 0 {
  1728. return b, nil
  1729. }
  1730. b = protowire.AppendVarint(b, f.wiretag)
  1731. b = protowire.AppendVarint(b, uint64(v))
  1732. return b, nil
  1733. }
  1734. var coderInt64NoZero = pointerCoderFuncs{
  1735. size: sizeInt64NoZero,
  1736. marshal: appendInt64NoZero,
  1737. unmarshal: consumeInt64,
  1738. merge: mergeInt64NoZero,
  1739. }
  1740. // sizeInt64Ptr returns the size of wire encoding a *int64 pointer as a Int64.
  1741. // It panics if the pointer is nil.
  1742. func sizeInt64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1743. v := **p.Int64Ptr()
  1744. return f.tagsize + protowire.SizeVarint(uint64(v))
  1745. }
  1746. // appendInt64Ptr wire encodes a *int64 pointer as a Int64.
  1747. // It panics if the pointer is nil.
  1748. func appendInt64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1749. v := **p.Int64Ptr()
  1750. b = protowire.AppendVarint(b, f.wiretag)
  1751. b = protowire.AppendVarint(b, uint64(v))
  1752. return b, nil
  1753. }
  1754. // consumeInt64Ptr wire decodes a *int64 pointer as a Int64.
  1755. func consumeInt64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  1756. if wtyp != protowire.VarintType {
  1757. return out, errUnknown
  1758. }
  1759. var v uint64
  1760. var n int
  1761. if len(b) >= 1 && b[0] < 0x80 {
  1762. v = uint64(b[0])
  1763. n = 1
  1764. } else if len(b) >= 2 && b[1] < 128 {
  1765. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1766. n = 2
  1767. } else {
  1768. v, n = protowire.ConsumeVarint(b)
  1769. }
  1770. if n < 0 {
  1771. return out, errDecode
  1772. }
  1773. vp := p.Int64Ptr()
  1774. if *vp == nil {
  1775. *vp = new(int64)
  1776. }
  1777. **vp = int64(v)
  1778. out.n = n
  1779. return out, nil
  1780. }
  1781. var coderInt64Ptr = pointerCoderFuncs{
  1782. size: sizeInt64Ptr,
  1783. marshal: appendInt64Ptr,
  1784. unmarshal: consumeInt64Ptr,
  1785. merge: mergeInt64Ptr,
  1786. }
  1787. // sizeInt64Slice returns the size of wire encoding a []int64 pointer as a repeated Int64.
  1788. func sizeInt64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1789. s := *p.Int64Slice()
  1790. for _, v := range s {
  1791. size += f.tagsize + protowire.SizeVarint(uint64(v))
  1792. }
  1793. return size
  1794. }
  1795. // appendInt64Slice encodes a []int64 pointer as a repeated Int64.
  1796. func appendInt64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1797. s := *p.Int64Slice()
  1798. for _, v := range s {
  1799. b = protowire.AppendVarint(b, f.wiretag)
  1800. b = protowire.AppendVarint(b, uint64(v))
  1801. }
  1802. return b, nil
  1803. }
  1804. // consumeInt64Slice wire decodes a []int64 pointer as a repeated Int64.
  1805. func consumeInt64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  1806. sp := p.Int64Slice()
  1807. if wtyp == protowire.BytesType {
  1808. s := *sp
  1809. b, n := protowire.ConsumeBytes(b)
  1810. if n < 0 {
  1811. return out, errDecode
  1812. }
  1813. for len(b) > 0 {
  1814. var v uint64
  1815. var n int
  1816. if len(b) >= 1 && b[0] < 0x80 {
  1817. v = uint64(b[0])
  1818. n = 1
  1819. } else if len(b) >= 2 && b[1] < 128 {
  1820. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1821. n = 2
  1822. } else {
  1823. v, n = protowire.ConsumeVarint(b)
  1824. }
  1825. if n < 0 {
  1826. return out, errDecode
  1827. }
  1828. s = append(s, int64(v))
  1829. b = b[n:]
  1830. }
  1831. *sp = s
  1832. out.n = n
  1833. return out, nil
  1834. }
  1835. if wtyp != protowire.VarintType {
  1836. return out, errUnknown
  1837. }
  1838. var v uint64
  1839. var n int
  1840. if len(b) >= 1 && b[0] < 0x80 {
  1841. v = uint64(b[0])
  1842. n = 1
  1843. } else if len(b) >= 2 && b[1] < 128 {
  1844. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1845. n = 2
  1846. } else {
  1847. v, n = protowire.ConsumeVarint(b)
  1848. }
  1849. if n < 0 {
  1850. return out, errDecode
  1851. }
  1852. *sp = append(*sp, int64(v))
  1853. out.n = n
  1854. return out, nil
  1855. }
  1856. var coderInt64Slice = pointerCoderFuncs{
  1857. size: sizeInt64Slice,
  1858. marshal: appendInt64Slice,
  1859. unmarshal: consumeInt64Slice,
  1860. merge: mergeInt64Slice,
  1861. }
  1862. // sizeInt64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Int64.
  1863. func sizeInt64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  1864. s := *p.Int64Slice()
  1865. if len(s) == 0 {
  1866. return 0
  1867. }
  1868. n := 0
  1869. for _, v := range s {
  1870. n += protowire.SizeVarint(uint64(v))
  1871. }
  1872. return f.tagsize + protowire.SizeBytes(n)
  1873. }
  1874. // appendInt64PackedSlice encodes a []int64 pointer as a packed repeated Int64.
  1875. func appendInt64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  1876. s := *p.Int64Slice()
  1877. if len(s) == 0 {
  1878. return b, nil
  1879. }
  1880. b = protowire.AppendVarint(b, f.wiretag)
  1881. n := 0
  1882. for _, v := range s {
  1883. n += protowire.SizeVarint(uint64(v))
  1884. }
  1885. b = protowire.AppendVarint(b, uint64(n))
  1886. for _, v := range s {
  1887. b = protowire.AppendVarint(b, uint64(v))
  1888. }
  1889. return b, nil
  1890. }
  1891. var coderInt64PackedSlice = pointerCoderFuncs{
  1892. size: sizeInt64PackedSlice,
  1893. marshal: appendInt64PackedSlice,
  1894. unmarshal: consumeInt64Slice,
  1895. merge: mergeInt64Slice,
  1896. }
  1897. // sizeInt64Value returns the size of wire encoding a int64 value as a Int64.
  1898. func sizeInt64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  1899. return tagsize + protowire.SizeVarint(uint64(v.Int()))
  1900. }
  1901. // appendInt64Value encodes a int64 value as a Int64.
  1902. func appendInt64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  1903. b = protowire.AppendVarint(b, wiretag)
  1904. b = protowire.AppendVarint(b, uint64(v.Int()))
  1905. return b, nil
  1906. }
  1907. // consumeInt64Value decodes a int64 value as a Int64.
  1908. func consumeInt64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  1909. if wtyp != protowire.VarintType {
  1910. return protoreflect.Value{}, out, errUnknown
  1911. }
  1912. var v uint64
  1913. var n int
  1914. if len(b) >= 1 && b[0] < 0x80 {
  1915. v = uint64(b[0])
  1916. n = 1
  1917. } else if len(b) >= 2 && b[1] < 128 {
  1918. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1919. n = 2
  1920. } else {
  1921. v, n = protowire.ConsumeVarint(b)
  1922. }
  1923. if n < 0 {
  1924. return protoreflect.Value{}, out, errDecode
  1925. }
  1926. out.n = n
  1927. return protoreflect.ValueOfInt64(int64(v)), out, nil
  1928. }
  1929. var coderInt64Value = valueCoderFuncs{
  1930. size: sizeInt64Value,
  1931. marshal: appendInt64Value,
  1932. unmarshal: consumeInt64Value,
  1933. merge: mergeScalarValue,
  1934. }
  1935. // sizeInt64SliceValue returns the size of wire encoding a []int64 value as a repeated Int64.
  1936. func sizeInt64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  1937. list := listv.List()
  1938. for i, llen := 0, list.Len(); i < llen; i++ {
  1939. v := list.Get(i)
  1940. size += tagsize + protowire.SizeVarint(uint64(v.Int()))
  1941. }
  1942. return size
  1943. }
  1944. // appendInt64SliceValue encodes a []int64 value as a repeated Int64.
  1945. func appendInt64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  1946. list := listv.List()
  1947. for i, llen := 0, list.Len(); i < llen; i++ {
  1948. v := list.Get(i)
  1949. b = protowire.AppendVarint(b, wiretag)
  1950. b = protowire.AppendVarint(b, uint64(v.Int()))
  1951. }
  1952. return b, nil
  1953. }
  1954. // consumeInt64SliceValue wire decodes a []int64 value as a repeated Int64.
  1955. func consumeInt64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  1956. list := listv.List()
  1957. if wtyp == protowire.BytesType {
  1958. b, n := protowire.ConsumeBytes(b)
  1959. if n < 0 {
  1960. return protoreflect.Value{}, out, errDecode
  1961. }
  1962. for len(b) > 0 {
  1963. var v uint64
  1964. var n int
  1965. if len(b) >= 1 && b[0] < 0x80 {
  1966. v = uint64(b[0])
  1967. n = 1
  1968. } else if len(b) >= 2 && b[1] < 128 {
  1969. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1970. n = 2
  1971. } else {
  1972. v, n = protowire.ConsumeVarint(b)
  1973. }
  1974. if n < 0 {
  1975. return protoreflect.Value{}, out, errDecode
  1976. }
  1977. list.Append(protoreflect.ValueOfInt64(int64(v)))
  1978. b = b[n:]
  1979. }
  1980. out.n = n
  1981. return listv, out, nil
  1982. }
  1983. if wtyp != protowire.VarintType {
  1984. return protoreflect.Value{}, out, errUnknown
  1985. }
  1986. var v uint64
  1987. var n int
  1988. if len(b) >= 1 && b[0] < 0x80 {
  1989. v = uint64(b[0])
  1990. n = 1
  1991. } else if len(b) >= 2 && b[1] < 128 {
  1992. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  1993. n = 2
  1994. } else {
  1995. v, n = protowire.ConsumeVarint(b)
  1996. }
  1997. if n < 0 {
  1998. return protoreflect.Value{}, out, errDecode
  1999. }
  2000. list.Append(protoreflect.ValueOfInt64(int64(v)))
  2001. out.n = n
  2002. return listv, out, nil
  2003. }
  2004. var coderInt64SliceValue = valueCoderFuncs{
  2005. size: sizeInt64SliceValue,
  2006. marshal: appendInt64SliceValue,
  2007. unmarshal: consumeInt64SliceValue,
  2008. merge: mergeListValue,
  2009. }
  2010. // sizeInt64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Int64.
  2011. func sizeInt64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  2012. list := listv.List()
  2013. llen := list.Len()
  2014. if llen == 0 {
  2015. return 0
  2016. }
  2017. n := 0
  2018. for i, llen := 0, llen; i < llen; i++ {
  2019. v := list.Get(i)
  2020. n += protowire.SizeVarint(uint64(v.Int()))
  2021. }
  2022. return tagsize + protowire.SizeBytes(n)
  2023. }
  2024. // appendInt64PackedSliceValue encodes a []int64 value as a packed repeated Int64.
  2025. func appendInt64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  2026. list := listv.List()
  2027. llen := list.Len()
  2028. if llen == 0 {
  2029. return b, nil
  2030. }
  2031. b = protowire.AppendVarint(b, wiretag)
  2032. n := 0
  2033. for i := 0; i < llen; i++ {
  2034. v := list.Get(i)
  2035. n += protowire.SizeVarint(uint64(v.Int()))
  2036. }
  2037. b = protowire.AppendVarint(b, uint64(n))
  2038. for i := 0; i < llen; i++ {
  2039. v := list.Get(i)
  2040. b = protowire.AppendVarint(b, uint64(v.Int()))
  2041. }
  2042. return b, nil
  2043. }
  2044. var coderInt64PackedSliceValue = valueCoderFuncs{
  2045. size: sizeInt64PackedSliceValue,
  2046. marshal: appendInt64PackedSliceValue,
  2047. unmarshal: consumeInt64SliceValue,
  2048. merge: mergeListValue,
  2049. }
  2050. // sizeSint64 returns the size of wire encoding a int64 pointer as a Sint64.
  2051. func sizeSint64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2052. v := *p.Int64()
  2053. return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v))
  2054. }
  2055. // appendSint64 wire encodes a int64 pointer as a Sint64.
  2056. func appendSint64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2057. v := *p.Int64()
  2058. b = protowire.AppendVarint(b, f.wiretag)
  2059. b = protowire.AppendVarint(b, protowire.EncodeZigZag(v))
  2060. return b, nil
  2061. }
  2062. // consumeSint64 wire decodes a int64 pointer as a Sint64.
  2063. func consumeSint64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  2064. if wtyp != protowire.VarintType {
  2065. return out, errUnknown
  2066. }
  2067. var v uint64
  2068. var n int
  2069. if len(b) >= 1 && b[0] < 0x80 {
  2070. v = uint64(b[0])
  2071. n = 1
  2072. } else if len(b) >= 2 && b[1] < 128 {
  2073. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2074. n = 2
  2075. } else {
  2076. v, n = protowire.ConsumeVarint(b)
  2077. }
  2078. if n < 0 {
  2079. return out, errDecode
  2080. }
  2081. *p.Int64() = protowire.DecodeZigZag(v)
  2082. out.n = n
  2083. return out, nil
  2084. }
  2085. var coderSint64 = pointerCoderFuncs{
  2086. size: sizeSint64,
  2087. marshal: appendSint64,
  2088. unmarshal: consumeSint64,
  2089. merge: mergeInt64,
  2090. }
  2091. // sizeSint64NoZero returns the size of wire encoding a int64 pointer as a Sint64.
  2092. // The zero value is not encoded.
  2093. func sizeSint64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2094. v := *p.Int64()
  2095. if v == 0 {
  2096. return 0
  2097. }
  2098. return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v))
  2099. }
  2100. // appendSint64NoZero wire encodes a int64 pointer as a Sint64.
  2101. // The zero value is not encoded.
  2102. func appendSint64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2103. v := *p.Int64()
  2104. if v == 0 {
  2105. return b, nil
  2106. }
  2107. b = protowire.AppendVarint(b, f.wiretag)
  2108. b = protowire.AppendVarint(b, protowire.EncodeZigZag(v))
  2109. return b, nil
  2110. }
  2111. var coderSint64NoZero = pointerCoderFuncs{
  2112. size: sizeSint64NoZero,
  2113. marshal: appendSint64NoZero,
  2114. unmarshal: consumeSint64,
  2115. merge: mergeInt64NoZero,
  2116. }
  2117. // sizeSint64Ptr returns the size of wire encoding a *int64 pointer as a Sint64.
  2118. // It panics if the pointer is nil.
  2119. func sizeSint64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2120. v := **p.Int64Ptr()
  2121. return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v))
  2122. }
  2123. // appendSint64Ptr wire encodes a *int64 pointer as a Sint64.
  2124. // It panics if the pointer is nil.
  2125. func appendSint64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2126. v := **p.Int64Ptr()
  2127. b = protowire.AppendVarint(b, f.wiretag)
  2128. b = protowire.AppendVarint(b, protowire.EncodeZigZag(v))
  2129. return b, nil
  2130. }
  2131. // consumeSint64Ptr wire decodes a *int64 pointer as a Sint64.
  2132. func consumeSint64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  2133. if wtyp != protowire.VarintType {
  2134. return out, errUnknown
  2135. }
  2136. var v uint64
  2137. var n int
  2138. if len(b) >= 1 && b[0] < 0x80 {
  2139. v = uint64(b[0])
  2140. n = 1
  2141. } else if len(b) >= 2 && b[1] < 128 {
  2142. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2143. n = 2
  2144. } else {
  2145. v, n = protowire.ConsumeVarint(b)
  2146. }
  2147. if n < 0 {
  2148. return out, errDecode
  2149. }
  2150. vp := p.Int64Ptr()
  2151. if *vp == nil {
  2152. *vp = new(int64)
  2153. }
  2154. **vp = protowire.DecodeZigZag(v)
  2155. out.n = n
  2156. return out, nil
  2157. }
  2158. var coderSint64Ptr = pointerCoderFuncs{
  2159. size: sizeSint64Ptr,
  2160. marshal: appendSint64Ptr,
  2161. unmarshal: consumeSint64Ptr,
  2162. merge: mergeInt64Ptr,
  2163. }
  2164. // sizeSint64Slice returns the size of wire encoding a []int64 pointer as a repeated Sint64.
  2165. func sizeSint64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2166. s := *p.Int64Slice()
  2167. for _, v := range s {
  2168. size += f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v))
  2169. }
  2170. return size
  2171. }
  2172. // appendSint64Slice encodes a []int64 pointer as a repeated Sint64.
  2173. func appendSint64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2174. s := *p.Int64Slice()
  2175. for _, v := range s {
  2176. b = protowire.AppendVarint(b, f.wiretag)
  2177. b = protowire.AppendVarint(b, protowire.EncodeZigZag(v))
  2178. }
  2179. return b, nil
  2180. }
  2181. // consumeSint64Slice wire decodes a []int64 pointer as a repeated Sint64.
  2182. func consumeSint64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  2183. sp := p.Int64Slice()
  2184. if wtyp == protowire.BytesType {
  2185. s := *sp
  2186. b, n := protowire.ConsumeBytes(b)
  2187. if n < 0 {
  2188. return out, errDecode
  2189. }
  2190. for len(b) > 0 {
  2191. var v uint64
  2192. var n int
  2193. if len(b) >= 1 && b[0] < 0x80 {
  2194. v = uint64(b[0])
  2195. n = 1
  2196. } else if len(b) >= 2 && b[1] < 128 {
  2197. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2198. n = 2
  2199. } else {
  2200. v, n = protowire.ConsumeVarint(b)
  2201. }
  2202. if n < 0 {
  2203. return out, errDecode
  2204. }
  2205. s = append(s, protowire.DecodeZigZag(v))
  2206. b = b[n:]
  2207. }
  2208. *sp = s
  2209. out.n = n
  2210. return out, nil
  2211. }
  2212. if wtyp != protowire.VarintType {
  2213. return out, errUnknown
  2214. }
  2215. var v uint64
  2216. var n int
  2217. if len(b) >= 1 && b[0] < 0x80 {
  2218. v = uint64(b[0])
  2219. n = 1
  2220. } else if len(b) >= 2 && b[1] < 128 {
  2221. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2222. n = 2
  2223. } else {
  2224. v, n = protowire.ConsumeVarint(b)
  2225. }
  2226. if n < 0 {
  2227. return out, errDecode
  2228. }
  2229. *sp = append(*sp, protowire.DecodeZigZag(v))
  2230. out.n = n
  2231. return out, nil
  2232. }
  2233. var coderSint64Slice = pointerCoderFuncs{
  2234. size: sizeSint64Slice,
  2235. marshal: appendSint64Slice,
  2236. unmarshal: consumeSint64Slice,
  2237. merge: mergeInt64Slice,
  2238. }
  2239. // sizeSint64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sint64.
  2240. func sizeSint64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2241. s := *p.Int64Slice()
  2242. if len(s) == 0 {
  2243. return 0
  2244. }
  2245. n := 0
  2246. for _, v := range s {
  2247. n += protowire.SizeVarint(protowire.EncodeZigZag(v))
  2248. }
  2249. return f.tagsize + protowire.SizeBytes(n)
  2250. }
  2251. // appendSint64PackedSlice encodes a []int64 pointer as a packed repeated Sint64.
  2252. func appendSint64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2253. s := *p.Int64Slice()
  2254. if len(s) == 0 {
  2255. return b, nil
  2256. }
  2257. b = protowire.AppendVarint(b, f.wiretag)
  2258. n := 0
  2259. for _, v := range s {
  2260. n += protowire.SizeVarint(protowire.EncodeZigZag(v))
  2261. }
  2262. b = protowire.AppendVarint(b, uint64(n))
  2263. for _, v := range s {
  2264. b = protowire.AppendVarint(b, protowire.EncodeZigZag(v))
  2265. }
  2266. return b, nil
  2267. }
  2268. var coderSint64PackedSlice = pointerCoderFuncs{
  2269. size: sizeSint64PackedSlice,
  2270. marshal: appendSint64PackedSlice,
  2271. unmarshal: consumeSint64Slice,
  2272. merge: mergeInt64Slice,
  2273. }
  2274. // sizeSint64Value returns the size of wire encoding a int64 value as a Sint64.
  2275. func sizeSint64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  2276. return tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v.Int()))
  2277. }
  2278. // appendSint64Value encodes a int64 value as a Sint64.
  2279. func appendSint64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  2280. b = protowire.AppendVarint(b, wiretag)
  2281. b = protowire.AppendVarint(b, protowire.EncodeZigZag(v.Int()))
  2282. return b, nil
  2283. }
  2284. // consumeSint64Value decodes a int64 value as a Sint64.
  2285. func consumeSint64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  2286. if wtyp != protowire.VarintType {
  2287. return protoreflect.Value{}, out, errUnknown
  2288. }
  2289. var v uint64
  2290. var n int
  2291. if len(b) >= 1 && b[0] < 0x80 {
  2292. v = uint64(b[0])
  2293. n = 1
  2294. } else if len(b) >= 2 && b[1] < 128 {
  2295. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2296. n = 2
  2297. } else {
  2298. v, n = protowire.ConsumeVarint(b)
  2299. }
  2300. if n < 0 {
  2301. return protoreflect.Value{}, out, errDecode
  2302. }
  2303. out.n = n
  2304. return protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)), out, nil
  2305. }
  2306. var coderSint64Value = valueCoderFuncs{
  2307. size: sizeSint64Value,
  2308. marshal: appendSint64Value,
  2309. unmarshal: consumeSint64Value,
  2310. merge: mergeScalarValue,
  2311. }
  2312. // sizeSint64SliceValue returns the size of wire encoding a []int64 value as a repeated Sint64.
  2313. func sizeSint64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  2314. list := listv.List()
  2315. for i, llen := 0, list.Len(); i < llen; i++ {
  2316. v := list.Get(i)
  2317. size += tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v.Int()))
  2318. }
  2319. return size
  2320. }
  2321. // appendSint64SliceValue encodes a []int64 value as a repeated Sint64.
  2322. func appendSint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  2323. list := listv.List()
  2324. for i, llen := 0, list.Len(); i < llen; i++ {
  2325. v := list.Get(i)
  2326. b = protowire.AppendVarint(b, wiretag)
  2327. b = protowire.AppendVarint(b, protowire.EncodeZigZag(v.Int()))
  2328. }
  2329. return b, nil
  2330. }
  2331. // consumeSint64SliceValue wire decodes a []int64 value as a repeated Sint64.
  2332. func consumeSint64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  2333. list := listv.List()
  2334. if wtyp == protowire.BytesType {
  2335. b, n := protowire.ConsumeBytes(b)
  2336. if n < 0 {
  2337. return protoreflect.Value{}, out, errDecode
  2338. }
  2339. for len(b) > 0 {
  2340. var v uint64
  2341. var n int
  2342. if len(b) >= 1 && b[0] < 0x80 {
  2343. v = uint64(b[0])
  2344. n = 1
  2345. } else if len(b) >= 2 && b[1] < 128 {
  2346. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2347. n = 2
  2348. } else {
  2349. v, n = protowire.ConsumeVarint(b)
  2350. }
  2351. if n < 0 {
  2352. return protoreflect.Value{}, out, errDecode
  2353. }
  2354. list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)))
  2355. b = b[n:]
  2356. }
  2357. out.n = n
  2358. return listv, out, nil
  2359. }
  2360. if wtyp != protowire.VarintType {
  2361. return protoreflect.Value{}, out, errUnknown
  2362. }
  2363. var v uint64
  2364. var n int
  2365. if len(b) >= 1 && b[0] < 0x80 {
  2366. v = uint64(b[0])
  2367. n = 1
  2368. } else if len(b) >= 2 && b[1] < 128 {
  2369. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2370. n = 2
  2371. } else {
  2372. v, n = protowire.ConsumeVarint(b)
  2373. }
  2374. if n < 0 {
  2375. return protoreflect.Value{}, out, errDecode
  2376. }
  2377. list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)))
  2378. out.n = n
  2379. return listv, out, nil
  2380. }
  2381. var coderSint64SliceValue = valueCoderFuncs{
  2382. size: sizeSint64SliceValue,
  2383. marshal: appendSint64SliceValue,
  2384. unmarshal: consumeSint64SliceValue,
  2385. merge: mergeListValue,
  2386. }
  2387. // sizeSint64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sint64.
  2388. func sizeSint64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  2389. list := listv.List()
  2390. llen := list.Len()
  2391. if llen == 0 {
  2392. return 0
  2393. }
  2394. n := 0
  2395. for i, llen := 0, llen; i < llen; i++ {
  2396. v := list.Get(i)
  2397. n += protowire.SizeVarint(protowire.EncodeZigZag(v.Int()))
  2398. }
  2399. return tagsize + protowire.SizeBytes(n)
  2400. }
  2401. // appendSint64PackedSliceValue encodes a []int64 value as a packed repeated Sint64.
  2402. func appendSint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  2403. list := listv.List()
  2404. llen := list.Len()
  2405. if llen == 0 {
  2406. return b, nil
  2407. }
  2408. b = protowire.AppendVarint(b, wiretag)
  2409. n := 0
  2410. for i := 0; i < llen; i++ {
  2411. v := list.Get(i)
  2412. n += protowire.SizeVarint(protowire.EncodeZigZag(v.Int()))
  2413. }
  2414. b = protowire.AppendVarint(b, uint64(n))
  2415. for i := 0; i < llen; i++ {
  2416. v := list.Get(i)
  2417. b = protowire.AppendVarint(b, protowire.EncodeZigZag(v.Int()))
  2418. }
  2419. return b, nil
  2420. }
  2421. var coderSint64PackedSliceValue = valueCoderFuncs{
  2422. size: sizeSint64PackedSliceValue,
  2423. marshal: appendSint64PackedSliceValue,
  2424. unmarshal: consumeSint64SliceValue,
  2425. merge: mergeListValue,
  2426. }
  2427. // sizeUint64 returns the size of wire encoding a uint64 pointer as a Uint64.
  2428. func sizeUint64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2429. v := *p.Uint64()
  2430. return f.tagsize + protowire.SizeVarint(v)
  2431. }
  2432. // appendUint64 wire encodes a uint64 pointer as a Uint64.
  2433. func appendUint64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2434. v := *p.Uint64()
  2435. b = protowire.AppendVarint(b, f.wiretag)
  2436. b = protowire.AppendVarint(b, v)
  2437. return b, nil
  2438. }
  2439. // consumeUint64 wire decodes a uint64 pointer as a Uint64.
  2440. func consumeUint64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  2441. if wtyp != protowire.VarintType {
  2442. return out, errUnknown
  2443. }
  2444. var v uint64
  2445. var n int
  2446. if len(b) >= 1 && b[0] < 0x80 {
  2447. v = uint64(b[0])
  2448. n = 1
  2449. } else if len(b) >= 2 && b[1] < 128 {
  2450. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2451. n = 2
  2452. } else {
  2453. v, n = protowire.ConsumeVarint(b)
  2454. }
  2455. if n < 0 {
  2456. return out, errDecode
  2457. }
  2458. *p.Uint64() = v
  2459. out.n = n
  2460. return out, nil
  2461. }
  2462. var coderUint64 = pointerCoderFuncs{
  2463. size: sizeUint64,
  2464. marshal: appendUint64,
  2465. unmarshal: consumeUint64,
  2466. merge: mergeUint64,
  2467. }
  2468. // sizeUint64NoZero returns the size of wire encoding a uint64 pointer as a Uint64.
  2469. // The zero value is not encoded.
  2470. func sizeUint64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2471. v := *p.Uint64()
  2472. if v == 0 {
  2473. return 0
  2474. }
  2475. return f.tagsize + protowire.SizeVarint(v)
  2476. }
  2477. // appendUint64NoZero wire encodes a uint64 pointer as a Uint64.
  2478. // The zero value is not encoded.
  2479. func appendUint64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2480. v := *p.Uint64()
  2481. if v == 0 {
  2482. return b, nil
  2483. }
  2484. b = protowire.AppendVarint(b, f.wiretag)
  2485. b = protowire.AppendVarint(b, v)
  2486. return b, nil
  2487. }
  2488. var coderUint64NoZero = pointerCoderFuncs{
  2489. size: sizeUint64NoZero,
  2490. marshal: appendUint64NoZero,
  2491. unmarshal: consumeUint64,
  2492. merge: mergeUint64NoZero,
  2493. }
  2494. // sizeUint64Ptr returns the size of wire encoding a *uint64 pointer as a Uint64.
  2495. // It panics if the pointer is nil.
  2496. func sizeUint64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2497. v := **p.Uint64Ptr()
  2498. return f.tagsize + protowire.SizeVarint(v)
  2499. }
  2500. // appendUint64Ptr wire encodes a *uint64 pointer as a Uint64.
  2501. // It panics if the pointer is nil.
  2502. func appendUint64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2503. v := **p.Uint64Ptr()
  2504. b = protowire.AppendVarint(b, f.wiretag)
  2505. b = protowire.AppendVarint(b, v)
  2506. return b, nil
  2507. }
  2508. // consumeUint64Ptr wire decodes a *uint64 pointer as a Uint64.
  2509. func consumeUint64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  2510. if wtyp != protowire.VarintType {
  2511. return out, errUnknown
  2512. }
  2513. var v uint64
  2514. var n int
  2515. if len(b) >= 1 && b[0] < 0x80 {
  2516. v = uint64(b[0])
  2517. n = 1
  2518. } else if len(b) >= 2 && b[1] < 128 {
  2519. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2520. n = 2
  2521. } else {
  2522. v, n = protowire.ConsumeVarint(b)
  2523. }
  2524. if n < 0 {
  2525. return out, errDecode
  2526. }
  2527. vp := p.Uint64Ptr()
  2528. if *vp == nil {
  2529. *vp = new(uint64)
  2530. }
  2531. **vp = v
  2532. out.n = n
  2533. return out, nil
  2534. }
  2535. var coderUint64Ptr = pointerCoderFuncs{
  2536. size: sizeUint64Ptr,
  2537. marshal: appendUint64Ptr,
  2538. unmarshal: consumeUint64Ptr,
  2539. merge: mergeUint64Ptr,
  2540. }
  2541. // sizeUint64Slice returns the size of wire encoding a []uint64 pointer as a repeated Uint64.
  2542. func sizeUint64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2543. s := *p.Uint64Slice()
  2544. for _, v := range s {
  2545. size += f.tagsize + protowire.SizeVarint(v)
  2546. }
  2547. return size
  2548. }
  2549. // appendUint64Slice encodes a []uint64 pointer as a repeated Uint64.
  2550. func appendUint64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2551. s := *p.Uint64Slice()
  2552. for _, v := range s {
  2553. b = protowire.AppendVarint(b, f.wiretag)
  2554. b = protowire.AppendVarint(b, v)
  2555. }
  2556. return b, nil
  2557. }
  2558. // consumeUint64Slice wire decodes a []uint64 pointer as a repeated Uint64.
  2559. func consumeUint64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  2560. sp := p.Uint64Slice()
  2561. if wtyp == protowire.BytesType {
  2562. s := *sp
  2563. b, n := protowire.ConsumeBytes(b)
  2564. if n < 0 {
  2565. return out, errDecode
  2566. }
  2567. for len(b) > 0 {
  2568. var v uint64
  2569. var n int
  2570. if len(b) >= 1 && b[0] < 0x80 {
  2571. v = uint64(b[0])
  2572. n = 1
  2573. } else if len(b) >= 2 && b[1] < 128 {
  2574. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2575. n = 2
  2576. } else {
  2577. v, n = protowire.ConsumeVarint(b)
  2578. }
  2579. if n < 0 {
  2580. return out, errDecode
  2581. }
  2582. s = append(s, v)
  2583. b = b[n:]
  2584. }
  2585. *sp = s
  2586. out.n = n
  2587. return out, nil
  2588. }
  2589. if wtyp != protowire.VarintType {
  2590. return out, errUnknown
  2591. }
  2592. var v uint64
  2593. var n int
  2594. if len(b) >= 1 && b[0] < 0x80 {
  2595. v = uint64(b[0])
  2596. n = 1
  2597. } else if len(b) >= 2 && b[1] < 128 {
  2598. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2599. n = 2
  2600. } else {
  2601. v, n = protowire.ConsumeVarint(b)
  2602. }
  2603. if n < 0 {
  2604. return out, errDecode
  2605. }
  2606. *sp = append(*sp, v)
  2607. out.n = n
  2608. return out, nil
  2609. }
  2610. var coderUint64Slice = pointerCoderFuncs{
  2611. size: sizeUint64Slice,
  2612. marshal: appendUint64Slice,
  2613. unmarshal: consumeUint64Slice,
  2614. merge: mergeUint64Slice,
  2615. }
  2616. // sizeUint64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Uint64.
  2617. func sizeUint64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2618. s := *p.Uint64Slice()
  2619. if len(s) == 0 {
  2620. return 0
  2621. }
  2622. n := 0
  2623. for _, v := range s {
  2624. n += protowire.SizeVarint(v)
  2625. }
  2626. return f.tagsize + protowire.SizeBytes(n)
  2627. }
  2628. // appendUint64PackedSlice encodes a []uint64 pointer as a packed repeated Uint64.
  2629. func appendUint64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2630. s := *p.Uint64Slice()
  2631. if len(s) == 0 {
  2632. return b, nil
  2633. }
  2634. b = protowire.AppendVarint(b, f.wiretag)
  2635. n := 0
  2636. for _, v := range s {
  2637. n += protowire.SizeVarint(v)
  2638. }
  2639. b = protowire.AppendVarint(b, uint64(n))
  2640. for _, v := range s {
  2641. b = protowire.AppendVarint(b, v)
  2642. }
  2643. return b, nil
  2644. }
  2645. var coderUint64PackedSlice = pointerCoderFuncs{
  2646. size: sizeUint64PackedSlice,
  2647. marshal: appendUint64PackedSlice,
  2648. unmarshal: consumeUint64Slice,
  2649. merge: mergeUint64Slice,
  2650. }
  2651. // sizeUint64Value returns the size of wire encoding a uint64 value as a Uint64.
  2652. func sizeUint64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  2653. return tagsize + protowire.SizeVarint(v.Uint())
  2654. }
  2655. // appendUint64Value encodes a uint64 value as a Uint64.
  2656. func appendUint64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  2657. b = protowire.AppendVarint(b, wiretag)
  2658. b = protowire.AppendVarint(b, v.Uint())
  2659. return b, nil
  2660. }
  2661. // consumeUint64Value decodes a uint64 value as a Uint64.
  2662. func consumeUint64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  2663. if wtyp != protowire.VarintType {
  2664. return protoreflect.Value{}, out, errUnknown
  2665. }
  2666. var v uint64
  2667. var n int
  2668. if len(b) >= 1 && b[0] < 0x80 {
  2669. v = uint64(b[0])
  2670. n = 1
  2671. } else if len(b) >= 2 && b[1] < 128 {
  2672. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2673. n = 2
  2674. } else {
  2675. v, n = protowire.ConsumeVarint(b)
  2676. }
  2677. if n < 0 {
  2678. return protoreflect.Value{}, out, errDecode
  2679. }
  2680. out.n = n
  2681. return protoreflect.ValueOfUint64(v), out, nil
  2682. }
  2683. var coderUint64Value = valueCoderFuncs{
  2684. size: sizeUint64Value,
  2685. marshal: appendUint64Value,
  2686. unmarshal: consumeUint64Value,
  2687. merge: mergeScalarValue,
  2688. }
  2689. // sizeUint64SliceValue returns the size of wire encoding a []uint64 value as a repeated Uint64.
  2690. func sizeUint64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  2691. list := listv.List()
  2692. for i, llen := 0, list.Len(); i < llen; i++ {
  2693. v := list.Get(i)
  2694. size += tagsize + protowire.SizeVarint(v.Uint())
  2695. }
  2696. return size
  2697. }
  2698. // appendUint64SliceValue encodes a []uint64 value as a repeated Uint64.
  2699. func appendUint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  2700. list := listv.List()
  2701. for i, llen := 0, list.Len(); i < llen; i++ {
  2702. v := list.Get(i)
  2703. b = protowire.AppendVarint(b, wiretag)
  2704. b = protowire.AppendVarint(b, v.Uint())
  2705. }
  2706. return b, nil
  2707. }
  2708. // consumeUint64SliceValue wire decodes a []uint64 value as a repeated Uint64.
  2709. func consumeUint64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  2710. list := listv.List()
  2711. if wtyp == protowire.BytesType {
  2712. b, n := protowire.ConsumeBytes(b)
  2713. if n < 0 {
  2714. return protoreflect.Value{}, out, errDecode
  2715. }
  2716. for len(b) > 0 {
  2717. var v uint64
  2718. var n int
  2719. if len(b) >= 1 && b[0] < 0x80 {
  2720. v = uint64(b[0])
  2721. n = 1
  2722. } else if len(b) >= 2 && b[1] < 128 {
  2723. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2724. n = 2
  2725. } else {
  2726. v, n = protowire.ConsumeVarint(b)
  2727. }
  2728. if n < 0 {
  2729. return protoreflect.Value{}, out, errDecode
  2730. }
  2731. list.Append(protoreflect.ValueOfUint64(v))
  2732. b = b[n:]
  2733. }
  2734. out.n = n
  2735. return listv, out, nil
  2736. }
  2737. if wtyp != protowire.VarintType {
  2738. return protoreflect.Value{}, out, errUnknown
  2739. }
  2740. var v uint64
  2741. var n int
  2742. if len(b) >= 1 && b[0] < 0x80 {
  2743. v = uint64(b[0])
  2744. n = 1
  2745. } else if len(b) >= 2 && b[1] < 128 {
  2746. v = uint64(b[0]&0x7f) + uint64(b[1])<<7
  2747. n = 2
  2748. } else {
  2749. v, n = protowire.ConsumeVarint(b)
  2750. }
  2751. if n < 0 {
  2752. return protoreflect.Value{}, out, errDecode
  2753. }
  2754. list.Append(protoreflect.ValueOfUint64(v))
  2755. out.n = n
  2756. return listv, out, nil
  2757. }
  2758. var coderUint64SliceValue = valueCoderFuncs{
  2759. size: sizeUint64SliceValue,
  2760. marshal: appendUint64SliceValue,
  2761. unmarshal: consumeUint64SliceValue,
  2762. merge: mergeListValue,
  2763. }
  2764. // sizeUint64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Uint64.
  2765. func sizeUint64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  2766. list := listv.List()
  2767. llen := list.Len()
  2768. if llen == 0 {
  2769. return 0
  2770. }
  2771. n := 0
  2772. for i, llen := 0, llen; i < llen; i++ {
  2773. v := list.Get(i)
  2774. n += protowire.SizeVarint(v.Uint())
  2775. }
  2776. return tagsize + protowire.SizeBytes(n)
  2777. }
  2778. // appendUint64PackedSliceValue encodes a []uint64 value as a packed repeated Uint64.
  2779. func appendUint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  2780. list := listv.List()
  2781. llen := list.Len()
  2782. if llen == 0 {
  2783. return b, nil
  2784. }
  2785. b = protowire.AppendVarint(b, wiretag)
  2786. n := 0
  2787. for i := 0; i < llen; i++ {
  2788. v := list.Get(i)
  2789. n += protowire.SizeVarint(v.Uint())
  2790. }
  2791. b = protowire.AppendVarint(b, uint64(n))
  2792. for i := 0; i < llen; i++ {
  2793. v := list.Get(i)
  2794. b = protowire.AppendVarint(b, v.Uint())
  2795. }
  2796. return b, nil
  2797. }
  2798. var coderUint64PackedSliceValue = valueCoderFuncs{
  2799. size: sizeUint64PackedSliceValue,
  2800. marshal: appendUint64PackedSliceValue,
  2801. unmarshal: consumeUint64SliceValue,
  2802. merge: mergeListValue,
  2803. }
  2804. // sizeSfixed32 returns the size of wire encoding a int32 pointer as a Sfixed32.
  2805. func sizeSfixed32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2806. return f.tagsize + protowire.SizeFixed32()
  2807. }
  2808. // appendSfixed32 wire encodes a int32 pointer as a Sfixed32.
  2809. func appendSfixed32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2810. v := *p.Int32()
  2811. b = protowire.AppendVarint(b, f.wiretag)
  2812. b = protowire.AppendFixed32(b, uint32(v))
  2813. return b, nil
  2814. }
  2815. // consumeSfixed32 wire decodes a int32 pointer as a Sfixed32.
  2816. func consumeSfixed32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  2817. if wtyp != protowire.Fixed32Type {
  2818. return out, errUnknown
  2819. }
  2820. v, n := protowire.ConsumeFixed32(b)
  2821. if n < 0 {
  2822. return out, errDecode
  2823. }
  2824. *p.Int32() = int32(v)
  2825. out.n = n
  2826. return out, nil
  2827. }
  2828. var coderSfixed32 = pointerCoderFuncs{
  2829. size: sizeSfixed32,
  2830. marshal: appendSfixed32,
  2831. unmarshal: consumeSfixed32,
  2832. merge: mergeInt32,
  2833. }
  2834. // sizeSfixed32NoZero returns the size of wire encoding a int32 pointer as a Sfixed32.
  2835. // The zero value is not encoded.
  2836. func sizeSfixed32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2837. v := *p.Int32()
  2838. if v == 0 {
  2839. return 0
  2840. }
  2841. return f.tagsize + protowire.SizeFixed32()
  2842. }
  2843. // appendSfixed32NoZero wire encodes a int32 pointer as a Sfixed32.
  2844. // The zero value is not encoded.
  2845. func appendSfixed32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2846. v := *p.Int32()
  2847. if v == 0 {
  2848. return b, nil
  2849. }
  2850. b = protowire.AppendVarint(b, f.wiretag)
  2851. b = protowire.AppendFixed32(b, uint32(v))
  2852. return b, nil
  2853. }
  2854. var coderSfixed32NoZero = pointerCoderFuncs{
  2855. size: sizeSfixed32NoZero,
  2856. marshal: appendSfixed32NoZero,
  2857. unmarshal: consumeSfixed32,
  2858. merge: mergeInt32NoZero,
  2859. }
  2860. // sizeSfixed32Ptr returns the size of wire encoding a *int32 pointer as a Sfixed32.
  2861. // It panics if the pointer is nil.
  2862. func sizeSfixed32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2863. return f.tagsize + protowire.SizeFixed32()
  2864. }
  2865. // appendSfixed32Ptr wire encodes a *int32 pointer as a Sfixed32.
  2866. // It panics if the pointer is nil.
  2867. func appendSfixed32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2868. v := **p.Int32Ptr()
  2869. b = protowire.AppendVarint(b, f.wiretag)
  2870. b = protowire.AppendFixed32(b, uint32(v))
  2871. return b, nil
  2872. }
  2873. // consumeSfixed32Ptr wire decodes a *int32 pointer as a Sfixed32.
  2874. func consumeSfixed32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  2875. if wtyp != protowire.Fixed32Type {
  2876. return out, errUnknown
  2877. }
  2878. v, n := protowire.ConsumeFixed32(b)
  2879. if n < 0 {
  2880. return out, errDecode
  2881. }
  2882. vp := p.Int32Ptr()
  2883. if *vp == nil {
  2884. *vp = new(int32)
  2885. }
  2886. **vp = int32(v)
  2887. out.n = n
  2888. return out, nil
  2889. }
  2890. var coderSfixed32Ptr = pointerCoderFuncs{
  2891. size: sizeSfixed32Ptr,
  2892. marshal: appendSfixed32Ptr,
  2893. unmarshal: consumeSfixed32Ptr,
  2894. merge: mergeInt32Ptr,
  2895. }
  2896. // sizeSfixed32Slice returns the size of wire encoding a []int32 pointer as a repeated Sfixed32.
  2897. func sizeSfixed32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2898. s := *p.Int32Slice()
  2899. size = len(s) * (f.tagsize + protowire.SizeFixed32())
  2900. return size
  2901. }
  2902. // appendSfixed32Slice encodes a []int32 pointer as a repeated Sfixed32.
  2903. func appendSfixed32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2904. s := *p.Int32Slice()
  2905. for _, v := range s {
  2906. b = protowire.AppendVarint(b, f.wiretag)
  2907. b = protowire.AppendFixed32(b, uint32(v))
  2908. }
  2909. return b, nil
  2910. }
  2911. // consumeSfixed32Slice wire decodes a []int32 pointer as a repeated Sfixed32.
  2912. func consumeSfixed32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  2913. sp := p.Int32Slice()
  2914. if wtyp == protowire.BytesType {
  2915. s := *sp
  2916. b, n := protowire.ConsumeBytes(b)
  2917. if n < 0 {
  2918. return out, errDecode
  2919. }
  2920. for len(b) > 0 {
  2921. v, n := protowire.ConsumeFixed32(b)
  2922. if n < 0 {
  2923. return out, errDecode
  2924. }
  2925. s = append(s, int32(v))
  2926. b = b[n:]
  2927. }
  2928. *sp = s
  2929. out.n = n
  2930. return out, nil
  2931. }
  2932. if wtyp != protowire.Fixed32Type {
  2933. return out, errUnknown
  2934. }
  2935. v, n := protowire.ConsumeFixed32(b)
  2936. if n < 0 {
  2937. return out, errDecode
  2938. }
  2939. *sp = append(*sp, int32(v))
  2940. out.n = n
  2941. return out, nil
  2942. }
  2943. var coderSfixed32Slice = pointerCoderFuncs{
  2944. size: sizeSfixed32Slice,
  2945. marshal: appendSfixed32Slice,
  2946. unmarshal: consumeSfixed32Slice,
  2947. merge: mergeInt32Slice,
  2948. }
  2949. // sizeSfixed32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sfixed32.
  2950. func sizeSfixed32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  2951. s := *p.Int32Slice()
  2952. if len(s) == 0 {
  2953. return 0
  2954. }
  2955. n := len(s) * protowire.SizeFixed32()
  2956. return f.tagsize + protowire.SizeBytes(n)
  2957. }
  2958. // appendSfixed32PackedSlice encodes a []int32 pointer as a packed repeated Sfixed32.
  2959. func appendSfixed32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  2960. s := *p.Int32Slice()
  2961. if len(s) == 0 {
  2962. return b, nil
  2963. }
  2964. b = protowire.AppendVarint(b, f.wiretag)
  2965. n := len(s) * protowire.SizeFixed32()
  2966. b = protowire.AppendVarint(b, uint64(n))
  2967. for _, v := range s {
  2968. b = protowire.AppendFixed32(b, uint32(v))
  2969. }
  2970. return b, nil
  2971. }
  2972. var coderSfixed32PackedSlice = pointerCoderFuncs{
  2973. size: sizeSfixed32PackedSlice,
  2974. marshal: appendSfixed32PackedSlice,
  2975. unmarshal: consumeSfixed32Slice,
  2976. merge: mergeInt32Slice,
  2977. }
  2978. // sizeSfixed32Value returns the size of wire encoding a int32 value as a Sfixed32.
  2979. func sizeSfixed32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  2980. return tagsize + protowire.SizeFixed32()
  2981. }
  2982. // appendSfixed32Value encodes a int32 value as a Sfixed32.
  2983. func appendSfixed32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  2984. b = protowire.AppendVarint(b, wiretag)
  2985. b = protowire.AppendFixed32(b, uint32(v.Int()))
  2986. return b, nil
  2987. }
  2988. // consumeSfixed32Value decodes a int32 value as a Sfixed32.
  2989. func consumeSfixed32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  2990. if wtyp != protowire.Fixed32Type {
  2991. return protoreflect.Value{}, out, errUnknown
  2992. }
  2993. v, n := protowire.ConsumeFixed32(b)
  2994. if n < 0 {
  2995. return protoreflect.Value{}, out, errDecode
  2996. }
  2997. out.n = n
  2998. return protoreflect.ValueOfInt32(int32(v)), out, nil
  2999. }
  3000. var coderSfixed32Value = valueCoderFuncs{
  3001. size: sizeSfixed32Value,
  3002. marshal: appendSfixed32Value,
  3003. unmarshal: consumeSfixed32Value,
  3004. merge: mergeScalarValue,
  3005. }
  3006. // sizeSfixed32SliceValue returns the size of wire encoding a []int32 value as a repeated Sfixed32.
  3007. func sizeSfixed32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  3008. list := listv.List()
  3009. size = list.Len() * (tagsize + protowire.SizeFixed32())
  3010. return size
  3011. }
  3012. // appendSfixed32SliceValue encodes a []int32 value as a repeated Sfixed32.
  3013. func appendSfixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3014. list := listv.List()
  3015. for i, llen := 0, list.Len(); i < llen; i++ {
  3016. v := list.Get(i)
  3017. b = protowire.AppendVarint(b, wiretag)
  3018. b = protowire.AppendFixed32(b, uint32(v.Int()))
  3019. }
  3020. return b, nil
  3021. }
  3022. // consumeSfixed32SliceValue wire decodes a []int32 value as a repeated Sfixed32.
  3023. func consumeSfixed32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  3024. list := listv.List()
  3025. if wtyp == protowire.BytesType {
  3026. b, n := protowire.ConsumeBytes(b)
  3027. if n < 0 {
  3028. return protoreflect.Value{}, out, errDecode
  3029. }
  3030. for len(b) > 0 {
  3031. v, n := protowire.ConsumeFixed32(b)
  3032. if n < 0 {
  3033. return protoreflect.Value{}, out, errDecode
  3034. }
  3035. list.Append(protoreflect.ValueOfInt32(int32(v)))
  3036. b = b[n:]
  3037. }
  3038. out.n = n
  3039. return listv, out, nil
  3040. }
  3041. if wtyp != protowire.Fixed32Type {
  3042. return protoreflect.Value{}, out, errUnknown
  3043. }
  3044. v, n := protowire.ConsumeFixed32(b)
  3045. if n < 0 {
  3046. return protoreflect.Value{}, out, errDecode
  3047. }
  3048. list.Append(protoreflect.ValueOfInt32(int32(v)))
  3049. out.n = n
  3050. return listv, out, nil
  3051. }
  3052. var coderSfixed32SliceValue = valueCoderFuncs{
  3053. size: sizeSfixed32SliceValue,
  3054. marshal: appendSfixed32SliceValue,
  3055. unmarshal: consumeSfixed32SliceValue,
  3056. merge: mergeListValue,
  3057. }
  3058. // sizeSfixed32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sfixed32.
  3059. func sizeSfixed32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  3060. list := listv.List()
  3061. llen := list.Len()
  3062. if llen == 0 {
  3063. return 0
  3064. }
  3065. n := llen * protowire.SizeFixed32()
  3066. return tagsize + protowire.SizeBytes(n)
  3067. }
  3068. // appendSfixed32PackedSliceValue encodes a []int32 value as a packed repeated Sfixed32.
  3069. func appendSfixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3070. list := listv.List()
  3071. llen := list.Len()
  3072. if llen == 0 {
  3073. return b, nil
  3074. }
  3075. b = protowire.AppendVarint(b, wiretag)
  3076. n := llen * protowire.SizeFixed32()
  3077. b = protowire.AppendVarint(b, uint64(n))
  3078. for i := 0; i < llen; i++ {
  3079. v := list.Get(i)
  3080. b = protowire.AppendFixed32(b, uint32(v.Int()))
  3081. }
  3082. return b, nil
  3083. }
  3084. var coderSfixed32PackedSliceValue = valueCoderFuncs{
  3085. size: sizeSfixed32PackedSliceValue,
  3086. marshal: appendSfixed32PackedSliceValue,
  3087. unmarshal: consumeSfixed32SliceValue,
  3088. merge: mergeListValue,
  3089. }
  3090. // sizeFixed32 returns the size of wire encoding a uint32 pointer as a Fixed32.
  3091. func sizeFixed32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3092. return f.tagsize + protowire.SizeFixed32()
  3093. }
  3094. // appendFixed32 wire encodes a uint32 pointer as a Fixed32.
  3095. func appendFixed32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3096. v := *p.Uint32()
  3097. b = protowire.AppendVarint(b, f.wiretag)
  3098. b = protowire.AppendFixed32(b, v)
  3099. return b, nil
  3100. }
  3101. // consumeFixed32 wire decodes a uint32 pointer as a Fixed32.
  3102. func consumeFixed32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  3103. if wtyp != protowire.Fixed32Type {
  3104. return out, errUnknown
  3105. }
  3106. v, n := protowire.ConsumeFixed32(b)
  3107. if n < 0 {
  3108. return out, errDecode
  3109. }
  3110. *p.Uint32() = v
  3111. out.n = n
  3112. return out, nil
  3113. }
  3114. var coderFixed32 = pointerCoderFuncs{
  3115. size: sizeFixed32,
  3116. marshal: appendFixed32,
  3117. unmarshal: consumeFixed32,
  3118. merge: mergeUint32,
  3119. }
  3120. // sizeFixed32NoZero returns the size of wire encoding a uint32 pointer as a Fixed32.
  3121. // The zero value is not encoded.
  3122. func sizeFixed32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3123. v := *p.Uint32()
  3124. if v == 0 {
  3125. return 0
  3126. }
  3127. return f.tagsize + protowire.SizeFixed32()
  3128. }
  3129. // appendFixed32NoZero wire encodes a uint32 pointer as a Fixed32.
  3130. // The zero value is not encoded.
  3131. func appendFixed32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3132. v := *p.Uint32()
  3133. if v == 0 {
  3134. return b, nil
  3135. }
  3136. b = protowire.AppendVarint(b, f.wiretag)
  3137. b = protowire.AppendFixed32(b, v)
  3138. return b, nil
  3139. }
  3140. var coderFixed32NoZero = pointerCoderFuncs{
  3141. size: sizeFixed32NoZero,
  3142. marshal: appendFixed32NoZero,
  3143. unmarshal: consumeFixed32,
  3144. merge: mergeUint32NoZero,
  3145. }
  3146. // sizeFixed32Ptr returns the size of wire encoding a *uint32 pointer as a Fixed32.
  3147. // It panics if the pointer is nil.
  3148. func sizeFixed32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3149. return f.tagsize + protowire.SizeFixed32()
  3150. }
  3151. // appendFixed32Ptr wire encodes a *uint32 pointer as a Fixed32.
  3152. // It panics if the pointer is nil.
  3153. func appendFixed32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3154. v := **p.Uint32Ptr()
  3155. b = protowire.AppendVarint(b, f.wiretag)
  3156. b = protowire.AppendFixed32(b, v)
  3157. return b, nil
  3158. }
  3159. // consumeFixed32Ptr wire decodes a *uint32 pointer as a Fixed32.
  3160. func consumeFixed32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  3161. if wtyp != protowire.Fixed32Type {
  3162. return out, errUnknown
  3163. }
  3164. v, n := protowire.ConsumeFixed32(b)
  3165. if n < 0 {
  3166. return out, errDecode
  3167. }
  3168. vp := p.Uint32Ptr()
  3169. if *vp == nil {
  3170. *vp = new(uint32)
  3171. }
  3172. **vp = v
  3173. out.n = n
  3174. return out, nil
  3175. }
  3176. var coderFixed32Ptr = pointerCoderFuncs{
  3177. size: sizeFixed32Ptr,
  3178. marshal: appendFixed32Ptr,
  3179. unmarshal: consumeFixed32Ptr,
  3180. merge: mergeUint32Ptr,
  3181. }
  3182. // sizeFixed32Slice returns the size of wire encoding a []uint32 pointer as a repeated Fixed32.
  3183. func sizeFixed32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3184. s := *p.Uint32Slice()
  3185. size = len(s) * (f.tagsize + protowire.SizeFixed32())
  3186. return size
  3187. }
  3188. // appendFixed32Slice encodes a []uint32 pointer as a repeated Fixed32.
  3189. func appendFixed32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3190. s := *p.Uint32Slice()
  3191. for _, v := range s {
  3192. b = protowire.AppendVarint(b, f.wiretag)
  3193. b = protowire.AppendFixed32(b, v)
  3194. }
  3195. return b, nil
  3196. }
  3197. // consumeFixed32Slice wire decodes a []uint32 pointer as a repeated Fixed32.
  3198. func consumeFixed32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  3199. sp := p.Uint32Slice()
  3200. if wtyp == protowire.BytesType {
  3201. s := *sp
  3202. b, n := protowire.ConsumeBytes(b)
  3203. if n < 0 {
  3204. return out, errDecode
  3205. }
  3206. for len(b) > 0 {
  3207. v, n := protowire.ConsumeFixed32(b)
  3208. if n < 0 {
  3209. return out, errDecode
  3210. }
  3211. s = append(s, v)
  3212. b = b[n:]
  3213. }
  3214. *sp = s
  3215. out.n = n
  3216. return out, nil
  3217. }
  3218. if wtyp != protowire.Fixed32Type {
  3219. return out, errUnknown
  3220. }
  3221. v, n := protowire.ConsumeFixed32(b)
  3222. if n < 0 {
  3223. return out, errDecode
  3224. }
  3225. *sp = append(*sp, v)
  3226. out.n = n
  3227. return out, nil
  3228. }
  3229. var coderFixed32Slice = pointerCoderFuncs{
  3230. size: sizeFixed32Slice,
  3231. marshal: appendFixed32Slice,
  3232. unmarshal: consumeFixed32Slice,
  3233. merge: mergeUint32Slice,
  3234. }
  3235. // sizeFixed32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Fixed32.
  3236. func sizeFixed32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3237. s := *p.Uint32Slice()
  3238. if len(s) == 0 {
  3239. return 0
  3240. }
  3241. n := len(s) * protowire.SizeFixed32()
  3242. return f.tagsize + protowire.SizeBytes(n)
  3243. }
  3244. // appendFixed32PackedSlice encodes a []uint32 pointer as a packed repeated Fixed32.
  3245. func appendFixed32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3246. s := *p.Uint32Slice()
  3247. if len(s) == 0 {
  3248. return b, nil
  3249. }
  3250. b = protowire.AppendVarint(b, f.wiretag)
  3251. n := len(s) * protowire.SizeFixed32()
  3252. b = protowire.AppendVarint(b, uint64(n))
  3253. for _, v := range s {
  3254. b = protowire.AppendFixed32(b, v)
  3255. }
  3256. return b, nil
  3257. }
  3258. var coderFixed32PackedSlice = pointerCoderFuncs{
  3259. size: sizeFixed32PackedSlice,
  3260. marshal: appendFixed32PackedSlice,
  3261. unmarshal: consumeFixed32Slice,
  3262. merge: mergeUint32Slice,
  3263. }
  3264. // sizeFixed32Value returns the size of wire encoding a uint32 value as a Fixed32.
  3265. func sizeFixed32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  3266. return tagsize + protowire.SizeFixed32()
  3267. }
  3268. // appendFixed32Value encodes a uint32 value as a Fixed32.
  3269. func appendFixed32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3270. b = protowire.AppendVarint(b, wiretag)
  3271. b = protowire.AppendFixed32(b, uint32(v.Uint()))
  3272. return b, nil
  3273. }
  3274. // consumeFixed32Value decodes a uint32 value as a Fixed32.
  3275. func consumeFixed32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  3276. if wtyp != protowire.Fixed32Type {
  3277. return protoreflect.Value{}, out, errUnknown
  3278. }
  3279. v, n := protowire.ConsumeFixed32(b)
  3280. if n < 0 {
  3281. return protoreflect.Value{}, out, errDecode
  3282. }
  3283. out.n = n
  3284. return protoreflect.ValueOfUint32(uint32(v)), out, nil
  3285. }
  3286. var coderFixed32Value = valueCoderFuncs{
  3287. size: sizeFixed32Value,
  3288. marshal: appendFixed32Value,
  3289. unmarshal: consumeFixed32Value,
  3290. merge: mergeScalarValue,
  3291. }
  3292. // sizeFixed32SliceValue returns the size of wire encoding a []uint32 value as a repeated Fixed32.
  3293. func sizeFixed32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  3294. list := listv.List()
  3295. size = list.Len() * (tagsize + protowire.SizeFixed32())
  3296. return size
  3297. }
  3298. // appendFixed32SliceValue encodes a []uint32 value as a repeated Fixed32.
  3299. func appendFixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3300. list := listv.List()
  3301. for i, llen := 0, list.Len(); i < llen; i++ {
  3302. v := list.Get(i)
  3303. b = protowire.AppendVarint(b, wiretag)
  3304. b = protowire.AppendFixed32(b, uint32(v.Uint()))
  3305. }
  3306. return b, nil
  3307. }
  3308. // consumeFixed32SliceValue wire decodes a []uint32 value as a repeated Fixed32.
  3309. func consumeFixed32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  3310. list := listv.List()
  3311. if wtyp == protowire.BytesType {
  3312. b, n := protowire.ConsumeBytes(b)
  3313. if n < 0 {
  3314. return protoreflect.Value{}, out, errDecode
  3315. }
  3316. for len(b) > 0 {
  3317. v, n := protowire.ConsumeFixed32(b)
  3318. if n < 0 {
  3319. return protoreflect.Value{}, out, errDecode
  3320. }
  3321. list.Append(protoreflect.ValueOfUint32(uint32(v)))
  3322. b = b[n:]
  3323. }
  3324. out.n = n
  3325. return listv, out, nil
  3326. }
  3327. if wtyp != protowire.Fixed32Type {
  3328. return protoreflect.Value{}, out, errUnknown
  3329. }
  3330. v, n := protowire.ConsumeFixed32(b)
  3331. if n < 0 {
  3332. return protoreflect.Value{}, out, errDecode
  3333. }
  3334. list.Append(protoreflect.ValueOfUint32(uint32(v)))
  3335. out.n = n
  3336. return listv, out, nil
  3337. }
  3338. var coderFixed32SliceValue = valueCoderFuncs{
  3339. size: sizeFixed32SliceValue,
  3340. marshal: appendFixed32SliceValue,
  3341. unmarshal: consumeFixed32SliceValue,
  3342. merge: mergeListValue,
  3343. }
  3344. // sizeFixed32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Fixed32.
  3345. func sizeFixed32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  3346. list := listv.List()
  3347. llen := list.Len()
  3348. if llen == 0 {
  3349. return 0
  3350. }
  3351. n := llen * protowire.SizeFixed32()
  3352. return tagsize + protowire.SizeBytes(n)
  3353. }
  3354. // appendFixed32PackedSliceValue encodes a []uint32 value as a packed repeated Fixed32.
  3355. func appendFixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3356. list := listv.List()
  3357. llen := list.Len()
  3358. if llen == 0 {
  3359. return b, nil
  3360. }
  3361. b = protowire.AppendVarint(b, wiretag)
  3362. n := llen * protowire.SizeFixed32()
  3363. b = protowire.AppendVarint(b, uint64(n))
  3364. for i := 0; i < llen; i++ {
  3365. v := list.Get(i)
  3366. b = protowire.AppendFixed32(b, uint32(v.Uint()))
  3367. }
  3368. return b, nil
  3369. }
  3370. var coderFixed32PackedSliceValue = valueCoderFuncs{
  3371. size: sizeFixed32PackedSliceValue,
  3372. marshal: appendFixed32PackedSliceValue,
  3373. unmarshal: consumeFixed32SliceValue,
  3374. merge: mergeListValue,
  3375. }
  3376. // sizeFloat returns the size of wire encoding a float32 pointer as a Float.
  3377. func sizeFloat(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3378. return f.tagsize + protowire.SizeFixed32()
  3379. }
  3380. // appendFloat wire encodes a float32 pointer as a Float.
  3381. func appendFloat(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3382. v := *p.Float32()
  3383. b = protowire.AppendVarint(b, f.wiretag)
  3384. b = protowire.AppendFixed32(b, math.Float32bits(v))
  3385. return b, nil
  3386. }
  3387. // consumeFloat wire decodes a float32 pointer as a Float.
  3388. func consumeFloat(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  3389. if wtyp != protowire.Fixed32Type {
  3390. return out, errUnknown
  3391. }
  3392. v, n := protowire.ConsumeFixed32(b)
  3393. if n < 0 {
  3394. return out, errDecode
  3395. }
  3396. *p.Float32() = math.Float32frombits(v)
  3397. out.n = n
  3398. return out, nil
  3399. }
  3400. var coderFloat = pointerCoderFuncs{
  3401. size: sizeFloat,
  3402. marshal: appendFloat,
  3403. unmarshal: consumeFloat,
  3404. merge: mergeFloat32,
  3405. }
  3406. // sizeFloatNoZero returns the size of wire encoding a float32 pointer as a Float.
  3407. // The zero value is not encoded.
  3408. func sizeFloatNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3409. v := *p.Float32()
  3410. if v == 0 && !math.Signbit(float64(v)) {
  3411. return 0
  3412. }
  3413. return f.tagsize + protowire.SizeFixed32()
  3414. }
  3415. // appendFloatNoZero wire encodes a float32 pointer as a Float.
  3416. // The zero value is not encoded.
  3417. func appendFloatNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3418. v := *p.Float32()
  3419. if v == 0 && !math.Signbit(float64(v)) {
  3420. return b, nil
  3421. }
  3422. b = protowire.AppendVarint(b, f.wiretag)
  3423. b = protowire.AppendFixed32(b, math.Float32bits(v))
  3424. return b, nil
  3425. }
  3426. var coderFloatNoZero = pointerCoderFuncs{
  3427. size: sizeFloatNoZero,
  3428. marshal: appendFloatNoZero,
  3429. unmarshal: consumeFloat,
  3430. merge: mergeFloat32NoZero,
  3431. }
  3432. // sizeFloatPtr returns the size of wire encoding a *float32 pointer as a Float.
  3433. // It panics if the pointer is nil.
  3434. func sizeFloatPtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3435. return f.tagsize + protowire.SizeFixed32()
  3436. }
  3437. // appendFloatPtr wire encodes a *float32 pointer as a Float.
  3438. // It panics if the pointer is nil.
  3439. func appendFloatPtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3440. v := **p.Float32Ptr()
  3441. b = protowire.AppendVarint(b, f.wiretag)
  3442. b = protowire.AppendFixed32(b, math.Float32bits(v))
  3443. return b, nil
  3444. }
  3445. // consumeFloatPtr wire decodes a *float32 pointer as a Float.
  3446. func consumeFloatPtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  3447. if wtyp != protowire.Fixed32Type {
  3448. return out, errUnknown
  3449. }
  3450. v, n := protowire.ConsumeFixed32(b)
  3451. if n < 0 {
  3452. return out, errDecode
  3453. }
  3454. vp := p.Float32Ptr()
  3455. if *vp == nil {
  3456. *vp = new(float32)
  3457. }
  3458. **vp = math.Float32frombits(v)
  3459. out.n = n
  3460. return out, nil
  3461. }
  3462. var coderFloatPtr = pointerCoderFuncs{
  3463. size: sizeFloatPtr,
  3464. marshal: appendFloatPtr,
  3465. unmarshal: consumeFloatPtr,
  3466. merge: mergeFloat32Ptr,
  3467. }
  3468. // sizeFloatSlice returns the size of wire encoding a []float32 pointer as a repeated Float.
  3469. func sizeFloatSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3470. s := *p.Float32Slice()
  3471. size = len(s) * (f.tagsize + protowire.SizeFixed32())
  3472. return size
  3473. }
  3474. // appendFloatSlice encodes a []float32 pointer as a repeated Float.
  3475. func appendFloatSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3476. s := *p.Float32Slice()
  3477. for _, v := range s {
  3478. b = protowire.AppendVarint(b, f.wiretag)
  3479. b = protowire.AppendFixed32(b, math.Float32bits(v))
  3480. }
  3481. return b, nil
  3482. }
  3483. // consumeFloatSlice wire decodes a []float32 pointer as a repeated Float.
  3484. func consumeFloatSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  3485. sp := p.Float32Slice()
  3486. if wtyp == protowire.BytesType {
  3487. s := *sp
  3488. b, n := protowire.ConsumeBytes(b)
  3489. if n < 0 {
  3490. return out, errDecode
  3491. }
  3492. for len(b) > 0 {
  3493. v, n := protowire.ConsumeFixed32(b)
  3494. if n < 0 {
  3495. return out, errDecode
  3496. }
  3497. s = append(s, math.Float32frombits(v))
  3498. b = b[n:]
  3499. }
  3500. *sp = s
  3501. out.n = n
  3502. return out, nil
  3503. }
  3504. if wtyp != protowire.Fixed32Type {
  3505. return out, errUnknown
  3506. }
  3507. v, n := protowire.ConsumeFixed32(b)
  3508. if n < 0 {
  3509. return out, errDecode
  3510. }
  3511. *sp = append(*sp, math.Float32frombits(v))
  3512. out.n = n
  3513. return out, nil
  3514. }
  3515. var coderFloatSlice = pointerCoderFuncs{
  3516. size: sizeFloatSlice,
  3517. marshal: appendFloatSlice,
  3518. unmarshal: consumeFloatSlice,
  3519. merge: mergeFloat32Slice,
  3520. }
  3521. // sizeFloatPackedSlice returns the size of wire encoding a []float32 pointer as a packed repeated Float.
  3522. func sizeFloatPackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3523. s := *p.Float32Slice()
  3524. if len(s) == 0 {
  3525. return 0
  3526. }
  3527. n := len(s) * protowire.SizeFixed32()
  3528. return f.tagsize + protowire.SizeBytes(n)
  3529. }
  3530. // appendFloatPackedSlice encodes a []float32 pointer as a packed repeated Float.
  3531. func appendFloatPackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3532. s := *p.Float32Slice()
  3533. if len(s) == 0 {
  3534. return b, nil
  3535. }
  3536. b = protowire.AppendVarint(b, f.wiretag)
  3537. n := len(s) * protowire.SizeFixed32()
  3538. b = protowire.AppendVarint(b, uint64(n))
  3539. for _, v := range s {
  3540. b = protowire.AppendFixed32(b, math.Float32bits(v))
  3541. }
  3542. return b, nil
  3543. }
  3544. var coderFloatPackedSlice = pointerCoderFuncs{
  3545. size: sizeFloatPackedSlice,
  3546. marshal: appendFloatPackedSlice,
  3547. unmarshal: consumeFloatSlice,
  3548. merge: mergeFloat32Slice,
  3549. }
  3550. // sizeFloatValue returns the size of wire encoding a float32 value as a Float.
  3551. func sizeFloatValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  3552. return tagsize + protowire.SizeFixed32()
  3553. }
  3554. // appendFloatValue encodes a float32 value as a Float.
  3555. func appendFloatValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3556. b = protowire.AppendVarint(b, wiretag)
  3557. b = protowire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
  3558. return b, nil
  3559. }
  3560. // consumeFloatValue decodes a float32 value as a Float.
  3561. func consumeFloatValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  3562. if wtyp != protowire.Fixed32Type {
  3563. return protoreflect.Value{}, out, errUnknown
  3564. }
  3565. v, n := protowire.ConsumeFixed32(b)
  3566. if n < 0 {
  3567. return protoreflect.Value{}, out, errDecode
  3568. }
  3569. out.n = n
  3570. return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), out, nil
  3571. }
  3572. var coderFloatValue = valueCoderFuncs{
  3573. size: sizeFloatValue,
  3574. marshal: appendFloatValue,
  3575. unmarshal: consumeFloatValue,
  3576. merge: mergeScalarValue,
  3577. }
  3578. // sizeFloatSliceValue returns the size of wire encoding a []float32 value as a repeated Float.
  3579. func sizeFloatSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  3580. list := listv.List()
  3581. size = list.Len() * (tagsize + protowire.SizeFixed32())
  3582. return size
  3583. }
  3584. // appendFloatSliceValue encodes a []float32 value as a repeated Float.
  3585. func appendFloatSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3586. list := listv.List()
  3587. for i, llen := 0, list.Len(); i < llen; i++ {
  3588. v := list.Get(i)
  3589. b = protowire.AppendVarint(b, wiretag)
  3590. b = protowire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
  3591. }
  3592. return b, nil
  3593. }
  3594. // consumeFloatSliceValue wire decodes a []float32 value as a repeated Float.
  3595. func consumeFloatSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  3596. list := listv.List()
  3597. if wtyp == protowire.BytesType {
  3598. b, n := protowire.ConsumeBytes(b)
  3599. if n < 0 {
  3600. return protoreflect.Value{}, out, errDecode
  3601. }
  3602. for len(b) > 0 {
  3603. v, n := protowire.ConsumeFixed32(b)
  3604. if n < 0 {
  3605. return protoreflect.Value{}, out, errDecode
  3606. }
  3607. list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
  3608. b = b[n:]
  3609. }
  3610. out.n = n
  3611. return listv, out, nil
  3612. }
  3613. if wtyp != protowire.Fixed32Type {
  3614. return protoreflect.Value{}, out, errUnknown
  3615. }
  3616. v, n := protowire.ConsumeFixed32(b)
  3617. if n < 0 {
  3618. return protoreflect.Value{}, out, errDecode
  3619. }
  3620. list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
  3621. out.n = n
  3622. return listv, out, nil
  3623. }
  3624. var coderFloatSliceValue = valueCoderFuncs{
  3625. size: sizeFloatSliceValue,
  3626. marshal: appendFloatSliceValue,
  3627. unmarshal: consumeFloatSliceValue,
  3628. merge: mergeListValue,
  3629. }
  3630. // sizeFloatPackedSliceValue returns the size of wire encoding a []float32 value as a packed repeated Float.
  3631. func sizeFloatPackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  3632. list := listv.List()
  3633. llen := list.Len()
  3634. if llen == 0 {
  3635. return 0
  3636. }
  3637. n := llen * protowire.SizeFixed32()
  3638. return tagsize + protowire.SizeBytes(n)
  3639. }
  3640. // appendFloatPackedSliceValue encodes a []float32 value as a packed repeated Float.
  3641. func appendFloatPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3642. list := listv.List()
  3643. llen := list.Len()
  3644. if llen == 0 {
  3645. return b, nil
  3646. }
  3647. b = protowire.AppendVarint(b, wiretag)
  3648. n := llen * protowire.SizeFixed32()
  3649. b = protowire.AppendVarint(b, uint64(n))
  3650. for i := 0; i < llen; i++ {
  3651. v := list.Get(i)
  3652. b = protowire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
  3653. }
  3654. return b, nil
  3655. }
  3656. var coderFloatPackedSliceValue = valueCoderFuncs{
  3657. size: sizeFloatPackedSliceValue,
  3658. marshal: appendFloatPackedSliceValue,
  3659. unmarshal: consumeFloatSliceValue,
  3660. merge: mergeListValue,
  3661. }
  3662. // sizeSfixed64 returns the size of wire encoding a int64 pointer as a Sfixed64.
  3663. func sizeSfixed64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3664. return f.tagsize + protowire.SizeFixed64()
  3665. }
  3666. // appendSfixed64 wire encodes a int64 pointer as a Sfixed64.
  3667. func appendSfixed64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3668. v := *p.Int64()
  3669. b = protowire.AppendVarint(b, f.wiretag)
  3670. b = protowire.AppendFixed64(b, uint64(v))
  3671. return b, nil
  3672. }
  3673. // consumeSfixed64 wire decodes a int64 pointer as a Sfixed64.
  3674. func consumeSfixed64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  3675. if wtyp != protowire.Fixed64Type {
  3676. return out, errUnknown
  3677. }
  3678. v, n := protowire.ConsumeFixed64(b)
  3679. if n < 0 {
  3680. return out, errDecode
  3681. }
  3682. *p.Int64() = int64(v)
  3683. out.n = n
  3684. return out, nil
  3685. }
  3686. var coderSfixed64 = pointerCoderFuncs{
  3687. size: sizeSfixed64,
  3688. marshal: appendSfixed64,
  3689. unmarshal: consumeSfixed64,
  3690. merge: mergeInt64,
  3691. }
  3692. // sizeSfixed64NoZero returns the size of wire encoding a int64 pointer as a Sfixed64.
  3693. // The zero value is not encoded.
  3694. func sizeSfixed64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3695. v := *p.Int64()
  3696. if v == 0 {
  3697. return 0
  3698. }
  3699. return f.tagsize + protowire.SizeFixed64()
  3700. }
  3701. // appendSfixed64NoZero wire encodes a int64 pointer as a Sfixed64.
  3702. // The zero value is not encoded.
  3703. func appendSfixed64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3704. v := *p.Int64()
  3705. if v == 0 {
  3706. return b, nil
  3707. }
  3708. b = protowire.AppendVarint(b, f.wiretag)
  3709. b = protowire.AppendFixed64(b, uint64(v))
  3710. return b, nil
  3711. }
  3712. var coderSfixed64NoZero = pointerCoderFuncs{
  3713. size: sizeSfixed64NoZero,
  3714. marshal: appendSfixed64NoZero,
  3715. unmarshal: consumeSfixed64,
  3716. merge: mergeInt64NoZero,
  3717. }
  3718. // sizeSfixed64Ptr returns the size of wire encoding a *int64 pointer as a Sfixed64.
  3719. // It panics if the pointer is nil.
  3720. func sizeSfixed64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3721. return f.tagsize + protowire.SizeFixed64()
  3722. }
  3723. // appendSfixed64Ptr wire encodes a *int64 pointer as a Sfixed64.
  3724. // It panics if the pointer is nil.
  3725. func appendSfixed64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3726. v := **p.Int64Ptr()
  3727. b = protowire.AppendVarint(b, f.wiretag)
  3728. b = protowire.AppendFixed64(b, uint64(v))
  3729. return b, nil
  3730. }
  3731. // consumeSfixed64Ptr wire decodes a *int64 pointer as a Sfixed64.
  3732. func consumeSfixed64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  3733. if wtyp != protowire.Fixed64Type {
  3734. return out, errUnknown
  3735. }
  3736. v, n := protowire.ConsumeFixed64(b)
  3737. if n < 0 {
  3738. return out, errDecode
  3739. }
  3740. vp := p.Int64Ptr()
  3741. if *vp == nil {
  3742. *vp = new(int64)
  3743. }
  3744. **vp = int64(v)
  3745. out.n = n
  3746. return out, nil
  3747. }
  3748. var coderSfixed64Ptr = pointerCoderFuncs{
  3749. size: sizeSfixed64Ptr,
  3750. marshal: appendSfixed64Ptr,
  3751. unmarshal: consumeSfixed64Ptr,
  3752. merge: mergeInt64Ptr,
  3753. }
  3754. // sizeSfixed64Slice returns the size of wire encoding a []int64 pointer as a repeated Sfixed64.
  3755. func sizeSfixed64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3756. s := *p.Int64Slice()
  3757. size = len(s) * (f.tagsize + protowire.SizeFixed64())
  3758. return size
  3759. }
  3760. // appendSfixed64Slice encodes a []int64 pointer as a repeated Sfixed64.
  3761. func appendSfixed64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3762. s := *p.Int64Slice()
  3763. for _, v := range s {
  3764. b = protowire.AppendVarint(b, f.wiretag)
  3765. b = protowire.AppendFixed64(b, uint64(v))
  3766. }
  3767. return b, nil
  3768. }
  3769. // consumeSfixed64Slice wire decodes a []int64 pointer as a repeated Sfixed64.
  3770. func consumeSfixed64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  3771. sp := p.Int64Slice()
  3772. if wtyp == protowire.BytesType {
  3773. s := *sp
  3774. b, n := protowire.ConsumeBytes(b)
  3775. if n < 0 {
  3776. return out, errDecode
  3777. }
  3778. for len(b) > 0 {
  3779. v, n := protowire.ConsumeFixed64(b)
  3780. if n < 0 {
  3781. return out, errDecode
  3782. }
  3783. s = append(s, int64(v))
  3784. b = b[n:]
  3785. }
  3786. *sp = s
  3787. out.n = n
  3788. return out, nil
  3789. }
  3790. if wtyp != protowire.Fixed64Type {
  3791. return out, errUnknown
  3792. }
  3793. v, n := protowire.ConsumeFixed64(b)
  3794. if n < 0 {
  3795. return out, errDecode
  3796. }
  3797. *sp = append(*sp, int64(v))
  3798. out.n = n
  3799. return out, nil
  3800. }
  3801. var coderSfixed64Slice = pointerCoderFuncs{
  3802. size: sizeSfixed64Slice,
  3803. marshal: appendSfixed64Slice,
  3804. unmarshal: consumeSfixed64Slice,
  3805. merge: mergeInt64Slice,
  3806. }
  3807. // sizeSfixed64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sfixed64.
  3808. func sizeSfixed64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3809. s := *p.Int64Slice()
  3810. if len(s) == 0 {
  3811. return 0
  3812. }
  3813. n := len(s) * protowire.SizeFixed64()
  3814. return f.tagsize + protowire.SizeBytes(n)
  3815. }
  3816. // appendSfixed64PackedSlice encodes a []int64 pointer as a packed repeated Sfixed64.
  3817. func appendSfixed64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3818. s := *p.Int64Slice()
  3819. if len(s) == 0 {
  3820. return b, nil
  3821. }
  3822. b = protowire.AppendVarint(b, f.wiretag)
  3823. n := len(s) * protowire.SizeFixed64()
  3824. b = protowire.AppendVarint(b, uint64(n))
  3825. for _, v := range s {
  3826. b = protowire.AppendFixed64(b, uint64(v))
  3827. }
  3828. return b, nil
  3829. }
  3830. var coderSfixed64PackedSlice = pointerCoderFuncs{
  3831. size: sizeSfixed64PackedSlice,
  3832. marshal: appendSfixed64PackedSlice,
  3833. unmarshal: consumeSfixed64Slice,
  3834. merge: mergeInt64Slice,
  3835. }
  3836. // sizeSfixed64Value returns the size of wire encoding a int64 value as a Sfixed64.
  3837. func sizeSfixed64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  3838. return tagsize + protowire.SizeFixed64()
  3839. }
  3840. // appendSfixed64Value encodes a int64 value as a Sfixed64.
  3841. func appendSfixed64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3842. b = protowire.AppendVarint(b, wiretag)
  3843. b = protowire.AppendFixed64(b, uint64(v.Int()))
  3844. return b, nil
  3845. }
  3846. // consumeSfixed64Value decodes a int64 value as a Sfixed64.
  3847. func consumeSfixed64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  3848. if wtyp != protowire.Fixed64Type {
  3849. return protoreflect.Value{}, out, errUnknown
  3850. }
  3851. v, n := protowire.ConsumeFixed64(b)
  3852. if n < 0 {
  3853. return protoreflect.Value{}, out, errDecode
  3854. }
  3855. out.n = n
  3856. return protoreflect.ValueOfInt64(int64(v)), out, nil
  3857. }
  3858. var coderSfixed64Value = valueCoderFuncs{
  3859. size: sizeSfixed64Value,
  3860. marshal: appendSfixed64Value,
  3861. unmarshal: consumeSfixed64Value,
  3862. merge: mergeScalarValue,
  3863. }
  3864. // sizeSfixed64SliceValue returns the size of wire encoding a []int64 value as a repeated Sfixed64.
  3865. func sizeSfixed64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  3866. list := listv.List()
  3867. size = list.Len() * (tagsize + protowire.SizeFixed64())
  3868. return size
  3869. }
  3870. // appendSfixed64SliceValue encodes a []int64 value as a repeated Sfixed64.
  3871. func appendSfixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3872. list := listv.List()
  3873. for i, llen := 0, list.Len(); i < llen; i++ {
  3874. v := list.Get(i)
  3875. b = protowire.AppendVarint(b, wiretag)
  3876. b = protowire.AppendFixed64(b, uint64(v.Int()))
  3877. }
  3878. return b, nil
  3879. }
  3880. // consumeSfixed64SliceValue wire decodes a []int64 value as a repeated Sfixed64.
  3881. func consumeSfixed64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  3882. list := listv.List()
  3883. if wtyp == protowire.BytesType {
  3884. b, n := protowire.ConsumeBytes(b)
  3885. if n < 0 {
  3886. return protoreflect.Value{}, out, errDecode
  3887. }
  3888. for len(b) > 0 {
  3889. v, n := protowire.ConsumeFixed64(b)
  3890. if n < 0 {
  3891. return protoreflect.Value{}, out, errDecode
  3892. }
  3893. list.Append(protoreflect.ValueOfInt64(int64(v)))
  3894. b = b[n:]
  3895. }
  3896. out.n = n
  3897. return listv, out, nil
  3898. }
  3899. if wtyp != protowire.Fixed64Type {
  3900. return protoreflect.Value{}, out, errUnknown
  3901. }
  3902. v, n := protowire.ConsumeFixed64(b)
  3903. if n < 0 {
  3904. return protoreflect.Value{}, out, errDecode
  3905. }
  3906. list.Append(protoreflect.ValueOfInt64(int64(v)))
  3907. out.n = n
  3908. return listv, out, nil
  3909. }
  3910. var coderSfixed64SliceValue = valueCoderFuncs{
  3911. size: sizeSfixed64SliceValue,
  3912. marshal: appendSfixed64SliceValue,
  3913. unmarshal: consumeSfixed64SliceValue,
  3914. merge: mergeListValue,
  3915. }
  3916. // sizeSfixed64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sfixed64.
  3917. func sizeSfixed64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  3918. list := listv.List()
  3919. llen := list.Len()
  3920. if llen == 0 {
  3921. return 0
  3922. }
  3923. n := llen * protowire.SizeFixed64()
  3924. return tagsize + protowire.SizeBytes(n)
  3925. }
  3926. // appendSfixed64PackedSliceValue encodes a []int64 value as a packed repeated Sfixed64.
  3927. func appendSfixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  3928. list := listv.List()
  3929. llen := list.Len()
  3930. if llen == 0 {
  3931. return b, nil
  3932. }
  3933. b = protowire.AppendVarint(b, wiretag)
  3934. n := llen * protowire.SizeFixed64()
  3935. b = protowire.AppendVarint(b, uint64(n))
  3936. for i := 0; i < llen; i++ {
  3937. v := list.Get(i)
  3938. b = protowire.AppendFixed64(b, uint64(v.Int()))
  3939. }
  3940. return b, nil
  3941. }
  3942. var coderSfixed64PackedSliceValue = valueCoderFuncs{
  3943. size: sizeSfixed64PackedSliceValue,
  3944. marshal: appendSfixed64PackedSliceValue,
  3945. unmarshal: consumeSfixed64SliceValue,
  3946. merge: mergeListValue,
  3947. }
  3948. // sizeFixed64 returns the size of wire encoding a uint64 pointer as a Fixed64.
  3949. func sizeFixed64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3950. return f.tagsize + protowire.SizeFixed64()
  3951. }
  3952. // appendFixed64 wire encodes a uint64 pointer as a Fixed64.
  3953. func appendFixed64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3954. v := *p.Uint64()
  3955. b = protowire.AppendVarint(b, f.wiretag)
  3956. b = protowire.AppendFixed64(b, v)
  3957. return b, nil
  3958. }
  3959. // consumeFixed64 wire decodes a uint64 pointer as a Fixed64.
  3960. func consumeFixed64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  3961. if wtyp != protowire.Fixed64Type {
  3962. return out, errUnknown
  3963. }
  3964. v, n := protowire.ConsumeFixed64(b)
  3965. if n < 0 {
  3966. return out, errDecode
  3967. }
  3968. *p.Uint64() = v
  3969. out.n = n
  3970. return out, nil
  3971. }
  3972. var coderFixed64 = pointerCoderFuncs{
  3973. size: sizeFixed64,
  3974. marshal: appendFixed64,
  3975. unmarshal: consumeFixed64,
  3976. merge: mergeUint64,
  3977. }
  3978. // sizeFixed64NoZero returns the size of wire encoding a uint64 pointer as a Fixed64.
  3979. // The zero value is not encoded.
  3980. func sizeFixed64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  3981. v := *p.Uint64()
  3982. if v == 0 {
  3983. return 0
  3984. }
  3985. return f.tagsize + protowire.SizeFixed64()
  3986. }
  3987. // appendFixed64NoZero wire encodes a uint64 pointer as a Fixed64.
  3988. // The zero value is not encoded.
  3989. func appendFixed64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  3990. v := *p.Uint64()
  3991. if v == 0 {
  3992. return b, nil
  3993. }
  3994. b = protowire.AppendVarint(b, f.wiretag)
  3995. b = protowire.AppendFixed64(b, v)
  3996. return b, nil
  3997. }
  3998. var coderFixed64NoZero = pointerCoderFuncs{
  3999. size: sizeFixed64NoZero,
  4000. marshal: appendFixed64NoZero,
  4001. unmarshal: consumeFixed64,
  4002. merge: mergeUint64NoZero,
  4003. }
  4004. // sizeFixed64Ptr returns the size of wire encoding a *uint64 pointer as a Fixed64.
  4005. // It panics if the pointer is nil.
  4006. func sizeFixed64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4007. return f.tagsize + protowire.SizeFixed64()
  4008. }
  4009. // appendFixed64Ptr wire encodes a *uint64 pointer as a Fixed64.
  4010. // It panics if the pointer is nil.
  4011. func appendFixed64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4012. v := **p.Uint64Ptr()
  4013. b = protowire.AppendVarint(b, f.wiretag)
  4014. b = protowire.AppendFixed64(b, v)
  4015. return b, nil
  4016. }
  4017. // consumeFixed64Ptr wire decodes a *uint64 pointer as a Fixed64.
  4018. func consumeFixed64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4019. if wtyp != protowire.Fixed64Type {
  4020. return out, errUnknown
  4021. }
  4022. v, n := protowire.ConsumeFixed64(b)
  4023. if n < 0 {
  4024. return out, errDecode
  4025. }
  4026. vp := p.Uint64Ptr()
  4027. if *vp == nil {
  4028. *vp = new(uint64)
  4029. }
  4030. **vp = v
  4031. out.n = n
  4032. return out, nil
  4033. }
  4034. var coderFixed64Ptr = pointerCoderFuncs{
  4035. size: sizeFixed64Ptr,
  4036. marshal: appendFixed64Ptr,
  4037. unmarshal: consumeFixed64Ptr,
  4038. merge: mergeUint64Ptr,
  4039. }
  4040. // sizeFixed64Slice returns the size of wire encoding a []uint64 pointer as a repeated Fixed64.
  4041. func sizeFixed64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4042. s := *p.Uint64Slice()
  4043. size = len(s) * (f.tagsize + protowire.SizeFixed64())
  4044. return size
  4045. }
  4046. // appendFixed64Slice encodes a []uint64 pointer as a repeated Fixed64.
  4047. func appendFixed64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4048. s := *p.Uint64Slice()
  4049. for _, v := range s {
  4050. b = protowire.AppendVarint(b, f.wiretag)
  4051. b = protowire.AppendFixed64(b, v)
  4052. }
  4053. return b, nil
  4054. }
  4055. // consumeFixed64Slice wire decodes a []uint64 pointer as a repeated Fixed64.
  4056. func consumeFixed64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4057. sp := p.Uint64Slice()
  4058. if wtyp == protowire.BytesType {
  4059. s := *sp
  4060. b, n := protowire.ConsumeBytes(b)
  4061. if n < 0 {
  4062. return out, errDecode
  4063. }
  4064. for len(b) > 0 {
  4065. v, n := protowire.ConsumeFixed64(b)
  4066. if n < 0 {
  4067. return out, errDecode
  4068. }
  4069. s = append(s, v)
  4070. b = b[n:]
  4071. }
  4072. *sp = s
  4073. out.n = n
  4074. return out, nil
  4075. }
  4076. if wtyp != protowire.Fixed64Type {
  4077. return out, errUnknown
  4078. }
  4079. v, n := protowire.ConsumeFixed64(b)
  4080. if n < 0 {
  4081. return out, errDecode
  4082. }
  4083. *sp = append(*sp, v)
  4084. out.n = n
  4085. return out, nil
  4086. }
  4087. var coderFixed64Slice = pointerCoderFuncs{
  4088. size: sizeFixed64Slice,
  4089. marshal: appendFixed64Slice,
  4090. unmarshal: consumeFixed64Slice,
  4091. merge: mergeUint64Slice,
  4092. }
  4093. // sizeFixed64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Fixed64.
  4094. func sizeFixed64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4095. s := *p.Uint64Slice()
  4096. if len(s) == 0 {
  4097. return 0
  4098. }
  4099. n := len(s) * protowire.SizeFixed64()
  4100. return f.tagsize + protowire.SizeBytes(n)
  4101. }
  4102. // appendFixed64PackedSlice encodes a []uint64 pointer as a packed repeated Fixed64.
  4103. func appendFixed64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4104. s := *p.Uint64Slice()
  4105. if len(s) == 0 {
  4106. return b, nil
  4107. }
  4108. b = protowire.AppendVarint(b, f.wiretag)
  4109. n := len(s) * protowire.SizeFixed64()
  4110. b = protowire.AppendVarint(b, uint64(n))
  4111. for _, v := range s {
  4112. b = protowire.AppendFixed64(b, v)
  4113. }
  4114. return b, nil
  4115. }
  4116. var coderFixed64PackedSlice = pointerCoderFuncs{
  4117. size: sizeFixed64PackedSlice,
  4118. marshal: appendFixed64PackedSlice,
  4119. unmarshal: consumeFixed64Slice,
  4120. merge: mergeUint64Slice,
  4121. }
  4122. // sizeFixed64Value returns the size of wire encoding a uint64 value as a Fixed64.
  4123. func sizeFixed64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  4124. return tagsize + protowire.SizeFixed64()
  4125. }
  4126. // appendFixed64Value encodes a uint64 value as a Fixed64.
  4127. func appendFixed64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  4128. b = protowire.AppendVarint(b, wiretag)
  4129. b = protowire.AppendFixed64(b, v.Uint())
  4130. return b, nil
  4131. }
  4132. // consumeFixed64Value decodes a uint64 value as a Fixed64.
  4133. func consumeFixed64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  4134. if wtyp != protowire.Fixed64Type {
  4135. return protoreflect.Value{}, out, errUnknown
  4136. }
  4137. v, n := protowire.ConsumeFixed64(b)
  4138. if n < 0 {
  4139. return protoreflect.Value{}, out, errDecode
  4140. }
  4141. out.n = n
  4142. return protoreflect.ValueOfUint64(v), out, nil
  4143. }
  4144. var coderFixed64Value = valueCoderFuncs{
  4145. size: sizeFixed64Value,
  4146. marshal: appendFixed64Value,
  4147. unmarshal: consumeFixed64Value,
  4148. merge: mergeScalarValue,
  4149. }
  4150. // sizeFixed64SliceValue returns the size of wire encoding a []uint64 value as a repeated Fixed64.
  4151. func sizeFixed64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  4152. list := listv.List()
  4153. size = list.Len() * (tagsize + protowire.SizeFixed64())
  4154. return size
  4155. }
  4156. // appendFixed64SliceValue encodes a []uint64 value as a repeated Fixed64.
  4157. func appendFixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  4158. list := listv.List()
  4159. for i, llen := 0, list.Len(); i < llen; i++ {
  4160. v := list.Get(i)
  4161. b = protowire.AppendVarint(b, wiretag)
  4162. b = protowire.AppendFixed64(b, v.Uint())
  4163. }
  4164. return b, nil
  4165. }
  4166. // consumeFixed64SliceValue wire decodes a []uint64 value as a repeated Fixed64.
  4167. func consumeFixed64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  4168. list := listv.List()
  4169. if wtyp == protowire.BytesType {
  4170. b, n := protowire.ConsumeBytes(b)
  4171. if n < 0 {
  4172. return protoreflect.Value{}, out, errDecode
  4173. }
  4174. for len(b) > 0 {
  4175. v, n := protowire.ConsumeFixed64(b)
  4176. if n < 0 {
  4177. return protoreflect.Value{}, out, errDecode
  4178. }
  4179. list.Append(protoreflect.ValueOfUint64(v))
  4180. b = b[n:]
  4181. }
  4182. out.n = n
  4183. return listv, out, nil
  4184. }
  4185. if wtyp != protowire.Fixed64Type {
  4186. return protoreflect.Value{}, out, errUnknown
  4187. }
  4188. v, n := protowire.ConsumeFixed64(b)
  4189. if n < 0 {
  4190. return protoreflect.Value{}, out, errDecode
  4191. }
  4192. list.Append(protoreflect.ValueOfUint64(v))
  4193. out.n = n
  4194. return listv, out, nil
  4195. }
  4196. var coderFixed64SliceValue = valueCoderFuncs{
  4197. size: sizeFixed64SliceValue,
  4198. marshal: appendFixed64SliceValue,
  4199. unmarshal: consumeFixed64SliceValue,
  4200. merge: mergeListValue,
  4201. }
  4202. // sizeFixed64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Fixed64.
  4203. func sizeFixed64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  4204. list := listv.List()
  4205. llen := list.Len()
  4206. if llen == 0 {
  4207. return 0
  4208. }
  4209. n := llen * protowire.SizeFixed64()
  4210. return tagsize + protowire.SizeBytes(n)
  4211. }
  4212. // appendFixed64PackedSliceValue encodes a []uint64 value as a packed repeated Fixed64.
  4213. func appendFixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  4214. list := listv.List()
  4215. llen := list.Len()
  4216. if llen == 0 {
  4217. return b, nil
  4218. }
  4219. b = protowire.AppendVarint(b, wiretag)
  4220. n := llen * protowire.SizeFixed64()
  4221. b = protowire.AppendVarint(b, uint64(n))
  4222. for i := 0; i < llen; i++ {
  4223. v := list.Get(i)
  4224. b = protowire.AppendFixed64(b, v.Uint())
  4225. }
  4226. return b, nil
  4227. }
  4228. var coderFixed64PackedSliceValue = valueCoderFuncs{
  4229. size: sizeFixed64PackedSliceValue,
  4230. marshal: appendFixed64PackedSliceValue,
  4231. unmarshal: consumeFixed64SliceValue,
  4232. merge: mergeListValue,
  4233. }
  4234. // sizeDouble returns the size of wire encoding a float64 pointer as a Double.
  4235. func sizeDouble(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4236. return f.tagsize + protowire.SizeFixed64()
  4237. }
  4238. // appendDouble wire encodes a float64 pointer as a Double.
  4239. func appendDouble(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4240. v := *p.Float64()
  4241. b = protowire.AppendVarint(b, f.wiretag)
  4242. b = protowire.AppendFixed64(b, math.Float64bits(v))
  4243. return b, nil
  4244. }
  4245. // consumeDouble wire decodes a float64 pointer as a Double.
  4246. func consumeDouble(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4247. if wtyp != protowire.Fixed64Type {
  4248. return out, errUnknown
  4249. }
  4250. v, n := protowire.ConsumeFixed64(b)
  4251. if n < 0 {
  4252. return out, errDecode
  4253. }
  4254. *p.Float64() = math.Float64frombits(v)
  4255. out.n = n
  4256. return out, nil
  4257. }
  4258. var coderDouble = pointerCoderFuncs{
  4259. size: sizeDouble,
  4260. marshal: appendDouble,
  4261. unmarshal: consumeDouble,
  4262. merge: mergeFloat64,
  4263. }
  4264. // sizeDoubleNoZero returns the size of wire encoding a float64 pointer as a Double.
  4265. // The zero value is not encoded.
  4266. func sizeDoubleNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4267. v := *p.Float64()
  4268. if v == 0 && !math.Signbit(float64(v)) {
  4269. return 0
  4270. }
  4271. return f.tagsize + protowire.SizeFixed64()
  4272. }
  4273. // appendDoubleNoZero wire encodes a float64 pointer as a Double.
  4274. // The zero value is not encoded.
  4275. func appendDoubleNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4276. v := *p.Float64()
  4277. if v == 0 && !math.Signbit(float64(v)) {
  4278. return b, nil
  4279. }
  4280. b = protowire.AppendVarint(b, f.wiretag)
  4281. b = protowire.AppendFixed64(b, math.Float64bits(v))
  4282. return b, nil
  4283. }
  4284. var coderDoubleNoZero = pointerCoderFuncs{
  4285. size: sizeDoubleNoZero,
  4286. marshal: appendDoubleNoZero,
  4287. unmarshal: consumeDouble,
  4288. merge: mergeFloat64NoZero,
  4289. }
  4290. // sizeDoublePtr returns the size of wire encoding a *float64 pointer as a Double.
  4291. // It panics if the pointer is nil.
  4292. func sizeDoublePtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4293. return f.tagsize + protowire.SizeFixed64()
  4294. }
  4295. // appendDoublePtr wire encodes a *float64 pointer as a Double.
  4296. // It panics if the pointer is nil.
  4297. func appendDoublePtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4298. v := **p.Float64Ptr()
  4299. b = protowire.AppendVarint(b, f.wiretag)
  4300. b = protowire.AppendFixed64(b, math.Float64bits(v))
  4301. return b, nil
  4302. }
  4303. // consumeDoublePtr wire decodes a *float64 pointer as a Double.
  4304. func consumeDoublePtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4305. if wtyp != protowire.Fixed64Type {
  4306. return out, errUnknown
  4307. }
  4308. v, n := protowire.ConsumeFixed64(b)
  4309. if n < 0 {
  4310. return out, errDecode
  4311. }
  4312. vp := p.Float64Ptr()
  4313. if *vp == nil {
  4314. *vp = new(float64)
  4315. }
  4316. **vp = math.Float64frombits(v)
  4317. out.n = n
  4318. return out, nil
  4319. }
  4320. var coderDoublePtr = pointerCoderFuncs{
  4321. size: sizeDoublePtr,
  4322. marshal: appendDoublePtr,
  4323. unmarshal: consumeDoublePtr,
  4324. merge: mergeFloat64Ptr,
  4325. }
  4326. // sizeDoubleSlice returns the size of wire encoding a []float64 pointer as a repeated Double.
  4327. func sizeDoubleSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4328. s := *p.Float64Slice()
  4329. size = len(s) * (f.tagsize + protowire.SizeFixed64())
  4330. return size
  4331. }
  4332. // appendDoubleSlice encodes a []float64 pointer as a repeated Double.
  4333. func appendDoubleSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4334. s := *p.Float64Slice()
  4335. for _, v := range s {
  4336. b = protowire.AppendVarint(b, f.wiretag)
  4337. b = protowire.AppendFixed64(b, math.Float64bits(v))
  4338. }
  4339. return b, nil
  4340. }
  4341. // consumeDoubleSlice wire decodes a []float64 pointer as a repeated Double.
  4342. func consumeDoubleSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4343. sp := p.Float64Slice()
  4344. if wtyp == protowire.BytesType {
  4345. s := *sp
  4346. b, n := protowire.ConsumeBytes(b)
  4347. if n < 0 {
  4348. return out, errDecode
  4349. }
  4350. for len(b) > 0 {
  4351. v, n := protowire.ConsumeFixed64(b)
  4352. if n < 0 {
  4353. return out, errDecode
  4354. }
  4355. s = append(s, math.Float64frombits(v))
  4356. b = b[n:]
  4357. }
  4358. *sp = s
  4359. out.n = n
  4360. return out, nil
  4361. }
  4362. if wtyp != protowire.Fixed64Type {
  4363. return out, errUnknown
  4364. }
  4365. v, n := protowire.ConsumeFixed64(b)
  4366. if n < 0 {
  4367. return out, errDecode
  4368. }
  4369. *sp = append(*sp, math.Float64frombits(v))
  4370. out.n = n
  4371. return out, nil
  4372. }
  4373. var coderDoubleSlice = pointerCoderFuncs{
  4374. size: sizeDoubleSlice,
  4375. marshal: appendDoubleSlice,
  4376. unmarshal: consumeDoubleSlice,
  4377. merge: mergeFloat64Slice,
  4378. }
  4379. // sizeDoublePackedSlice returns the size of wire encoding a []float64 pointer as a packed repeated Double.
  4380. func sizeDoublePackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4381. s := *p.Float64Slice()
  4382. if len(s) == 0 {
  4383. return 0
  4384. }
  4385. n := len(s) * protowire.SizeFixed64()
  4386. return f.tagsize + protowire.SizeBytes(n)
  4387. }
  4388. // appendDoublePackedSlice encodes a []float64 pointer as a packed repeated Double.
  4389. func appendDoublePackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4390. s := *p.Float64Slice()
  4391. if len(s) == 0 {
  4392. return b, nil
  4393. }
  4394. b = protowire.AppendVarint(b, f.wiretag)
  4395. n := len(s) * protowire.SizeFixed64()
  4396. b = protowire.AppendVarint(b, uint64(n))
  4397. for _, v := range s {
  4398. b = protowire.AppendFixed64(b, math.Float64bits(v))
  4399. }
  4400. return b, nil
  4401. }
  4402. var coderDoublePackedSlice = pointerCoderFuncs{
  4403. size: sizeDoublePackedSlice,
  4404. marshal: appendDoublePackedSlice,
  4405. unmarshal: consumeDoubleSlice,
  4406. merge: mergeFloat64Slice,
  4407. }
  4408. // sizeDoubleValue returns the size of wire encoding a float64 value as a Double.
  4409. func sizeDoubleValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  4410. return tagsize + protowire.SizeFixed64()
  4411. }
  4412. // appendDoubleValue encodes a float64 value as a Double.
  4413. func appendDoubleValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  4414. b = protowire.AppendVarint(b, wiretag)
  4415. b = protowire.AppendFixed64(b, math.Float64bits(v.Float()))
  4416. return b, nil
  4417. }
  4418. // consumeDoubleValue decodes a float64 value as a Double.
  4419. func consumeDoubleValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  4420. if wtyp != protowire.Fixed64Type {
  4421. return protoreflect.Value{}, out, errUnknown
  4422. }
  4423. v, n := protowire.ConsumeFixed64(b)
  4424. if n < 0 {
  4425. return protoreflect.Value{}, out, errDecode
  4426. }
  4427. out.n = n
  4428. return protoreflect.ValueOfFloat64(math.Float64frombits(v)), out, nil
  4429. }
  4430. var coderDoubleValue = valueCoderFuncs{
  4431. size: sizeDoubleValue,
  4432. marshal: appendDoubleValue,
  4433. unmarshal: consumeDoubleValue,
  4434. merge: mergeScalarValue,
  4435. }
  4436. // sizeDoubleSliceValue returns the size of wire encoding a []float64 value as a repeated Double.
  4437. func sizeDoubleSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  4438. list := listv.List()
  4439. size = list.Len() * (tagsize + protowire.SizeFixed64())
  4440. return size
  4441. }
  4442. // appendDoubleSliceValue encodes a []float64 value as a repeated Double.
  4443. func appendDoubleSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  4444. list := listv.List()
  4445. for i, llen := 0, list.Len(); i < llen; i++ {
  4446. v := list.Get(i)
  4447. b = protowire.AppendVarint(b, wiretag)
  4448. b = protowire.AppendFixed64(b, math.Float64bits(v.Float()))
  4449. }
  4450. return b, nil
  4451. }
  4452. // consumeDoubleSliceValue wire decodes a []float64 value as a repeated Double.
  4453. func consumeDoubleSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  4454. list := listv.List()
  4455. if wtyp == protowire.BytesType {
  4456. b, n := protowire.ConsumeBytes(b)
  4457. if n < 0 {
  4458. return protoreflect.Value{}, out, errDecode
  4459. }
  4460. for len(b) > 0 {
  4461. v, n := protowire.ConsumeFixed64(b)
  4462. if n < 0 {
  4463. return protoreflect.Value{}, out, errDecode
  4464. }
  4465. list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
  4466. b = b[n:]
  4467. }
  4468. out.n = n
  4469. return listv, out, nil
  4470. }
  4471. if wtyp != protowire.Fixed64Type {
  4472. return protoreflect.Value{}, out, errUnknown
  4473. }
  4474. v, n := protowire.ConsumeFixed64(b)
  4475. if n < 0 {
  4476. return protoreflect.Value{}, out, errDecode
  4477. }
  4478. list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
  4479. out.n = n
  4480. return listv, out, nil
  4481. }
  4482. var coderDoubleSliceValue = valueCoderFuncs{
  4483. size: sizeDoubleSliceValue,
  4484. marshal: appendDoubleSliceValue,
  4485. unmarshal: consumeDoubleSliceValue,
  4486. merge: mergeListValue,
  4487. }
  4488. // sizeDoublePackedSliceValue returns the size of wire encoding a []float64 value as a packed repeated Double.
  4489. func sizeDoublePackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  4490. list := listv.List()
  4491. llen := list.Len()
  4492. if llen == 0 {
  4493. return 0
  4494. }
  4495. n := llen * protowire.SizeFixed64()
  4496. return tagsize + protowire.SizeBytes(n)
  4497. }
  4498. // appendDoublePackedSliceValue encodes a []float64 value as a packed repeated Double.
  4499. func appendDoublePackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  4500. list := listv.List()
  4501. llen := list.Len()
  4502. if llen == 0 {
  4503. return b, nil
  4504. }
  4505. b = protowire.AppendVarint(b, wiretag)
  4506. n := llen * protowire.SizeFixed64()
  4507. b = protowire.AppendVarint(b, uint64(n))
  4508. for i := 0; i < llen; i++ {
  4509. v := list.Get(i)
  4510. b = protowire.AppendFixed64(b, math.Float64bits(v.Float()))
  4511. }
  4512. return b, nil
  4513. }
  4514. var coderDoublePackedSliceValue = valueCoderFuncs{
  4515. size: sizeDoublePackedSliceValue,
  4516. marshal: appendDoublePackedSliceValue,
  4517. unmarshal: consumeDoubleSliceValue,
  4518. merge: mergeListValue,
  4519. }
  4520. // sizeString returns the size of wire encoding a string pointer as a String.
  4521. func sizeString(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4522. v := *p.String()
  4523. return f.tagsize + protowire.SizeBytes(len(v))
  4524. }
  4525. // appendString wire encodes a string pointer as a String.
  4526. func appendString(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4527. v := *p.String()
  4528. b = protowire.AppendVarint(b, f.wiretag)
  4529. b = protowire.AppendString(b, v)
  4530. return b, nil
  4531. }
  4532. // consumeString wire decodes a string pointer as a String.
  4533. func consumeString(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4534. if wtyp != protowire.BytesType {
  4535. return out, errUnknown
  4536. }
  4537. v, n := protowire.ConsumeBytes(b)
  4538. if n < 0 {
  4539. return out, errDecode
  4540. }
  4541. *p.String() = string(v)
  4542. out.n = n
  4543. return out, nil
  4544. }
  4545. var coderString = pointerCoderFuncs{
  4546. size: sizeString,
  4547. marshal: appendString,
  4548. unmarshal: consumeString,
  4549. merge: mergeString,
  4550. }
  4551. // appendStringValidateUTF8 wire encodes a string pointer as a String.
  4552. func appendStringValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4553. v := *p.String()
  4554. b = protowire.AppendVarint(b, f.wiretag)
  4555. b = protowire.AppendString(b, v)
  4556. if !utf8.ValidString(v) {
  4557. return b, errInvalidUTF8{}
  4558. }
  4559. return b, nil
  4560. }
  4561. // consumeStringValidateUTF8 wire decodes a string pointer as a String.
  4562. func consumeStringValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4563. if wtyp != protowire.BytesType {
  4564. return out, errUnknown
  4565. }
  4566. v, n := protowire.ConsumeBytes(b)
  4567. if n < 0 {
  4568. return out, errDecode
  4569. }
  4570. if !utf8.Valid(v) {
  4571. return out, errInvalidUTF8{}
  4572. }
  4573. *p.String() = string(v)
  4574. out.n = n
  4575. return out, nil
  4576. }
  4577. var coderStringValidateUTF8 = pointerCoderFuncs{
  4578. size: sizeString,
  4579. marshal: appendStringValidateUTF8,
  4580. unmarshal: consumeStringValidateUTF8,
  4581. merge: mergeString,
  4582. }
  4583. // sizeStringNoZero returns the size of wire encoding a string pointer as a String.
  4584. // The zero value is not encoded.
  4585. func sizeStringNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4586. v := *p.String()
  4587. if len(v) == 0 {
  4588. return 0
  4589. }
  4590. return f.tagsize + protowire.SizeBytes(len(v))
  4591. }
  4592. // appendStringNoZero wire encodes a string pointer as a String.
  4593. // The zero value is not encoded.
  4594. func appendStringNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4595. v := *p.String()
  4596. if len(v) == 0 {
  4597. return b, nil
  4598. }
  4599. b = protowire.AppendVarint(b, f.wiretag)
  4600. b = protowire.AppendString(b, v)
  4601. return b, nil
  4602. }
  4603. var coderStringNoZero = pointerCoderFuncs{
  4604. size: sizeStringNoZero,
  4605. marshal: appendStringNoZero,
  4606. unmarshal: consumeString,
  4607. merge: mergeStringNoZero,
  4608. }
  4609. // appendStringNoZeroValidateUTF8 wire encodes a string pointer as a String.
  4610. // The zero value is not encoded.
  4611. func appendStringNoZeroValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4612. v := *p.String()
  4613. if len(v) == 0 {
  4614. return b, nil
  4615. }
  4616. b = protowire.AppendVarint(b, f.wiretag)
  4617. b = protowire.AppendString(b, v)
  4618. if !utf8.ValidString(v) {
  4619. return b, errInvalidUTF8{}
  4620. }
  4621. return b, nil
  4622. }
  4623. var coderStringNoZeroValidateUTF8 = pointerCoderFuncs{
  4624. size: sizeStringNoZero,
  4625. marshal: appendStringNoZeroValidateUTF8,
  4626. unmarshal: consumeStringValidateUTF8,
  4627. merge: mergeStringNoZero,
  4628. }
  4629. // sizeStringPtr returns the size of wire encoding a *string pointer as a String.
  4630. // It panics if the pointer is nil.
  4631. func sizeStringPtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4632. v := **p.StringPtr()
  4633. return f.tagsize + protowire.SizeBytes(len(v))
  4634. }
  4635. // appendStringPtr wire encodes a *string pointer as a String.
  4636. // It panics if the pointer is nil.
  4637. func appendStringPtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4638. v := **p.StringPtr()
  4639. b = protowire.AppendVarint(b, f.wiretag)
  4640. b = protowire.AppendString(b, v)
  4641. return b, nil
  4642. }
  4643. // consumeStringPtr wire decodes a *string pointer as a String.
  4644. func consumeStringPtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4645. if wtyp != protowire.BytesType {
  4646. return out, errUnknown
  4647. }
  4648. v, n := protowire.ConsumeBytes(b)
  4649. if n < 0 {
  4650. return out, errDecode
  4651. }
  4652. vp := p.StringPtr()
  4653. if *vp == nil {
  4654. *vp = new(string)
  4655. }
  4656. **vp = string(v)
  4657. out.n = n
  4658. return out, nil
  4659. }
  4660. var coderStringPtr = pointerCoderFuncs{
  4661. size: sizeStringPtr,
  4662. marshal: appendStringPtr,
  4663. unmarshal: consumeStringPtr,
  4664. merge: mergeStringPtr,
  4665. }
  4666. // appendStringPtrValidateUTF8 wire encodes a *string pointer as a String.
  4667. // It panics if the pointer is nil.
  4668. func appendStringPtrValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4669. v := **p.StringPtr()
  4670. b = protowire.AppendVarint(b, f.wiretag)
  4671. b = protowire.AppendString(b, v)
  4672. if !utf8.ValidString(v) {
  4673. return b, errInvalidUTF8{}
  4674. }
  4675. return b, nil
  4676. }
  4677. // consumeStringPtrValidateUTF8 wire decodes a *string pointer as a String.
  4678. func consumeStringPtrValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4679. if wtyp != protowire.BytesType {
  4680. return out, errUnknown
  4681. }
  4682. v, n := protowire.ConsumeBytes(b)
  4683. if n < 0 {
  4684. return out, errDecode
  4685. }
  4686. if !utf8.Valid(v) {
  4687. return out, errInvalidUTF8{}
  4688. }
  4689. vp := p.StringPtr()
  4690. if *vp == nil {
  4691. *vp = new(string)
  4692. }
  4693. **vp = string(v)
  4694. out.n = n
  4695. return out, nil
  4696. }
  4697. var coderStringPtrValidateUTF8 = pointerCoderFuncs{
  4698. size: sizeStringPtr,
  4699. marshal: appendStringPtrValidateUTF8,
  4700. unmarshal: consumeStringPtrValidateUTF8,
  4701. merge: mergeStringPtr,
  4702. }
  4703. // sizeStringSlice returns the size of wire encoding a []string pointer as a repeated String.
  4704. func sizeStringSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4705. s := *p.StringSlice()
  4706. for _, v := range s {
  4707. size += f.tagsize + protowire.SizeBytes(len(v))
  4708. }
  4709. return size
  4710. }
  4711. // appendStringSlice encodes a []string pointer as a repeated String.
  4712. func appendStringSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4713. s := *p.StringSlice()
  4714. for _, v := range s {
  4715. b = protowire.AppendVarint(b, f.wiretag)
  4716. b = protowire.AppendString(b, v)
  4717. }
  4718. return b, nil
  4719. }
  4720. // consumeStringSlice wire decodes a []string pointer as a repeated String.
  4721. func consumeStringSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4722. sp := p.StringSlice()
  4723. if wtyp != protowire.BytesType {
  4724. return out, errUnknown
  4725. }
  4726. v, n := protowire.ConsumeBytes(b)
  4727. if n < 0 {
  4728. return out, errDecode
  4729. }
  4730. *sp = append(*sp, string(v))
  4731. out.n = n
  4732. return out, nil
  4733. }
  4734. var coderStringSlice = pointerCoderFuncs{
  4735. size: sizeStringSlice,
  4736. marshal: appendStringSlice,
  4737. unmarshal: consumeStringSlice,
  4738. merge: mergeStringSlice,
  4739. }
  4740. // appendStringSliceValidateUTF8 encodes a []string pointer as a repeated String.
  4741. func appendStringSliceValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4742. s := *p.StringSlice()
  4743. for _, v := range s {
  4744. b = protowire.AppendVarint(b, f.wiretag)
  4745. b = protowire.AppendString(b, v)
  4746. if !utf8.ValidString(v) {
  4747. return b, errInvalidUTF8{}
  4748. }
  4749. }
  4750. return b, nil
  4751. }
  4752. // consumeStringSliceValidateUTF8 wire decodes a []string pointer as a repeated String.
  4753. func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4754. if wtyp != protowire.BytesType {
  4755. return out, errUnknown
  4756. }
  4757. v, n := protowire.ConsumeBytes(b)
  4758. if n < 0 {
  4759. return out, errDecode
  4760. }
  4761. if !utf8.Valid(v) {
  4762. return out, errInvalidUTF8{}
  4763. }
  4764. sp := p.StringSlice()
  4765. *sp = append(*sp, string(v))
  4766. out.n = n
  4767. return out, nil
  4768. }
  4769. var coderStringSliceValidateUTF8 = pointerCoderFuncs{
  4770. size: sizeStringSlice,
  4771. marshal: appendStringSliceValidateUTF8,
  4772. unmarshal: consumeStringSliceValidateUTF8,
  4773. merge: mergeStringSlice,
  4774. }
  4775. // sizeStringValue returns the size of wire encoding a string value as a String.
  4776. func sizeStringValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  4777. return tagsize + protowire.SizeBytes(len(v.String()))
  4778. }
  4779. // appendStringValue encodes a string value as a String.
  4780. func appendStringValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  4781. b = protowire.AppendVarint(b, wiretag)
  4782. b = protowire.AppendString(b, v.String())
  4783. return b, nil
  4784. }
  4785. // consumeStringValue decodes a string value as a String.
  4786. func consumeStringValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  4787. if wtyp != protowire.BytesType {
  4788. return protoreflect.Value{}, out, errUnknown
  4789. }
  4790. v, n := protowire.ConsumeBytes(b)
  4791. if n < 0 {
  4792. return protoreflect.Value{}, out, errDecode
  4793. }
  4794. out.n = n
  4795. return protoreflect.ValueOfString(string(v)), out, nil
  4796. }
  4797. var coderStringValue = valueCoderFuncs{
  4798. size: sizeStringValue,
  4799. marshal: appendStringValue,
  4800. unmarshal: consumeStringValue,
  4801. merge: mergeScalarValue,
  4802. }
  4803. // appendStringValueValidateUTF8 encodes a string value as a String.
  4804. func appendStringValueValidateUTF8(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  4805. b = protowire.AppendVarint(b, wiretag)
  4806. b = protowire.AppendString(b, v.String())
  4807. if !utf8.ValidString(v.String()) {
  4808. return b, errInvalidUTF8{}
  4809. }
  4810. return b, nil
  4811. }
  4812. // consumeStringValueValidateUTF8 decodes a string value as a String.
  4813. func consumeStringValueValidateUTF8(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  4814. if wtyp != protowire.BytesType {
  4815. return protoreflect.Value{}, out, errUnknown
  4816. }
  4817. v, n := protowire.ConsumeBytes(b)
  4818. if n < 0 {
  4819. return protoreflect.Value{}, out, errDecode
  4820. }
  4821. if !utf8.Valid(v) {
  4822. return protoreflect.Value{}, out, errInvalidUTF8{}
  4823. }
  4824. out.n = n
  4825. return protoreflect.ValueOfString(string(v)), out, nil
  4826. }
  4827. var coderStringValueValidateUTF8 = valueCoderFuncs{
  4828. size: sizeStringValue,
  4829. marshal: appendStringValueValidateUTF8,
  4830. unmarshal: consumeStringValueValidateUTF8,
  4831. merge: mergeScalarValue,
  4832. }
  4833. // sizeStringSliceValue returns the size of wire encoding a []string value as a repeated String.
  4834. func sizeStringSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  4835. list := listv.List()
  4836. for i, llen := 0, list.Len(); i < llen; i++ {
  4837. v := list.Get(i)
  4838. size += tagsize + protowire.SizeBytes(len(v.String()))
  4839. }
  4840. return size
  4841. }
  4842. // appendStringSliceValue encodes a []string value as a repeated String.
  4843. func appendStringSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  4844. list := listv.List()
  4845. for i, llen := 0, list.Len(); i < llen; i++ {
  4846. v := list.Get(i)
  4847. b = protowire.AppendVarint(b, wiretag)
  4848. b = protowire.AppendString(b, v.String())
  4849. }
  4850. return b, nil
  4851. }
  4852. // consumeStringSliceValue wire decodes a []string value as a repeated String.
  4853. func consumeStringSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  4854. list := listv.List()
  4855. if wtyp != protowire.BytesType {
  4856. return protoreflect.Value{}, out, errUnknown
  4857. }
  4858. v, n := protowire.ConsumeBytes(b)
  4859. if n < 0 {
  4860. return protoreflect.Value{}, out, errDecode
  4861. }
  4862. list.Append(protoreflect.ValueOfString(string(v)))
  4863. out.n = n
  4864. return listv, out, nil
  4865. }
  4866. var coderStringSliceValue = valueCoderFuncs{
  4867. size: sizeStringSliceValue,
  4868. marshal: appendStringSliceValue,
  4869. unmarshal: consumeStringSliceValue,
  4870. merge: mergeListValue,
  4871. }
  4872. // sizeBytes returns the size of wire encoding a []byte pointer as a Bytes.
  4873. func sizeBytes(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4874. v := *p.Bytes()
  4875. return f.tagsize + protowire.SizeBytes(len(v))
  4876. }
  4877. // appendBytes wire encodes a []byte pointer as a Bytes.
  4878. func appendBytes(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4879. v := *p.Bytes()
  4880. b = protowire.AppendVarint(b, f.wiretag)
  4881. b = protowire.AppendBytes(b, v)
  4882. return b, nil
  4883. }
  4884. // consumeBytes wire decodes a []byte pointer as a Bytes.
  4885. func consumeBytes(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4886. if wtyp != protowire.BytesType {
  4887. return out, errUnknown
  4888. }
  4889. v, n := protowire.ConsumeBytes(b)
  4890. if n < 0 {
  4891. return out, errDecode
  4892. }
  4893. *p.Bytes() = append(emptyBuf[:], v...)
  4894. out.n = n
  4895. return out, nil
  4896. }
  4897. var coderBytes = pointerCoderFuncs{
  4898. size: sizeBytes,
  4899. marshal: appendBytes,
  4900. unmarshal: consumeBytes,
  4901. merge: mergeBytes,
  4902. }
  4903. // appendBytesValidateUTF8 wire encodes a []byte pointer as a Bytes.
  4904. func appendBytesValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4905. v := *p.Bytes()
  4906. b = protowire.AppendVarint(b, f.wiretag)
  4907. b = protowire.AppendBytes(b, v)
  4908. if !utf8.Valid(v) {
  4909. return b, errInvalidUTF8{}
  4910. }
  4911. return b, nil
  4912. }
  4913. // consumeBytesValidateUTF8 wire decodes a []byte pointer as a Bytes.
  4914. func consumeBytesValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4915. if wtyp != protowire.BytesType {
  4916. return out, errUnknown
  4917. }
  4918. v, n := protowire.ConsumeBytes(b)
  4919. if n < 0 {
  4920. return out, errDecode
  4921. }
  4922. if !utf8.Valid(v) {
  4923. return out, errInvalidUTF8{}
  4924. }
  4925. *p.Bytes() = append(emptyBuf[:], v...)
  4926. out.n = n
  4927. return out, nil
  4928. }
  4929. var coderBytesValidateUTF8 = pointerCoderFuncs{
  4930. size: sizeBytes,
  4931. marshal: appendBytesValidateUTF8,
  4932. unmarshal: consumeBytesValidateUTF8,
  4933. merge: mergeBytes,
  4934. }
  4935. // sizeBytesNoZero returns the size of wire encoding a []byte pointer as a Bytes.
  4936. // The zero value is not encoded.
  4937. func sizeBytesNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  4938. v := *p.Bytes()
  4939. if len(v) == 0 {
  4940. return 0
  4941. }
  4942. return f.tagsize + protowire.SizeBytes(len(v))
  4943. }
  4944. // appendBytesNoZero wire encodes a []byte pointer as a Bytes.
  4945. // The zero value is not encoded.
  4946. func appendBytesNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4947. v := *p.Bytes()
  4948. if len(v) == 0 {
  4949. return b, nil
  4950. }
  4951. b = protowire.AppendVarint(b, f.wiretag)
  4952. b = protowire.AppendBytes(b, v)
  4953. return b, nil
  4954. }
  4955. // consumeBytesNoZero wire decodes a []byte pointer as a Bytes.
  4956. // The zero value is not decoded.
  4957. func consumeBytesNoZero(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4958. if wtyp != protowire.BytesType {
  4959. return out, errUnknown
  4960. }
  4961. v, n := protowire.ConsumeBytes(b)
  4962. if n < 0 {
  4963. return out, errDecode
  4964. }
  4965. *p.Bytes() = append(([]byte)(nil), v...)
  4966. out.n = n
  4967. return out, nil
  4968. }
  4969. var coderBytesNoZero = pointerCoderFuncs{
  4970. size: sizeBytesNoZero,
  4971. marshal: appendBytesNoZero,
  4972. unmarshal: consumeBytesNoZero,
  4973. merge: mergeBytesNoZero,
  4974. }
  4975. // appendBytesNoZeroValidateUTF8 wire encodes a []byte pointer as a Bytes.
  4976. // The zero value is not encoded.
  4977. func appendBytesNoZeroValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  4978. v := *p.Bytes()
  4979. if len(v) == 0 {
  4980. return b, nil
  4981. }
  4982. b = protowire.AppendVarint(b, f.wiretag)
  4983. b = protowire.AppendBytes(b, v)
  4984. if !utf8.Valid(v) {
  4985. return b, errInvalidUTF8{}
  4986. }
  4987. return b, nil
  4988. }
  4989. // consumeBytesNoZeroValidateUTF8 wire decodes a []byte pointer as a Bytes.
  4990. func consumeBytesNoZeroValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  4991. if wtyp != protowire.BytesType {
  4992. return out, errUnknown
  4993. }
  4994. v, n := protowire.ConsumeBytes(b)
  4995. if n < 0 {
  4996. return out, errDecode
  4997. }
  4998. if !utf8.Valid(v) {
  4999. return out, errInvalidUTF8{}
  5000. }
  5001. *p.Bytes() = append(([]byte)(nil), v...)
  5002. out.n = n
  5003. return out, nil
  5004. }
  5005. var coderBytesNoZeroValidateUTF8 = pointerCoderFuncs{
  5006. size: sizeBytesNoZero,
  5007. marshal: appendBytesNoZeroValidateUTF8,
  5008. unmarshal: consumeBytesNoZeroValidateUTF8,
  5009. merge: mergeBytesNoZero,
  5010. }
  5011. // sizeBytesSlice returns the size of wire encoding a [][]byte pointer as a repeated Bytes.
  5012. func sizeBytesSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
  5013. s := *p.BytesSlice()
  5014. for _, v := range s {
  5015. size += f.tagsize + protowire.SizeBytes(len(v))
  5016. }
  5017. return size
  5018. }
  5019. // appendBytesSlice encodes a [][]byte pointer as a repeated Bytes.
  5020. func appendBytesSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  5021. s := *p.BytesSlice()
  5022. for _, v := range s {
  5023. b = protowire.AppendVarint(b, f.wiretag)
  5024. b = protowire.AppendBytes(b, v)
  5025. }
  5026. return b, nil
  5027. }
  5028. // consumeBytesSlice wire decodes a [][]byte pointer as a repeated Bytes.
  5029. func consumeBytesSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  5030. sp := p.BytesSlice()
  5031. if wtyp != protowire.BytesType {
  5032. return out, errUnknown
  5033. }
  5034. v, n := protowire.ConsumeBytes(b)
  5035. if n < 0 {
  5036. return out, errDecode
  5037. }
  5038. *sp = append(*sp, append(emptyBuf[:], v...))
  5039. out.n = n
  5040. return out, nil
  5041. }
  5042. var coderBytesSlice = pointerCoderFuncs{
  5043. size: sizeBytesSlice,
  5044. marshal: appendBytesSlice,
  5045. unmarshal: consumeBytesSlice,
  5046. merge: mergeBytesSlice,
  5047. }
  5048. // appendBytesSliceValidateUTF8 encodes a [][]byte pointer as a repeated Bytes.
  5049. func appendBytesSliceValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
  5050. s := *p.BytesSlice()
  5051. for _, v := range s {
  5052. b = protowire.AppendVarint(b, f.wiretag)
  5053. b = protowire.AppendBytes(b, v)
  5054. if !utf8.Valid(v) {
  5055. return b, errInvalidUTF8{}
  5056. }
  5057. }
  5058. return b, nil
  5059. }
  5060. // consumeBytesSliceValidateUTF8 wire decodes a [][]byte pointer as a repeated Bytes.
  5061. func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
  5062. if wtyp != protowire.BytesType {
  5063. return out, errUnknown
  5064. }
  5065. v, n := protowire.ConsumeBytes(b)
  5066. if n < 0 {
  5067. return out, errDecode
  5068. }
  5069. if !utf8.Valid(v) {
  5070. return out, errInvalidUTF8{}
  5071. }
  5072. sp := p.BytesSlice()
  5073. *sp = append(*sp, append(emptyBuf[:], v...))
  5074. out.n = n
  5075. return out, nil
  5076. }
  5077. var coderBytesSliceValidateUTF8 = pointerCoderFuncs{
  5078. size: sizeBytesSlice,
  5079. marshal: appendBytesSliceValidateUTF8,
  5080. unmarshal: consumeBytesSliceValidateUTF8,
  5081. merge: mergeBytesSlice,
  5082. }
  5083. // sizeBytesValue returns the size of wire encoding a []byte value as a Bytes.
  5084. func sizeBytesValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
  5085. return tagsize + protowire.SizeBytes(len(v.Bytes()))
  5086. }
  5087. // appendBytesValue encodes a []byte value as a Bytes.
  5088. func appendBytesValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  5089. b = protowire.AppendVarint(b, wiretag)
  5090. b = protowire.AppendBytes(b, v.Bytes())
  5091. return b, nil
  5092. }
  5093. // consumeBytesValue decodes a []byte value as a Bytes.
  5094. func consumeBytesValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  5095. if wtyp != protowire.BytesType {
  5096. return protoreflect.Value{}, out, errUnknown
  5097. }
  5098. v, n := protowire.ConsumeBytes(b)
  5099. if n < 0 {
  5100. return protoreflect.Value{}, out, errDecode
  5101. }
  5102. out.n = n
  5103. return protoreflect.ValueOfBytes(append(emptyBuf[:], v...)), out, nil
  5104. }
  5105. var coderBytesValue = valueCoderFuncs{
  5106. size: sizeBytesValue,
  5107. marshal: appendBytesValue,
  5108. unmarshal: consumeBytesValue,
  5109. merge: mergeBytesValue,
  5110. }
  5111. // sizeBytesSliceValue returns the size of wire encoding a [][]byte value as a repeated Bytes.
  5112. func sizeBytesSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
  5113. list := listv.List()
  5114. for i, llen := 0, list.Len(); i < llen; i++ {
  5115. v := list.Get(i)
  5116. size += tagsize + protowire.SizeBytes(len(v.Bytes()))
  5117. }
  5118. return size
  5119. }
  5120. // appendBytesSliceValue encodes a [][]byte value as a repeated Bytes.
  5121. func appendBytesSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
  5122. list := listv.List()
  5123. for i, llen := 0, list.Len(); i < llen; i++ {
  5124. v := list.Get(i)
  5125. b = protowire.AppendVarint(b, wiretag)
  5126. b = protowire.AppendBytes(b, v.Bytes())
  5127. }
  5128. return b, nil
  5129. }
  5130. // consumeBytesSliceValue wire decodes a [][]byte value as a repeated Bytes.
  5131. func consumeBytesSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
  5132. list := listv.List()
  5133. if wtyp != protowire.BytesType {
  5134. return protoreflect.Value{}, out, errUnknown
  5135. }
  5136. v, n := protowire.ConsumeBytes(b)
  5137. if n < 0 {
  5138. return protoreflect.Value{}, out, errDecode
  5139. }
  5140. list.Append(protoreflect.ValueOfBytes(append(emptyBuf[:], v...)))
  5141. out.n = n
  5142. return listv, out, nil
  5143. }
  5144. var coderBytesSliceValue = valueCoderFuncs{
  5145. size: sizeBytesSliceValue,
  5146. marshal: appendBytesSliceValue,
  5147. unmarshal: consumeBytesSliceValue,
  5148. merge: mergeBytesListValue,
  5149. }
  5150. // We append to an empty array rather than a nil []byte to get non-nil zero-length byte slices.
  5151. var emptyBuf [0]byte
  5152. var wireTypes = map[protoreflect.Kind]protowire.Type{
  5153. protoreflect.BoolKind: protowire.VarintType,
  5154. protoreflect.EnumKind: protowire.VarintType,
  5155. protoreflect.Int32Kind: protowire.VarintType,
  5156. protoreflect.Sint32Kind: protowire.VarintType,
  5157. protoreflect.Uint32Kind: protowire.VarintType,
  5158. protoreflect.Int64Kind: protowire.VarintType,
  5159. protoreflect.Sint64Kind: protowire.VarintType,
  5160. protoreflect.Uint64Kind: protowire.VarintType,
  5161. protoreflect.Sfixed32Kind: protowire.Fixed32Type,
  5162. protoreflect.Fixed32Kind: protowire.Fixed32Type,
  5163. protoreflect.FloatKind: protowire.Fixed32Type,
  5164. protoreflect.Sfixed64Kind: protowire.Fixed64Type,
  5165. protoreflect.Fixed64Kind: protowire.Fixed64Type,
  5166. protoreflect.DoubleKind: protowire.Fixed64Type,
  5167. protoreflect.StringKind: protowire.BytesType,
  5168. protoreflect.BytesKind: protowire.BytesType,
  5169. protoreflect.MessageKind: protowire.BytesType,
  5170. protoreflect.GroupKind: protowire.StartGroupType,
  5171. }