codec_gen.go 163 KB

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