opencost_codecs.go 240 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // DO NOT MODIFY
  4. //
  5. // ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻
  6. //
  7. //
  8. // This source file was automatically generated by bingen.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. package opencost
  12. import (
  13. "fmt"
  14. "io"
  15. "iter"
  16. "os"
  17. "reflect"
  18. "strings"
  19. "sync"
  20. "sync/atomic"
  21. "time"
  22. "unsafe"
  23. util "github.com/opencost/opencost/core/pkg/util"
  24. )
  25. const (
  26. // GeneratorPackageName is the package the generator is targetting
  27. GeneratorPackageName string = "opencost"
  28. )
  29. // BinaryTags represent the formatting tag used for specific optimization features
  30. const (
  31. // BinaryTagStringTable is written and/or read prior to the existence of a string
  32. // table (where each index is encoded as a string entry in the resource
  33. BinaryTagStringTable string = "BGST"
  34. )
  35. const (
  36. // CloudCostCodecVersion is used for any resources listed in the CloudCost version set
  37. CloudCostCodecVersion uint8 = 3
  38. // NetworkInsightCodecVersion is used for any resources listed in the NetworkInsight version set
  39. NetworkInsightCodecVersion uint8 = 1
  40. // DefaultCodecVersion is used for any resources listed in the Default version set
  41. DefaultCodecVersion uint8 = 18
  42. // AssetsCodecVersion is used for any resources listed in the Assets version set
  43. AssetsCodecVersion uint8 = 21
  44. // AllocationCodecVersion is used for any resources listed in the Allocation version set
  45. AllocationCodecVersion uint8 = 25
  46. )
  47. //--------------------------------------------------------------------------
  48. // Configuration
  49. //--------------------------------------------------------------------------
  50. var (
  51. bingenConfigLock sync.RWMutex
  52. bingenConfig *BingenConfiguration = DefaultBingenConfiguration()
  53. )
  54. // BingenConfiguration is used to set any custom configuration in the way files are encoded
  55. // or decoded.
  56. type BingenConfiguration struct {
  57. // FileBackedStringTableEnabled enables the use of file-backed string tables for streaming
  58. // bingen decoding.
  59. FileBackedStringTableEnabled bool
  60. // FileBackedStringTableDir is the directory to write the string table files for reading.
  61. FileBackedStringTableDir string
  62. // FileBackedStringTableMemoMaxBytes limits in-memory memoization for file-backed table lookups.
  63. // 0 disables memoization.
  64. FileBackedStringTableMemoMaxBytes int64
  65. }
  66. // DefaultBingenConfiguration creates the default implementation of the bingen configuration
  67. // and returns it.
  68. func DefaultBingenConfiguration() *BingenConfiguration {
  69. return &BingenConfiguration{
  70. FileBackedStringTableEnabled: false,
  71. FileBackedStringTableDir: os.TempDir(),
  72. FileBackedStringTableMemoMaxBytes: 0,
  73. }
  74. }
  75. // ConfigureBingen accepts a new *BingenConfiguration instance which updates the internal decoder
  76. // and encoder behavior.
  77. func ConfigureBingen(config *BingenConfiguration) {
  78. bingenConfigLock.Lock()
  79. defer bingenConfigLock.Unlock()
  80. if config == nil {
  81. config = DefaultBingenConfiguration()
  82. }
  83. bingenConfig = config
  84. }
  85. // IsBingenFileBackedStringTableEnabled accessor for file backed string table configuration
  86. func IsBingenFileBackedStringTableEnabled() bool {
  87. bingenConfigLock.RLock()
  88. defer bingenConfigLock.RUnlock()
  89. return bingenConfig.FileBackedStringTableEnabled
  90. }
  91. // BingenFileBackedStringTableDir returns the directory configured for file backed string tables.
  92. func BingenFileBackedStringTableDir() string {
  93. bingenConfigLock.RLock()
  94. defer bingenConfigLock.RUnlock()
  95. return bingenConfig.FileBackedStringTableDir
  96. }
  97. // BingenFileBackedStringTableMemoMaxBytes returns the maximum bytes used for file-backed memo cache.
  98. func BingenFileBackedStringTableMemoMaxBytes() int64 {
  99. bingenConfigLock.RLock()
  100. defer bingenConfigLock.RUnlock()
  101. return bingenConfig.FileBackedStringTableMemoMaxBytes
  102. }
  103. //--------------------------------------------------------------------------
  104. // Type Map
  105. //--------------------------------------------------------------------------
  106. // Generated type map for resolving interface implementations to
  107. // to concrete types
  108. var typeMap map[string]reflect.Type = map[string]reflect.Type{
  109. "Allocation": reflect.TypeFor[Allocation](),
  110. "AllocationProperties": reflect.TypeFor[AllocationProperties](),
  111. "AllocationSet": reflect.TypeFor[AllocationSet](),
  112. "AllocationSetRange": reflect.TypeFor[AllocationSetRange](),
  113. "Any": reflect.TypeFor[Any](),
  114. "AssetProperties": reflect.TypeFor[AssetProperties](),
  115. "AssetSet": reflect.TypeFor[AssetSet](),
  116. "AssetSetRange": reflect.TypeFor[AssetSetRange](),
  117. "Breakdown": reflect.TypeFor[Breakdown](),
  118. "Cloud": reflect.TypeFor[Cloud](),
  119. "CloudCost": reflect.TypeFor[CloudCost](),
  120. "CloudCostProperties": reflect.TypeFor[CloudCostProperties](),
  121. "CloudCostSet": reflect.TypeFor[CloudCostSet](),
  122. "CloudCostSetRange": reflect.TypeFor[CloudCostSetRange](),
  123. "ClusterManagement": reflect.TypeFor[ClusterManagement](),
  124. "CostMetric": reflect.TypeFor[CostMetric](),
  125. "Disk": reflect.TypeFor[Disk](),
  126. "GPUAllocation": reflect.TypeFor[GPUAllocation](),
  127. "LbAllocation": reflect.TypeFor[LbAllocation](),
  128. "LoadBalancer": reflect.TypeFor[LoadBalancer](),
  129. "Network": reflect.TypeFor[Network](),
  130. "NetworkDetail": reflect.TypeFor[NetworkDetail](),
  131. "NetworkInsight": reflect.TypeFor[NetworkInsight](),
  132. "NetworkInsightSet": reflect.TypeFor[NetworkInsightSet](),
  133. "Node": reflect.TypeFor[Node](),
  134. "NodeOverhead": reflect.TypeFor[NodeOverhead](),
  135. "PVAllocation": reflect.TypeFor[PVAllocation](),
  136. "PVKey": reflect.TypeFor[PVKey](),
  137. "RawAllocationOnlyData": reflect.TypeFor[RawAllocationOnlyData](),
  138. "SharedAsset": reflect.TypeFor[SharedAsset](),
  139. "Window": reflect.TypeFor[Window](),
  140. }
  141. //--------------------------------------------------------------------------
  142. // Type Helpers
  143. //--------------------------------------------------------------------------
  144. // isBinaryTag returns true when the first bytes in the provided binary matches the tag
  145. func isBinaryTag(data []byte, tag string) bool {
  146. if len(data) < len(tag) {
  147. return false
  148. }
  149. return string(data[:len(tag)]) == tag
  150. }
  151. // isReaderBinaryTag is used to peek the header for an io.Reader Buffer
  152. func isReaderBinaryTag(buff *util.Buffer, tag string) bool {
  153. data, err := buff.Peek(len(tag))
  154. if err != nil && err != io.EOF {
  155. panic(fmt.Sprintf("called Peek() on a non buffered reader: %s", err))
  156. }
  157. if len(data) < len(tag) {
  158. return false
  159. }
  160. return string(data[:len(tag)]) == tag
  161. }
  162. // appendBytes combines a and b into a new byte array
  163. func appendBytes(a []byte, b []byte) []byte {
  164. al := len(a)
  165. bl := len(b)
  166. tl := al + bl
  167. // allocate a new byte array for the combined
  168. // use native copy for speedy byte copying
  169. result := make([]byte, tl)
  170. copy(result, a)
  171. copy(result[al:], b)
  172. return result
  173. }
  174. // typeToString determines the basic properties of the type, the qualifier, package path, and
  175. // type name, and returns the qualified type
  176. func typeToString(f interface{}) string {
  177. qual := ""
  178. t := reflect.TypeOf(f)
  179. if t.Kind() == reflect.Ptr {
  180. t = t.Elem()
  181. qual = "*"
  182. }
  183. return fmt.Sprintf("%s%s.%s", qual, t.PkgPath(), t.Name())
  184. }
  185. // resolveType uses the name of a type and returns the package, base type name, and whether
  186. // or not it's a pointer.
  187. func resolveType(t string) (pkg string, name string, isPtr bool) {
  188. isPtr = t[:1] == "*"
  189. if isPtr {
  190. t = t[1:]
  191. }
  192. slashIndex := strings.LastIndex(t, "/")
  193. if slashIndex >= 0 {
  194. t = t[slashIndex+1:]
  195. }
  196. parts := strings.Split(t, ".")
  197. if parts[0] == GeneratorPackageName {
  198. parts[0] = ""
  199. }
  200. pkg = parts[0]
  201. name = parts[1]
  202. return
  203. }
  204. //--------------------------------------------------------------------------
  205. // Stream Helpers
  206. //--------------------------------------------------------------------------
  207. // StreamFactoryFunc is an alias for a func that creates a BingenStream implementation.
  208. type StreamFactoryFunc func(io.Reader) BingenStream
  209. // Generated streamable factory map for finding the specific new stream methods
  210. // by T type
  211. var streamFactoryMap map[reflect.Type]StreamFactoryFunc = map[reflect.Type]StreamFactoryFunc{
  212. reflect.TypeFor[AllocationSet](): NewAllocationSetStream,
  213. reflect.TypeFor[AssetSet](): NewAssetSetStream,
  214. reflect.TypeFor[CloudCostSet](): NewCloudCostSetStream,
  215. reflect.TypeFor[NetworkInsightSet](): NewNetworkInsightSetStream,
  216. }
  217. // NewStreamFor accepts an io.Reader, and returns a new BingenStream for the generic T
  218. // type provided _if_ it is a registered bingen type that is annotated as 'streamable'. See
  219. // the streamFactoryMap for generated type listings.
  220. func NewStreamFor[T any](reader io.Reader) (BingenStream, error) {
  221. typeKey := reflect.TypeFor[T]()
  222. factory, ok := streamFactoryMap[typeKey]
  223. if !ok {
  224. return nil, fmt.Errorf("the type: %s is not a registered bingen streamable type", typeKey.Name())
  225. }
  226. return factory(reader), nil
  227. }
  228. // BingenStream is the stream interface for all streamable types
  229. type BingenStream interface {
  230. // Stream returns the iterator which will stream each field of the target type and
  231. // return the field info as well as the value.
  232. Stream() iter.Seq2[BingenFieldInfo, *BingenValue]
  233. // Close will close any dynamic io.Reader used to stream in the fields
  234. Close()
  235. // Error returns an error if one occurred during the process of streaming the type's fields.
  236. // This can be checked after iterating through the Stream().
  237. Error() error
  238. }
  239. // BingenValue contains the value of a field as well as any index/key associated with that value.
  240. type BingenValue struct {
  241. Value any
  242. Index any
  243. }
  244. // IsNil is just a method accessor way to check to see if the value returned was nil
  245. func (bv *BingenValue) IsNil() bool {
  246. return bv == nil
  247. }
  248. // creates a single BingenValue instance without a key or index
  249. func singleV(value any) *BingenValue {
  250. return &BingenValue{
  251. Value: value,
  252. }
  253. }
  254. // creates a pair of key/index and value.
  255. func pairV(index any, value any) *BingenValue {
  256. return &BingenValue{
  257. Value: value,
  258. Index: index,
  259. }
  260. }
  261. // BingenFieldInfo contains the type of the field being streamed as well as the name of the field.
  262. type BingenFieldInfo struct {
  263. Type reflect.Type
  264. Name string
  265. }
  266. //--------------------------------------------------------------------------
  267. // String Table Writer
  268. //--------------------------------------------------------------------------
  269. // StringTableWriter maps strings to specific indices for encoding
  270. type StringTableWriter struct {
  271. l sync.Mutex
  272. indices map[string]int
  273. next int
  274. }
  275. // NewStringTableWriter Creates a new StringTableWriter instance with provided contents
  276. func NewStringTableWriter(contents ...string) *StringTableWriter {
  277. st := &StringTableWriter{
  278. indices: make(map[string]int, len(contents)),
  279. next: len(contents),
  280. }
  281. for i, entry := range contents {
  282. st.indices[entry] = i
  283. }
  284. return st
  285. }
  286. // AddOrGet atomically retrieves a string entry's index if it exist. Otherwise, it will
  287. // add the entry and return the index.
  288. func (st *StringTableWriter) AddOrGet(s string) int {
  289. st.l.Lock()
  290. defer st.l.Unlock()
  291. if ind, ok := st.indices[s]; ok {
  292. return ind
  293. }
  294. current := st.next
  295. st.next++
  296. st.indices[s] = current
  297. return current
  298. }
  299. // ToSlice Converts the contents to a string array for encoding.
  300. func (st *StringTableWriter) ToSlice() []string {
  301. st.l.Lock()
  302. defer st.l.Unlock()
  303. if st.next == 0 {
  304. return []string{}
  305. }
  306. sl := make([]string, st.next)
  307. for s, i := range st.indices {
  308. sl[i] = s
  309. }
  310. return sl
  311. }
  312. // ToBytes Converts the contents to a binary encoded representation
  313. func (st *StringTableWriter) ToBytes() []byte {
  314. buff := util.NewBuffer()
  315. buff.WriteBytes([]byte(BinaryTagStringTable)) // bingen table header
  316. strs := st.ToSlice()
  317. buff.WriteInt(len(strs)) // table length
  318. for _, s := range strs {
  319. buff.WriteString(s)
  320. }
  321. return buff.Bytes()
  322. }
  323. //--------------------------------------------------------------------------
  324. // String Table Reader
  325. //--------------------------------------------------------------------------
  326. // StringTableReader is the interface used to read the string table from the decoding.
  327. type StringTableReader interface {
  328. // At returns the string entry at a specific index, or panics on out of bounds.
  329. At(index int) string
  330. // Len returns the total number of strings loaded in the string table.
  331. Len() int
  332. // Close will clear the loaded table, and drop any external resources used.
  333. Close() error
  334. }
  335. // SliceStringTableReader is a basic pre-loaded []string that provides index-based access.
  336. // The cost of this implementation is holding all strings in memory, which provides faster
  337. // lookup performance for memory usage.
  338. type SliceStringTableReader struct {
  339. table []string
  340. }
  341. // NewSliceStringTableReaderFrom creates a new SliceStringTableReader instance loading
  342. // data directly from the buffer. The buffer's position should start at the table length.
  343. func NewSliceStringTableReaderFrom(buffer *util.Buffer) StringTableReader {
  344. // table length
  345. tl := buffer.ReadInt()
  346. var table []string
  347. if tl > 0 {
  348. table = make([]string, tl)
  349. for i := range tl {
  350. table[i] = buffer.ReadString()
  351. }
  352. }
  353. return &SliceStringTableReader{
  354. table: table,
  355. }
  356. }
  357. // At returns the string entry at a specific index, or panics on out of bounds.
  358. func (sstr *SliceStringTableReader) At(index int) string {
  359. if index < 0 || index >= len(sstr.table) {
  360. panic(fmt.Errorf("%s: string table index out of bounds: %d", GeneratorPackageName, index))
  361. }
  362. return sstr.table[index]
  363. }
  364. // Len returns the total number of strings loaded in the string table.
  365. func (sstr *SliceStringTableReader) Len() int {
  366. if sstr == nil {
  367. return 0
  368. }
  369. return len(sstr.table)
  370. }
  371. // Close for the slice tables just nils out the slice and returns
  372. func (sstr *SliceStringTableReader) Close() error {
  373. sstr.table = nil
  374. return nil
  375. }
  376. // fileStringRef maps a bingen string-table index to a payload stored in a temp file.
  377. type fileStringRef struct {
  378. off int64
  379. length int
  380. }
  381. // FileStringTableReader leverages a local file to write string table data for lookup. On
  382. // memory focused systems, this allows a slower parse with a significant decrease in memory
  383. // usage. This implementation is often pair with streaming readers for high throughput with
  384. // reduced memory usage.
  385. type FileStringTableReader struct {
  386. f *os.File
  387. refs []fileStringRef
  388. memo []atomic.Pointer[string]
  389. memoHits []atomic.Uint64
  390. memoBytes atomic.Int64
  391. memoMaxBytes int64
  392. evictStop chan struct{}
  393. evictDone chan struct{}
  394. evictScratch []memoEvictionCandidate
  395. }
  396. // NewFileStringTableFromBuffer reads exactly tl length-prefixed (uint16) string payloads from buffer
  397. // and appends each payload to a new temp file. It does not retain full strings in memory.
  398. func NewFileStringTableReaderFrom(buffer *util.Buffer, dir string) StringTableReader {
  399. // helper func to cast a string in-place to a byte slice.
  400. // NOTE: Return value is READ-ONLY. DO NOT MODIFY!
  401. byteSliceFor := func(s string) []byte {
  402. return unsafe.Slice(unsafe.StringData(s), len(s))
  403. }
  404. err := os.MkdirAll(dir, 0755)
  405. if err != nil {
  406. panic(fmt.Errorf("%s: failed to create string table directory: %w", GeneratorPackageName, err))
  407. }
  408. f, err := os.CreateTemp(dir, fmt.Sprintf("%s-bgst-*", GeneratorPackageName))
  409. if err != nil {
  410. panic(fmt.Errorf("%s: failed to create string table file: %w", GeneratorPackageName, err))
  411. }
  412. var writeErr error
  413. defer func() {
  414. if writeErr != nil {
  415. _ = f.Close()
  416. }
  417. }()
  418. // table length
  419. tl := buffer.ReadInt()
  420. var refs []fileStringRef
  421. if tl > 0 {
  422. refs = make([]fileStringRef, tl)
  423. for i := range tl {
  424. payload := byteSliceFor(buffer.ReadString())
  425. var off int64
  426. if len(payload) > 0 {
  427. off, err = f.Seek(0, io.SeekEnd)
  428. if err != nil {
  429. writeErr = fmt.Errorf("%s: failed to seek string table file: %w", GeneratorPackageName, err)
  430. panic(writeErr)
  431. }
  432. if _, err := f.Write(payload); err != nil {
  433. writeErr = fmt.Errorf("%s: failed to write string table entry %d: %w", GeneratorPackageName, i, err)
  434. panic(writeErr)
  435. }
  436. }
  437. refs[i] = fileStringRef{
  438. off: off,
  439. length: len(payload),
  440. }
  441. }
  442. }
  443. reader := &FileStringTableReader{
  444. f: f,
  445. refs: refs,
  446. memo: make([]atomic.Pointer[string], len(refs)),
  447. memoHits: make([]atomic.Uint64, len(refs)),
  448. memoMaxBytes: BingenFileBackedStringTableMemoMaxBytes(),
  449. evictScratch: make([]memoEvictionCandidate, len(refs)),
  450. }
  451. if reader.memoMaxBytes > 0 {
  452. reader.startMemoEvictionLoop()
  453. }
  454. return reader
  455. }
  456. // At returns the string from the internal file using the reference's offset and length.
  457. func (fstr *FileStringTableReader) At(index int) string {
  458. if fstr == nil || fstr.f == nil {
  459. panic(fmt.Errorf("%s: failed to read file string table data", GeneratorPackageName))
  460. }
  461. if index < 0 || index >= len(fstr.refs) {
  462. panic(fmt.Errorf("%s: string table index out of bounds: %d", GeneratorPackageName, index))
  463. }
  464. ref := fstr.refs[index]
  465. if ref.length == 0 {
  466. return ""
  467. }
  468. if fstr.memoMaxBytes > 0 {
  469. if cached := fstr.memo[index].Load(); cached != nil {
  470. if index < len(fstr.memoHits) {
  471. fstr.memoHits[index].Add(1)
  472. }
  473. return *cached
  474. }
  475. }
  476. b := make([]byte, ref.length)
  477. _, err := fstr.f.ReadAt(b, ref.off)
  478. if err != nil {
  479. return ""
  480. }
  481. // cast the allocated bytes to a string in-place, as we were the ones that allocated the bytes
  482. s := unsafe.String(unsafe.SliceData(b), len(b))
  483. if fstr.memoMaxBytes > 0 {
  484. if existing := fstr.memo[index].Load(); existing != nil {
  485. if index < len(fstr.memoHits) {
  486. fstr.memoHits[index].Add(1)
  487. }
  488. return *existing
  489. }
  490. need := int64(len(s))
  491. for {
  492. current := fstr.memoBytes.Load()
  493. if current+need > fstr.memoMaxBytes {
  494. break
  495. }
  496. if fstr.memoBytes.CompareAndSwap(current, current+need) {
  497. toStore := new(string)
  498. *toStore = s
  499. if fstr.memo[index].CompareAndSwap(nil, toStore) {
  500. if index < len(fstr.memoHits) {
  501. fstr.memoHits[index].Store(1)
  502. }
  503. return s
  504. }
  505. // Another goroutine won the race for this slot; refund bytes.
  506. fstr.memoBytes.Add(-need)
  507. if stored := fstr.memo[index].Load(); stored != nil {
  508. if index < len(fstr.memoHits) {
  509. fstr.memoHits[index].Add(1)
  510. }
  511. return *stored
  512. }
  513. break
  514. }
  515. }
  516. }
  517. return s
  518. }
  519. // Len returns the total number of strings loaded in the string table.
  520. func (fstr *FileStringTableReader) Len() int {
  521. if fstr == nil {
  522. return 0
  523. }
  524. return len(fstr.refs)
  525. }
  526. // Close for the file string table reader closes the file and deletes it.
  527. func (fstr *FileStringTableReader) Close() error {
  528. if fstr == nil || fstr.f == nil {
  529. return nil
  530. }
  531. if fstr.evictStop != nil {
  532. close(fstr.evictStop)
  533. <-fstr.evictDone
  534. fstr.evictStop = nil
  535. fstr.evictDone = nil
  536. }
  537. path := fstr.f.Name()
  538. err := fstr.f.Close()
  539. fstr.f = nil
  540. fstr.refs = nil
  541. for i := range fstr.memo {
  542. fstr.memo[i].Store(nil)
  543. if i < len(fstr.memoHits) {
  544. fstr.memoHits[i].Store(0)
  545. }
  546. }
  547. fstr.memo = nil
  548. fstr.memoHits = nil
  549. fstr.memoBytes.Store(0)
  550. if path != "" {
  551. _ = os.Remove(path)
  552. }
  553. return err
  554. }
  555. type memoEvictionCandidate struct {
  556. idx int
  557. hits uint64
  558. }
  559. func (fstr *FileStringTableReader) startMemoEvictionLoop() {
  560. fstr.evictStop = make(chan struct{})
  561. fstr.evictDone = make(chan struct{})
  562. go func() {
  563. defer close(fstr.evictDone)
  564. ticker := time.NewTicker(10 * time.Second)
  565. defer ticker.Stop()
  566. for {
  567. select {
  568. case <-fstr.evictStop:
  569. return
  570. case <-ticker.C:
  571. fstr.evictLeastUsedMemoEntries(0.20)
  572. }
  573. }
  574. }()
  575. }
  576. func (fstr *FileStringTableReader) evictLeastUsedMemoEntries(percent float64) {
  577. if fstr == nil || len(fstr.memo) == 0 || percent <= 0 {
  578. return
  579. }
  580. if fstr.memoMaxBytes <= 0 {
  581. return
  582. }
  583. if fstr.memoBytes.Load() < (fstr.memoMaxBytes*9)/10 {
  584. return
  585. }
  586. candidates := fstr.evictScratch
  587. n := 0
  588. for i := range fstr.memo {
  589. if fstr.memo[i].Load() == nil {
  590. continue
  591. }
  592. candidates[n] = memoEvictionCandidate{
  593. idx: i,
  594. hits: fstr.memoHits[i].Load(),
  595. }
  596. n++
  597. }
  598. if n == 0 {
  599. return
  600. }
  601. candidates = candidates[:n]
  602. evictCount := int(float64(len(candidates)) * percent)
  603. if evictCount <= 0 {
  604. evictCount = 1
  605. }
  606. if evictCount > len(candidates) {
  607. evictCount = len(candidates)
  608. }
  609. // Partition in-place around the evictCount-th smallest hit count.
  610. cutoff := selectKthSmallestHits(candidates, evictCount-1)
  611. evicted := 0
  612. for i := 0; i < len(candidates); i++ {
  613. if candidates[i].hits > cutoff {
  614. continue
  615. }
  616. idx := candidates[i].idx
  617. existing := fstr.memo[idx].Load()
  618. if existing == nil {
  619. continue
  620. }
  621. if fstr.memo[idx].CompareAndSwap(existing, nil) {
  622. fstr.memoHits[idx].Store(0)
  623. fstr.memoBytes.Add(-int64(fstr.refs[idx].length))
  624. evicted++
  625. if evicted >= evictCount {
  626. break
  627. }
  628. }
  629. }
  630. }
  631. func selectKthSmallestHits(c []memoEvictionCandidate, k int) uint64 {
  632. if len(c) == 0 {
  633. return 0
  634. }
  635. if k < 0 {
  636. k = 0
  637. }
  638. if k >= len(c) {
  639. k = len(c) - 1
  640. }
  641. left, right := 0, len(c)-1
  642. for left <= right {
  643. p := partitionByHits(c, left, right)
  644. switch {
  645. case p == k:
  646. return c[p].hits
  647. case p < k:
  648. left = p + 1
  649. default:
  650. right = p - 1
  651. }
  652. }
  653. return c[k].hits
  654. }
  655. func partitionByHits(c []memoEvictionCandidate, left, right int) int {
  656. pivot := c[right].hits
  657. i := left
  658. for j := left; j < right; j++ {
  659. if c[j].hits <= pivot {
  660. c[i], c[j] = c[j], c[i]
  661. i++
  662. }
  663. }
  664. c[i], c[right] = c[right], c[i]
  665. return i
  666. }
  667. //--------------------------------------------------------------------------
  668. // Codec Context
  669. //--------------------------------------------------------------------------
  670. // EncodingContext is a context object passed to the encoders to ensure reuse of buffer
  671. // and table data
  672. type EncodingContext struct {
  673. Buffer *util.Buffer
  674. Table *StringTableWriter
  675. }
  676. // IsStringTable returns true if the table is available
  677. func (ec *EncodingContext) IsStringTable() bool {
  678. return ec.Table != nil
  679. }
  680. // DecodingContext is a context object passed to the decoders to ensure parent objects
  681. // reuse as much data as possible
  682. type DecodingContext struct {
  683. Buffer *util.Buffer
  684. Table StringTableReader
  685. }
  686. // NewDecodingContextFromBytes creates a new DecodingContext instance using an byte slice
  687. func NewDecodingContextFromBytes(data []byte) *DecodingContext {
  688. var table StringTableReader
  689. buff := util.NewBufferFromBytes(data)
  690. // string table header validation
  691. if isBinaryTag(data, BinaryTagStringTable) {
  692. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  693. // always use a slice string table with a byte array since the
  694. // data is already in memory
  695. table = NewSliceStringTableReaderFrom(buff)
  696. }
  697. return &DecodingContext{
  698. Buffer: buff,
  699. Table: table,
  700. }
  701. }
  702. // NewDecodingContextFromReader creates a new DecodingContext instance using an io.Reader
  703. // implementation
  704. func NewDecodingContextFromReader(reader io.Reader) *DecodingContext {
  705. var table StringTableReader
  706. buff := util.NewBufferFromReader(reader)
  707. if isReaderBinaryTag(buff, BinaryTagStringTable) {
  708. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  709. // create correct string table implementation
  710. if IsBingenFileBackedStringTableEnabled() {
  711. table = NewFileStringTableReaderFrom(buff, BingenFileBackedStringTableDir())
  712. } else {
  713. table = NewSliceStringTableReaderFrom(buff)
  714. }
  715. }
  716. return &DecodingContext{
  717. Buffer: buff,
  718. Table: table,
  719. }
  720. }
  721. // IsStringTable returns true if the table is available
  722. func (dc *DecodingContext) IsStringTable() bool {
  723. return dc.Table != nil && dc.Table.Len() > 0
  724. }
  725. // Close will ensure that any string table resources and buffer resources are
  726. // cleaned up.
  727. func (dc *DecodingContext) Close() {
  728. if dc.Table != nil {
  729. _ = dc.Table.Close()
  730. dc.Table = nil
  731. }
  732. }
  733. //--------------------------------------------------------------------------
  734. // Binary Codec
  735. //--------------------------------------------------------------------------
  736. // BinEncoder is an encoding interface which defines a context based marshal contract.
  737. type BinEncoder interface {
  738. MarshalBinaryWithContext(*EncodingContext) error
  739. }
  740. // BinDecoder is a decoding interface which defines a context based unmarshal contract.
  741. type BinDecoder interface {
  742. UnmarshalBinaryWithContext(*DecodingContext) error
  743. }
  744. //--------------------------------------------------------------------------
  745. // Allocation
  746. //--------------------------------------------------------------------------
  747. // MarshalBinary serializes the internal properties of this Allocation instance
  748. // into a byte array
  749. func (target *Allocation) MarshalBinary() (data []byte, err error) {
  750. ctx := &EncodingContext{
  751. Buffer: util.NewBuffer(),
  752. Table: nil,
  753. }
  754. e := target.MarshalBinaryWithContext(ctx)
  755. if e != nil {
  756. return nil, e
  757. }
  758. encBytes := ctx.Buffer.Bytes()
  759. return encBytes, nil
  760. }
  761. // MarshalBinaryWithContext serializes the internal properties of this Allocation instance
  762. // into a byte array leveraging a predefined context.
  763. func (target *Allocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  764. // panics are recovered and propagated as errors
  765. defer func() {
  766. if r := recover(); r != nil {
  767. if e, ok := r.(error); ok {
  768. err = e
  769. } else if s, ok := r.(string); ok {
  770. err = fmt.Errorf("Unexpected panic: %s", s)
  771. } else {
  772. err = fmt.Errorf("Unexpected panic: %+v", r)
  773. }
  774. }
  775. }()
  776. buff := ctx.Buffer
  777. buff.WriteUInt8(AllocationCodecVersion) // version
  778. if ctx.IsStringTable() {
  779. a := ctx.Table.AddOrGet(target.Name)
  780. buff.WriteInt(a) // write table index
  781. } else {
  782. buff.WriteString(target.Name) // write string
  783. }
  784. if target.Properties == nil {
  785. buff.WriteUInt8(uint8(0)) // write nil byte
  786. } else {
  787. buff.WriteUInt8(uint8(1)) // write non-nil byte
  788. // --- [begin][write][struct](AllocationProperties) ---
  789. buff.WriteInt(0) // [compatibility, unused]
  790. errA := target.Properties.MarshalBinaryWithContext(ctx)
  791. if errA != nil {
  792. return errA
  793. }
  794. // --- [end][write][struct](AllocationProperties) ---
  795. }
  796. // --- [begin][write][struct](Window) ---
  797. buff.WriteInt(0) // [compatibility, unused]
  798. errB := target.Window.MarshalBinaryWithContext(ctx)
  799. if errB != nil {
  800. return errB
  801. }
  802. // --- [end][write][struct](Window) ---
  803. // --- [begin][write][reference](time.Time) ---
  804. b, errC := target.Start.MarshalBinary()
  805. if errC != nil {
  806. return errC
  807. }
  808. buff.WriteInt(len(b))
  809. buff.WriteBytes(b)
  810. // --- [end][write][reference](time.Time) ---
  811. // --- [begin][write][reference](time.Time) ---
  812. c, errD := target.End.MarshalBinary()
  813. if errD != nil {
  814. return errD
  815. }
  816. buff.WriteInt(len(c))
  817. buff.WriteBytes(c)
  818. // --- [end][write][reference](time.Time) ---
  819. buff.WriteFloat64(target.CPUCoreHours) // write float64
  820. buff.WriteFloat64(target.CPUCoreRequestAverage) // write float64
  821. buff.WriteFloat64(target.CPUCoreUsageAverage) // write float64
  822. buff.WriteFloat64(target.CPUCost) // write float64
  823. buff.WriteFloat64(target.CPUCostAdjustment) // write float64
  824. buff.WriteFloat64(target.GPUHours) // write float64
  825. buff.WriteFloat64(target.GPUCost) // write float64
  826. buff.WriteFloat64(target.GPUCostAdjustment) // write float64
  827. buff.WriteFloat64(target.NetworkTransferBytes) // write float64
  828. buff.WriteFloat64(target.NetworkReceiveBytes) // write float64
  829. buff.WriteFloat64(target.NetworkCost) // write float64
  830. buff.WriteFloat64(target.NetworkCrossZoneCost) // write float64
  831. buff.WriteFloat64(target.NetworkCrossRegionCost) // write float64
  832. buff.WriteFloat64(target.NetworkInternetCost) // write float64
  833. buff.WriteFloat64(target.NetworkCostAdjustment) // write float64
  834. buff.WriteFloat64(target.LoadBalancerCost) // write float64
  835. buff.WriteFloat64(target.LoadBalancerCostAdjustment) // write float64
  836. // --- [begin][write][alias](PVAllocations) ---
  837. if map[PVKey]*PVAllocation(target.PVs) == nil {
  838. buff.WriteUInt8(uint8(0)) // write nil byte
  839. } else {
  840. buff.WriteUInt8(uint8(1)) // write non-nil byte
  841. // --- [begin][write][map](map[PVKey]*PVAllocation) ---
  842. buff.WriteInt(len(map[PVKey]*PVAllocation(target.PVs))) // map length
  843. for v, z := range map[PVKey]*PVAllocation(target.PVs) {
  844. // --- [begin][write][struct](PVKey) ---
  845. buff.WriteInt(0) // [compatibility, unused]
  846. errE := v.MarshalBinaryWithContext(ctx)
  847. if errE != nil {
  848. return errE
  849. }
  850. // --- [end][write][struct](PVKey) ---
  851. if z == nil {
  852. buff.WriteUInt8(uint8(0)) // write nil byte
  853. } else {
  854. buff.WriteUInt8(uint8(1)) // write non-nil byte
  855. // --- [begin][write][struct](PVAllocation) ---
  856. buff.WriteInt(0) // [compatibility, unused]
  857. errF := z.MarshalBinaryWithContext(ctx)
  858. if errF != nil {
  859. return errF
  860. }
  861. // --- [end][write][struct](PVAllocation) ---
  862. }
  863. }
  864. // --- [end][write][map](map[PVKey]*PVAllocation) ---
  865. }
  866. // --- [end][write][alias](PVAllocations) ---
  867. buff.WriteFloat64(target.PVCostAdjustment) // write float64
  868. buff.WriteFloat64(target.RAMByteHours) // write float64
  869. buff.WriteFloat64(target.RAMBytesRequestAverage) // write float64
  870. buff.WriteFloat64(target.RAMBytesUsageAverage) // write float64
  871. buff.WriteFloat64(target.RAMCost) // write float64
  872. buff.WriteFloat64(target.RAMCostAdjustment) // write float64
  873. buff.WriteFloat64(target.SharedCost) // write float64
  874. buff.WriteFloat64(target.ExternalCost) // write float64
  875. if target.RawAllocationOnly == nil {
  876. buff.WriteUInt8(uint8(0)) // write nil byte
  877. } else {
  878. buff.WriteUInt8(uint8(1)) // write non-nil byte
  879. // --- [begin][write][struct](RawAllocationOnlyData) ---
  880. buff.WriteInt(0) // [compatibility, unused]
  881. errG := target.RawAllocationOnly.MarshalBinaryWithContext(ctx)
  882. if errG != nil {
  883. return errG
  884. }
  885. // --- [end][write][struct](RawAllocationOnlyData) ---
  886. }
  887. // --- [begin][write][alias](LbAllocations) ---
  888. if map[string]*LbAllocation(target.LoadBalancers) == nil {
  889. buff.WriteUInt8(uint8(0)) // write nil byte
  890. } else {
  891. buff.WriteUInt8(uint8(1)) // write non-nil byte
  892. // --- [begin][write][map](map[string]*LbAllocation) ---
  893. buff.WriteInt(len(map[string]*LbAllocation(target.LoadBalancers))) // map length
  894. for vv, zz := range map[string]*LbAllocation(target.LoadBalancers) {
  895. if ctx.IsStringTable() {
  896. d := ctx.Table.AddOrGet(vv)
  897. buff.WriteInt(d) // write table index
  898. } else {
  899. buff.WriteString(vv) // write string
  900. }
  901. if zz == nil {
  902. buff.WriteUInt8(uint8(0)) // write nil byte
  903. } else {
  904. buff.WriteUInt8(uint8(1)) // write non-nil byte
  905. // --- [begin][write][struct](LbAllocation) ---
  906. buff.WriteInt(0) // [compatibility, unused]
  907. errH := zz.MarshalBinaryWithContext(ctx)
  908. if errH != nil {
  909. return errH
  910. }
  911. // --- [end][write][struct](LbAllocation) ---
  912. }
  913. }
  914. // --- [end][write][map](map[string]*LbAllocation) ---
  915. }
  916. // --- [end][write][alias](LbAllocations) ---
  917. buff.WriteFloat64(target.deprecatedGPURequestAverage) // write float64
  918. buff.WriteFloat64(target.deprecatedGPUUsageAverage) // write float64
  919. if target.GPUAllocation == nil {
  920. buff.WriteUInt8(uint8(0)) // write nil byte
  921. } else {
  922. buff.WriteUInt8(uint8(1)) // write non-nil byte
  923. // --- [begin][write][struct](GPUAllocation) ---
  924. buff.WriteInt(0) // [compatibility, unused]
  925. errI := target.GPUAllocation.MarshalBinaryWithContext(ctx)
  926. if errI != nil {
  927. return errI
  928. }
  929. // --- [end][write][struct](GPUAllocation) ---
  930. }
  931. buff.WriteFloat64(target.CPUCoreLimitAverage) // write float64
  932. buff.WriteFloat64(target.RAMBytesLimitAverage) // write float64
  933. buff.WriteFloat64(target.NetworkNatGatewayEgressCost) // write float64
  934. buff.WriteFloat64(target.NetworkNatGatewayIngressCost) // write float64
  935. return nil
  936. }
  937. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  938. // the Allocation type
  939. func (target *Allocation) UnmarshalBinary(data []byte) error {
  940. ctx := NewDecodingContextFromBytes(data)
  941. defer ctx.Close()
  942. err := target.UnmarshalBinaryWithContext(ctx)
  943. if err != nil {
  944. return err
  945. }
  946. return nil
  947. }
  948. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  949. // the Allocation type
  950. func (target *Allocation) UnmarshalBinaryFromReader(reader io.Reader) error {
  951. ctx := NewDecodingContextFromReader(reader)
  952. defer ctx.Close()
  953. err := target.UnmarshalBinaryWithContext(ctx)
  954. if err != nil {
  955. return err
  956. }
  957. return nil
  958. }
  959. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  960. // the Allocation type
  961. func (target *Allocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  962. // panics are recovered and propagated as errors
  963. defer func() {
  964. if r := recover(); r != nil {
  965. if e, ok := r.(error); ok {
  966. err = e
  967. } else if s, ok := r.(string); ok {
  968. err = fmt.Errorf("Unexpected panic: %s", s)
  969. } else {
  970. err = fmt.Errorf("Unexpected panic: %+v", r)
  971. }
  972. }
  973. }()
  974. buff := ctx.Buffer
  975. version := buff.ReadUInt8()
  976. if version > AllocationCodecVersion {
  977. return fmt.Errorf("Invalid Version Unmarshaling Allocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  978. }
  979. var b string
  980. if ctx.IsStringTable() {
  981. c := buff.ReadInt() // read string index
  982. b = ctx.Table.At(c)
  983. } else {
  984. b = buff.ReadString() // read string
  985. }
  986. a := b
  987. target.Name = a
  988. if buff.ReadUInt8() == uint8(0) {
  989. target.Properties = nil
  990. } else {
  991. // --- [begin][read][struct](AllocationProperties) ---
  992. d := &AllocationProperties{}
  993. buff.ReadInt() // [compatibility, unused]
  994. errA := d.UnmarshalBinaryWithContext(ctx)
  995. if errA != nil {
  996. return errA
  997. }
  998. target.Properties = d
  999. // --- [end][read][struct](AllocationProperties) ---
  1000. }
  1001. // --- [begin][read][struct](Window) ---
  1002. e := &Window{}
  1003. buff.ReadInt() // [compatibility, unused]
  1004. errB := e.UnmarshalBinaryWithContext(ctx)
  1005. if errB != nil {
  1006. return errB
  1007. }
  1008. target.Window = *e
  1009. // --- [end][read][struct](Window) ---
  1010. // --- [begin][read][reference](time.Time) ---
  1011. f := &time.Time{}
  1012. g := buff.ReadInt() // byte array length
  1013. h := buff.ReadBytes(g) // byte array
  1014. errC := f.UnmarshalBinary(h)
  1015. if errC != nil {
  1016. return errC
  1017. }
  1018. target.Start = *f
  1019. // --- [end][read][reference](time.Time) ---
  1020. // --- [begin][read][reference](time.Time) ---
  1021. l := &time.Time{}
  1022. m := buff.ReadInt() // byte array length
  1023. n := buff.ReadBytes(m) // byte array
  1024. errD := l.UnmarshalBinary(n)
  1025. if errD != nil {
  1026. return errD
  1027. }
  1028. target.End = *l
  1029. // --- [end][read][reference](time.Time) ---
  1030. o := buff.ReadFloat64() // read float64
  1031. target.CPUCoreHours = o
  1032. p := buff.ReadFloat64() // read float64
  1033. target.CPUCoreRequestAverage = p
  1034. q := buff.ReadFloat64() // read float64
  1035. target.CPUCoreUsageAverage = q
  1036. r := buff.ReadFloat64() // read float64
  1037. target.CPUCost = r
  1038. s := buff.ReadFloat64() // read float64
  1039. target.CPUCostAdjustment = s
  1040. t := buff.ReadFloat64() // read float64
  1041. target.GPUHours = t
  1042. u := buff.ReadFloat64() // read float64
  1043. target.GPUCost = u
  1044. w := buff.ReadFloat64() // read float64
  1045. target.GPUCostAdjustment = w
  1046. x := buff.ReadFloat64() // read float64
  1047. target.NetworkTransferBytes = x
  1048. y := buff.ReadFloat64() // read float64
  1049. target.NetworkReceiveBytes = y
  1050. aa := buff.ReadFloat64() // read float64
  1051. target.NetworkCost = aa
  1052. // field version check
  1053. if uint8(16) <= version {
  1054. bb := buff.ReadFloat64() // read float64
  1055. target.NetworkCrossZoneCost = bb
  1056. } else {
  1057. target.NetworkCrossZoneCost = float64(0) // default
  1058. }
  1059. // field version check
  1060. if uint8(16) <= version {
  1061. cc := buff.ReadFloat64() // read float64
  1062. target.NetworkCrossRegionCost = cc
  1063. } else {
  1064. target.NetworkCrossRegionCost = float64(0) // default
  1065. }
  1066. // field version check
  1067. if uint8(16) <= version {
  1068. dd := buff.ReadFloat64() // read float64
  1069. target.NetworkInternetCost = dd
  1070. } else {
  1071. target.NetworkInternetCost = float64(0) // default
  1072. }
  1073. ee := buff.ReadFloat64() // read float64
  1074. target.NetworkCostAdjustment = ee
  1075. ff := buff.ReadFloat64() // read float64
  1076. target.LoadBalancerCost = ff
  1077. gg := buff.ReadFloat64() // read float64
  1078. target.LoadBalancerCostAdjustment = gg
  1079. // --- [begin][read][alias](PVAllocations) ---
  1080. var hh map[PVKey]*PVAllocation
  1081. if buff.ReadUInt8() == uint8(0) {
  1082. hh = nil
  1083. } else {
  1084. // --- [begin][read][map](map[PVKey]*PVAllocation) ---
  1085. mm := buff.ReadInt() // map len
  1086. ll := make(map[PVKey]*PVAllocation, mm)
  1087. for i := 0; i < mm; i++ {
  1088. // --- [begin][read][struct](PVKey) ---
  1089. nn := &PVKey{}
  1090. buff.ReadInt() // [compatibility, unused]
  1091. errE := nn.UnmarshalBinaryWithContext(ctx)
  1092. if errE != nil {
  1093. return errE
  1094. }
  1095. v := *nn
  1096. // --- [end][read][struct](PVKey) ---
  1097. var z *PVAllocation
  1098. if buff.ReadUInt8() == uint8(0) {
  1099. z = nil
  1100. } else {
  1101. // --- [begin][read][struct](PVAllocation) ---
  1102. oo := &PVAllocation{}
  1103. buff.ReadInt() // [compatibility, unused]
  1104. errF := oo.UnmarshalBinaryWithContext(ctx)
  1105. if errF != nil {
  1106. return errF
  1107. }
  1108. z = oo
  1109. // --- [end][read][struct](PVAllocation) ---
  1110. }
  1111. ll[v] = z
  1112. }
  1113. hh = ll
  1114. // --- [end][read][map](map[PVKey]*PVAllocation) ---
  1115. }
  1116. target.PVs = PVAllocations(hh)
  1117. // --- [end][read][alias](PVAllocations) ---
  1118. pp := buff.ReadFloat64() // read float64
  1119. target.PVCostAdjustment = pp
  1120. qq := buff.ReadFloat64() // read float64
  1121. target.RAMByteHours = qq
  1122. rr := buff.ReadFloat64() // read float64
  1123. target.RAMBytesRequestAverage = rr
  1124. ss := buff.ReadFloat64() // read float64
  1125. target.RAMBytesUsageAverage = ss
  1126. tt := buff.ReadFloat64() // read float64
  1127. target.RAMCost = tt
  1128. uu := buff.ReadFloat64() // read float64
  1129. target.RAMCostAdjustment = uu
  1130. ww := buff.ReadFloat64() // read float64
  1131. target.SharedCost = ww
  1132. xx := buff.ReadFloat64() // read float64
  1133. target.ExternalCost = xx
  1134. if buff.ReadUInt8() == uint8(0) {
  1135. target.RawAllocationOnly = nil
  1136. } else {
  1137. // --- [begin][read][struct](RawAllocationOnlyData) ---
  1138. yy := &RawAllocationOnlyData{}
  1139. buff.ReadInt() // [compatibility, unused]
  1140. errG := yy.UnmarshalBinaryWithContext(ctx)
  1141. if errG != nil {
  1142. return errG
  1143. }
  1144. target.RawAllocationOnly = yy
  1145. // --- [end][read][struct](RawAllocationOnlyData) ---
  1146. }
  1147. // field version check
  1148. if uint8(18) <= version {
  1149. // --- [begin][read][alias](LbAllocations) ---
  1150. var aaa map[string]*LbAllocation
  1151. if buff.ReadUInt8() == uint8(0) {
  1152. aaa = nil
  1153. } else {
  1154. // --- [begin][read][map](map[string]*LbAllocation) ---
  1155. ccc := buff.ReadInt() // map len
  1156. bbb := make(map[string]*LbAllocation, ccc)
  1157. for j := 0; j < ccc; j++ {
  1158. var vv string
  1159. var eee string
  1160. if ctx.IsStringTable() {
  1161. fff := buff.ReadInt() // read string index
  1162. eee = ctx.Table.At(fff)
  1163. } else {
  1164. eee = buff.ReadString() // read string
  1165. }
  1166. ddd := eee
  1167. vv = ddd
  1168. var zz *LbAllocation
  1169. if buff.ReadUInt8() == uint8(0) {
  1170. zz = nil
  1171. } else {
  1172. // --- [begin][read][struct](LbAllocation) ---
  1173. ggg := &LbAllocation{}
  1174. buff.ReadInt() // [compatibility, unused]
  1175. errH := ggg.UnmarshalBinaryWithContext(ctx)
  1176. if errH != nil {
  1177. return errH
  1178. }
  1179. zz = ggg
  1180. // --- [end][read][struct](LbAllocation) ---
  1181. }
  1182. bbb[vv] = zz
  1183. }
  1184. aaa = bbb
  1185. // --- [end][read][map](map[string]*LbAllocation) ---
  1186. }
  1187. target.LoadBalancers = LbAllocations(aaa)
  1188. // --- [end][read][alias](LbAllocations) ---
  1189. } else {
  1190. }
  1191. // field version check
  1192. if uint8(22) <= version {
  1193. hhh := buff.ReadFloat64() // read float64
  1194. target.deprecatedGPURequestAverage = hhh
  1195. } else {
  1196. target.deprecatedGPURequestAverage = float64(0) // default
  1197. }
  1198. // field version check
  1199. if uint8(22) <= version {
  1200. lll := buff.ReadFloat64() // read float64
  1201. target.deprecatedGPUUsageAverage = lll
  1202. } else {
  1203. target.deprecatedGPUUsageAverage = float64(0) // default
  1204. }
  1205. // field version check
  1206. if uint8(23) <= version {
  1207. if buff.ReadUInt8() == uint8(0) {
  1208. target.GPUAllocation = nil
  1209. } else {
  1210. // --- [begin][read][struct](GPUAllocation) ---
  1211. mmm := &GPUAllocation{}
  1212. buff.ReadInt() // [compatibility, unused]
  1213. errI := mmm.UnmarshalBinaryWithContext(ctx)
  1214. if errI != nil {
  1215. return errI
  1216. }
  1217. target.GPUAllocation = mmm
  1218. // --- [end][read][struct](GPUAllocation) ---
  1219. }
  1220. } else {
  1221. target.GPUAllocation = nil
  1222. }
  1223. // field version check
  1224. if uint8(24) <= version {
  1225. nnn := buff.ReadFloat64() // read float64
  1226. target.CPUCoreLimitAverage = nnn
  1227. } else {
  1228. target.CPUCoreLimitAverage = float64(0) // default
  1229. }
  1230. // field version check
  1231. if uint8(24) <= version {
  1232. ooo := buff.ReadFloat64() // read float64
  1233. target.RAMBytesLimitAverage = ooo
  1234. } else {
  1235. target.RAMBytesLimitAverage = float64(0) // default
  1236. }
  1237. // field version check
  1238. if uint8(25) <= version {
  1239. ppp := buff.ReadFloat64() // read float64
  1240. target.NetworkNatGatewayEgressCost = ppp
  1241. } else {
  1242. target.NetworkNatGatewayEgressCost = float64(0) // default
  1243. }
  1244. // field version check
  1245. if uint8(25) <= version {
  1246. qqq := buff.ReadFloat64() // read float64
  1247. target.NetworkNatGatewayIngressCost = qqq
  1248. } else {
  1249. target.NetworkNatGatewayIngressCost = float64(0) // default
  1250. }
  1251. // execute migration func if version delta detected
  1252. if version != AllocationCodecVersion {
  1253. migrateAllocation(target, version, AllocationCodecVersion)
  1254. }
  1255. return nil
  1256. }
  1257. //--------------------------------------------------------------------------
  1258. // AllocationProperties
  1259. //--------------------------------------------------------------------------
  1260. // MarshalBinary serializes the internal properties of this AllocationProperties instance
  1261. // into a byte array
  1262. func (target *AllocationProperties) MarshalBinary() (data []byte, err error) {
  1263. ctx := &EncodingContext{
  1264. Buffer: util.NewBuffer(),
  1265. Table: nil,
  1266. }
  1267. e := target.MarshalBinaryWithContext(ctx)
  1268. if e != nil {
  1269. return nil, e
  1270. }
  1271. encBytes := ctx.Buffer.Bytes()
  1272. return encBytes, nil
  1273. }
  1274. // MarshalBinaryWithContext serializes the internal properties of this AllocationProperties instance
  1275. // into a byte array leveraging a predefined context.
  1276. func (target *AllocationProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1277. // panics are recovered and propagated as errors
  1278. defer func() {
  1279. if r := recover(); r != nil {
  1280. if e, ok := r.(error); ok {
  1281. err = e
  1282. } else if s, ok := r.(string); ok {
  1283. err = fmt.Errorf("Unexpected panic: %s", s)
  1284. } else {
  1285. err = fmt.Errorf("Unexpected panic: %+v", r)
  1286. }
  1287. }
  1288. }()
  1289. buff := ctx.Buffer
  1290. buff.WriteUInt8(AllocationCodecVersion) // version
  1291. if ctx.IsStringTable() {
  1292. a := ctx.Table.AddOrGet(target.Cluster)
  1293. buff.WriteInt(a) // write table index
  1294. } else {
  1295. buff.WriteString(target.Cluster) // write string
  1296. }
  1297. if ctx.IsStringTable() {
  1298. b := ctx.Table.AddOrGet(target.Node)
  1299. buff.WriteInt(b) // write table index
  1300. } else {
  1301. buff.WriteString(target.Node) // write string
  1302. }
  1303. if ctx.IsStringTable() {
  1304. c := ctx.Table.AddOrGet(target.Container)
  1305. buff.WriteInt(c) // write table index
  1306. } else {
  1307. buff.WriteString(target.Container) // write string
  1308. }
  1309. if ctx.IsStringTable() {
  1310. d := ctx.Table.AddOrGet(target.Controller)
  1311. buff.WriteInt(d) // write table index
  1312. } else {
  1313. buff.WriteString(target.Controller) // write string
  1314. }
  1315. if ctx.IsStringTable() {
  1316. e := ctx.Table.AddOrGet(target.ControllerKind)
  1317. buff.WriteInt(e) // write table index
  1318. } else {
  1319. buff.WriteString(target.ControllerKind) // write string
  1320. }
  1321. if ctx.IsStringTable() {
  1322. f := ctx.Table.AddOrGet(target.Namespace)
  1323. buff.WriteInt(f) // write table index
  1324. } else {
  1325. buff.WriteString(target.Namespace) // write string
  1326. }
  1327. if ctx.IsStringTable() {
  1328. g := ctx.Table.AddOrGet(target.Pod)
  1329. buff.WriteInt(g) // write table index
  1330. } else {
  1331. buff.WriteString(target.Pod) // write string
  1332. }
  1333. if target.Services == nil {
  1334. buff.WriteUInt8(uint8(0)) // write nil byte
  1335. } else {
  1336. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1337. // --- [begin][write][slice]([]string) ---
  1338. buff.WriteInt(len(target.Services)) // array length
  1339. for i := 0; i < len(target.Services); i++ {
  1340. if ctx.IsStringTable() {
  1341. h := ctx.Table.AddOrGet(target.Services[i])
  1342. buff.WriteInt(h) // write table index
  1343. } else {
  1344. buff.WriteString(target.Services[i]) // write string
  1345. }
  1346. }
  1347. // --- [end][write][slice]([]string) ---
  1348. }
  1349. if ctx.IsStringTable() {
  1350. l := ctx.Table.AddOrGet(target.ProviderID)
  1351. buff.WriteInt(l) // write table index
  1352. } else {
  1353. buff.WriteString(target.ProviderID) // write string
  1354. }
  1355. // --- [begin][write][alias](AllocationLabels) ---
  1356. if map[string]string(target.Labels) == nil {
  1357. buff.WriteUInt8(uint8(0)) // write nil byte
  1358. } else {
  1359. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1360. // --- [begin][write][map](map[string]string) ---
  1361. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  1362. for v, z := range map[string]string(target.Labels) {
  1363. if ctx.IsStringTable() {
  1364. m := ctx.Table.AddOrGet(v)
  1365. buff.WriteInt(m) // write table index
  1366. } else {
  1367. buff.WriteString(v) // write string
  1368. }
  1369. if ctx.IsStringTable() {
  1370. n := ctx.Table.AddOrGet(z)
  1371. buff.WriteInt(n) // write table index
  1372. } else {
  1373. buff.WriteString(z) // write string
  1374. }
  1375. }
  1376. // --- [end][write][map](map[string]string) ---
  1377. }
  1378. // --- [end][write][alias](AllocationLabels) ---
  1379. // --- [begin][write][alias](AllocationAnnotations) ---
  1380. if map[string]string(target.Annotations) == nil {
  1381. buff.WriteUInt8(uint8(0)) // write nil byte
  1382. } else {
  1383. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1384. // --- [begin][write][map](map[string]string) ---
  1385. buff.WriteInt(len(map[string]string(target.Annotations))) // map length
  1386. for vv, zz := range map[string]string(target.Annotations) {
  1387. if ctx.IsStringTable() {
  1388. o := ctx.Table.AddOrGet(vv)
  1389. buff.WriteInt(o) // write table index
  1390. } else {
  1391. buff.WriteString(vv) // write string
  1392. }
  1393. if ctx.IsStringTable() {
  1394. p := ctx.Table.AddOrGet(zz)
  1395. buff.WriteInt(p) // write table index
  1396. } else {
  1397. buff.WriteString(zz) // write string
  1398. }
  1399. }
  1400. // --- [end][write][map](map[string]string) ---
  1401. }
  1402. // --- [end][write][alias](AllocationAnnotations) ---
  1403. // --- [begin][write][alias](AllocationLabels) ---
  1404. if map[string]string(target.NamespaceLabels) == nil {
  1405. buff.WriteUInt8(uint8(0)) // write nil byte
  1406. } else {
  1407. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1408. // --- [begin][write][map](map[string]string) ---
  1409. buff.WriteInt(len(map[string]string(target.NamespaceLabels))) // map length
  1410. for vvv, zzz := range map[string]string(target.NamespaceLabels) {
  1411. if ctx.IsStringTable() {
  1412. q := ctx.Table.AddOrGet(vvv)
  1413. buff.WriteInt(q) // write table index
  1414. } else {
  1415. buff.WriteString(vvv) // write string
  1416. }
  1417. if ctx.IsStringTable() {
  1418. r := ctx.Table.AddOrGet(zzz)
  1419. buff.WriteInt(r) // write table index
  1420. } else {
  1421. buff.WriteString(zzz) // write string
  1422. }
  1423. }
  1424. // --- [end][write][map](map[string]string) ---
  1425. }
  1426. // --- [end][write][alias](AllocationLabels) ---
  1427. // --- [begin][write][alias](AllocationAnnotations) ---
  1428. if map[string]string(target.NamespaceAnnotations) == nil {
  1429. buff.WriteUInt8(uint8(0)) // write nil byte
  1430. } else {
  1431. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1432. // --- [begin][write][map](map[string]string) ---
  1433. buff.WriteInt(len(map[string]string(target.NamespaceAnnotations))) // map length
  1434. for vvvv, zzzz := range map[string]string(target.NamespaceAnnotations) {
  1435. if ctx.IsStringTable() {
  1436. s := ctx.Table.AddOrGet(vvvv)
  1437. buff.WriteInt(s) // write table index
  1438. } else {
  1439. buff.WriteString(vvvv) // write string
  1440. }
  1441. if ctx.IsStringTable() {
  1442. t := ctx.Table.AddOrGet(zzzz)
  1443. buff.WriteInt(t) // write table index
  1444. } else {
  1445. buff.WriteString(zzzz) // write string
  1446. }
  1447. }
  1448. // --- [end][write][map](map[string]string) ---
  1449. }
  1450. // --- [end][write][alias](AllocationAnnotations) ---
  1451. return nil
  1452. }
  1453. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1454. // the AllocationProperties type
  1455. func (target *AllocationProperties) UnmarshalBinary(data []byte) error {
  1456. ctx := NewDecodingContextFromBytes(data)
  1457. defer ctx.Close()
  1458. err := target.UnmarshalBinaryWithContext(ctx)
  1459. if err != nil {
  1460. return err
  1461. }
  1462. return nil
  1463. }
  1464. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  1465. // the AllocationProperties type
  1466. func (target *AllocationProperties) UnmarshalBinaryFromReader(reader io.Reader) error {
  1467. ctx := NewDecodingContextFromReader(reader)
  1468. defer ctx.Close()
  1469. err := target.UnmarshalBinaryWithContext(ctx)
  1470. if err != nil {
  1471. return err
  1472. }
  1473. return nil
  1474. }
  1475. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1476. // the AllocationProperties type
  1477. func (target *AllocationProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1478. // panics are recovered and propagated as errors
  1479. defer func() {
  1480. if r := recover(); r != nil {
  1481. if e, ok := r.(error); ok {
  1482. err = e
  1483. } else if s, ok := r.(string); ok {
  1484. err = fmt.Errorf("Unexpected panic: %s", s)
  1485. } else {
  1486. err = fmt.Errorf("Unexpected panic: %+v", r)
  1487. }
  1488. }
  1489. }()
  1490. buff := ctx.Buffer
  1491. version := buff.ReadUInt8()
  1492. if version > AllocationCodecVersion {
  1493. return fmt.Errorf("Invalid Version Unmarshaling AllocationProperties. Expected %d or less, got %d", AllocationCodecVersion, version)
  1494. }
  1495. var b string
  1496. if ctx.IsStringTable() {
  1497. c := buff.ReadInt() // read string index
  1498. b = ctx.Table.At(c)
  1499. } else {
  1500. b = buff.ReadString() // read string
  1501. }
  1502. a := b
  1503. target.Cluster = a
  1504. var e string
  1505. if ctx.IsStringTable() {
  1506. f := buff.ReadInt() // read string index
  1507. e = ctx.Table.At(f)
  1508. } else {
  1509. e = buff.ReadString() // read string
  1510. }
  1511. d := e
  1512. target.Node = d
  1513. var h string
  1514. if ctx.IsStringTable() {
  1515. l := buff.ReadInt() // read string index
  1516. h = ctx.Table.At(l)
  1517. } else {
  1518. h = buff.ReadString() // read string
  1519. }
  1520. g := h
  1521. target.Container = g
  1522. var n string
  1523. if ctx.IsStringTable() {
  1524. o := buff.ReadInt() // read string index
  1525. n = ctx.Table.At(o)
  1526. } else {
  1527. n = buff.ReadString() // read string
  1528. }
  1529. m := n
  1530. target.Controller = m
  1531. var q string
  1532. if ctx.IsStringTable() {
  1533. r := buff.ReadInt() // read string index
  1534. q = ctx.Table.At(r)
  1535. } else {
  1536. q = buff.ReadString() // read string
  1537. }
  1538. p := q
  1539. target.ControllerKind = p
  1540. var t string
  1541. if ctx.IsStringTable() {
  1542. u := buff.ReadInt() // read string index
  1543. t = ctx.Table.At(u)
  1544. } else {
  1545. t = buff.ReadString() // read string
  1546. }
  1547. s := t
  1548. target.Namespace = s
  1549. var x string
  1550. if ctx.IsStringTable() {
  1551. y := buff.ReadInt() // read string index
  1552. x = ctx.Table.At(y)
  1553. } else {
  1554. x = buff.ReadString() // read string
  1555. }
  1556. w := x
  1557. target.Pod = w
  1558. if buff.ReadUInt8() == uint8(0) {
  1559. target.Services = nil
  1560. } else {
  1561. // --- [begin][read][slice]([]string) ---
  1562. bb := buff.ReadInt() // array len
  1563. aa := make([]string, bb)
  1564. for i := 0; i < bb; i++ {
  1565. var cc string
  1566. var ee string
  1567. if ctx.IsStringTable() {
  1568. ff := buff.ReadInt() // read string index
  1569. ee = ctx.Table.At(ff)
  1570. } else {
  1571. ee = buff.ReadString() // read string
  1572. }
  1573. dd := ee
  1574. cc = dd
  1575. aa[i] = cc
  1576. }
  1577. target.Services = aa
  1578. // --- [end][read][slice]([]string) ---
  1579. }
  1580. var hh string
  1581. if ctx.IsStringTable() {
  1582. ll := buff.ReadInt() // read string index
  1583. hh = ctx.Table.At(ll)
  1584. } else {
  1585. hh = buff.ReadString() // read string
  1586. }
  1587. gg := hh
  1588. target.ProviderID = gg
  1589. // --- [begin][read][alias](AllocationLabels) ---
  1590. var mm map[string]string
  1591. if buff.ReadUInt8() == uint8(0) {
  1592. mm = nil
  1593. } else {
  1594. // --- [begin][read][map](map[string]string) ---
  1595. oo := buff.ReadInt() // map len
  1596. nn := make(map[string]string, oo)
  1597. for j := 0; j < oo; j++ {
  1598. var v string
  1599. var qq string
  1600. if ctx.IsStringTable() {
  1601. rr := buff.ReadInt() // read string index
  1602. qq = ctx.Table.At(rr)
  1603. } else {
  1604. qq = buff.ReadString() // read string
  1605. }
  1606. pp := qq
  1607. v = pp
  1608. var z string
  1609. var tt string
  1610. if ctx.IsStringTable() {
  1611. uu := buff.ReadInt() // read string index
  1612. tt = ctx.Table.At(uu)
  1613. } else {
  1614. tt = buff.ReadString() // read string
  1615. }
  1616. ss := tt
  1617. z = ss
  1618. nn[v] = z
  1619. }
  1620. mm = nn
  1621. // --- [end][read][map](map[string]string) ---
  1622. }
  1623. target.Labels = AllocationLabels(mm)
  1624. // --- [end][read][alias](AllocationLabels) ---
  1625. // --- [begin][read][alias](AllocationAnnotations) ---
  1626. var ww map[string]string
  1627. if buff.ReadUInt8() == uint8(0) {
  1628. ww = nil
  1629. } else {
  1630. // --- [begin][read][map](map[string]string) ---
  1631. yy := buff.ReadInt() // map len
  1632. xx := make(map[string]string, yy)
  1633. for ii := 0; ii < yy; ii++ {
  1634. var vv string
  1635. var bbb string
  1636. if ctx.IsStringTable() {
  1637. ccc := buff.ReadInt() // read string index
  1638. bbb = ctx.Table.At(ccc)
  1639. } else {
  1640. bbb = buff.ReadString() // read string
  1641. }
  1642. aaa := bbb
  1643. vv = aaa
  1644. var zz string
  1645. var eee string
  1646. if ctx.IsStringTable() {
  1647. fff := buff.ReadInt() // read string index
  1648. eee = ctx.Table.At(fff)
  1649. } else {
  1650. eee = buff.ReadString() // read string
  1651. }
  1652. ddd := eee
  1653. zz = ddd
  1654. xx[vv] = zz
  1655. }
  1656. ww = xx
  1657. // --- [end][read][map](map[string]string) ---
  1658. }
  1659. target.Annotations = AllocationAnnotations(ww)
  1660. // --- [end][read][alias](AllocationAnnotations) ---
  1661. // field version check
  1662. if uint8(17) <= version {
  1663. // --- [begin][read][alias](AllocationLabels) ---
  1664. var ggg map[string]string
  1665. if buff.ReadUInt8() == uint8(0) {
  1666. ggg = nil
  1667. } else {
  1668. // --- [begin][read][map](map[string]string) ---
  1669. lll := buff.ReadInt() // map len
  1670. hhh := make(map[string]string, lll)
  1671. for jj := 0; jj < lll; jj++ {
  1672. var vvv string
  1673. var nnn string
  1674. if ctx.IsStringTable() {
  1675. ooo := buff.ReadInt() // read string index
  1676. nnn = ctx.Table.At(ooo)
  1677. } else {
  1678. nnn = buff.ReadString() // read string
  1679. }
  1680. mmm := nnn
  1681. vvv = mmm
  1682. var zzz string
  1683. var qqq string
  1684. if ctx.IsStringTable() {
  1685. rrr := buff.ReadInt() // read string index
  1686. qqq = ctx.Table.At(rrr)
  1687. } else {
  1688. qqq = buff.ReadString() // read string
  1689. }
  1690. ppp := qqq
  1691. zzz = ppp
  1692. hhh[vvv] = zzz
  1693. }
  1694. ggg = hhh
  1695. // --- [end][read][map](map[string]string) ---
  1696. }
  1697. target.NamespaceLabels = AllocationLabels(ggg)
  1698. // --- [end][read][alias](AllocationLabels) ---
  1699. } else {
  1700. }
  1701. // field version check
  1702. if uint8(17) <= version {
  1703. // --- [begin][read][alias](AllocationAnnotations) ---
  1704. var sss map[string]string
  1705. if buff.ReadUInt8() == uint8(0) {
  1706. sss = nil
  1707. } else {
  1708. // --- [begin][read][map](map[string]string) ---
  1709. uuu := buff.ReadInt() // map len
  1710. ttt := make(map[string]string, uuu)
  1711. for iii := 0; iii < uuu; iii++ {
  1712. var vvvv string
  1713. var xxx string
  1714. if ctx.IsStringTable() {
  1715. yyy := buff.ReadInt() // read string index
  1716. xxx = ctx.Table.At(yyy)
  1717. } else {
  1718. xxx = buff.ReadString() // read string
  1719. }
  1720. www := xxx
  1721. vvvv = www
  1722. var zzzz string
  1723. var bbbb string
  1724. if ctx.IsStringTable() {
  1725. cccc := buff.ReadInt() // read string index
  1726. bbbb = ctx.Table.At(cccc)
  1727. } else {
  1728. bbbb = buff.ReadString() // read string
  1729. }
  1730. aaaa := bbbb
  1731. zzzz = aaaa
  1732. ttt[vvvv] = zzzz
  1733. }
  1734. sss = ttt
  1735. // --- [end][read][map](map[string]string) ---
  1736. }
  1737. target.NamespaceAnnotations = AllocationAnnotations(sss)
  1738. // --- [end][read][alias](AllocationAnnotations) ---
  1739. } else {
  1740. }
  1741. return nil
  1742. }
  1743. //--------------------------------------------------------------------------
  1744. // AllocationSet
  1745. //--------------------------------------------------------------------------
  1746. // MarshalBinary serializes the internal properties of this AllocationSet instance
  1747. // into a byte array
  1748. func (target *AllocationSet) MarshalBinary() (data []byte, err error) {
  1749. ctx := &EncodingContext{
  1750. Buffer: util.NewBuffer(),
  1751. Table: NewStringTableWriter(),
  1752. }
  1753. e := target.MarshalBinaryWithContext(ctx)
  1754. if e != nil {
  1755. return nil, e
  1756. }
  1757. encBytes := ctx.Buffer.Bytes()
  1758. sTableBytes := ctx.Table.ToBytes()
  1759. merged := appendBytes(sTableBytes, encBytes)
  1760. return merged, nil
  1761. }
  1762. // MarshalBinaryWithContext serializes the internal properties of this AllocationSet instance
  1763. // into a byte array leveraging a predefined context.
  1764. func (target *AllocationSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1765. // panics are recovered and propagated as errors
  1766. defer func() {
  1767. if r := recover(); r != nil {
  1768. if e, ok := r.(error); ok {
  1769. err = e
  1770. } else if s, ok := r.(string); ok {
  1771. err = fmt.Errorf("Unexpected panic: %s", s)
  1772. } else {
  1773. err = fmt.Errorf("Unexpected panic: %+v", r)
  1774. }
  1775. }
  1776. }()
  1777. buff := ctx.Buffer
  1778. buff.WriteUInt8(AllocationCodecVersion) // version
  1779. if target.Allocations == nil {
  1780. buff.WriteUInt8(uint8(0)) // write nil byte
  1781. } else {
  1782. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1783. // --- [begin][write][map](map[string]*Allocation) ---
  1784. buff.WriteInt(len(target.Allocations)) // map length
  1785. for v, z := range target.Allocations {
  1786. if ctx.IsStringTable() {
  1787. a := ctx.Table.AddOrGet(v)
  1788. buff.WriteInt(a) // write table index
  1789. } else {
  1790. buff.WriteString(v) // write string
  1791. }
  1792. if z == nil {
  1793. buff.WriteUInt8(uint8(0)) // write nil byte
  1794. } else {
  1795. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1796. // --- [begin][write][struct](Allocation) ---
  1797. buff.WriteInt(0) // [compatibility, unused]
  1798. errA := z.MarshalBinaryWithContext(ctx)
  1799. if errA != nil {
  1800. return errA
  1801. }
  1802. // --- [end][write][struct](Allocation) ---
  1803. }
  1804. }
  1805. // --- [end][write][map](map[string]*Allocation) ---
  1806. }
  1807. if target.ExternalKeys == nil {
  1808. buff.WriteUInt8(uint8(0)) // write nil byte
  1809. } else {
  1810. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1811. // --- [begin][write][map](map[string]bool) ---
  1812. buff.WriteInt(len(target.ExternalKeys)) // map length
  1813. for vv, zz := range target.ExternalKeys {
  1814. if ctx.IsStringTable() {
  1815. b := ctx.Table.AddOrGet(vv)
  1816. buff.WriteInt(b) // write table index
  1817. } else {
  1818. buff.WriteString(vv) // write string
  1819. }
  1820. buff.WriteBool(zz) // write bool
  1821. }
  1822. // --- [end][write][map](map[string]bool) ---
  1823. }
  1824. if target.IdleKeys == nil {
  1825. buff.WriteUInt8(uint8(0)) // write nil byte
  1826. } else {
  1827. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1828. // --- [begin][write][map](map[string]bool) ---
  1829. buff.WriteInt(len(target.IdleKeys)) // map length
  1830. for vvv, zzz := range target.IdleKeys {
  1831. if ctx.IsStringTable() {
  1832. c := ctx.Table.AddOrGet(vvv)
  1833. buff.WriteInt(c) // write table index
  1834. } else {
  1835. buff.WriteString(vvv) // write string
  1836. }
  1837. buff.WriteBool(zzz) // write bool
  1838. }
  1839. // --- [end][write][map](map[string]bool) ---
  1840. }
  1841. if ctx.IsStringTable() {
  1842. d := ctx.Table.AddOrGet(target.FromSource)
  1843. buff.WriteInt(d) // write table index
  1844. } else {
  1845. buff.WriteString(target.FromSource) // write string
  1846. }
  1847. // --- [begin][write][struct](Window) ---
  1848. buff.WriteInt(0) // [compatibility, unused]
  1849. errB := target.Window.MarshalBinaryWithContext(ctx)
  1850. if errB != nil {
  1851. return errB
  1852. }
  1853. // --- [end][write][struct](Window) ---
  1854. if target.Warnings == nil {
  1855. buff.WriteUInt8(uint8(0)) // write nil byte
  1856. } else {
  1857. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1858. // --- [begin][write][slice]([]string) ---
  1859. buff.WriteInt(len(target.Warnings)) // array length
  1860. for i := 0; i < len(target.Warnings); i++ {
  1861. if ctx.IsStringTable() {
  1862. e := ctx.Table.AddOrGet(target.Warnings[i])
  1863. buff.WriteInt(e) // write table index
  1864. } else {
  1865. buff.WriteString(target.Warnings[i]) // write string
  1866. }
  1867. }
  1868. // --- [end][write][slice]([]string) ---
  1869. }
  1870. if target.Errors == nil {
  1871. buff.WriteUInt8(uint8(0)) // write nil byte
  1872. } else {
  1873. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1874. // --- [begin][write][slice]([]string) ---
  1875. buff.WriteInt(len(target.Errors)) // array length
  1876. for j := 0; j < len(target.Errors); j++ {
  1877. if ctx.IsStringTable() {
  1878. f := ctx.Table.AddOrGet(target.Errors[j])
  1879. buff.WriteInt(f) // write table index
  1880. } else {
  1881. buff.WriteString(target.Errors[j]) // write string
  1882. }
  1883. }
  1884. // --- [end][write][slice]([]string) ---
  1885. }
  1886. return nil
  1887. }
  1888. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1889. // the AllocationSet type
  1890. func (target *AllocationSet) UnmarshalBinary(data []byte) error {
  1891. ctx := NewDecodingContextFromBytes(data)
  1892. defer ctx.Close()
  1893. err := target.UnmarshalBinaryWithContext(ctx)
  1894. if err != nil {
  1895. return err
  1896. }
  1897. return nil
  1898. }
  1899. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  1900. // the AllocationSet type
  1901. func (target *AllocationSet) UnmarshalBinaryFromReader(reader io.Reader) error {
  1902. ctx := NewDecodingContextFromReader(reader)
  1903. defer ctx.Close()
  1904. err := target.UnmarshalBinaryWithContext(ctx)
  1905. if err != nil {
  1906. return err
  1907. }
  1908. return nil
  1909. }
  1910. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1911. // the AllocationSet type
  1912. func (target *AllocationSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1913. // panics are recovered and propagated as errors
  1914. defer func() {
  1915. if r := recover(); r != nil {
  1916. if e, ok := r.(error); ok {
  1917. err = e
  1918. } else if s, ok := r.(string); ok {
  1919. err = fmt.Errorf("Unexpected panic: %s", s)
  1920. } else {
  1921. err = fmt.Errorf("Unexpected panic: %+v", r)
  1922. }
  1923. }
  1924. }()
  1925. buff := ctx.Buffer
  1926. version := buff.ReadUInt8()
  1927. if version > AllocationCodecVersion {
  1928. return fmt.Errorf("Invalid Version Unmarshaling AllocationSet. Expected %d or less, got %d", AllocationCodecVersion, version)
  1929. }
  1930. if buff.ReadUInt8() == uint8(0) {
  1931. target.Allocations = nil
  1932. } else {
  1933. // --- [begin][read][map](map[string]*Allocation) ---
  1934. b := buff.ReadInt() // map len
  1935. a := make(map[string]*Allocation, b)
  1936. for i := 0; i < b; i++ {
  1937. var v string
  1938. var d string
  1939. if ctx.IsStringTable() {
  1940. e := buff.ReadInt() // read string index
  1941. d = ctx.Table.At(e)
  1942. } else {
  1943. d = buff.ReadString() // read string
  1944. }
  1945. c := d
  1946. v = c
  1947. var z *Allocation
  1948. if buff.ReadUInt8() == uint8(0) {
  1949. z = nil
  1950. } else {
  1951. // --- [begin][read][struct](Allocation) ---
  1952. f := &Allocation{}
  1953. buff.ReadInt() // [compatibility, unused]
  1954. errA := f.UnmarshalBinaryWithContext(ctx)
  1955. if errA != nil {
  1956. return errA
  1957. }
  1958. z = f
  1959. // --- [end][read][struct](Allocation) ---
  1960. }
  1961. a[v] = z
  1962. }
  1963. target.Allocations = a
  1964. // --- [end][read][map](map[string]*Allocation) ---
  1965. }
  1966. if buff.ReadUInt8() == uint8(0) {
  1967. target.ExternalKeys = nil
  1968. } else {
  1969. // --- [begin][read][map](map[string]bool) ---
  1970. h := buff.ReadInt() // map len
  1971. g := make(map[string]bool, h)
  1972. for j := 0; j < h; j++ {
  1973. var vv string
  1974. var m string
  1975. if ctx.IsStringTable() {
  1976. n := buff.ReadInt() // read string index
  1977. m = ctx.Table.At(n)
  1978. } else {
  1979. m = buff.ReadString() // read string
  1980. }
  1981. l := m
  1982. vv = l
  1983. var zz bool
  1984. o := buff.ReadBool() // read bool
  1985. zz = o
  1986. g[vv] = zz
  1987. }
  1988. target.ExternalKeys = g
  1989. // --- [end][read][map](map[string]bool) ---
  1990. }
  1991. if buff.ReadUInt8() == uint8(0) {
  1992. target.IdleKeys = nil
  1993. } else {
  1994. // --- [begin][read][map](map[string]bool) ---
  1995. q := buff.ReadInt() // map len
  1996. p := make(map[string]bool, q)
  1997. for ii := 0; ii < q; ii++ {
  1998. var vvv string
  1999. var s string
  2000. if ctx.IsStringTable() {
  2001. t := buff.ReadInt() // read string index
  2002. s = ctx.Table.At(t)
  2003. } else {
  2004. s = buff.ReadString() // read string
  2005. }
  2006. r := s
  2007. vvv = r
  2008. var zzz bool
  2009. u := buff.ReadBool() // read bool
  2010. zzz = u
  2011. p[vvv] = zzz
  2012. }
  2013. target.IdleKeys = p
  2014. // --- [end][read][map](map[string]bool) ---
  2015. }
  2016. var x string
  2017. if ctx.IsStringTable() {
  2018. y := buff.ReadInt() // read string index
  2019. x = ctx.Table.At(y)
  2020. } else {
  2021. x = buff.ReadString() // read string
  2022. }
  2023. w := x
  2024. target.FromSource = w
  2025. // --- [begin][read][struct](Window) ---
  2026. aa := &Window{}
  2027. buff.ReadInt() // [compatibility, unused]
  2028. errB := aa.UnmarshalBinaryWithContext(ctx)
  2029. if errB != nil {
  2030. return errB
  2031. }
  2032. target.Window = *aa
  2033. // --- [end][read][struct](Window) ---
  2034. if buff.ReadUInt8() == uint8(0) {
  2035. target.Warnings = nil
  2036. } else {
  2037. // --- [begin][read][slice]([]string) ---
  2038. cc := buff.ReadInt() // array len
  2039. bb := make([]string, cc)
  2040. for jj := 0; jj < cc; jj++ {
  2041. var dd string
  2042. var ff string
  2043. if ctx.IsStringTable() {
  2044. gg := buff.ReadInt() // read string index
  2045. ff = ctx.Table.At(gg)
  2046. } else {
  2047. ff = buff.ReadString() // read string
  2048. }
  2049. ee := ff
  2050. dd = ee
  2051. bb[jj] = dd
  2052. }
  2053. target.Warnings = bb
  2054. // --- [end][read][slice]([]string) ---
  2055. }
  2056. if buff.ReadUInt8() == uint8(0) {
  2057. target.Errors = nil
  2058. } else {
  2059. // --- [begin][read][slice]([]string) ---
  2060. ll := buff.ReadInt() // array len
  2061. hh := make([]string, ll)
  2062. for iii := 0; iii < ll; iii++ {
  2063. var mm string
  2064. var oo string
  2065. if ctx.IsStringTable() {
  2066. pp := buff.ReadInt() // read string index
  2067. oo = ctx.Table.At(pp)
  2068. } else {
  2069. oo = buff.ReadString() // read string
  2070. }
  2071. nn := oo
  2072. mm = nn
  2073. hh[iii] = mm
  2074. }
  2075. target.Errors = hh
  2076. // --- [end][read][slice]([]string) ---
  2077. }
  2078. return nil
  2079. }
  2080. //--------------------------------------------------------------------------
  2081. // AllocationSetStream
  2082. //--------------------------------------------------------------------------
  2083. // AllocationSetStream is a single use field stream for the contents of an AllocationSet instance. Instead of creating an instance and populating
  2084. // the fields on that instance, we provide a streaming iterator which yields (BingenFieldInfo, *BingenValue) tuples for each
  2085. // stremable element. All slices and maps will be flattened one depth and each element streamed individually.
  2086. type AllocationSetStream struct {
  2087. reader io.Reader
  2088. ctx *DecodingContext
  2089. err error
  2090. }
  2091. // Closes closes the internal io.Reader used to read and parse the AllocationSet fields.
  2092. // This should be called once the stream is no longer needed.
  2093. func (stream *AllocationSetStream) Close() {
  2094. if closer, ok := stream.reader.(io.Closer); ok {
  2095. closer.Close()
  2096. }
  2097. stream.ctx.Close()
  2098. }
  2099. // Error returns an error if one occurred during the process of streaming the AllocationSet
  2100. // This can be checked after iterating through the Stream().
  2101. func (stream *AllocationSetStream) Error() error {
  2102. return stream.err
  2103. }
  2104. // NewAllocationSetStream creates a new AllocationSetStream, which uses the io.Reader data to stream all internal fields of an AllocationSet instance
  2105. func NewAllocationSetStream(reader io.Reader) BingenStream {
  2106. ctx := NewDecodingContextFromReader(reader)
  2107. return &AllocationSetStream{
  2108. ctx: ctx,
  2109. reader: reader,
  2110. }
  2111. }
  2112. // Stream returns the iterator which will stream each field of the target type.
  2113. func (stream *AllocationSetStream) Stream() iter.Seq2[BingenFieldInfo, *BingenValue] {
  2114. return func(yield func(BingenFieldInfo, *BingenValue) bool) {
  2115. var fi BingenFieldInfo
  2116. ctx := stream.ctx
  2117. buff := ctx.Buffer
  2118. version := buff.ReadUInt8()
  2119. if version > AllocationCodecVersion {
  2120. stream.err = fmt.Errorf("Invalid Version Unmarshaling AllocationSet. Expected %d or less, got %d", AllocationCodecVersion, version)
  2121. return
  2122. }
  2123. fi = BingenFieldInfo{
  2124. Type: reflect.TypeFor[map[string]*Allocation](),
  2125. Name: "Allocations",
  2126. }
  2127. if buff.ReadUInt8() == uint8(0) {
  2128. if !yield(fi, nil) {
  2129. return
  2130. }
  2131. } else {
  2132. // --- [begin][read][streaming-map](map[string]*Allocation) ---
  2133. a := buff.ReadInt() // map len
  2134. for i := 0; i < a; i++ {
  2135. var v string
  2136. var c string
  2137. if ctx.IsStringTable() {
  2138. d := buff.ReadInt() // read string index
  2139. c = ctx.Table.At(d)
  2140. } else {
  2141. c = buff.ReadString() // read string
  2142. }
  2143. b := c
  2144. v = b
  2145. var z *Allocation
  2146. if buff.ReadUInt8() == uint8(0) {
  2147. z = nil
  2148. } else {
  2149. // --- [begin][read][struct](Allocation) ---
  2150. e := &Allocation{}
  2151. buff.ReadInt() // [compatibility, unused]
  2152. errA := e.UnmarshalBinaryWithContext(ctx)
  2153. if errA != nil {
  2154. stream.err = errA
  2155. return
  2156. }
  2157. z = e
  2158. // --- [end][read][struct](Allocation) ---
  2159. }
  2160. if !yield(fi, pairV(v, z)) {
  2161. return
  2162. }
  2163. }
  2164. // --- [end][read][streaming-map](map[string]*Allocation) ---
  2165. }
  2166. fi = BingenFieldInfo{
  2167. Type: reflect.TypeFor[map[string]bool](),
  2168. Name: "ExternalKeys",
  2169. }
  2170. if buff.ReadUInt8() == uint8(0) {
  2171. if !yield(fi, nil) {
  2172. return
  2173. }
  2174. } else {
  2175. // --- [begin][read][streaming-map](map[string]bool) ---
  2176. f := buff.ReadInt() // map len
  2177. for j := 0; j < f; j++ {
  2178. var vv string
  2179. var h string
  2180. if ctx.IsStringTable() {
  2181. l := buff.ReadInt() // read string index
  2182. h = ctx.Table.At(l)
  2183. } else {
  2184. h = buff.ReadString() // read string
  2185. }
  2186. g := h
  2187. vv = g
  2188. var zz bool
  2189. m := buff.ReadBool() // read bool
  2190. zz = m
  2191. if !yield(fi, pairV(vv, zz)) {
  2192. return
  2193. }
  2194. }
  2195. // --- [end][read][streaming-map](map[string]bool) ---
  2196. }
  2197. fi = BingenFieldInfo{
  2198. Type: reflect.TypeFor[map[string]bool](),
  2199. Name: "IdleKeys",
  2200. }
  2201. if buff.ReadUInt8() == uint8(0) {
  2202. if !yield(fi, nil) {
  2203. return
  2204. }
  2205. } else {
  2206. // --- [begin][read][streaming-map](map[string]bool) ---
  2207. n := buff.ReadInt() // map len
  2208. for ii := 0; ii < n; ii++ {
  2209. var vvv string
  2210. var p string
  2211. if ctx.IsStringTable() {
  2212. q := buff.ReadInt() // read string index
  2213. p = ctx.Table.At(q)
  2214. } else {
  2215. p = buff.ReadString() // read string
  2216. }
  2217. o := p
  2218. vvv = o
  2219. var zzz bool
  2220. r := buff.ReadBool() // read bool
  2221. zzz = r
  2222. if !yield(fi, pairV(vvv, zzz)) {
  2223. return
  2224. }
  2225. }
  2226. // --- [end][read][streaming-map](map[string]bool) ---
  2227. }
  2228. fi = BingenFieldInfo{
  2229. Type: reflect.TypeFor[string](),
  2230. Name: "FromSource",
  2231. }
  2232. var s string
  2233. var u string
  2234. if ctx.IsStringTable() {
  2235. w := buff.ReadInt() // read string index
  2236. u = ctx.Table.At(w)
  2237. } else {
  2238. u = buff.ReadString() // read string
  2239. }
  2240. t := u
  2241. s = t
  2242. if !yield(fi, singleV(s)) {
  2243. return
  2244. }
  2245. fi = BingenFieldInfo{
  2246. Type: reflect.TypeFor[Window](),
  2247. Name: "Window",
  2248. }
  2249. // --- [begin][read][struct](Window) ---
  2250. y := &Window{}
  2251. buff.ReadInt() // [compatibility, unused]
  2252. errB := y.UnmarshalBinaryWithContext(ctx)
  2253. if errB != nil {
  2254. stream.err = errB
  2255. return
  2256. }
  2257. x := *y
  2258. // --- [end][read][struct](Window) ---
  2259. if !yield(fi, singleV(x)) {
  2260. return
  2261. }
  2262. fi = BingenFieldInfo{
  2263. Type: reflect.TypeFor[[]string](),
  2264. Name: "Warnings",
  2265. }
  2266. if buff.ReadUInt8() == uint8(0) {
  2267. if !yield(fi, nil) {
  2268. return
  2269. }
  2270. } else {
  2271. // --- [begin][read][streaming-slice]([]string) ---
  2272. aa := buff.ReadInt() // array len
  2273. for jj := 0; jj < aa; jj++ {
  2274. var bb string
  2275. var dd string
  2276. if ctx.IsStringTable() {
  2277. ee := buff.ReadInt() // read string index
  2278. dd = ctx.Table.At(ee)
  2279. } else {
  2280. dd = buff.ReadString() // read string
  2281. }
  2282. cc := dd
  2283. bb = cc
  2284. if !yield(fi, pairV(jj, bb)) {
  2285. return
  2286. }
  2287. }
  2288. // --- [end][read][streaming-slice]([]string) ---
  2289. }
  2290. fi = BingenFieldInfo{
  2291. Type: reflect.TypeFor[[]string](),
  2292. Name: "Errors",
  2293. }
  2294. if buff.ReadUInt8() == uint8(0) {
  2295. if !yield(fi, nil) {
  2296. return
  2297. }
  2298. } else {
  2299. // --- [begin][read][streaming-slice]([]string) ---
  2300. ff := buff.ReadInt() // array len
  2301. for iii := 0; iii < ff; iii++ {
  2302. var gg string
  2303. var ll string
  2304. if ctx.IsStringTable() {
  2305. mm := buff.ReadInt() // read string index
  2306. ll = ctx.Table.At(mm)
  2307. } else {
  2308. ll = buff.ReadString() // read string
  2309. }
  2310. hh := ll
  2311. gg = hh
  2312. if !yield(fi, pairV(iii, gg)) {
  2313. return
  2314. }
  2315. }
  2316. // --- [end][read][streaming-slice]([]string) ---
  2317. }
  2318. }
  2319. }
  2320. //--------------------------------------------------------------------------
  2321. // AllocationSetRange
  2322. //--------------------------------------------------------------------------
  2323. // MarshalBinary serializes the internal properties of this AllocationSetRange instance
  2324. // into a byte array
  2325. func (target *AllocationSetRange) MarshalBinary() (data []byte, err error) {
  2326. ctx := &EncodingContext{
  2327. Buffer: util.NewBuffer(),
  2328. Table: nil,
  2329. }
  2330. e := target.MarshalBinaryWithContext(ctx)
  2331. if e != nil {
  2332. return nil, e
  2333. }
  2334. encBytes := ctx.Buffer.Bytes()
  2335. return encBytes, nil
  2336. }
  2337. // MarshalBinaryWithContext serializes the internal properties of this AllocationSetRange instance
  2338. // into a byte array leveraging a predefined context.
  2339. func (target *AllocationSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2340. // panics are recovered and propagated as errors
  2341. defer func() {
  2342. if r := recover(); r != nil {
  2343. if e, ok := r.(error); ok {
  2344. err = e
  2345. } else if s, ok := r.(string); ok {
  2346. err = fmt.Errorf("Unexpected panic: %s", s)
  2347. } else {
  2348. err = fmt.Errorf("Unexpected panic: %+v", r)
  2349. }
  2350. }
  2351. }()
  2352. buff := ctx.Buffer
  2353. buff.WriteUInt8(AllocationCodecVersion) // version
  2354. if target.Allocations == nil {
  2355. buff.WriteUInt8(uint8(0)) // write nil byte
  2356. } else {
  2357. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2358. // --- [begin][write][slice]([]*AllocationSet) ---
  2359. buff.WriteInt(len(target.Allocations)) // array length
  2360. for i := 0; i < len(target.Allocations); i++ {
  2361. if target.Allocations[i] == nil {
  2362. buff.WriteUInt8(uint8(0)) // write nil byte
  2363. } else {
  2364. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2365. // --- [begin][write][struct](AllocationSet) ---
  2366. buff.WriteInt(0) // [compatibility, unused]
  2367. errA := target.Allocations[i].MarshalBinaryWithContext(ctx)
  2368. if errA != nil {
  2369. return errA
  2370. }
  2371. // --- [end][write][struct](AllocationSet) ---
  2372. }
  2373. }
  2374. // --- [end][write][slice]([]*AllocationSet) ---
  2375. }
  2376. if ctx.IsStringTable() {
  2377. a := ctx.Table.AddOrGet(target.FromStore)
  2378. buff.WriteInt(a) // write table index
  2379. } else {
  2380. buff.WriteString(target.FromStore) // write string
  2381. }
  2382. return nil
  2383. }
  2384. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2385. // the AllocationSetRange type
  2386. func (target *AllocationSetRange) UnmarshalBinary(data []byte) error {
  2387. ctx := NewDecodingContextFromBytes(data)
  2388. defer ctx.Close()
  2389. err := target.UnmarshalBinaryWithContext(ctx)
  2390. if err != nil {
  2391. return err
  2392. }
  2393. return nil
  2394. }
  2395. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  2396. // the AllocationSetRange type
  2397. func (target *AllocationSetRange) UnmarshalBinaryFromReader(reader io.Reader) error {
  2398. ctx := NewDecodingContextFromReader(reader)
  2399. defer ctx.Close()
  2400. err := target.UnmarshalBinaryWithContext(ctx)
  2401. if err != nil {
  2402. return err
  2403. }
  2404. return nil
  2405. }
  2406. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2407. // the AllocationSetRange type
  2408. func (target *AllocationSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2409. // panics are recovered and propagated as errors
  2410. defer func() {
  2411. if r := recover(); r != nil {
  2412. if e, ok := r.(error); ok {
  2413. err = e
  2414. } else if s, ok := r.(string); ok {
  2415. err = fmt.Errorf("Unexpected panic: %s", s)
  2416. } else {
  2417. err = fmt.Errorf("Unexpected panic: %+v", r)
  2418. }
  2419. }
  2420. }()
  2421. buff := ctx.Buffer
  2422. version := buff.ReadUInt8()
  2423. if version > AllocationCodecVersion {
  2424. return fmt.Errorf("Invalid Version Unmarshaling AllocationSetRange. Expected %d or less, got %d", AllocationCodecVersion, version)
  2425. }
  2426. if buff.ReadUInt8() == uint8(0) {
  2427. target.Allocations = nil
  2428. } else {
  2429. // --- [begin][read][slice]([]*AllocationSet) ---
  2430. b := buff.ReadInt() // array len
  2431. a := make([]*AllocationSet, b)
  2432. for i := 0; i < b; i++ {
  2433. var c *AllocationSet
  2434. if buff.ReadUInt8() == uint8(0) {
  2435. c = nil
  2436. } else {
  2437. // --- [begin][read][struct](AllocationSet) ---
  2438. d := &AllocationSet{}
  2439. buff.ReadInt() // [compatibility, unused]
  2440. errA := d.UnmarshalBinaryWithContext(ctx)
  2441. if errA != nil {
  2442. return errA
  2443. }
  2444. c = d
  2445. // --- [end][read][struct](AllocationSet) ---
  2446. }
  2447. a[i] = c
  2448. }
  2449. target.Allocations = a
  2450. // --- [end][read][slice]([]*AllocationSet) ---
  2451. }
  2452. var f string
  2453. if ctx.IsStringTable() {
  2454. g := buff.ReadInt() // read string index
  2455. f = ctx.Table.At(g)
  2456. } else {
  2457. f = buff.ReadString() // read string
  2458. }
  2459. e := f
  2460. target.FromStore = e
  2461. return nil
  2462. }
  2463. //--------------------------------------------------------------------------
  2464. // Any
  2465. //--------------------------------------------------------------------------
  2466. // MarshalBinary serializes the internal properties of this Any instance
  2467. // into a byte array
  2468. func (target *Any) MarshalBinary() (data []byte, err error) {
  2469. ctx := &EncodingContext{
  2470. Buffer: util.NewBuffer(),
  2471. Table: nil,
  2472. }
  2473. e := target.MarshalBinaryWithContext(ctx)
  2474. if e != nil {
  2475. return nil, e
  2476. }
  2477. encBytes := ctx.Buffer.Bytes()
  2478. return encBytes, nil
  2479. }
  2480. // MarshalBinaryWithContext serializes the internal properties of this Any instance
  2481. // into a byte array leveraging a predefined context.
  2482. func (target *Any) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2483. // panics are recovered and propagated as errors
  2484. defer func() {
  2485. if r := recover(); r != nil {
  2486. if e, ok := r.(error); ok {
  2487. err = e
  2488. } else if s, ok := r.(string); ok {
  2489. err = fmt.Errorf("Unexpected panic: %s", s)
  2490. } else {
  2491. err = fmt.Errorf("Unexpected panic: %+v", r)
  2492. }
  2493. }
  2494. }()
  2495. buff := ctx.Buffer
  2496. buff.WriteUInt8(AssetsCodecVersion) // version
  2497. // --- [begin][write][alias](AssetLabels) ---
  2498. if map[string]string(target.Labels) == nil {
  2499. buff.WriteUInt8(uint8(0)) // write nil byte
  2500. } else {
  2501. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2502. // --- [begin][write][map](map[string]string) ---
  2503. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  2504. for v, z := range map[string]string(target.Labels) {
  2505. if ctx.IsStringTable() {
  2506. a := ctx.Table.AddOrGet(v)
  2507. buff.WriteInt(a) // write table index
  2508. } else {
  2509. buff.WriteString(v) // write string
  2510. }
  2511. if ctx.IsStringTable() {
  2512. b := ctx.Table.AddOrGet(z)
  2513. buff.WriteInt(b) // write table index
  2514. } else {
  2515. buff.WriteString(z) // write string
  2516. }
  2517. }
  2518. // --- [end][write][map](map[string]string) ---
  2519. }
  2520. // --- [end][write][alias](AssetLabels) ---
  2521. if target.Properties == nil {
  2522. buff.WriteUInt8(uint8(0)) // write nil byte
  2523. } else {
  2524. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2525. // --- [begin][write][struct](AssetProperties) ---
  2526. buff.WriteInt(0) // [compatibility, unused]
  2527. errA := target.Properties.MarshalBinaryWithContext(ctx)
  2528. if errA != nil {
  2529. return errA
  2530. }
  2531. // --- [end][write][struct](AssetProperties) ---
  2532. }
  2533. // --- [begin][write][reference](time.Time) ---
  2534. c, errB := target.Start.MarshalBinary()
  2535. if errB != nil {
  2536. return errB
  2537. }
  2538. buff.WriteInt(len(c))
  2539. buff.WriteBytes(c)
  2540. // --- [end][write][reference](time.Time) ---
  2541. // --- [begin][write][reference](time.Time) ---
  2542. d, errC := target.End.MarshalBinary()
  2543. if errC != nil {
  2544. return errC
  2545. }
  2546. buff.WriteInt(len(d))
  2547. buff.WriteBytes(d)
  2548. // --- [end][write][reference](time.Time) ---
  2549. // --- [begin][write][struct](Window) ---
  2550. buff.WriteInt(0) // [compatibility, unused]
  2551. errD := target.Window.MarshalBinaryWithContext(ctx)
  2552. if errD != nil {
  2553. return errD
  2554. }
  2555. // --- [end][write][struct](Window) ---
  2556. buff.WriteFloat64(target.Adjustment) // write float64
  2557. buff.WriteFloat64(target.Cost) // write float64
  2558. return nil
  2559. }
  2560. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2561. // the Any type
  2562. func (target *Any) UnmarshalBinary(data []byte) error {
  2563. ctx := NewDecodingContextFromBytes(data)
  2564. defer ctx.Close()
  2565. err := target.UnmarshalBinaryWithContext(ctx)
  2566. if err != nil {
  2567. return err
  2568. }
  2569. return nil
  2570. }
  2571. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  2572. // the Any type
  2573. func (target *Any) UnmarshalBinaryFromReader(reader io.Reader) error {
  2574. ctx := NewDecodingContextFromReader(reader)
  2575. defer ctx.Close()
  2576. err := target.UnmarshalBinaryWithContext(ctx)
  2577. if err != nil {
  2578. return err
  2579. }
  2580. return nil
  2581. }
  2582. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2583. // the Any type
  2584. func (target *Any) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2585. // panics are recovered and propagated as errors
  2586. defer func() {
  2587. if r := recover(); r != nil {
  2588. if e, ok := r.(error); ok {
  2589. err = e
  2590. } else if s, ok := r.(string); ok {
  2591. err = fmt.Errorf("Unexpected panic: %s", s)
  2592. } else {
  2593. err = fmt.Errorf("Unexpected panic: %+v", r)
  2594. }
  2595. }
  2596. }()
  2597. buff := ctx.Buffer
  2598. version := buff.ReadUInt8()
  2599. if version > AssetsCodecVersion {
  2600. return fmt.Errorf("Invalid Version Unmarshaling Any. Expected %d or less, got %d", AssetsCodecVersion, version)
  2601. }
  2602. // --- [begin][read][alias](AssetLabels) ---
  2603. var a map[string]string
  2604. if buff.ReadUInt8() == uint8(0) {
  2605. a = nil
  2606. } else {
  2607. // --- [begin][read][map](map[string]string) ---
  2608. c := buff.ReadInt() // map len
  2609. b := make(map[string]string, c)
  2610. for i := 0; i < c; i++ {
  2611. var v string
  2612. var e string
  2613. if ctx.IsStringTable() {
  2614. f := buff.ReadInt() // read string index
  2615. e = ctx.Table.At(f)
  2616. } else {
  2617. e = buff.ReadString() // read string
  2618. }
  2619. d := e
  2620. v = d
  2621. var z string
  2622. var h string
  2623. if ctx.IsStringTable() {
  2624. l := buff.ReadInt() // read string index
  2625. h = ctx.Table.At(l)
  2626. } else {
  2627. h = buff.ReadString() // read string
  2628. }
  2629. g := h
  2630. z = g
  2631. b[v] = z
  2632. }
  2633. a = b
  2634. // --- [end][read][map](map[string]string) ---
  2635. }
  2636. target.Labels = AssetLabels(a)
  2637. // --- [end][read][alias](AssetLabels) ---
  2638. if buff.ReadUInt8() == uint8(0) {
  2639. target.Properties = nil
  2640. } else {
  2641. // --- [begin][read][struct](AssetProperties) ---
  2642. m := &AssetProperties{}
  2643. buff.ReadInt() // [compatibility, unused]
  2644. errA := m.UnmarshalBinaryWithContext(ctx)
  2645. if errA != nil {
  2646. return errA
  2647. }
  2648. target.Properties = m
  2649. // --- [end][read][struct](AssetProperties) ---
  2650. }
  2651. // --- [begin][read][reference](time.Time) ---
  2652. n := &time.Time{}
  2653. o := buff.ReadInt() // byte array length
  2654. p := buff.ReadBytes(o) // byte array
  2655. errB := n.UnmarshalBinary(p)
  2656. if errB != nil {
  2657. return errB
  2658. }
  2659. target.Start = *n
  2660. // --- [end][read][reference](time.Time) ---
  2661. // --- [begin][read][reference](time.Time) ---
  2662. q := &time.Time{}
  2663. r := buff.ReadInt() // byte array length
  2664. s := buff.ReadBytes(r) // byte array
  2665. errC := q.UnmarshalBinary(s)
  2666. if errC != nil {
  2667. return errC
  2668. }
  2669. target.End = *q
  2670. // --- [end][read][reference](time.Time) ---
  2671. // --- [begin][read][struct](Window) ---
  2672. t := &Window{}
  2673. buff.ReadInt() // [compatibility, unused]
  2674. errD := t.UnmarshalBinaryWithContext(ctx)
  2675. if errD != nil {
  2676. return errD
  2677. }
  2678. target.Window = *t
  2679. // --- [end][read][struct](Window) ---
  2680. u := buff.ReadFloat64() // read float64
  2681. target.Adjustment = u
  2682. w := buff.ReadFloat64() // read float64
  2683. target.Cost = w
  2684. return nil
  2685. }
  2686. //--------------------------------------------------------------------------
  2687. // AssetProperties
  2688. //--------------------------------------------------------------------------
  2689. // MarshalBinary serializes the internal properties of this AssetProperties instance
  2690. // into a byte array
  2691. func (target *AssetProperties) MarshalBinary() (data []byte, err error) {
  2692. ctx := &EncodingContext{
  2693. Buffer: util.NewBuffer(),
  2694. Table: nil,
  2695. }
  2696. e := target.MarshalBinaryWithContext(ctx)
  2697. if e != nil {
  2698. return nil, e
  2699. }
  2700. encBytes := ctx.Buffer.Bytes()
  2701. return encBytes, nil
  2702. }
  2703. // MarshalBinaryWithContext serializes the internal properties of this AssetProperties instance
  2704. // into a byte array leveraging a predefined context.
  2705. func (target *AssetProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2706. // panics are recovered and propagated as errors
  2707. defer func() {
  2708. if r := recover(); r != nil {
  2709. if e, ok := r.(error); ok {
  2710. err = e
  2711. } else if s, ok := r.(string); ok {
  2712. err = fmt.Errorf("Unexpected panic: %s", s)
  2713. } else {
  2714. err = fmt.Errorf("Unexpected panic: %+v", r)
  2715. }
  2716. }
  2717. }()
  2718. buff := ctx.Buffer
  2719. buff.WriteUInt8(AssetsCodecVersion) // version
  2720. if ctx.IsStringTable() {
  2721. a := ctx.Table.AddOrGet(target.Category)
  2722. buff.WriteInt(a) // write table index
  2723. } else {
  2724. buff.WriteString(target.Category) // write string
  2725. }
  2726. if ctx.IsStringTable() {
  2727. b := ctx.Table.AddOrGet(target.Provider)
  2728. buff.WriteInt(b) // write table index
  2729. } else {
  2730. buff.WriteString(target.Provider) // write string
  2731. }
  2732. if ctx.IsStringTable() {
  2733. c := ctx.Table.AddOrGet(target.Account)
  2734. buff.WriteInt(c) // write table index
  2735. } else {
  2736. buff.WriteString(target.Account) // write string
  2737. }
  2738. if ctx.IsStringTable() {
  2739. d := ctx.Table.AddOrGet(target.Project)
  2740. buff.WriteInt(d) // write table index
  2741. } else {
  2742. buff.WriteString(target.Project) // write string
  2743. }
  2744. if ctx.IsStringTable() {
  2745. e := ctx.Table.AddOrGet(target.Service)
  2746. buff.WriteInt(e) // write table index
  2747. } else {
  2748. buff.WriteString(target.Service) // write string
  2749. }
  2750. if ctx.IsStringTable() {
  2751. f := ctx.Table.AddOrGet(target.Cluster)
  2752. buff.WriteInt(f) // write table index
  2753. } else {
  2754. buff.WriteString(target.Cluster) // write string
  2755. }
  2756. if ctx.IsStringTable() {
  2757. g := ctx.Table.AddOrGet(target.Name)
  2758. buff.WriteInt(g) // write table index
  2759. } else {
  2760. buff.WriteString(target.Name) // write string
  2761. }
  2762. if ctx.IsStringTable() {
  2763. h := ctx.Table.AddOrGet(target.ProviderID)
  2764. buff.WriteInt(h) // write table index
  2765. } else {
  2766. buff.WriteString(target.ProviderID) // write string
  2767. }
  2768. return nil
  2769. }
  2770. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2771. // the AssetProperties type
  2772. func (target *AssetProperties) UnmarshalBinary(data []byte) error {
  2773. ctx := NewDecodingContextFromBytes(data)
  2774. defer ctx.Close()
  2775. err := target.UnmarshalBinaryWithContext(ctx)
  2776. if err != nil {
  2777. return err
  2778. }
  2779. return nil
  2780. }
  2781. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  2782. // the AssetProperties type
  2783. func (target *AssetProperties) UnmarshalBinaryFromReader(reader io.Reader) error {
  2784. ctx := NewDecodingContextFromReader(reader)
  2785. defer ctx.Close()
  2786. err := target.UnmarshalBinaryWithContext(ctx)
  2787. if err != nil {
  2788. return err
  2789. }
  2790. return nil
  2791. }
  2792. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2793. // the AssetProperties type
  2794. func (target *AssetProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2795. // panics are recovered and propagated as errors
  2796. defer func() {
  2797. if r := recover(); r != nil {
  2798. if e, ok := r.(error); ok {
  2799. err = e
  2800. } else if s, ok := r.(string); ok {
  2801. err = fmt.Errorf("Unexpected panic: %s", s)
  2802. } else {
  2803. err = fmt.Errorf("Unexpected panic: %+v", r)
  2804. }
  2805. }
  2806. }()
  2807. buff := ctx.Buffer
  2808. version := buff.ReadUInt8()
  2809. if version > AssetsCodecVersion {
  2810. return fmt.Errorf("Invalid Version Unmarshaling AssetProperties. Expected %d or less, got %d", AssetsCodecVersion, version)
  2811. }
  2812. var b string
  2813. if ctx.IsStringTable() {
  2814. c := buff.ReadInt() // read string index
  2815. b = ctx.Table.At(c)
  2816. } else {
  2817. b = buff.ReadString() // read string
  2818. }
  2819. a := b
  2820. target.Category = a
  2821. var e string
  2822. if ctx.IsStringTable() {
  2823. f := buff.ReadInt() // read string index
  2824. e = ctx.Table.At(f)
  2825. } else {
  2826. e = buff.ReadString() // read string
  2827. }
  2828. d := e
  2829. target.Provider = d
  2830. var h string
  2831. if ctx.IsStringTable() {
  2832. l := buff.ReadInt() // read string index
  2833. h = ctx.Table.At(l)
  2834. } else {
  2835. h = buff.ReadString() // read string
  2836. }
  2837. g := h
  2838. target.Account = g
  2839. var n string
  2840. if ctx.IsStringTable() {
  2841. o := buff.ReadInt() // read string index
  2842. n = ctx.Table.At(o)
  2843. } else {
  2844. n = buff.ReadString() // read string
  2845. }
  2846. m := n
  2847. target.Project = m
  2848. var q string
  2849. if ctx.IsStringTable() {
  2850. r := buff.ReadInt() // read string index
  2851. q = ctx.Table.At(r)
  2852. } else {
  2853. q = buff.ReadString() // read string
  2854. }
  2855. p := q
  2856. target.Service = p
  2857. var t string
  2858. if ctx.IsStringTable() {
  2859. u := buff.ReadInt() // read string index
  2860. t = ctx.Table.At(u)
  2861. } else {
  2862. t = buff.ReadString() // read string
  2863. }
  2864. s := t
  2865. target.Cluster = s
  2866. var x string
  2867. if ctx.IsStringTable() {
  2868. y := buff.ReadInt() // read string index
  2869. x = ctx.Table.At(y)
  2870. } else {
  2871. x = buff.ReadString() // read string
  2872. }
  2873. w := x
  2874. target.Name = w
  2875. var bb string
  2876. if ctx.IsStringTable() {
  2877. cc := buff.ReadInt() // read string index
  2878. bb = ctx.Table.At(cc)
  2879. } else {
  2880. bb = buff.ReadString() // read string
  2881. }
  2882. aa := bb
  2883. target.ProviderID = aa
  2884. return nil
  2885. }
  2886. //--------------------------------------------------------------------------
  2887. // AssetSet
  2888. //--------------------------------------------------------------------------
  2889. // MarshalBinary serializes the internal properties of this AssetSet instance
  2890. // into a byte array
  2891. func (target *AssetSet) MarshalBinary() (data []byte, err error) {
  2892. ctx := &EncodingContext{
  2893. Buffer: util.NewBuffer(),
  2894. Table: NewStringTableWriter(),
  2895. }
  2896. e := target.MarshalBinaryWithContext(ctx)
  2897. if e != nil {
  2898. return nil, e
  2899. }
  2900. encBytes := ctx.Buffer.Bytes()
  2901. sTableBytes := ctx.Table.ToBytes()
  2902. merged := appendBytes(sTableBytes, encBytes)
  2903. return merged, nil
  2904. }
  2905. // MarshalBinaryWithContext serializes the internal properties of this AssetSet instance
  2906. // into a byte array leveraging a predefined context.
  2907. func (target *AssetSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2908. // panics are recovered and propagated as errors
  2909. defer func() {
  2910. if r := recover(); r != nil {
  2911. if e, ok := r.(error); ok {
  2912. err = e
  2913. } else if s, ok := r.(string); ok {
  2914. err = fmt.Errorf("Unexpected panic: %s", s)
  2915. } else {
  2916. err = fmt.Errorf("Unexpected panic: %+v", r)
  2917. }
  2918. }
  2919. }()
  2920. buff := ctx.Buffer
  2921. buff.WriteUInt8(AssetsCodecVersion) // version
  2922. // execute pre-processing func
  2923. preProcessAssetSet(target)
  2924. if target.AggregationKeys == nil {
  2925. buff.WriteUInt8(uint8(0)) // write nil byte
  2926. } else {
  2927. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2928. // --- [begin][write][slice]([]string) ---
  2929. buff.WriteInt(len(target.AggregationKeys)) // array length
  2930. for i := 0; i < len(target.AggregationKeys); i++ {
  2931. if ctx.IsStringTable() {
  2932. a := ctx.Table.AddOrGet(target.AggregationKeys[i])
  2933. buff.WriteInt(a) // write table index
  2934. } else {
  2935. buff.WriteString(target.AggregationKeys[i]) // write string
  2936. }
  2937. }
  2938. // --- [end][write][slice]([]string) ---
  2939. }
  2940. if target.Assets == nil {
  2941. buff.WriteUInt8(uint8(0)) // write nil byte
  2942. } else {
  2943. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2944. // --- [begin][write][map](map[string]Asset) ---
  2945. buff.WriteInt(len(target.Assets)) // map length
  2946. for v, z := range target.Assets {
  2947. if ctx.IsStringTable() {
  2948. b := ctx.Table.AddOrGet(v)
  2949. buff.WriteInt(b) // write table index
  2950. } else {
  2951. buff.WriteString(v) // write string
  2952. }
  2953. if z == nil {
  2954. buff.WriteUInt8(uint8(0)) // write nil byte
  2955. } else {
  2956. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2957. // --- [begin][write][interface](Asset) ---
  2958. c := reflect.ValueOf(z).Interface()
  2959. d, okA := c.(BinEncoder)
  2960. if !okA {
  2961. return fmt.Errorf("Type: %s does not implement %s.BinEncoder", typeToString(z), GeneratorPackageName)
  2962. }
  2963. buff.WriteString(typeToString(z))
  2964. buff.WriteInt(0) // [compatibility, unused]
  2965. errA := d.MarshalBinaryWithContext(ctx)
  2966. if errA != nil {
  2967. return errA
  2968. }
  2969. // --- [end][write][interface](Asset) ---
  2970. }
  2971. }
  2972. // --- [end][write][map](map[string]Asset) ---
  2973. }
  2974. if ctx.IsStringTable() {
  2975. e := ctx.Table.AddOrGet(target.FromSource)
  2976. buff.WriteInt(e) // write table index
  2977. } else {
  2978. buff.WriteString(target.FromSource) // write string
  2979. }
  2980. // --- [begin][write][struct](Window) ---
  2981. buff.WriteInt(0) // [compatibility, unused]
  2982. errB := target.Window.MarshalBinaryWithContext(ctx)
  2983. if errB != nil {
  2984. return errB
  2985. }
  2986. // --- [end][write][struct](Window) ---
  2987. if target.Warnings == nil {
  2988. buff.WriteUInt8(uint8(0)) // write nil byte
  2989. } else {
  2990. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2991. // --- [begin][write][slice]([]string) ---
  2992. buff.WriteInt(len(target.Warnings)) // array length
  2993. for j := 0; j < len(target.Warnings); j++ {
  2994. if ctx.IsStringTable() {
  2995. f := ctx.Table.AddOrGet(target.Warnings[j])
  2996. buff.WriteInt(f) // write table index
  2997. } else {
  2998. buff.WriteString(target.Warnings[j]) // write string
  2999. }
  3000. }
  3001. // --- [end][write][slice]([]string) ---
  3002. }
  3003. if target.Errors == nil {
  3004. buff.WriteUInt8(uint8(0)) // write nil byte
  3005. } else {
  3006. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3007. // --- [begin][write][slice]([]string) ---
  3008. buff.WriteInt(len(target.Errors)) // array length
  3009. for ii := 0; ii < len(target.Errors); ii++ {
  3010. if ctx.IsStringTable() {
  3011. g := ctx.Table.AddOrGet(target.Errors[ii])
  3012. buff.WriteInt(g) // write table index
  3013. } else {
  3014. buff.WriteString(target.Errors[ii]) // write string
  3015. }
  3016. }
  3017. // --- [end][write][slice]([]string) ---
  3018. }
  3019. return nil
  3020. }
  3021. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3022. // the AssetSet type
  3023. func (target *AssetSet) UnmarshalBinary(data []byte) error {
  3024. ctx := NewDecodingContextFromBytes(data)
  3025. defer ctx.Close()
  3026. err := target.UnmarshalBinaryWithContext(ctx)
  3027. if err != nil {
  3028. return err
  3029. }
  3030. return nil
  3031. }
  3032. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  3033. // the AssetSet type
  3034. func (target *AssetSet) UnmarshalBinaryFromReader(reader io.Reader) error {
  3035. ctx := NewDecodingContextFromReader(reader)
  3036. defer ctx.Close()
  3037. err := target.UnmarshalBinaryWithContext(ctx)
  3038. if err != nil {
  3039. return err
  3040. }
  3041. return nil
  3042. }
  3043. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3044. // the AssetSet type
  3045. func (target *AssetSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3046. // panics are recovered and propagated as errors
  3047. defer func() {
  3048. if r := recover(); r != nil {
  3049. if e, ok := r.(error); ok {
  3050. err = e
  3051. } else if s, ok := r.(string); ok {
  3052. err = fmt.Errorf("Unexpected panic: %s", s)
  3053. } else {
  3054. err = fmt.Errorf("Unexpected panic: %+v", r)
  3055. }
  3056. }
  3057. }()
  3058. buff := ctx.Buffer
  3059. version := buff.ReadUInt8()
  3060. if version > AssetsCodecVersion {
  3061. return fmt.Errorf("Invalid Version Unmarshaling AssetSet. Expected %d or less, got %d", AssetsCodecVersion, version)
  3062. }
  3063. if buff.ReadUInt8() == uint8(0) {
  3064. target.AggregationKeys = nil
  3065. } else {
  3066. // --- [begin][read][slice]([]string) ---
  3067. b := buff.ReadInt() // array len
  3068. a := make([]string, b)
  3069. for i := 0; i < b; i++ {
  3070. var c string
  3071. var e string
  3072. if ctx.IsStringTable() {
  3073. f := buff.ReadInt() // read string index
  3074. e = ctx.Table.At(f)
  3075. } else {
  3076. e = buff.ReadString() // read string
  3077. }
  3078. d := e
  3079. c = d
  3080. a[i] = c
  3081. }
  3082. target.AggregationKeys = a
  3083. // --- [end][read][slice]([]string) ---
  3084. }
  3085. if buff.ReadUInt8() == uint8(0) {
  3086. target.Assets = nil
  3087. } else {
  3088. // --- [begin][read][map](map[string]Asset) ---
  3089. h := buff.ReadInt() // map len
  3090. g := make(map[string]Asset, h)
  3091. for j := 0; j < h; j++ {
  3092. var v string
  3093. var m string
  3094. if ctx.IsStringTable() {
  3095. n := buff.ReadInt() // read string index
  3096. m = ctx.Table.At(n)
  3097. } else {
  3098. m = buff.ReadString() // read string
  3099. }
  3100. l := m
  3101. v = l
  3102. var z Asset
  3103. if buff.ReadUInt8() == uint8(0) {
  3104. z = nil
  3105. } else {
  3106. // --- [begin][read][interface](Asset) ---
  3107. o := buff.ReadString()
  3108. _, p, _ := resolveType(o)
  3109. if _, ok := typeMap[p]; !ok {
  3110. return fmt.Errorf("Unknown Type: %s", p)
  3111. }
  3112. q, okA := reflect.New(typeMap[p]).Interface().(BinDecoder)
  3113. if !okA {
  3114. return fmt.Errorf("Type: %s does not implement %s.BinDecoder.", p, GeneratorPackageName)
  3115. }
  3116. buff.ReadInt() // [compatibility, unused]
  3117. errA := q.UnmarshalBinaryWithContext(ctx)
  3118. if errA != nil {
  3119. return errA
  3120. }
  3121. z = q.(Asset)
  3122. // --- [end][read][interface](Asset) ---
  3123. }
  3124. g[v] = z
  3125. }
  3126. target.Assets = g
  3127. // --- [end][read][map](map[string]Asset) ---
  3128. }
  3129. var s string
  3130. if ctx.IsStringTable() {
  3131. t := buff.ReadInt() // read string index
  3132. s = ctx.Table.At(t)
  3133. } else {
  3134. s = buff.ReadString() // read string
  3135. }
  3136. r := s
  3137. target.FromSource = r
  3138. // --- [begin][read][struct](Window) ---
  3139. u := &Window{}
  3140. buff.ReadInt() // [compatibility, unused]
  3141. errB := u.UnmarshalBinaryWithContext(ctx)
  3142. if errB != nil {
  3143. return errB
  3144. }
  3145. target.Window = *u
  3146. // --- [end][read][struct](Window) ---
  3147. if buff.ReadUInt8() == uint8(0) {
  3148. target.Warnings = nil
  3149. } else {
  3150. // --- [begin][read][slice]([]string) ---
  3151. x := buff.ReadInt() // array len
  3152. w := make([]string, x)
  3153. for ii := 0; ii < x; ii++ {
  3154. var y string
  3155. var bb string
  3156. if ctx.IsStringTable() {
  3157. cc := buff.ReadInt() // read string index
  3158. bb = ctx.Table.At(cc)
  3159. } else {
  3160. bb = buff.ReadString() // read string
  3161. }
  3162. aa := bb
  3163. y = aa
  3164. w[ii] = y
  3165. }
  3166. target.Warnings = w
  3167. // --- [end][read][slice]([]string) ---
  3168. }
  3169. if buff.ReadUInt8() == uint8(0) {
  3170. target.Errors = nil
  3171. } else {
  3172. // --- [begin][read][slice]([]string) ---
  3173. ee := buff.ReadInt() // array len
  3174. dd := make([]string, ee)
  3175. for jj := 0; jj < ee; jj++ {
  3176. var ff string
  3177. var hh string
  3178. if ctx.IsStringTable() {
  3179. ll := buff.ReadInt() // read string index
  3180. hh = ctx.Table.At(ll)
  3181. } else {
  3182. hh = buff.ReadString() // read string
  3183. }
  3184. gg := hh
  3185. ff = gg
  3186. dd[jj] = ff
  3187. }
  3188. target.Errors = dd
  3189. // --- [end][read][slice]([]string) ---
  3190. }
  3191. // execute post-processing func
  3192. postProcessAssetSet(target)
  3193. return nil
  3194. }
  3195. //--------------------------------------------------------------------------
  3196. // AssetSetStream
  3197. //--------------------------------------------------------------------------
  3198. // AssetSetStream is a single use field stream for the contents of an AssetSet instance. Instead of creating an instance and populating
  3199. // the fields on that instance, we provide a streaming iterator which yields (BingenFieldInfo, *BingenValue) tuples for each
  3200. // stremable element. All slices and maps will be flattened one depth and each element streamed individually.
  3201. type AssetSetStream struct {
  3202. reader io.Reader
  3203. ctx *DecodingContext
  3204. err error
  3205. }
  3206. // Closes closes the internal io.Reader used to read and parse the AssetSet fields.
  3207. // This should be called once the stream is no longer needed.
  3208. func (stream *AssetSetStream) Close() {
  3209. if closer, ok := stream.reader.(io.Closer); ok {
  3210. closer.Close()
  3211. }
  3212. stream.ctx.Close()
  3213. }
  3214. // Error returns an error if one occurred during the process of streaming the AssetSet
  3215. // This can be checked after iterating through the Stream().
  3216. func (stream *AssetSetStream) Error() error {
  3217. return stream.err
  3218. }
  3219. // NewAssetSetStream creates a new AssetSetStream, which uses the io.Reader data to stream all internal fields of an AssetSet instance
  3220. func NewAssetSetStream(reader io.Reader) BingenStream {
  3221. ctx := NewDecodingContextFromReader(reader)
  3222. return &AssetSetStream{
  3223. ctx: ctx,
  3224. reader: reader,
  3225. }
  3226. }
  3227. // Stream returns the iterator which will stream each field of the target type.
  3228. func (stream *AssetSetStream) Stream() iter.Seq2[BingenFieldInfo, *BingenValue] {
  3229. return func(yield func(BingenFieldInfo, *BingenValue) bool) {
  3230. var fi BingenFieldInfo
  3231. ctx := stream.ctx
  3232. buff := ctx.Buffer
  3233. version := buff.ReadUInt8()
  3234. if version > AssetsCodecVersion {
  3235. stream.err = fmt.Errorf("Invalid Version Unmarshaling AssetSet. Expected %d or less, got %d", AssetsCodecVersion, version)
  3236. return
  3237. }
  3238. fi = BingenFieldInfo{
  3239. Type: reflect.TypeFor[[]string](),
  3240. Name: "AggregationKeys",
  3241. }
  3242. if buff.ReadUInt8() == uint8(0) {
  3243. if !yield(fi, nil) {
  3244. return
  3245. }
  3246. } else {
  3247. // --- [begin][read][streaming-slice]([]string) ---
  3248. a := buff.ReadInt() // array len
  3249. for i := 0; i < a; i++ {
  3250. var b string
  3251. var d string
  3252. if ctx.IsStringTable() {
  3253. e := buff.ReadInt() // read string index
  3254. d = ctx.Table.At(e)
  3255. } else {
  3256. d = buff.ReadString() // read string
  3257. }
  3258. c := d
  3259. b = c
  3260. if !yield(fi, pairV(i, b)) {
  3261. return
  3262. }
  3263. }
  3264. // --- [end][read][streaming-slice]([]string) ---
  3265. }
  3266. fi = BingenFieldInfo{
  3267. Type: reflect.TypeFor[map[string]Asset](),
  3268. Name: "Assets",
  3269. }
  3270. if buff.ReadUInt8() == uint8(0) {
  3271. if !yield(fi, nil) {
  3272. return
  3273. }
  3274. } else {
  3275. // --- [begin][read][streaming-map](map[string]Asset) ---
  3276. f := buff.ReadInt() // map len
  3277. for j := 0; j < f; j++ {
  3278. var v string
  3279. var h string
  3280. if ctx.IsStringTable() {
  3281. l := buff.ReadInt() // read string index
  3282. h = ctx.Table.At(l)
  3283. } else {
  3284. h = buff.ReadString() // read string
  3285. }
  3286. g := h
  3287. v = g
  3288. var z Asset
  3289. if buff.ReadUInt8() == uint8(0) {
  3290. z = nil
  3291. } else {
  3292. // --- [begin][read][interface](Asset) ---
  3293. m := buff.ReadString()
  3294. _, n, _ := resolveType(m)
  3295. if _, ok := typeMap[n]; !ok {
  3296. stream.err = fmt.Errorf("Unknown Type: %s", n)
  3297. return
  3298. }
  3299. o, okA := reflect.New(typeMap[n]).Interface().(BinDecoder)
  3300. if !okA {
  3301. stream.err = fmt.Errorf("Type: %s does not implement %s.BinDecoder.", n, GeneratorPackageName)
  3302. return
  3303. }
  3304. buff.ReadInt() // [compatibility, unused]
  3305. errA := o.UnmarshalBinaryWithContext(ctx)
  3306. if errA != nil {
  3307. stream.err = errA
  3308. return
  3309. }
  3310. z = o.(Asset)
  3311. // --- [end][read][interface](Asset) ---
  3312. }
  3313. if !yield(fi, pairV(v, z)) {
  3314. return
  3315. }
  3316. }
  3317. // --- [end][read][streaming-map](map[string]Asset) ---
  3318. }
  3319. fi = BingenFieldInfo{
  3320. Type: reflect.TypeFor[string](),
  3321. Name: "FromSource",
  3322. }
  3323. var p string
  3324. var r string
  3325. if ctx.IsStringTable() {
  3326. s := buff.ReadInt() // read string index
  3327. r = ctx.Table.At(s)
  3328. } else {
  3329. r = buff.ReadString() // read string
  3330. }
  3331. q := r
  3332. p = q
  3333. if !yield(fi, singleV(p)) {
  3334. return
  3335. }
  3336. fi = BingenFieldInfo{
  3337. Type: reflect.TypeFor[Window](),
  3338. Name: "Window",
  3339. }
  3340. // --- [begin][read][struct](Window) ---
  3341. u := &Window{}
  3342. buff.ReadInt() // [compatibility, unused]
  3343. errB := u.UnmarshalBinaryWithContext(ctx)
  3344. if errB != nil {
  3345. stream.err = errB
  3346. return
  3347. }
  3348. t := *u
  3349. // --- [end][read][struct](Window) ---
  3350. if !yield(fi, singleV(t)) {
  3351. return
  3352. }
  3353. fi = BingenFieldInfo{
  3354. Type: reflect.TypeFor[[]string](),
  3355. Name: "Warnings",
  3356. }
  3357. if buff.ReadUInt8() == uint8(0) {
  3358. if !yield(fi, nil) {
  3359. return
  3360. }
  3361. } else {
  3362. // --- [begin][read][streaming-slice]([]string) ---
  3363. w := buff.ReadInt() // array len
  3364. for ii := 0; ii < w; ii++ {
  3365. var x string
  3366. var aa string
  3367. if ctx.IsStringTable() {
  3368. bb := buff.ReadInt() // read string index
  3369. aa = ctx.Table.At(bb)
  3370. } else {
  3371. aa = buff.ReadString() // read string
  3372. }
  3373. y := aa
  3374. x = y
  3375. if !yield(fi, pairV(ii, x)) {
  3376. return
  3377. }
  3378. }
  3379. // --- [end][read][streaming-slice]([]string) ---
  3380. }
  3381. fi = BingenFieldInfo{
  3382. Type: reflect.TypeFor[[]string](),
  3383. Name: "Errors",
  3384. }
  3385. if buff.ReadUInt8() == uint8(0) {
  3386. if !yield(fi, nil) {
  3387. return
  3388. }
  3389. } else {
  3390. // --- [begin][read][streaming-slice]([]string) ---
  3391. cc := buff.ReadInt() // array len
  3392. for jj := 0; jj < cc; jj++ {
  3393. var dd string
  3394. var ff string
  3395. if ctx.IsStringTable() {
  3396. gg := buff.ReadInt() // read string index
  3397. ff = ctx.Table.At(gg)
  3398. } else {
  3399. ff = buff.ReadString() // read string
  3400. }
  3401. ee := ff
  3402. dd = ee
  3403. if !yield(fi, pairV(jj, dd)) {
  3404. return
  3405. }
  3406. }
  3407. // --- [end][read][streaming-slice]([]string) ---
  3408. }
  3409. }
  3410. }
  3411. //--------------------------------------------------------------------------
  3412. // AssetSetRange
  3413. //--------------------------------------------------------------------------
  3414. // MarshalBinary serializes the internal properties of this AssetSetRange instance
  3415. // into a byte array
  3416. func (target *AssetSetRange) MarshalBinary() (data []byte, err error) {
  3417. ctx := &EncodingContext{
  3418. Buffer: util.NewBuffer(),
  3419. Table: nil,
  3420. }
  3421. e := target.MarshalBinaryWithContext(ctx)
  3422. if e != nil {
  3423. return nil, e
  3424. }
  3425. encBytes := ctx.Buffer.Bytes()
  3426. return encBytes, nil
  3427. }
  3428. // MarshalBinaryWithContext serializes the internal properties of this AssetSetRange instance
  3429. // into a byte array leveraging a predefined context.
  3430. func (target *AssetSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3431. // panics are recovered and propagated as errors
  3432. defer func() {
  3433. if r := recover(); r != nil {
  3434. if e, ok := r.(error); ok {
  3435. err = e
  3436. } else if s, ok := r.(string); ok {
  3437. err = fmt.Errorf("Unexpected panic: %s", s)
  3438. } else {
  3439. err = fmt.Errorf("Unexpected panic: %+v", r)
  3440. }
  3441. }
  3442. }()
  3443. buff := ctx.Buffer
  3444. buff.WriteUInt8(AssetsCodecVersion) // version
  3445. if target.Assets == nil {
  3446. buff.WriteUInt8(uint8(0)) // write nil byte
  3447. } else {
  3448. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3449. // --- [begin][write][slice]([]*AssetSet) ---
  3450. buff.WriteInt(len(target.Assets)) // array length
  3451. for i := 0; i < len(target.Assets); i++ {
  3452. if target.Assets[i] == nil {
  3453. buff.WriteUInt8(uint8(0)) // write nil byte
  3454. } else {
  3455. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3456. // --- [begin][write][struct](AssetSet) ---
  3457. buff.WriteInt(0) // [compatibility, unused]
  3458. errA := target.Assets[i].MarshalBinaryWithContext(ctx)
  3459. if errA != nil {
  3460. return errA
  3461. }
  3462. // --- [end][write][struct](AssetSet) ---
  3463. }
  3464. }
  3465. // --- [end][write][slice]([]*AssetSet) ---
  3466. }
  3467. if ctx.IsStringTable() {
  3468. a := ctx.Table.AddOrGet(target.FromStore)
  3469. buff.WriteInt(a) // write table index
  3470. } else {
  3471. buff.WriteString(target.FromStore) // write string
  3472. }
  3473. return nil
  3474. }
  3475. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3476. // the AssetSetRange type
  3477. func (target *AssetSetRange) UnmarshalBinary(data []byte) error {
  3478. ctx := NewDecodingContextFromBytes(data)
  3479. defer ctx.Close()
  3480. err := target.UnmarshalBinaryWithContext(ctx)
  3481. if err != nil {
  3482. return err
  3483. }
  3484. return nil
  3485. }
  3486. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  3487. // the AssetSetRange type
  3488. func (target *AssetSetRange) UnmarshalBinaryFromReader(reader io.Reader) error {
  3489. ctx := NewDecodingContextFromReader(reader)
  3490. defer ctx.Close()
  3491. err := target.UnmarshalBinaryWithContext(ctx)
  3492. if err != nil {
  3493. return err
  3494. }
  3495. return nil
  3496. }
  3497. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3498. // the AssetSetRange type
  3499. func (target *AssetSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3500. // panics are recovered and propagated as errors
  3501. defer func() {
  3502. if r := recover(); r != nil {
  3503. if e, ok := r.(error); ok {
  3504. err = e
  3505. } else if s, ok := r.(string); ok {
  3506. err = fmt.Errorf("Unexpected panic: %s", s)
  3507. } else {
  3508. err = fmt.Errorf("Unexpected panic: %+v", r)
  3509. }
  3510. }
  3511. }()
  3512. buff := ctx.Buffer
  3513. version := buff.ReadUInt8()
  3514. if version > AssetsCodecVersion {
  3515. return fmt.Errorf("Invalid Version Unmarshaling AssetSetRange. Expected %d or less, got %d", AssetsCodecVersion, version)
  3516. }
  3517. if buff.ReadUInt8() == uint8(0) {
  3518. target.Assets = nil
  3519. } else {
  3520. // --- [begin][read][slice]([]*AssetSet) ---
  3521. b := buff.ReadInt() // array len
  3522. a := make([]*AssetSet, b)
  3523. for i := 0; i < b; i++ {
  3524. var c *AssetSet
  3525. if buff.ReadUInt8() == uint8(0) {
  3526. c = nil
  3527. } else {
  3528. // --- [begin][read][struct](AssetSet) ---
  3529. d := &AssetSet{}
  3530. buff.ReadInt() // [compatibility, unused]
  3531. errA := d.UnmarshalBinaryWithContext(ctx)
  3532. if errA != nil {
  3533. return errA
  3534. }
  3535. c = d
  3536. // --- [end][read][struct](AssetSet) ---
  3537. }
  3538. a[i] = c
  3539. }
  3540. target.Assets = a
  3541. // --- [end][read][slice]([]*AssetSet) ---
  3542. }
  3543. var f string
  3544. if ctx.IsStringTable() {
  3545. g := buff.ReadInt() // read string index
  3546. f = ctx.Table.At(g)
  3547. } else {
  3548. f = buff.ReadString() // read string
  3549. }
  3550. e := f
  3551. target.FromStore = e
  3552. return nil
  3553. }
  3554. //--------------------------------------------------------------------------
  3555. // Breakdown
  3556. //--------------------------------------------------------------------------
  3557. // MarshalBinary serializes the internal properties of this Breakdown instance
  3558. // into a byte array
  3559. func (target *Breakdown) MarshalBinary() (data []byte, err error) {
  3560. ctx := &EncodingContext{
  3561. Buffer: util.NewBuffer(),
  3562. Table: nil,
  3563. }
  3564. e := target.MarshalBinaryWithContext(ctx)
  3565. if e != nil {
  3566. return nil, e
  3567. }
  3568. encBytes := ctx.Buffer.Bytes()
  3569. return encBytes, nil
  3570. }
  3571. // MarshalBinaryWithContext serializes the internal properties of this Breakdown instance
  3572. // into a byte array leveraging a predefined context.
  3573. func (target *Breakdown) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3574. // panics are recovered and propagated as errors
  3575. defer func() {
  3576. if r := recover(); r != nil {
  3577. if e, ok := r.(error); ok {
  3578. err = e
  3579. } else if s, ok := r.(string); ok {
  3580. err = fmt.Errorf("Unexpected panic: %s", s)
  3581. } else {
  3582. err = fmt.Errorf("Unexpected panic: %+v", r)
  3583. }
  3584. }
  3585. }()
  3586. buff := ctx.Buffer
  3587. buff.WriteUInt8(AssetsCodecVersion) // version
  3588. buff.WriteFloat64(target.Idle) // write float64
  3589. buff.WriteFloat64(target.Other) // write float64
  3590. buff.WriteFloat64(target.System) // write float64
  3591. buff.WriteFloat64(target.User) // write float64
  3592. return nil
  3593. }
  3594. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3595. // the Breakdown type
  3596. func (target *Breakdown) UnmarshalBinary(data []byte) error {
  3597. ctx := NewDecodingContextFromBytes(data)
  3598. defer ctx.Close()
  3599. err := target.UnmarshalBinaryWithContext(ctx)
  3600. if err != nil {
  3601. return err
  3602. }
  3603. return nil
  3604. }
  3605. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  3606. // the Breakdown type
  3607. func (target *Breakdown) UnmarshalBinaryFromReader(reader io.Reader) error {
  3608. ctx := NewDecodingContextFromReader(reader)
  3609. defer ctx.Close()
  3610. err := target.UnmarshalBinaryWithContext(ctx)
  3611. if err != nil {
  3612. return err
  3613. }
  3614. return nil
  3615. }
  3616. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3617. // the Breakdown type
  3618. func (target *Breakdown) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3619. // panics are recovered and propagated as errors
  3620. defer func() {
  3621. if r := recover(); r != nil {
  3622. if e, ok := r.(error); ok {
  3623. err = e
  3624. } else if s, ok := r.(string); ok {
  3625. err = fmt.Errorf("Unexpected panic: %s", s)
  3626. } else {
  3627. err = fmt.Errorf("Unexpected panic: %+v", r)
  3628. }
  3629. }
  3630. }()
  3631. buff := ctx.Buffer
  3632. version := buff.ReadUInt8()
  3633. if version > AssetsCodecVersion {
  3634. return fmt.Errorf("Invalid Version Unmarshaling Breakdown. Expected %d or less, got %d", AssetsCodecVersion, version)
  3635. }
  3636. a := buff.ReadFloat64() // read float64
  3637. target.Idle = a
  3638. b := buff.ReadFloat64() // read float64
  3639. target.Other = b
  3640. c := buff.ReadFloat64() // read float64
  3641. target.System = c
  3642. d := buff.ReadFloat64() // read float64
  3643. target.User = d
  3644. return nil
  3645. }
  3646. //--------------------------------------------------------------------------
  3647. // Cloud
  3648. //--------------------------------------------------------------------------
  3649. // MarshalBinary serializes the internal properties of this Cloud instance
  3650. // into a byte array
  3651. func (target *Cloud) MarshalBinary() (data []byte, err error) {
  3652. ctx := &EncodingContext{
  3653. Buffer: util.NewBuffer(),
  3654. Table: nil,
  3655. }
  3656. e := target.MarshalBinaryWithContext(ctx)
  3657. if e != nil {
  3658. return nil, e
  3659. }
  3660. encBytes := ctx.Buffer.Bytes()
  3661. return encBytes, nil
  3662. }
  3663. // MarshalBinaryWithContext serializes the internal properties of this Cloud instance
  3664. // into a byte array leveraging a predefined context.
  3665. func (target *Cloud) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3666. // panics are recovered and propagated as errors
  3667. defer func() {
  3668. if r := recover(); r != nil {
  3669. if e, ok := r.(error); ok {
  3670. err = e
  3671. } else if s, ok := r.(string); ok {
  3672. err = fmt.Errorf("Unexpected panic: %s", s)
  3673. } else {
  3674. err = fmt.Errorf("Unexpected panic: %+v", r)
  3675. }
  3676. }
  3677. }()
  3678. buff := ctx.Buffer
  3679. buff.WriteUInt8(AssetsCodecVersion) // version
  3680. // --- [begin][write][alias](AssetLabels) ---
  3681. if map[string]string(target.Labels) == nil {
  3682. buff.WriteUInt8(uint8(0)) // write nil byte
  3683. } else {
  3684. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3685. // --- [begin][write][map](map[string]string) ---
  3686. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  3687. for v, z := range map[string]string(target.Labels) {
  3688. if ctx.IsStringTable() {
  3689. a := ctx.Table.AddOrGet(v)
  3690. buff.WriteInt(a) // write table index
  3691. } else {
  3692. buff.WriteString(v) // write string
  3693. }
  3694. if ctx.IsStringTable() {
  3695. b := ctx.Table.AddOrGet(z)
  3696. buff.WriteInt(b) // write table index
  3697. } else {
  3698. buff.WriteString(z) // write string
  3699. }
  3700. }
  3701. // --- [end][write][map](map[string]string) ---
  3702. }
  3703. // --- [end][write][alias](AssetLabels) ---
  3704. if target.Properties == nil {
  3705. buff.WriteUInt8(uint8(0)) // write nil byte
  3706. } else {
  3707. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3708. // --- [begin][write][struct](AssetProperties) ---
  3709. buff.WriteInt(0) // [compatibility, unused]
  3710. errA := target.Properties.MarshalBinaryWithContext(ctx)
  3711. if errA != nil {
  3712. return errA
  3713. }
  3714. // --- [end][write][struct](AssetProperties) ---
  3715. }
  3716. // --- [begin][write][reference](time.Time) ---
  3717. c, errB := target.Start.MarshalBinary()
  3718. if errB != nil {
  3719. return errB
  3720. }
  3721. buff.WriteInt(len(c))
  3722. buff.WriteBytes(c)
  3723. // --- [end][write][reference](time.Time) ---
  3724. // --- [begin][write][reference](time.Time) ---
  3725. d, errC := target.End.MarshalBinary()
  3726. if errC != nil {
  3727. return errC
  3728. }
  3729. buff.WriteInt(len(d))
  3730. buff.WriteBytes(d)
  3731. // --- [end][write][reference](time.Time) ---
  3732. // --- [begin][write][struct](Window) ---
  3733. buff.WriteInt(0) // [compatibility, unused]
  3734. errD := target.Window.MarshalBinaryWithContext(ctx)
  3735. if errD != nil {
  3736. return errD
  3737. }
  3738. // --- [end][write][struct](Window) ---
  3739. buff.WriteFloat64(target.Adjustment) // write float64
  3740. buff.WriteFloat64(target.Cost) // write float64
  3741. buff.WriteFloat64(target.Credit) // write float64
  3742. return nil
  3743. }
  3744. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3745. // the Cloud type
  3746. func (target *Cloud) UnmarshalBinary(data []byte) error {
  3747. ctx := NewDecodingContextFromBytes(data)
  3748. defer ctx.Close()
  3749. err := target.UnmarshalBinaryWithContext(ctx)
  3750. if err != nil {
  3751. return err
  3752. }
  3753. return nil
  3754. }
  3755. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  3756. // the Cloud type
  3757. func (target *Cloud) UnmarshalBinaryFromReader(reader io.Reader) error {
  3758. ctx := NewDecodingContextFromReader(reader)
  3759. defer ctx.Close()
  3760. err := target.UnmarshalBinaryWithContext(ctx)
  3761. if err != nil {
  3762. return err
  3763. }
  3764. return nil
  3765. }
  3766. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3767. // the Cloud type
  3768. func (target *Cloud) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3769. // panics are recovered and propagated as errors
  3770. defer func() {
  3771. if r := recover(); r != nil {
  3772. if e, ok := r.(error); ok {
  3773. err = e
  3774. } else if s, ok := r.(string); ok {
  3775. err = fmt.Errorf("Unexpected panic: %s", s)
  3776. } else {
  3777. err = fmt.Errorf("Unexpected panic: %+v", r)
  3778. }
  3779. }
  3780. }()
  3781. buff := ctx.Buffer
  3782. version := buff.ReadUInt8()
  3783. if version > AssetsCodecVersion {
  3784. return fmt.Errorf("Invalid Version Unmarshaling Cloud. Expected %d or less, got %d", AssetsCodecVersion, version)
  3785. }
  3786. // --- [begin][read][alias](AssetLabels) ---
  3787. var a map[string]string
  3788. if buff.ReadUInt8() == uint8(0) {
  3789. a = nil
  3790. } else {
  3791. // --- [begin][read][map](map[string]string) ---
  3792. c := buff.ReadInt() // map len
  3793. b := make(map[string]string, c)
  3794. for i := 0; i < c; i++ {
  3795. var v string
  3796. var e string
  3797. if ctx.IsStringTable() {
  3798. f := buff.ReadInt() // read string index
  3799. e = ctx.Table.At(f)
  3800. } else {
  3801. e = buff.ReadString() // read string
  3802. }
  3803. d := e
  3804. v = d
  3805. var z string
  3806. var h string
  3807. if ctx.IsStringTable() {
  3808. l := buff.ReadInt() // read string index
  3809. h = ctx.Table.At(l)
  3810. } else {
  3811. h = buff.ReadString() // read string
  3812. }
  3813. g := h
  3814. z = g
  3815. b[v] = z
  3816. }
  3817. a = b
  3818. // --- [end][read][map](map[string]string) ---
  3819. }
  3820. target.Labels = AssetLabels(a)
  3821. // --- [end][read][alias](AssetLabels) ---
  3822. if buff.ReadUInt8() == uint8(0) {
  3823. target.Properties = nil
  3824. } else {
  3825. // --- [begin][read][struct](AssetProperties) ---
  3826. m := &AssetProperties{}
  3827. buff.ReadInt() // [compatibility, unused]
  3828. errA := m.UnmarshalBinaryWithContext(ctx)
  3829. if errA != nil {
  3830. return errA
  3831. }
  3832. target.Properties = m
  3833. // --- [end][read][struct](AssetProperties) ---
  3834. }
  3835. // --- [begin][read][reference](time.Time) ---
  3836. n := &time.Time{}
  3837. o := buff.ReadInt() // byte array length
  3838. p := buff.ReadBytes(o) // byte array
  3839. errB := n.UnmarshalBinary(p)
  3840. if errB != nil {
  3841. return errB
  3842. }
  3843. target.Start = *n
  3844. // --- [end][read][reference](time.Time) ---
  3845. // --- [begin][read][reference](time.Time) ---
  3846. q := &time.Time{}
  3847. r := buff.ReadInt() // byte array length
  3848. s := buff.ReadBytes(r) // byte array
  3849. errC := q.UnmarshalBinary(s)
  3850. if errC != nil {
  3851. return errC
  3852. }
  3853. target.End = *q
  3854. // --- [end][read][reference](time.Time) ---
  3855. // --- [begin][read][struct](Window) ---
  3856. t := &Window{}
  3857. buff.ReadInt() // [compatibility, unused]
  3858. errD := t.UnmarshalBinaryWithContext(ctx)
  3859. if errD != nil {
  3860. return errD
  3861. }
  3862. target.Window = *t
  3863. // --- [end][read][struct](Window) ---
  3864. u := buff.ReadFloat64() // read float64
  3865. target.Adjustment = u
  3866. w := buff.ReadFloat64() // read float64
  3867. target.Cost = w
  3868. x := buff.ReadFloat64() // read float64
  3869. target.Credit = x
  3870. return nil
  3871. }
  3872. //--------------------------------------------------------------------------
  3873. // CloudCost
  3874. //--------------------------------------------------------------------------
  3875. // MarshalBinary serializes the internal properties of this CloudCost instance
  3876. // into a byte array
  3877. func (target *CloudCost) MarshalBinary() (data []byte, err error) {
  3878. ctx := &EncodingContext{
  3879. Buffer: util.NewBuffer(),
  3880. Table: nil,
  3881. }
  3882. e := target.MarshalBinaryWithContext(ctx)
  3883. if e != nil {
  3884. return nil, e
  3885. }
  3886. encBytes := ctx.Buffer.Bytes()
  3887. return encBytes, nil
  3888. }
  3889. // MarshalBinaryWithContext serializes the internal properties of this CloudCost instance
  3890. // into a byte array leveraging a predefined context.
  3891. func (target *CloudCost) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3892. // panics are recovered and propagated as errors
  3893. defer func() {
  3894. if r := recover(); r != nil {
  3895. if e, ok := r.(error); ok {
  3896. err = e
  3897. } else if s, ok := r.(string); ok {
  3898. err = fmt.Errorf("Unexpected panic: %s", s)
  3899. } else {
  3900. err = fmt.Errorf("Unexpected panic: %+v", r)
  3901. }
  3902. }
  3903. }()
  3904. buff := ctx.Buffer
  3905. buff.WriteUInt8(CloudCostCodecVersion) // version
  3906. if target.Properties == nil {
  3907. buff.WriteUInt8(uint8(0)) // write nil byte
  3908. } else {
  3909. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3910. // --- [begin][write][struct](CloudCostProperties) ---
  3911. buff.WriteInt(0) // [compatibility, unused]
  3912. errA := target.Properties.MarshalBinaryWithContext(ctx)
  3913. if errA != nil {
  3914. return errA
  3915. }
  3916. // --- [end][write][struct](CloudCostProperties) ---
  3917. }
  3918. // --- [begin][write][struct](Window) ---
  3919. buff.WriteInt(0) // [compatibility, unused]
  3920. errB := target.Window.MarshalBinaryWithContext(ctx)
  3921. if errB != nil {
  3922. return errB
  3923. }
  3924. // --- [end][write][struct](Window) ---
  3925. // --- [begin][write][struct](CostMetric) ---
  3926. buff.WriteInt(0) // [compatibility, unused]
  3927. errC := target.ListCost.MarshalBinaryWithContext(ctx)
  3928. if errC != nil {
  3929. return errC
  3930. }
  3931. // --- [end][write][struct](CostMetric) ---
  3932. // --- [begin][write][struct](CostMetric) ---
  3933. buff.WriteInt(0) // [compatibility, unused]
  3934. errD := target.NetCost.MarshalBinaryWithContext(ctx)
  3935. if errD != nil {
  3936. return errD
  3937. }
  3938. // --- [end][write][struct](CostMetric) ---
  3939. // --- [begin][write][struct](CostMetric) ---
  3940. buff.WriteInt(0) // [compatibility, unused]
  3941. errE := target.AmortizedNetCost.MarshalBinaryWithContext(ctx)
  3942. if errE != nil {
  3943. return errE
  3944. }
  3945. // --- [end][write][struct](CostMetric) ---
  3946. // --- [begin][write][struct](CostMetric) ---
  3947. buff.WriteInt(0) // [compatibility, unused]
  3948. errF := target.InvoicedCost.MarshalBinaryWithContext(ctx)
  3949. if errF != nil {
  3950. return errF
  3951. }
  3952. // --- [end][write][struct](CostMetric) ---
  3953. // --- [begin][write][struct](CostMetric) ---
  3954. buff.WriteInt(0) // [compatibility, unused]
  3955. errG := target.AmortizedCost.MarshalBinaryWithContext(ctx)
  3956. if errG != nil {
  3957. return errG
  3958. }
  3959. // --- [end][write][struct](CostMetric) ---
  3960. return nil
  3961. }
  3962. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3963. // the CloudCost type
  3964. func (target *CloudCost) UnmarshalBinary(data []byte) error {
  3965. ctx := NewDecodingContextFromBytes(data)
  3966. defer ctx.Close()
  3967. err := target.UnmarshalBinaryWithContext(ctx)
  3968. if err != nil {
  3969. return err
  3970. }
  3971. return nil
  3972. }
  3973. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  3974. // the CloudCost type
  3975. func (target *CloudCost) UnmarshalBinaryFromReader(reader io.Reader) error {
  3976. ctx := NewDecodingContextFromReader(reader)
  3977. defer ctx.Close()
  3978. err := target.UnmarshalBinaryWithContext(ctx)
  3979. if err != nil {
  3980. return err
  3981. }
  3982. return nil
  3983. }
  3984. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3985. // the CloudCost type
  3986. func (target *CloudCost) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3987. // panics are recovered and propagated as errors
  3988. defer func() {
  3989. if r := recover(); r != nil {
  3990. if e, ok := r.(error); ok {
  3991. err = e
  3992. } else if s, ok := r.(string); ok {
  3993. err = fmt.Errorf("Unexpected panic: %s", s)
  3994. } else {
  3995. err = fmt.Errorf("Unexpected panic: %+v", r)
  3996. }
  3997. }
  3998. }()
  3999. buff := ctx.Buffer
  4000. version := buff.ReadUInt8()
  4001. if version > CloudCostCodecVersion {
  4002. return fmt.Errorf("Invalid Version Unmarshaling CloudCost. Expected %d or less, got %d", CloudCostCodecVersion, version)
  4003. }
  4004. if buff.ReadUInt8() == uint8(0) {
  4005. target.Properties = nil
  4006. } else {
  4007. // --- [begin][read][struct](CloudCostProperties) ---
  4008. a := &CloudCostProperties{}
  4009. buff.ReadInt() // [compatibility, unused]
  4010. errA := a.UnmarshalBinaryWithContext(ctx)
  4011. if errA != nil {
  4012. return errA
  4013. }
  4014. target.Properties = a
  4015. // --- [end][read][struct](CloudCostProperties) ---
  4016. }
  4017. // --- [begin][read][struct](Window) ---
  4018. b := &Window{}
  4019. buff.ReadInt() // [compatibility, unused]
  4020. errB := b.UnmarshalBinaryWithContext(ctx)
  4021. if errB != nil {
  4022. return errB
  4023. }
  4024. target.Window = *b
  4025. // --- [end][read][struct](Window) ---
  4026. // --- [begin][read][struct](CostMetric) ---
  4027. c := &CostMetric{}
  4028. buff.ReadInt() // [compatibility, unused]
  4029. errC := c.UnmarshalBinaryWithContext(ctx)
  4030. if errC != nil {
  4031. return errC
  4032. }
  4033. target.ListCost = *c
  4034. // --- [end][read][struct](CostMetric) ---
  4035. // --- [begin][read][struct](CostMetric) ---
  4036. d := &CostMetric{}
  4037. buff.ReadInt() // [compatibility, unused]
  4038. errD := d.UnmarshalBinaryWithContext(ctx)
  4039. if errD != nil {
  4040. return errD
  4041. }
  4042. target.NetCost = *d
  4043. // --- [end][read][struct](CostMetric) ---
  4044. // --- [begin][read][struct](CostMetric) ---
  4045. e := &CostMetric{}
  4046. buff.ReadInt() // [compatibility, unused]
  4047. errE := e.UnmarshalBinaryWithContext(ctx)
  4048. if errE != nil {
  4049. return errE
  4050. }
  4051. target.AmortizedNetCost = *e
  4052. // --- [end][read][struct](CostMetric) ---
  4053. // --- [begin][read][struct](CostMetric) ---
  4054. f := &CostMetric{}
  4055. buff.ReadInt() // [compatibility, unused]
  4056. errF := f.UnmarshalBinaryWithContext(ctx)
  4057. if errF != nil {
  4058. return errF
  4059. }
  4060. target.InvoicedCost = *f
  4061. // --- [end][read][struct](CostMetric) ---
  4062. // --- [begin][read][struct](CostMetric) ---
  4063. g := &CostMetric{}
  4064. buff.ReadInt() // [compatibility, unused]
  4065. errG := g.UnmarshalBinaryWithContext(ctx)
  4066. if errG != nil {
  4067. return errG
  4068. }
  4069. target.AmortizedCost = *g
  4070. // --- [end][read][struct](CostMetric) ---
  4071. return nil
  4072. }
  4073. //--------------------------------------------------------------------------
  4074. // CloudCostProperties
  4075. //--------------------------------------------------------------------------
  4076. // MarshalBinary serializes the internal properties of this CloudCostProperties instance
  4077. // into a byte array
  4078. func (target *CloudCostProperties) MarshalBinary() (data []byte, err error) {
  4079. ctx := &EncodingContext{
  4080. Buffer: util.NewBuffer(),
  4081. Table: nil,
  4082. }
  4083. e := target.MarshalBinaryWithContext(ctx)
  4084. if e != nil {
  4085. return nil, e
  4086. }
  4087. encBytes := ctx.Buffer.Bytes()
  4088. return encBytes, nil
  4089. }
  4090. // MarshalBinaryWithContext serializes the internal properties of this CloudCostProperties instance
  4091. // into a byte array leveraging a predefined context.
  4092. func (target *CloudCostProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4093. // panics are recovered and propagated as errors
  4094. defer func() {
  4095. if r := recover(); r != nil {
  4096. if e, ok := r.(error); ok {
  4097. err = e
  4098. } else if s, ok := r.(string); ok {
  4099. err = fmt.Errorf("Unexpected panic: %s", s)
  4100. } else {
  4101. err = fmt.Errorf("Unexpected panic: %+v", r)
  4102. }
  4103. }
  4104. }()
  4105. buff := ctx.Buffer
  4106. buff.WriteUInt8(CloudCostCodecVersion) // version
  4107. if ctx.IsStringTable() {
  4108. a := ctx.Table.AddOrGet(target.ProviderID)
  4109. buff.WriteInt(a) // write table index
  4110. } else {
  4111. buff.WriteString(target.ProviderID) // write string
  4112. }
  4113. if ctx.IsStringTable() {
  4114. b := ctx.Table.AddOrGet(target.Provider)
  4115. buff.WriteInt(b) // write table index
  4116. } else {
  4117. buff.WriteString(target.Provider) // write string
  4118. }
  4119. if ctx.IsStringTable() {
  4120. c := ctx.Table.AddOrGet(target.AccountID)
  4121. buff.WriteInt(c) // write table index
  4122. } else {
  4123. buff.WriteString(target.AccountID) // write string
  4124. }
  4125. if ctx.IsStringTable() {
  4126. d := ctx.Table.AddOrGet(target.AccountName)
  4127. buff.WriteInt(d) // write table index
  4128. } else {
  4129. buff.WriteString(target.AccountName) // write string
  4130. }
  4131. if ctx.IsStringTable() {
  4132. e := ctx.Table.AddOrGet(target.InvoiceEntityID)
  4133. buff.WriteInt(e) // write table index
  4134. } else {
  4135. buff.WriteString(target.InvoiceEntityID) // write string
  4136. }
  4137. if ctx.IsStringTable() {
  4138. f := ctx.Table.AddOrGet(target.InvoiceEntityName)
  4139. buff.WriteInt(f) // write table index
  4140. } else {
  4141. buff.WriteString(target.InvoiceEntityName) // write string
  4142. }
  4143. if ctx.IsStringTable() {
  4144. g := ctx.Table.AddOrGet(target.RegionID)
  4145. buff.WriteInt(g) // write table index
  4146. } else {
  4147. buff.WriteString(target.RegionID) // write string
  4148. }
  4149. if ctx.IsStringTable() {
  4150. h := ctx.Table.AddOrGet(target.AvailabilityZone)
  4151. buff.WriteInt(h) // write table index
  4152. } else {
  4153. buff.WriteString(target.AvailabilityZone) // write string
  4154. }
  4155. if ctx.IsStringTable() {
  4156. l := ctx.Table.AddOrGet(target.Service)
  4157. buff.WriteInt(l) // write table index
  4158. } else {
  4159. buff.WriteString(target.Service) // write string
  4160. }
  4161. if ctx.IsStringTable() {
  4162. m := ctx.Table.AddOrGet(target.Category)
  4163. buff.WriteInt(m) // write table index
  4164. } else {
  4165. buff.WriteString(target.Category) // write string
  4166. }
  4167. // --- [begin][write][alias](CloudCostLabels) ---
  4168. if map[string]string(target.Labels) == nil {
  4169. buff.WriteUInt8(uint8(0)) // write nil byte
  4170. } else {
  4171. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4172. // --- [begin][write][map](map[string]string) ---
  4173. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  4174. for v, z := range map[string]string(target.Labels) {
  4175. if ctx.IsStringTable() {
  4176. n := ctx.Table.AddOrGet(v)
  4177. buff.WriteInt(n) // write table index
  4178. } else {
  4179. buff.WriteString(v) // write string
  4180. }
  4181. if ctx.IsStringTable() {
  4182. o := ctx.Table.AddOrGet(z)
  4183. buff.WriteInt(o) // write table index
  4184. } else {
  4185. buff.WriteString(z) // write string
  4186. }
  4187. }
  4188. // --- [end][write][map](map[string]string) ---
  4189. }
  4190. // --- [end][write][alias](CloudCostLabels) ---
  4191. return nil
  4192. }
  4193. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4194. // the CloudCostProperties type
  4195. func (target *CloudCostProperties) UnmarshalBinary(data []byte) error {
  4196. ctx := NewDecodingContextFromBytes(data)
  4197. defer ctx.Close()
  4198. err := target.UnmarshalBinaryWithContext(ctx)
  4199. if err != nil {
  4200. return err
  4201. }
  4202. return nil
  4203. }
  4204. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  4205. // the CloudCostProperties type
  4206. func (target *CloudCostProperties) UnmarshalBinaryFromReader(reader io.Reader) error {
  4207. ctx := NewDecodingContextFromReader(reader)
  4208. defer ctx.Close()
  4209. err := target.UnmarshalBinaryWithContext(ctx)
  4210. if err != nil {
  4211. return err
  4212. }
  4213. return nil
  4214. }
  4215. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4216. // the CloudCostProperties type
  4217. func (target *CloudCostProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4218. // panics are recovered and propagated as errors
  4219. defer func() {
  4220. if r := recover(); r != nil {
  4221. if e, ok := r.(error); ok {
  4222. err = e
  4223. } else if s, ok := r.(string); ok {
  4224. err = fmt.Errorf("Unexpected panic: %s", s)
  4225. } else {
  4226. err = fmt.Errorf("Unexpected panic: %+v", r)
  4227. }
  4228. }
  4229. }()
  4230. buff := ctx.Buffer
  4231. version := buff.ReadUInt8()
  4232. if version > CloudCostCodecVersion {
  4233. return fmt.Errorf("Invalid Version Unmarshaling CloudCostProperties. Expected %d or less, got %d", CloudCostCodecVersion, version)
  4234. }
  4235. var b string
  4236. if ctx.IsStringTable() {
  4237. c := buff.ReadInt() // read string index
  4238. b = ctx.Table.At(c)
  4239. } else {
  4240. b = buff.ReadString() // read string
  4241. }
  4242. a := b
  4243. target.ProviderID = a
  4244. var e string
  4245. if ctx.IsStringTable() {
  4246. f := buff.ReadInt() // read string index
  4247. e = ctx.Table.At(f)
  4248. } else {
  4249. e = buff.ReadString() // read string
  4250. }
  4251. d := e
  4252. target.Provider = d
  4253. var h string
  4254. if ctx.IsStringTable() {
  4255. l := buff.ReadInt() // read string index
  4256. h = ctx.Table.At(l)
  4257. } else {
  4258. h = buff.ReadString() // read string
  4259. }
  4260. g := h
  4261. target.AccountID = g
  4262. // field version check
  4263. if uint8(3) <= version {
  4264. var n string
  4265. if ctx.IsStringTable() {
  4266. o := buff.ReadInt() // read string index
  4267. n = ctx.Table.At(o)
  4268. } else {
  4269. n = buff.ReadString() // read string
  4270. }
  4271. m := n
  4272. target.AccountName = m
  4273. } else {
  4274. target.AccountName = "" // default
  4275. }
  4276. var q string
  4277. if ctx.IsStringTable() {
  4278. r := buff.ReadInt() // read string index
  4279. q = ctx.Table.At(r)
  4280. } else {
  4281. q = buff.ReadString() // read string
  4282. }
  4283. p := q
  4284. target.InvoiceEntityID = p
  4285. // field version check
  4286. if uint8(3) <= version {
  4287. var t string
  4288. if ctx.IsStringTable() {
  4289. u := buff.ReadInt() // read string index
  4290. t = ctx.Table.At(u)
  4291. } else {
  4292. t = buff.ReadString() // read string
  4293. }
  4294. s := t
  4295. target.InvoiceEntityName = s
  4296. } else {
  4297. target.InvoiceEntityName = "" // default
  4298. }
  4299. // field version check
  4300. if uint8(3) <= version {
  4301. var x string
  4302. if ctx.IsStringTable() {
  4303. y := buff.ReadInt() // read string index
  4304. x = ctx.Table.At(y)
  4305. } else {
  4306. x = buff.ReadString() // read string
  4307. }
  4308. w := x
  4309. target.RegionID = w
  4310. } else {
  4311. target.RegionID = "" // default
  4312. }
  4313. // field version check
  4314. if uint8(3) <= version {
  4315. var bb string
  4316. if ctx.IsStringTable() {
  4317. cc := buff.ReadInt() // read string index
  4318. bb = ctx.Table.At(cc)
  4319. } else {
  4320. bb = buff.ReadString() // read string
  4321. }
  4322. aa := bb
  4323. target.AvailabilityZone = aa
  4324. } else {
  4325. target.AvailabilityZone = "" // default
  4326. }
  4327. var ee string
  4328. if ctx.IsStringTable() {
  4329. ff := buff.ReadInt() // read string index
  4330. ee = ctx.Table.At(ff)
  4331. } else {
  4332. ee = buff.ReadString() // read string
  4333. }
  4334. dd := ee
  4335. target.Service = dd
  4336. var hh string
  4337. if ctx.IsStringTable() {
  4338. ll := buff.ReadInt() // read string index
  4339. hh = ctx.Table.At(ll)
  4340. } else {
  4341. hh = buff.ReadString() // read string
  4342. }
  4343. gg := hh
  4344. target.Category = gg
  4345. // --- [begin][read][alias](CloudCostLabels) ---
  4346. var mm map[string]string
  4347. if buff.ReadUInt8() == uint8(0) {
  4348. mm = nil
  4349. } else {
  4350. // --- [begin][read][map](map[string]string) ---
  4351. oo := buff.ReadInt() // map len
  4352. nn := make(map[string]string, oo)
  4353. for i := 0; i < oo; i++ {
  4354. var v string
  4355. var qq string
  4356. if ctx.IsStringTable() {
  4357. rr := buff.ReadInt() // read string index
  4358. qq = ctx.Table.At(rr)
  4359. } else {
  4360. qq = buff.ReadString() // read string
  4361. }
  4362. pp := qq
  4363. v = pp
  4364. var z string
  4365. var tt string
  4366. if ctx.IsStringTable() {
  4367. uu := buff.ReadInt() // read string index
  4368. tt = ctx.Table.At(uu)
  4369. } else {
  4370. tt = buff.ReadString() // read string
  4371. }
  4372. ss := tt
  4373. z = ss
  4374. nn[v] = z
  4375. }
  4376. mm = nn
  4377. // --- [end][read][map](map[string]string) ---
  4378. }
  4379. target.Labels = CloudCostLabels(mm)
  4380. // --- [end][read][alias](CloudCostLabels) ---
  4381. return nil
  4382. }
  4383. //--------------------------------------------------------------------------
  4384. // CloudCostSet
  4385. //--------------------------------------------------------------------------
  4386. // MarshalBinary serializes the internal properties of this CloudCostSet instance
  4387. // into a byte array
  4388. func (target *CloudCostSet) MarshalBinary() (data []byte, err error) {
  4389. ctx := &EncodingContext{
  4390. Buffer: util.NewBuffer(),
  4391. Table: NewStringTableWriter(),
  4392. }
  4393. e := target.MarshalBinaryWithContext(ctx)
  4394. if e != nil {
  4395. return nil, e
  4396. }
  4397. encBytes := ctx.Buffer.Bytes()
  4398. sTableBytes := ctx.Table.ToBytes()
  4399. merged := appendBytes(sTableBytes, encBytes)
  4400. return merged, nil
  4401. }
  4402. // MarshalBinaryWithContext serializes the internal properties of this CloudCostSet instance
  4403. // into a byte array leveraging a predefined context.
  4404. func (target *CloudCostSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4405. // panics are recovered and propagated as errors
  4406. defer func() {
  4407. if r := recover(); r != nil {
  4408. if e, ok := r.(error); ok {
  4409. err = e
  4410. } else if s, ok := r.(string); ok {
  4411. err = fmt.Errorf("Unexpected panic: %s", s)
  4412. } else {
  4413. err = fmt.Errorf("Unexpected panic: %+v", r)
  4414. }
  4415. }
  4416. }()
  4417. buff := ctx.Buffer
  4418. buff.WriteUInt8(CloudCostCodecVersion) // version
  4419. if target.CloudCosts == nil {
  4420. buff.WriteUInt8(uint8(0)) // write nil byte
  4421. } else {
  4422. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4423. // --- [begin][write][map](map[string]*CloudCost) ---
  4424. buff.WriteInt(len(target.CloudCosts)) // map length
  4425. for v, z := range target.CloudCosts {
  4426. if ctx.IsStringTable() {
  4427. a := ctx.Table.AddOrGet(v)
  4428. buff.WriteInt(a) // write table index
  4429. } else {
  4430. buff.WriteString(v) // write string
  4431. }
  4432. if z == nil {
  4433. buff.WriteUInt8(uint8(0)) // write nil byte
  4434. } else {
  4435. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4436. // --- [begin][write][struct](CloudCost) ---
  4437. buff.WriteInt(0) // [compatibility, unused]
  4438. errA := z.MarshalBinaryWithContext(ctx)
  4439. if errA != nil {
  4440. return errA
  4441. }
  4442. // --- [end][write][struct](CloudCost) ---
  4443. }
  4444. }
  4445. // --- [end][write][map](map[string]*CloudCost) ---
  4446. }
  4447. // --- [begin][write][struct](Window) ---
  4448. buff.WriteInt(0) // [compatibility, unused]
  4449. errB := target.Window.MarshalBinaryWithContext(ctx)
  4450. if errB != nil {
  4451. return errB
  4452. }
  4453. // --- [end][write][struct](Window) ---
  4454. if ctx.IsStringTable() {
  4455. b := ctx.Table.AddOrGet(target.Integration)
  4456. buff.WriteInt(b) // write table index
  4457. } else {
  4458. buff.WriteString(target.Integration) // write string
  4459. }
  4460. if target.AggregationProperties == nil {
  4461. buff.WriteUInt8(uint8(0)) // write nil byte
  4462. } else {
  4463. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4464. // --- [begin][write][slice]([]string) ---
  4465. buff.WriteInt(len(target.AggregationProperties)) // array length
  4466. for i := 0; i < len(target.AggregationProperties); i++ {
  4467. if ctx.IsStringTable() {
  4468. c := ctx.Table.AddOrGet(target.AggregationProperties[i])
  4469. buff.WriteInt(c) // write table index
  4470. } else {
  4471. buff.WriteString(target.AggregationProperties[i]) // write string
  4472. }
  4473. }
  4474. // --- [end][write][slice]([]string) ---
  4475. }
  4476. return nil
  4477. }
  4478. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4479. // the CloudCostSet type
  4480. func (target *CloudCostSet) UnmarshalBinary(data []byte) error {
  4481. ctx := NewDecodingContextFromBytes(data)
  4482. defer ctx.Close()
  4483. err := target.UnmarshalBinaryWithContext(ctx)
  4484. if err != nil {
  4485. return err
  4486. }
  4487. return nil
  4488. }
  4489. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  4490. // the CloudCostSet type
  4491. func (target *CloudCostSet) UnmarshalBinaryFromReader(reader io.Reader) error {
  4492. ctx := NewDecodingContextFromReader(reader)
  4493. defer ctx.Close()
  4494. err := target.UnmarshalBinaryWithContext(ctx)
  4495. if err != nil {
  4496. return err
  4497. }
  4498. return nil
  4499. }
  4500. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4501. // the CloudCostSet type
  4502. func (target *CloudCostSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4503. // panics are recovered and propagated as errors
  4504. defer func() {
  4505. if r := recover(); r != nil {
  4506. if e, ok := r.(error); ok {
  4507. err = e
  4508. } else if s, ok := r.(string); ok {
  4509. err = fmt.Errorf("Unexpected panic: %s", s)
  4510. } else {
  4511. err = fmt.Errorf("Unexpected panic: %+v", r)
  4512. }
  4513. }
  4514. }()
  4515. buff := ctx.Buffer
  4516. version := buff.ReadUInt8()
  4517. if version > CloudCostCodecVersion {
  4518. return fmt.Errorf("Invalid Version Unmarshaling CloudCostSet. Expected %d or less, got %d", CloudCostCodecVersion, version)
  4519. }
  4520. if buff.ReadUInt8() == uint8(0) {
  4521. target.CloudCosts = nil
  4522. } else {
  4523. // --- [begin][read][map](map[string]*CloudCost) ---
  4524. b := buff.ReadInt() // map len
  4525. a := make(map[string]*CloudCost, b)
  4526. for i := 0; i < b; i++ {
  4527. var v string
  4528. var d string
  4529. if ctx.IsStringTable() {
  4530. e := buff.ReadInt() // read string index
  4531. d = ctx.Table.At(e)
  4532. } else {
  4533. d = buff.ReadString() // read string
  4534. }
  4535. c := d
  4536. v = c
  4537. var z *CloudCost
  4538. if buff.ReadUInt8() == uint8(0) {
  4539. z = nil
  4540. } else {
  4541. // --- [begin][read][struct](CloudCost) ---
  4542. f := &CloudCost{}
  4543. buff.ReadInt() // [compatibility, unused]
  4544. errA := f.UnmarshalBinaryWithContext(ctx)
  4545. if errA != nil {
  4546. return errA
  4547. }
  4548. z = f
  4549. // --- [end][read][struct](CloudCost) ---
  4550. }
  4551. a[v] = z
  4552. }
  4553. target.CloudCosts = a
  4554. // --- [end][read][map](map[string]*CloudCost) ---
  4555. }
  4556. // --- [begin][read][struct](Window) ---
  4557. g := &Window{}
  4558. buff.ReadInt() // [compatibility, unused]
  4559. errB := g.UnmarshalBinaryWithContext(ctx)
  4560. if errB != nil {
  4561. return errB
  4562. }
  4563. target.Window = *g
  4564. // --- [end][read][struct](Window) ---
  4565. var l string
  4566. if ctx.IsStringTable() {
  4567. m := buff.ReadInt() // read string index
  4568. l = ctx.Table.At(m)
  4569. } else {
  4570. l = buff.ReadString() // read string
  4571. }
  4572. h := l
  4573. target.Integration = h
  4574. if buff.ReadUInt8() == uint8(0) {
  4575. target.AggregationProperties = nil
  4576. } else {
  4577. // --- [begin][read][slice]([]string) ---
  4578. o := buff.ReadInt() // array len
  4579. n := make([]string, o)
  4580. for j := 0; j < o; j++ {
  4581. var p string
  4582. var r string
  4583. if ctx.IsStringTable() {
  4584. s := buff.ReadInt() // read string index
  4585. r = ctx.Table.At(s)
  4586. } else {
  4587. r = buff.ReadString() // read string
  4588. }
  4589. q := r
  4590. p = q
  4591. n[j] = p
  4592. }
  4593. target.AggregationProperties = n
  4594. // --- [end][read][slice]([]string) ---
  4595. }
  4596. return nil
  4597. }
  4598. //--------------------------------------------------------------------------
  4599. // CloudCostSetStream
  4600. //--------------------------------------------------------------------------
  4601. // CloudCostSetStream is a single use field stream for the contents of an CloudCostSet instance. Instead of creating an instance and populating
  4602. // the fields on that instance, we provide a streaming iterator which yields (BingenFieldInfo, *BingenValue) tuples for each
  4603. // stremable element. All slices and maps will be flattened one depth and each element streamed individually.
  4604. type CloudCostSetStream struct {
  4605. reader io.Reader
  4606. ctx *DecodingContext
  4607. err error
  4608. }
  4609. // Closes closes the internal io.Reader used to read and parse the CloudCostSet fields.
  4610. // This should be called once the stream is no longer needed.
  4611. func (stream *CloudCostSetStream) Close() {
  4612. if closer, ok := stream.reader.(io.Closer); ok {
  4613. closer.Close()
  4614. }
  4615. stream.ctx.Close()
  4616. }
  4617. // Error returns an error if one occurred during the process of streaming the CloudCostSet
  4618. // This can be checked after iterating through the Stream().
  4619. func (stream *CloudCostSetStream) Error() error {
  4620. return stream.err
  4621. }
  4622. // NewCloudCostSetStream creates a new CloudCostSetStream, which uses the io.Reader data to stream all internal fields of an CloudCostSet instance
  4623. func NewCloudCostSetStream(reader io.Reader) BingenStream {
  4624. ctx := NewDecodingContextFromReader(reader)
  4625. return &CloudCostSetStream{
  4626. ctx: ctx,
  4627. reader: reader,
  4628. }
  4629. }
  4630. // Stream returns the iterator which will stream each field of the target type.
  4631. func (stream *CloudCostSetStream) Stream() iter.Seq2[BingenFieldInfo, *BingenValue] {
  4632. return func(yield func(BingenFieldInfo, *BingenValue) bool) {
  4633. var fi BingenFieldInfo
  4634. ctx := stream.ctx
  4635. buff := ctx.Buffer
  4636. version := buff.ReadUInt8()
  4637. if version > CloudCostCodecVersion {
  4638. stream.err = fmt.Errorf("Invalid Version Unmarshaling CloudCostSet. Expected %d or less, got %d", CloudCostCodecVersion, version)
  4639. return
  4640. }
  4641. fi = BingenFieldInfo{
  4642. Type: reflect.TypeFor[map[string]*CloudCost](),
  4643. Name: "CloudCosts",
  4644. }
  4645. if buff.ReadUInt8() == uint8(0) {
  4646. if !yield(fi, nil) {
  4647. return
  4648. }
  4649. } else {
  4650. // --- [begin][read][streaming-map](map[string]*CloudCost) ---
  4651. a := buff.ReadInt() // map len
  4652. for i := 0; i < a; i++ {
  4653. var v string
  4654. var c string
  4655. if ctx.IsStringTable() {
  4656. d := buff.ReadInt() // read string index
  4657. c = ctx.Table.At(d)
  4658. } else {
  4659. c = buff.ReadString() // read string
  4660. }
  4661. b := c
  4662. v = b
  4663. var z *CloudCost
  4664. if buff.ReadUInt8() == uint8(0) {
  4665. z = nil
  4666. } else {
  4667. // --- [begin][read][struct](CloudCost) ---
  4668. e := &CloudCost{}
  4669. buff.ReadInt() // [compatibility, unused]
  4670. errA := e.UnmarshalBinaryWithContext(ctx)
  4671. if errA != nil {
  4672. stream.err = errA
  4673. return
  4674. }
  4675. z = e
  4676. // --- [end][read][struct](CloudCost) ---
  4677. }
  4678. if !yield(fi, pairV(v, z)) {
  4679. return
  4680. }
  4681. }
  4682. // --- [end][read][streaming-map](map[string]*CloudCost) ---
  4683. }
  4684. fi = BingenFieldInfo{
  4685. Type: reflect.TypeFor[Window](),
  4686. Name: "Window",
  4687. }
  4688. // --- [begin][read][struct](Window) ---
  4689. g := &Window{}
  4690. buff.ReadInt() // [compatibility, unused]
  4691. errB := g.UnmarshalBinaryWithContext(ctx)
  4692. if errB != nil {
  4693. stream.err = errB
  4694. return
  4695. }
  4696. f := *g
  4697. // --- [end][read][struct](Window) ---
  4698. if !yield(fi, singleV(f)) {
  4699. return
  4700. }
  4701. fi = BingenFieldInfo{
  4702. Type: reflect.TypeFor[string](),
  4703. Name: "Integration",
  4704. }
  4705. var h string
  4706. var m string
  4707. if ctx.IsStringTable() {
  4708. n := buff.ReadInt() // read string index
  4709. m = ctx.Table.At(n)
  4710. } else {
  4711. m = buff.ReadString() // read string
  4712. }
  4713. l := m
  4714. h = l
  4715. if !yield(fi, singleV(h)) {
  4716. return
  4717. }
  4718. fi = BingenFieldInfo{
  4719. Type: reflect.TypeFor[[]string](),
  4720. Name: "AggregationProperties",
  4721. }
  4722. if buff.ReadUInt8() == uint8(0) {
  4723. if !yield(fi, nil) {
  4724. return
  4725. }
  4726. } else {
  4727. // --- [begin][read][streaming-slice]([]string) ---
  4728. o := buff.ReadInt() // array len
  4729. for j := 0; j < o; j++ {
  4730. var p string
  4731. var r string
  4732. if ctx.IsStringTable() {
  4733. s := buff.ReadInt() // read string index
  4734. r = ctx.Table.At(s)
  4735. } else {
  4736. r = buff.ReadString() // read string
  4737. }
  4738. q := r
  4739. p = q
  4740. if !yield(fi, pairV(j, p)) {
  4741. return
  4742. }
  4743. }
  4744. // --- [end][read][streaming-slice]([]string) ---
  4745. }
  4746. }
  4747. }
  4748. //--------------------------------------------------------------------------
  4749. // CloudCostSetRange
  4750. //--------------------------------------------------------------------------
  4751. // MarshalBinary serializes the internal properties of this CloudCostSetRange instance
  4752. // into a byte array
  4753. func (target *CloudCostSetRange) MarshalBinary() (data []byte, err error) {
  4754. ctx := &EncodingContext{
  4755. Buffer: util.NewBuffer(),
  4756. Table: nil,
  4757. }
  4758. e := target.MarshalBinaryWithContext(ctx)
  4759. if e != nil {
  4760. return nil, e
  4761. }
  4762. encBytes := ctx.Buffer.Bytes()
  4763. return encBytes, nil
  4764. }
  4765. // MarshalBinaryWithContext serializes the internal properties of this CloudCostSetRange instance
  4766. // into a byte array leveraging a predefined context.
  4767. func (target *CloudCostSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4768. // panics are recovered and propagated as errors
  4769. defer func() {
  4770. if r := recover(); r != nil {
  4771. if e, ok := r.(error); ok {
  4772. err = e
  4773. } else if s, ok := r.(string); ok {
  4774. err = fmt.Errorf("Unexpected panic: %s", s)
  4775. } else {
  4776. err = fmt.Errorf("Unexpected panic: %+v", r)
  4777. }
  4778. }
  4779. }()
  4780. buff := ctx.Buffer
  4781. buff.WriteUInt8(CloudCostCodecVersion) // version
  4782. if target.CloudCostSets == nil {
  4783. buff.WriteUInt8(uint8(0)) // write nil byte
  4784. } else {
  4785. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4786. // --- [begin][write][slice]([]*CloudCostSet) ---
  4787. buff.WriteInt(len(target.CloudCostSets)) // array length
  4788. for i := 0; i < len(target.CloudCostSets); i++ {
  4789. if target.CloudCostSets[i] == nil {
  4790. buff.WriteUInt8(uint8(0)) // write nil byte
  4791. } else {
  4792. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4793. // --- [begin][write][struct](CloudCostSet) ---
  4794. buff.WriteInt(0) // [compatibility, unused]
  4795. errA := target.CloudCostSets[i].MarshalBinaryWithContext(ctx)
  4796. if errA != nil {
  4797. return errA
  4798. }
  4799. // --- [end][write][struct](CloudCostSet) ---
  4800. }
  4801. }
  4802. // --- [end][write][slice]([]*CloudCostSet) ---
  4803. }
  4804. // --- [begin][write][struct](Window) ---
  4805. buff.WriteInt(0) // [compatibility, unused]
  4806. errB := target.Window.MarshalBinaryWithContext(ctx)
  4807. if errB != nil {
  4808. return errB
  4809. }
  4810. // --- [end][write][struct](Window) ---
  4811. return nil
  4812. }
  4813. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4814. // the CloudCostSetRange type
  4815. func (target *CloudCostSetRange) UnmarshalBinary(data []byte) error {
  4816. ctx := NewDecodingContextFromBytes(data)
  4817. defer ctx.Close()
  4818. err := target.UnmarshalBinaryWithContext(ctx)
  4819. if err != nil {
  4820. return err
  4821. }
  4822. return nil
  4823. }
  4824. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  4825. // the CloudCostSetRange type
  4826. func (target *CloudCostSetRange) UnmarshalBinaryFromReader(reader io.Reader) error {
  4827. ctx := NewDecodingContextFromReader(reader)
  4828. defer ctx.Close()
  4829. err := target.UnmarshalBinaryWithContext(ctx)
  4830. if err != nil {
  4831. return err
  4832. }
  4833. return nil
  4834. }
  4835. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4836. // the CloudCostSetRange type
  4837. func (target *CloudCostSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4838. // panics are recovered and propagated as errors
  4839. defer func() {
  4840. if r := recover(); r != nil {
  4841. if e, ok := r.(error); ok {
  4842. err = e
  4843. } else if s, ok := r.(string); ok {
  4844. err = fmt.Errorf("Unexpected panic: %s", s)
  4845. } else {
  4846. err = fmt.Errorf("Unexpected panic: %+v", r)
  4847. }
  4848. }
  4849. }()
  4850. buff := ctx.Buffer
  4851. version := buff.ReadUInt8()
  4852. if version > CloudCostCodecVersion {
  4853. return fmt.Errorf("Invalid Version Unmarshaling CloudCostSetRange. Expected %d or less, got %d", CloudCostCodecVersion, version)
  4854. }
  4855. if buff.ReadUInt8() == uint8(0) {
  4856. target.CloudCostSets = nil
  4857. } else {
  4858. // --- [begin][read][slice]([]*CloudCostSet) ---
  4859. b := buff.ReadInt() // array len
  4860. a := make([]*CloudCostSet, b)
  4861. for i := 0; i < b; i++ {
  4862. var c *CloudCostSet
  4863. if buff.ReadUInt8() == uint8(0) {
  4864. c = nil
  4865. } else {
  4866. // --- [begin][read][struct](CloudCostSet) ---
  4867. d := &CloudCostSet{}
  4868. buff.ReadInt() // [compatibility, unused]
  4869. errA := d.UnmarshalBinaryWithContext(ctx)
  4870. if errA != nil {
  4871. return errA
  4872. }
  4873. c = d
  4874. // --- [end][read][struct](CloudCostSet) ---
  4875. }
  4876. a[i] = c
  4877. }
  4878. target.CloudCostSets = a
  4879. // --- [end][read][slice]([]*CloudCostSet) ---
  4880. }
  4881. // --- [begin][read][struct](Window) ---
  4882. e := &Window{}
  4883. buff.ReadInt() // [compatibility, unused]
  4884. errB := e.UnmarshalBinaryWithContext(ctx)
  4885. if errB != nil {
  4886. return errB
  4887. }
  4888. target.Window = *e
  4889. // --- [end][read][struct](Window) ---
  4890. return nil
  4891. }
  4892. //--------------------------------------------------------------------------
  4893. // ClusterManagement
  4894. //--------------------------------------------------------------------------
  4895. // MarshalBinary serializes the internal properties of this ClusterManagement instance
  4896. // into a byte array
  4897. func (target *ClusterManagement) MarshalBinary() (data []byte, err error) {
  4898. ctx := &EncodingContext{
  4899. Buffer: util.NewBuffer(),
  4900. Table: nil,
  4901. }
  4902. e := target.MarshalBinaryWithContext(ctx)
  4903. if e != nil {
  4904. return nil, e
  4905. }
  4906. encBytes := ctx.Buffer.Bytes()
  4907. return encBytes, nil
  4908. }
  4909. // MarshalBinaryWithContext serializes the internal properties of this ClusterManagement instance
  4910. // into a byte array leveraging a predefined context.
  4911. func (target *ClusterManagement) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4912. // panics are recovered and propagated as errors
  4913. defer func() {
  4914. if r := recover(); r != nil {
  4915. if e, ok := r.(error); ok {
  4916. err = e
  4917. } else if s, ok := r.(string); ok {
  4918. err = fmt.Errorf("Unexpected panic: %s", s)
  4919. } else {
  4920. err = fmt.Errorf("Unexpected panic: %+v", r)
  4921. }
  4922. }
  4923. }()
  4924. buff := ctx.Buffer
  4925. buff.WriteUInt8(AssetsCodecVersion) // version
  4926. // --- [begin][write][alias](AssetLabels) ---
  4927. if map[string]string(target.Labels) == nil {
  4928. buff.WriteUInt8(uint8(0)) // write nil byte
  4929. } else {
  4930. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4931. // --- [begin][write][map](map[string]string) ---
  4932. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  4933. for v, z := range map[string]string(target.Labels) {
  4934. if ctx.IsStringTable() {
  4935. a := ctx.Table.AddOrGet(v)
  4936. buff.WriteInt(a) // write table index
  4937. } else {
  4938. buff.WriteString(v) // write string
  4939. }
  4940. if ctx.IsStringTable() {
  4941. b := ctx.Table.AddOrGet(z)
  4942. buff.WriteInt(b) // write table index
  4943. } else {
  4944. buff.WriteString(z) // write string
  4945. }
  4946. }
  4947. // --- [end][write][map](map[string]string) ---
  4948. }
  4949. // --- [end][write][alias](AssetLabels) ---
  4950. if target.Properties == nil {
  4951. buff.WriteUInt8(uint8(0)) // write nil byte
  4952. } else {
  4953. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4954. // --- [begin][write][struct](AssetProperties) ---
  4955. buff.WriteInt(0) // [compatibility, unused]
  4956. errA := target.Properties.MarshalBinaryWithContext(ctx)
  4957. if errA != nil {
  4958. return errA
  4959. }
  4960. // --- [end][write][struct](AssetProperties) ---
  4961. }
  4962. // --- [begin][write][struct](Window) ---
  4963. buff.WriteInt(0) // [compatibility, unused]
  4964. errB := target.Window.MarshalBinaryWithContext(ctx)
  4965. if errB != nil {
  4966. return errB
  4967. }
  4968. // --- [end][write][struct](Window) ---
  4969. buff.WriteFloat64(target.Cost) // write float64
  4970. buff.WriteFloat64(target.Adjustment) // write float64
  4971. return nil
  4972. }
  4973. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4974. // the ClusterManagement type
  4975. func (target *ClusterManagement) UnmarshalBinary(data []byte) error {
  4976. ctx := NewDecodingContextFromBytes(data)
  4977. defer ctx.Close()
  4978. err := target.UnmarshalBinaryWithContext(ctx)
  4979. if err != nil {
  4980. return err
  4981. }
  4982. return nil
  4983. }
  4984. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  4985. // the ClusterManagement type
  4986. func (target *ClusterManagement) UnmarshalBinaryFromReader(reader io.Reader) error {
  4987. ctx := NewDecodingContextFromReader(reader)
  4988. defer ctx.Close()
  4989. err := target.UnmarshalBinaryWithContext(ctx)
  4990. if err != nil {
  4991. return err
  4992. }
  4993. return nil
  4994. }
  4995. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4996. // the ClusterManagement type
  4997. func (target *ClusterManagement) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4998. // panics are recovered and propagated as errors
  4999. defer func() {
  5000. if r := recover(); r != nil {
  5001. if e, ok := r.(error); ok {
  5002. err = e
  5003. } else if s, ok := r.(string); ok {
  5004. err = fmt.Errorf("Unexpected panic: %s", s)
  5005. } else {
  5006. err = fmt.Errorf("Unexpected panic: %+v", r)
  5007. }
  5008. }
  5009. }()
  5010. buff := ctx.Buffer
  5011. version := buff.ReadUInt8()
  5012. if version > AssetsCodecVersion {
  5013. return fmt.Errorf("Invalid Version Unmarshaling ClusterManagement. Expected %d or less, got %d", AssetsCodecVersion, version)
  5014. }
  5015. // --- [begin][read][alias](AssetLabels) ---
  5016. var a map[string]string
  5017. if buff.ReadUInt8() == uint8(0) {
  5018. a = nil
  5019. } else {
  5020. // --- [begin][read][map](map[string]string) ---
  5021. c := buff.ReadInt() // map len
  5022. b := make(map[string]string, c)
  5023. for i := 0; i < c; i++ {
  5024. var v string
  5025. var e string
  5026. if ctx.IsStringTable() {
  5027. f := buff.ReadInt() // read string index
  5028. e = ctx.Table.At(f)
  5029. } else {
  5030. e = buff.ReadString() // read string
  5031. }
  5032. d := e
  5033. v = d
  5034. var z string
  5035. var h string
  5036. if ctx.IsStringTable() {
  5037. l := buff.ReadInt() // read string index
  5038. h = ctx.Table.At(l)
  5039. } else {
  5040. h = buff.ReadString() // read string
  5041. }
  5042. g := h
  5043. z = g
  5044. b[v] = z
  5045. }
  5046. a = b
  5047. // --- [end][read][map](map[string]string) ---
  5048. }
  5049. target.Labels = AssetLabels(a)
  5050. // --- [end][read][alias](AssetLabels) ---
  5051. if buff.ReadUInt8() == uint8(0) {
  5052. target.Properties = nil
  5053. } else {
  5054. // --- [begin][read][struct](AssetProperties) ---
  5055. m := &AssetProperties{}
  5056. buff.ReadInt() // [compatibility, unused]
  5057. errA := m.UnmarshalBinaryWithContext(ctx)
  5058. if errA != nil {
  5059. return errA
  5060. }
  5061. target.Properties = m
  5062. // --- [end][read][struct](AssetProperties) ---
  5063. }
  5064. // --- [begin][read][struct](Window) ---
  5065. n := &Window{}
  5066. buff.ReadInt() // [compatibility, unused]
  5067. errB := n.UnmarshalBinaryWithContext(ctx)
  5068. if errB != nil {
  5069. return errB
  5070. }
  5071. target.Window = *n
  5072. // --- [end][read][struct](Window) ---
  5073. o := buff.ReadFloat64() // read float64
  5074. target.Cost = o
  5075. // field version check
  5076. if uint8(16) <= version {
  5077. p := buff.ReadFloat64() // read float64
  5078. target.Adjustment = p
  5079. } else {
  5080. target.Adjustment = float64(0) // default
  5081. }
  5082. return nil
  5083. }
  5084. //--------------------------------------------------------------------------
  5085. // CostMetric
  5086. //--------------------------------------------------------------------------
  5087. // MarshalBinary serializes the internal properties of this CostMetric instance
  5088. // into a byte array
  5089. func (target *CostMetric) MarshalBinary() (data []byte, err error) {
  5090. ctx := &EncodingContext{
  5091. Buffer: util.NewBuffer(),
  5092. Table: nil,
  5093. }
  5094. e := target.MarshalBinaryWithContext(ctx)
  5095. if e != nil {
  5096. return nil, e
  5097. }
  5098. encBytes := ctx.Buffer.Bytes()
  5099. return encBytes, nil
  5100. }
  5101. // MarshalBinaryWithContext serializes the internal properties of this CostMetric instance
  5102. // into a byte array leveraging a predefined context.
  5103. func (target *CostMetric) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5104. // panics are recovered and propagated as errors
  5105. defer func() {
  5106. if r := recover(); r != nil {
  5107. if e, ok := r.(error); ok {
  5108. err = e
  5109. } else if s, ok := r.(string); ok {
  5110. err = fmt.Errorf("Unexpected panic: %s", s)
  5111. } else {
  5112. err = fmt.Errorf("Unexpected panic: %+v", r)
  5113. }
  5114. }
  5115. }()
  5116. buff := ctx.Buffer
  5117. buff.WriteUInt8(CloudCostCodecVersion) // version
  5118. buff.WriteFloat64(target.Cost) // write float64
  5119. buff.WriteFloat64(target.KubernetesPercent) // write float64
  5120. return nil
  5121. }
  5122. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5123. // the CostMetric type
  5124. func (target *CostMetric) UnmarshalBinary(data []byte) error {
  5125. ctx := NewDecodingContextFromBytes(data)
  5126. defer ctx.Close()
  5127. err := target.UnmarshalBinaryWithContext(ctx)
  5128. if err != nil {
  5129. return err
  5130. }
  5131. return nil
  5132. }
  5133. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  5134. // the CostMetric type
  5135. func (target *CostMetric) UnmarshalBinaryFromReader(reader io.Reader) error {
  5136. ctx := NewDecodingContextFromReader(reader)
  5137. defer ctx.Close()
  5138. err := target.UnmarshalBinaryWithContext(ctx)
  5139. if err != nil {
  5140. return err
  5141. }
  5142. return nil
  5143. }
  5144. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5145. // the CostMetric type
  5146. func (target *CostMetric) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5147. // panics are recovered and propagated as errors
  5148. defer func() {
  5149. if r := recover(); r != nil {
  5150. if e, ok := r.(error); ok {
  5151. err = e
  5152. } else if s, ok := r.(string); ok {
  5153. err = fmt.Errorf("Unexpected panic: %s", s)
  5154. } else {
  5155. err = fmt.Errorf("Unexpected panic: %+v", r)
  5156. }
  5157. }
  5158. }()
  5159. buff := ctx.Buffer
  5160. version := buff.ReadUInt8()
  5161. if version > CloudCostCodecVersion {
  5162. return fmt.Errorf("Invalid Version Unmarshaling CostMetric. Expected %d or less, got %d", CloudCostCodecVersion, version)
  5163. }
  5164. a := buff.ReadFloat64() // read float64
  5165. target.Cost = a
  5166. b := buff.ReadFloat64() // read float64
  5167. target.KubernetesPercent = b
  5168. return nil
  5169. }
  5170. //--------------------------------------------------------------------------
  5171. // Disk
  5172. //--------------------------------------------------------------------------
  5173. // MarshalBinary serializes the internal properties of this Disk instance
  5174. // into a byte array
  5175. func (target *Disk) MarshalBinary() (data []byte, err error) {
  5176. ctx := &EncodingContext{
  5177. Buffer: util.NewBuffer(),
  5178. Table: nil,
  5179. }
  5180. e := target.MarshalBinaryWithContext(ctx)
  5181. if e != nil {
  5182. return nil, e
  5183. }
  5184. encBytes := ctx.Buffer.Bytes()
  5185. return encBytes, nil
  5186. }
  5187. // MarshalBinaryWithContext serializes the internal properties of this Disk instance
  5188. // into a byte array leveraging a predefined context.
  5189. func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5190. // panics are recovered and propagated as errors
  5191. defer func() {
  5192. if r := recover(); r != nil {
  5193. if e, ok := r.(error); ok {
  5194. err = e
  5195. } else if s, ok := r.(string); ok {
  5196. err = fmt.Errorf("Unexpected panic: %s", s)
  5197. } else {
  5198. err = fmt.Errorf("Unexpected panic: %+v", r)
  5199. }
  5200. }
  5201. }()
  5202. buff := ctx.Buffer
  5203. buff.WriteUInt8(AssetsCodecVersion) // version
  5204. // --- [begin][write][alias](AssetLabels) ---
  5205. if map[string]string(target.Labels) == nil {
  5206. buff.WriteUInt8(uint8(0)) // write nil byte
  5207. } else {
  5208. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5209. // --- [begin][write][map](map[string]string) ---
  5210. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  5211. for v, z := range map[string]string(target.Labels) {
  5212. if ctx.IsStringTable() {
  5213. a := ctx.Table.AddOrGet(v)
  5214. buff.WriteInt(a) // write table index
  5215. } else {
  5216. buff.WriteString(v) // write string
  5217. }
  5218. if ctx.IsStringTable() {
  5219. b := ctx.Table.AddOrGet(z)
  5220. buff.WriteInt(b) // write table index
  5221. } else {
  5222. buff.WriteString(z) // write string
  5223. }
  5224. }
  5225. // --- [end][write][map](map[string]string) ---
  5226. }
  5227. // --- [end][write][alias](AssetLabels) ---
  5228. if target.Properties == nil {
  5229. buff.WriteUInt8(uint8(0)) // write nil byte
  5230. } else {
  5231. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5232. // --- [begin][write][struct](AssetProperties) ---
  5233. buff.WriteInt(0) // [compatibility, unused]
  5234. errA := target.Properties.MarshalBinaryWithContext(ctx)
  5235. if errA != nil {
  5236. return errA
  5237. }
  5238. // --- [end][write][struct](AssetProperties) ---
  5239. }
  5240. // --- [begin][write][reference](time.Time) ---
  5241. c, errB := target.Start.MarshalBinary()
  5242. if errB != nil {
  5243. return errB
  5244. }
  5245. buff.WriteInt(len(c))
  5246. buff.WriteBytes(c)
  5247. // --- [end][write][reference](time.Time) ---
  5248. // --- [begin][write][reference](time.Time) ---
  5249. d, errC := target.End.MarshalBinary()
  5250. if errC != nil {
  5251. return errC
  5252. }
  5253. buff.WriteInt(len(d))
  5254. buff.WriteBytes(d)
  5255. // --- [end][write][reference](time.Time) ---
  5256. // --- [begin][write][struct](Window) ---
  5257. buff.WriteInt(0) // [compatibility, unused]
  5258. errD := target.Window.MarshalBinaryWithContext(ctx)
  5259. if errD != nil {
  5260. return errD
  5261. }
  5262. // --- [end][write][struct](Window) ---
  5263. buff.WriteFloat64(target.Adjustment) // write float64
  5264. buff.WriteFloat64(target.Cost) // write float64
  5265. buff.WriteFloat64(target.ByteHours) // write float64
  5266. buff.WriteFloat64(target.Local) // write float64
  5267. if target.Breakdown == nil {
  5268. buff.WriteUInt8(uint8(0)) // write nil byte
  5269. } else {
  5270. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5271. // --- [begin][write][struct](Breakdown) ---
  5272. buff.WriteInt(0) // [compatibility, unused]
  5273. errE := target.Breakdown.MarshalBinaryWithContext(ctx)
  5274. if errE != nil {
  5275. return errE
  5276. }
  5277. // --- [end][write][struct](Breakdown) ---
  5278. }
  5279. if ctx.IsStringTable() {
  5280. e := ctx.Table.AddOrGet(target.StorageClass)
  5281. buff.WriteInt(e) // write table index
  5282. } else {
  5283. buff.WriteString(target.StorageClass) // write string
  5284. }
  5285. if target.ByteHoursUsed == nil {
  5286. buff.WriteUInt8(uint8(0)) // write nil byte
  5287. } else {
  5288. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5289. buff.WriteFloat64(*target.ByteHoursUsed) // write float64
  5290. }
  5291. if target.ByteUsageMax == nil {
  5292. buff.WriteUInt8(uint8(0)) // write nil byte
  5293. } else {
  5294. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5295. buff.WriteFloat64(*target.ByteUsageMax) // write float64
  5296. }
  5297. if ctx.IsStringTable() {
  5298. f := ctx.Table.AddOrGet(target.VolumeName)
  5299. buff.WriteInt(f) // write table index
  5300. } else {
  5301. buff.WriteString(target.VolumeName) // write string
  5302. }
  5303. if ctx.IsStringTable() {
  5304. g := ctx.Table.AddOrGet(target.ClaimName)
  5305. buff.WriteInt(g) // write table index
  5306. } else {
  5307. buff.WriteString(target.ClaimName) // write string
  5308. }
  5309. if ctx.IsStringTable() {
  5310. h := ctx.Table.AddOrGet(target.ClaimNamespace)
  5311. buff.WriteInt(h) // write table index
  5312. } else {
  5313. buff.WriteString(target.ClaimNamespace) // write string
  5314. }
  5315. return nil
  5316. }
  5317. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5318. // the Disk type
  5319. func (target *Disk) UnmarshalBinary(data []byte) error {
  5320. ctx := NewDecodingContextFromBytes(data)
  5321. defer ctx.Close()
  5322. err := target.UnmarshalBinaryWithContext(ctx)
  5323. if err != nil {
  5324. return err
  5325. }
  5326. return nil
  5327. }
  5328. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  5329. // the Disk type
  5330. func (target *Disk) UnmarshalBinaryFromReader(reader io.Reader) error {
  5331. ctx := NewDecodingContextFromReader(reader)
  5332. defer ctx.Close()
  5333. err := target.UnmarshalBinaryWithContext(ctx)
  5334. if err != nil {
  5335. return err
  5336. }
  5337. return nil
  5338. }
  5339. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5340. // the Disk type
  5341. func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5342. // panics are recovered and propagated as errors
  5343. defer func() {
  5344. if r := recover(); r != nil {
  5345. if e, ok := r.(error); ok {
  5346. err = e
  5347. } else if s, ok := r.(string); ok {
  5348. err = fmt.Errorf("Unexpected panic: %s", s)
  5349. } else {
  5350. err = fmt.Errorf("Unexpected panic: %+v", r)
  5351. }
  5352. }
  5353. }()
  5354. buff := ctx.Buffer
  5355. version := buff.ReadUInt8()
  5356. if version > AssetsCodecVersion {
  5357. return fmt.Errorf("Invalid Version Unmarshaling Disk. Expected %d or less, got %d", AssetsCodecVersion, version)
  5358. }
  5359. // --- [begin][read][alias](AssetLabels) ---
  5360. var a map[string]string
  5361. if buff.ReadUInt8() == uint8(0) {
  5362. a = nil
  5363. } else {
  5364. // --- [begin][read][map](map[string]string) ---
  5365. c := buff.ReadInt() // map len
  5366. b := make(map[string]string, c)
  5367. for i := 0; i < c; i++ {
  5368. var v string
  5369. var e string
  5370. if ctx.IsStringTable() {
  5371. f := buff.ReadInt() // read string index
  5372. e = ctx.Table.At(f)
  5373. } else {
  5374. e = buff.ReadString() // read string
  5375. }
  5376. d := e
  5377. v = d
  5378. var z string
  5379. var h string
  5380. if ctx.IsStringTable() {
  5381. l := buff.ReadInt() // read string index
  5382. h = ctx.Table.At(l)
  5383. } else {
  5384. h = buff.ReadString() // read string
  5385. }
  5386. g := h
  5387. z = g
  5388. b[v] = z
  5389. }
  5390. a = b
  5391. // --- [end][read][map](map[string]string) ---
  5392. }
  5393. target.Labels = AssetLabels(a)
  5394. // --- [end][read][alias](AssetLabels) ---
  5395. if buff.ReadUInt8() == uint8(0) {
  5396. target.Properties = nil
  5397. } else {
  5398. // --- [begin][read][struct](AssetProperties) ---
  5399. m := &AssetProperties{}
  5400. buff.ReadInt() // [compatibility, unused]
  5401. errA := m.UnmarshalBinaryWithContext(ctx)
  5402. if errA != nil {
  5403. return errA
  5404. }
  5405. target.Properties = m
  5406. // --- [end][read][struct](AssetProperties) ---
  5407. }
  5408. // --- [begin][read][reference](time.Time) ---
  5409. n := &time.Time{}
  5410. o := buff.ReadInt() // byte array length
  5411. p := buff.ReadBytes(o) // byte array
  5412. errB := n.UnmarshalBinary(p)
  5413. if errB != nil {
  5414. return errB
  5415. }
  5416. target.Start = *n
  5417. // --- [end][read][reference](time.Time) ---
  5418. // --- [begin][read][reference](time.Time) ---
  5419. q := &time.Time{}
  5420. r := buff.ReadInt() // byte array length
  5421. s := buff.ReadBytes(r) // byte array
  5422. errC := q.UnmarshalBinary(s)
  5423. if errC != nil {
  5424. return errC
  5425. }
  5426. target.End = *q
  5427. // --- [end][read][reference](time.Time) ---
  5428. // --- [begin][read][struct](Window) ---
  5429. t := &Window{}
  5430. buff.ReadInt() // [compatibility, unused]
  5431. errD := t.UnmarshalBinaryWithContext(ctx)
  5432. if errD != nil {
  5433. return errD
  5434. }
  5435. target.Window = *t
  5436. // --- [end][read][struct](Window) ---
  5437. u := buff.ReadFloat64() // read float64
  5438. target.Adjustment = u
  5439. w := buff.ReadFloat64() // read float64
  5440. target.Cost = w
  5441. x := buff.ReadFloat64() // read float64
  5442. target.ByteHours = x
  5443. y := buff.ReadFloat64() // read float64
  5444. target.Local = y
  5445. if buff.ReadUInt8() == uint8(0) {
  5446. target.Breakdown = nil
  5447. } else {
  5448. // --- [begin][read][struct](Breakdown) ---
  5449. aa := &Breakdown{}
  5450. buff.ReadInt() // [compatibility, unused]
  5451. errE := aa.UnmarshalBinaryWithContext(ctx)
  5452. if errE != nil {
  5453. return errE
  5454. }
  5455. target.Breakdown = aa
  5456. // --- [end][read][struct](Breakdown) ---
  5457. }
  5458. // field version check
  5459. if uint8(17) <= version {
  5460. var cc string
  5461. if ctx.IsStringTable() {
  5462. dd := buff.ReadInt() // read string index
  5463. cc = ctx.Table.At(dd)
  5464. } else {
  5465. cc = buff.ReadString() // read string
  5466. }
  5467. bb := cc
  5468. target.StorageClass = bb
  5469. } else {
  5470. target.StorageClass = "" // default
  5471. }
  5472. // field version check
  5473. if uint8(18) <= version {
  5474. if buff.ReadUInt8() == uint8(0) {
  5475. target.ByteHoursUsed = nil
  5476. } else {
  5477. ee := buff.ReadFloat64() // read float64
  5478. target.ByteHoursUsed = &ee
  5479. }
  5480. } else {
  5481. target.ByteHoursUsed = nil
  5482. }
  5483. // field version check
  5484. if uint8(18) <= version {
  5485. if buff.ReadUInt8() == uint8(0) {
  5486. target.ByteUsageMax = nil
  5487. } else {
  5488. ff := buff.ReadFloat64() // read float64
  5489. target.ByteUsageMax = &ff
  5490. }
  5491. } else {
  5492. target.ByteUsageMax = nil
  5493. }
  5494. // field version check
  5495. if uint8(18) <= version {
  5496. var hh string
  5497. if ctx.IsStringTable() {
  5498. ll := buff.ReadInt() // read string index
  5499. hh = ctx.Table.At(ll)
  5500. } else {
  5501. hh = buff.ReadString() // read string
  5502. }
  5503. gg := hh
  5504. target.VolumeName = gg
  5505. } else {
  5506. target.VolumeName = "" // default
  5507. }
  5508. // field version check
  5509. if uint8(18) <= version {
  5510. var nn string
  5511. if ctx.IsStringTable() {
  5512. oo := buff.ReadInt() // read string index
  5513. nn = ctx.Table.At(oo)
  5514. } else {
  5515. nn = buff.ReadString() // read string
  5516. }
  5517. mm := nn
  5518. target.ClaimName = mm
  5519. } else {
  5520. target.ClaimName = "" // default
  5521. }
  5522. // field version check
  5523. if uint8(18) <= version {
  5524. var qq string
  5525. if ctx.IsStringTable() {
  5526. rr := buff.ReadInt() // read string index
  5527. qq = ctx.Table.At(rr)
  5528. } else {
  5529. qq = buff.ReadString() // read string
  5530. }
  5531. pp := qq
  5532. target.ClaimNamespace = pp
  5533. } else {
  5534. target.ClaimNamespace = "" // default
  5535. }
  5536. return nil
  5537. }
  5538. //--------------------------------------------------------------------------
  5539. // GPUAllocation
  5540. //--------------------------------------------------------------------------
  5541. // MarshalBinary serializes the internal properties of this GPUAllocation instance
  5542. // into a byte array
  5543. func (target *GPUAllocation) MarshalBinary() (data []byte, err error) {
  5544. ctx := &EncodingContext{
  5545. Buffer: util.NewBuffer(),
  5546. Table: nil,
  5547. }
  5548. e := target.MarshalBinaryWithContext(ctx)
  5549. if e != nil {
  5550. return nil, e
  5551. }
  5552. encBytes := ctx.Buffer.Bytes()
  5553. return encBytes, nil
  5554. }
  5555. // MarshalBinaryWithContext serializes the internal properties of this GPUAllocation instance
  5556. // into a byte array leveraging a predefined context.
  5557. func (target *GPUAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5558. // panics are recovered and propagated as errors
  5559. defer func() {
  5560. if r := recover(); r != nil {
  5561. if e, ok := r.(error); ok {
  5562. err = e
  5563. } else if s, ok := r.(string); ok {
  5564. err = fmt.Errorf("Unexpected panic: %s", s)
  5565. } else {
  5566. err = fmt.Errorf("Unexpected panic: %+v", r)
  5567. }
  5568. }
  5569. }()
  5570. buff := ctx.Buffer
  5571. buff.WriteUInt8(AllocationCodecVersion) // version
  5572. if ctx.IsStringTable() {
  5573. a := ctx.Table.AddOrGet(target.GPUDevice)
  5574. buff.WriteInt(a) // write table index
  5575. } else {
  5576. buff.WriteString(target.GPUDevice) // write string
  5577. }
  5578. if ctx.IsStringTable() {
  5579. b := ctx.Table.AddOrGet(target.GPUModel)
  5580. buff.WriteInt(b) // write table index
  5581. } else {
  5582. buff.WriteString(target.GPUModel) // write string
  5583. }
  5584. if ctx.IsStringTable() {
  5585. c := ctx.Table.AddOrGet(target.GPUUUID)
  5586. buff.WriteInt(c) // write table index
  5587. } else {
  5588. buff.WriteString(target.GPUUUID) // write string
  5589. }
  5590. if target.IsGPUShared == nil {
  5591. buff.WriteUInt8(uint8(0)) // write nil byte
  5592. } else {
  5593. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5594. buff.WriteBool(*target.IsGPUShared) // write bool
  5595. }
  5596. if target.GPUUsageAverage == nil {
  5597. buff.WriteUInt8(uint8(0)) // write nil byte
  5598. } else {
  5599. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5600. buff.WriteFloat64(*target.GPUUsageAverage) // write float64
  5601. }
  5602. if target.GPURequestAverage == nil {
  5603. buff.WriteUInt8(uint8(0)) // write nil byte
  5604. } else {
  5605. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5606. buff.WriteFloat64(*target.GPURequestAverage) // write float64
  5607. }
  5608. return nil
  5609. }
  5610. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5611. // the GPUAllocation type
  5612. func (target *GPUAllocation) UnmarshalBinary(data []byte) error {
  5613. ctx := NewDecodingContextFromBytes(data)
  5614. defer ctx.Close()
  5615. err := target.UnmarshalBinaryWithContext(ctx)
  5616. if err != nil {
  5617. return err
  5618. }
  5619. return nil
  5620. }
  5621. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  5622. // the GPUAllocation type
  5623. func (target *GPUAllocation) UnmarshalBinaryFromReader(reader io.Reader) error {
  5624. ctx := NewDecodingContextFromReader(reader)
  5625. defer ctx.Close()
  5626. err := target.UnmarshalBinaryWithContext(ctx)
  5627. if err != nil {
  5628. return err
  5629. }
  5630. return nil
  5631. }
  5632. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5633. // the GPUAllocation type
  5634. func (target *GPUAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5635. // panics are recovered and propagated as errors
  5636. defer func() {
  5637. if r := recover(); r != nil {
  5638. if e, ok := r.(error); ok {
  5639. err = e
  5640. } else if s, ok := r.(string); ok {
  5641. err = fmt.Errorf("Unexpected panic: %s", s)
  5642. } else {
  5643. err = fmt.Errorf("Unexpected panic: %+v", r)
  5644. }
  5645. }
  5646. }()
  5647. buff := ctx.Buffer
  5648. version := buff.ReadUInt8()
  5649. if version > AllocationCodecVersion {
  5650. return fmt.Errorf("Invalid Version Unmarshaling GPUAllocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  5651. }
  5652. var b string
  5653. if ctx.IsStringTable() {
  5654. c := buff.ReadInt() // read string index
  5655. b = ctx.Table.At(c)
  5656. } else {
  5657. b = buff.ReadString() // read string
  5658. }
  5659. a := b
  5660. target.GPUDevice = a
  5661. var e string
  5662. if ctx.IsStringTable() {
  5663. f := buff.ReadInt() // read string index
  5664. e = ctx.Table.At(f)
  5665. } else {
  5666. e = buff.ReadString() // read string
  5667. }
  5668. d := e
  5669. target.GPUModel = d
  5670. var h string
  5671. if ctx.IsStringTable() {
  5672. l := buff.ReadInt() // read string index
  5673. h = ctx.Table.At(l)
  5674. } else {
  5675. h = buff.ReadString() // read string
  5676. }
  5677. g := h
  5678. target.GPUUUID = g
  5679. if buff.ReadUInt8() == uint8(0) {
  5680. target.IsGPUShared = nil
  5681. } else {
  5682. m := buff.ReadBool() // read bool
  5683. target.IsGPUShared = &m
  5684. }
  5685. if buff.ReadUInt8() == uint8(0) {
  5686. target.GPUUsageAverage = nil
  5687. } else {
  5688. n := buff.ReadFloat64() // read float64
  5689. target.GPUUsageAverage = &n
  5690. }
  5691. if buff.ReadUInt8() == uint8(0) {
  5692. target.GPURequestAverage = nil
  5693. } else {
  5694. o := buff.ReadFloat64() // read float64
  5695. target.GPURequestAverage = &o
  5696. }
  5697. return nil
  5698. }
  5699. //--------------------------------------------------------------------------
  5700. // LbAllocation
  5701. //--------------------------------------------------------------------------
  5702. // MarshalBinary serializes the internal properties of this LbAllocation instance
  5703. // into a byte array
  5704. func (target *LbAllocation) MarshalBinary() (data []byte, err error) {
  5705. ctx := &EncodingContext{
  5706. Buffer: util.NewBuffer(),
  5707. Table: nil,
  5708. }
  5709. e := target.MarshalBinaryWithContext(ctx)
  5710. if e != nil {
  5711. return nil, e
  5712. }
  5713. encBytes := ctx.Buffer.Bytes()
  5714. return encBytes, nil
  5715. }
  5716. // MarshalBinaryWithContext serializes the internal properties of this LbAllocation instance
  5717. // into a byte array leveraging a predefined context.
  5718. func (target *LbAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5719. // panics are recovered and propagated as errors
  5720. defer func() {
  5721. if r := recover(); r != nil {
  5722. if e, ok := r.(error); ok {
  5723. err = e
  5724. } else if s, ok := r.(string); ok {
  5725. err = fmt.Errorf("Unexpected panic: %s", s)
  5726. } else {
  5727. err = fmt.Errorf("Unexpected panic: %+v", r)
  5728. }
  5729. }
  5730. }()
  5731. buff := ctx.Buffer
  5732. buff.WriteUInt8(AllocationCodecVersion) // version
  5733. if ctx.IsStringTable() {
  5734. a := ctx.Table.AddOrGet(target.Service)
  5735. buff.WriteInt(a) // write table index
  5736. } else {
  5737. buff.WriteString(target.Service) // write string
  5738. }
  5739. buff.WriteFloat64(target.Cost) // write float64
  5740. buff.WriteBool(target.Private) // write bool
  5741. if ctx.IsStringTable() {
  5742. b := ctx.Table.AddOrGet(target.Ip)
  5743. buff.WriteInt(b) // write table index
  5744. } else {
  5745. buff.WriteString(target.Ip) // write string
  5746. }
  5747. buff.WriteFloat64(target.Hours) // write float64
  5748. return nil
  5749. }
  5750. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5751. // the LbAllocation type
  5752. func (target *LbAllocation) UnmarshalBinary(data []byte) error {
  5753. ctx := NewDecodingContextFromBytes(data)
  5754. defer ctx.Close()
  5755. err := target.UnmarshalBinaryWithContext(ctx)
  5756. if err != nil {
  5757. return err
  5758. }
  5759. return nil
  5760. }
  5761. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  5762. // the LbAllocation type
  5763. func (target *LbAllocation) UnmarshalBinaryFromReader(reader io.Reader) error {
  5764. ctx := NewDecodingContextFromReader(reader)
  5765. defer ctx.Close()
  5766. err := target.UnmarshalBinaryWithContext(ctx)
  5767. if err != nil {
  5768. return err
  5769. }
  5770. return nil
  5771. }
  5772. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5773. // the LbAllocation type
  5774. func (target *LbAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5775. // panics are recovered and propagated as errors
  5776. defer func() {
  5777. if r := recover(); r != nil {
  5778. if e, ok := r.(error); ok {
  5779. err = e
  5780. } else if s, ok := r.(string); ok {
  5781. err = fmt.Errorf("Unexpected panic: %s", s)
  5782. } else {
  5783. err = fmt.Errorf("Unexpected panic: %+v", r)
  5784. }
  5785. }
  5786. }()
  5787. buff := ctx.Buffer
  5788. version := buff.ReadUInt8()
  5789. if version > AllocationCodecVersion {
  5790. return fmt.Errorf("Invalid Version Unmarshaling LbAllocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  5791. }
  5792. var b string
  5793. if ctx.IsStringTable() {
  5794. c := buff.ReadInt() // read string index
  5795. b = ctx.Table.At(c)
  5796. } else {
  5797. b = buff.ReadString() // read string
  5798. }
  5799. a := b
  5800. target.Service = a
  5801. d := buff.ReadFloat64() // read float64
  5802. target.Cost = d
  5803. e := buff.ReadBool() // read bool
  5804. target.Private = e
  5805. // field version check
  5806. if uint8(19) <= version {
  5807. var g string
  5808. if ctx.IsStringTable() {
  5809. h := buff.ReadInt() // read string index
  5810. g = ctx.Table.At(h)
  5811. } else {
  5812. g = buff.ReadString() // read string
  5813. }
  5814. f := g
  5815. target.Ip = f
  5816. } else {
  5817. target.Ip = "" // default
  5818. }
  5819. // field version check
  5820. if uint8(21) <= version {
  5821. l := buff.ReadFloat64() // read float64
  5822. target.Hours = l
  5823. } else {
  5824. target.Hours = float64(0) // default
  5825. }
  5826. return nil
  5827. }
  5828. //--------------------------------------------------------------------------
  5829. // LoadBalancer
  5830. //--------------------------------------------------------------------------
  5831. // MarshalBinary serializes the internal properties of this LoadBalancer instance
  5832. // into a byte array
  5833. func (target *LoadBalancer) MarshalBinary() (data []byte, err error) {
  5834. ctx := &EncodingContext{
  5835. Buffer: util.NewBuffer(),
  5836. Table: nil,
  5837. }
  5838. e := target.MarshalBinaryWithContext(ctx)
  5839. if e != nil {
  5840. return nil, e
  5841. }
  5842. encBytes := ctx.Buffer.Bytes()
  5843. return encBytes, nil
  5844. }
  5845. // MarshalBinaryWithContext serializes the internal properties of this LoadBalancer instance
  5846. // into a byte array leveraging a predefined context.
  5847. func (target *LoadBalancer) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5848. // panics are recovered and propagated as errors
  5849. defer func() {
  5850. if r := recover(); r != nil {
  5851. if e, ok := r.(error); ok {
  5852. err = e
  5853. } else if s, ok := r.(string); ok {
  5854. err = fmt.Errorf("Unexpected panic: %s", s)
  5855. } else {
  5856. err = fmt.Errorf("Unexpected panic: %+v", r)
  5857. }
  5858. }
  5859. }()
  5860. buff := ctx.Buffer
  5861. buff.WriteUInt8(AssetsCodecVersion) // version
  5862. if target.Properties == nil {
  5863. buff.WriteUInt8(uint8(0)) // write nil byte
  5864. } else {
  5865. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5866. // --- [begin][write][struct](AssetProperties) ---
  5867. buff.WriteInt(0) // [compatibility, unused]
  5868. errA := target.Properties.MarshalBinaryWithContext(ctx)
  5869. if errA != nil {
  5870. return errA
  5871. }
  5872. // --- [end][write][struct](AssetProperties) ---
  5873. }
  5874. // --- [begin][write][alias](AssetLabels) ---
  5875. if map[string]string(target.Labels) == nil {
  5876. buff.WriteUInt8(uint8(0)) // write nil byte
  5877. } else {
  5878. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5879. // --- [begin][write][map](map[string]string) ---
  5880. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  5881. for v, z := range map[string]string(target.Labels) {
  5882. if ctx.IsStringTable() {
  5883. a := ctx.Table.AddOrGet(v)
  5884. buff.WriteInt(a) // write table index
  5885. } else {
  5886. buff.WriteString(v) // write string
  5887. }
  5888. if ctx.IsStringTable() {
  5889. b := ctx.Table.AddOrGet(z)
  5890. buff.WriteInt(b) // write table index
  5891. } else {
  5892. buff.WriteString(z) // write string
  5893. }
  5894. }
  5895. // --- [end][write][map](map[string]string) ---
  5896. }
  5897. // --- [end][write][alias](AssetLabels) ---
  5898. // --- [begin][write][reference](time.Time) ---
  5899. c, errB := target.Start.MarshalBinary()
  5900. if errB != nil {
  5901. return errB
  5902. }
  5903. buff.WriteInt(len(c))
  5904. buff.WriteBytes(c)
  5905. // --- [end][write][reference](time.Time) ---
  5906. // --- [begin][write][reference](time.Time) ---
  5907. d, errC := target.End.MarshalBinary()
  5908. if errC != nil {
  5909. return errC
  5910. }
  5911. buff.WriteInt(len(d))
  5912. buff.WriteBytes(d)
  5913. // --- [end][write][reference](time.Time) ---
  5914. // --- [begin][write][struct](Window) ---
  5915. buff.WriteInt(0) // [compatibility, unused]
  5916. errD := target.Window.MarshalBinaryWithContext(ctx)
  5917. if errD != nil {
  5918. return errD
  5919. }
  5920. // --- [end][write][struct](Window) ---
  5921. buff.WriteFloat64(target.Adjustment) // write float64
  5922. buff.WriteFloat64(target.Cost) // write float64
  5923. buff.WriteBool(target.Private) // write bool
  5924. if ctx.IsStringTable() {
  5925. e := ctx.Table.AddOrGet(target.Ip)
  5926. buff.WriteInt(e) // write table index
  5927. } else {
  5928. buff.WriteString(target.Ip) // write string
  5929. }
  5930. return nil
  5931. }
  5932. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5933. // the LoadBalancer type
  5934. func (target *LoadBalancer) UnmarshalBinary(data []byte) error {
  5935. ctx := NewDecodingContextFromBytes(data)
  5936. defer ctx.Close()
  5937. err := target.UnmarshalBinaryWithContext(ctx)
  5938. if err != nil {
  5939. return err
  5940. }
  5941. return nil
  5942. }
  5943. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  5944. // the LoadBalancer type
  5945. func (target *LoadBalancer) UnmarshalBinaryFromReader(reader io.Reader) error {
  5946. ctx := NewDecodingContextFromReader(reader)
  5947. defer ctx.Close()
  5948. err := target.UnmarshalBinaryWithContext(ctx)
  5949. if err != nil {
  5950. return err
  5951. }
  5952. return nil
  5953. }
  5954. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5955. // the LoadBalancer type
  5956. func (target *LoadBalancer) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5957. // panics are recovered and propagated as errors
  5958. defer func() {
  5959. if r := recover(); r != nil {
  5960. if e, ok := r.(error); ok {
  5961. err = e
  5962. } else if s, ok := r.(string); ok {
  5963. err = fmt.Errorf("Unexpected panic: %s", s)
  5964. } else {
  5965. err = fmt.Errorf("Unexpected panic: %+v", r)
  5966. }
  5967. }
  5968. }()
  5969. buff := ctx.Buffer
  5970. version := buff.ReadUInt8()
  5971. if version > AssetsCodecVersion {
  5972. return fmt.Errorf("Invalid Version Unmarshaling LoadBalancer. Expected %d or less, got %d", AssetsCodecVersion, version)
  5973. }
  5974. if buff.ReadUInt8() == uint8(0) {
  5975. target.Properties = nil
  5976. } else {
  5977. // --- [begin][read][struct](AssetProperties) ---
  5978. a := &AssetProperties{}
  5979. buff.ReadInt() // [compatibility, unused]
  5980. errA := a.UnmarshalBinaryWithContext(ctx)
  5981. if errA != nil {
  5982. return errA
  5983. }
  5984. target.Properties = a
  5985. // --- [end][read][struct](AssetProperties) ---
  5986. }
  5987. // --- [begin][read][alias](AssetLabels) ---
  5988. var b map[string]string
  5989. if buff.ReadUInt8() == uint8(0) {
  5990. b = nil
  5991. } else {
  5992. // --- [begin][read][map](map[string]string) ---
  5993. d := buff.ReadInt() // map len
  5994. c := make(map[string]string, d)
  5995. for i := 0; i < d; i++ {
  5996. var v string
  5997. var f string
  5998. if ctx.IsStringTable() {
  5999. g := buff.ReadInt() // read string index
  6000. f = ctx.Table.At(g)
  6001. } else {
  6002. f = buff.ReadString() // read string
  6003. }
  6004. e := f
  6005. v = e
  6006. var z string
  6007. var l string
  6008. if ctx.IsStringTable() {
  6009. m := buff.ReadInt() // read string index
  6010. l = ctx.Table.At(m)
  6011. } else {
  6012. l = buff.ReadString() // read string
  6013. }
  6014. h := l
  6015. z = h
  6016. c[v] = z
  6017. }
  6018. b = c
  6019. // --- [end][read][map](map[string]string) ---
  6020. }
  6021. target.Labels = AssetLabels(b)
  6022. // --- [end][read][alias](AssetLabels) ---
  6023. // --- [begin][read][reference](time.Time) ---
  6024. n := &time.Time{}
  6025. o := buff.ReadInt() // byte array length
  6026. p := buff.ReadBytes(o) // byte array
  6027. errB := n.UnmarshalBinary(p)
  6028. if errB != nil {
  6029. return errB
  6030. }
  6031. target.Start = *n
  6032. // --- [end][read][reference](time.Time) ---
  6033. // --- [begin][read][reference](time.Time) ---
  6034. q := &time.Time{}
  6035. r := buff.ReadInt() // byte array length
  6036. s := buff.ReadBytes(r) // byte array
  6037. errC := q.UnmarshalBinary(s)
  6038. if errC != nil {
  6039. return errC
  6040. }
  6041. target.End = *q
  6042. // --- [end][read][reference](time.Time) ---
  6043. // --- [begin][read][struct](Window) ---
  6044. t := &Window{}
  6045. buff.ReadInt() // [compatibility, unused]
  6046. errD := t.UnmarshalBinaryWithContext(ctx)
  6047. if errD != nil {
  6048. return errD
  6049. }
  6050. target.Window = *t
  6051. // --- [end][read][struct](Window) ---
  6052. u := buff.ReadFloat64() // read float64
  6053. target.Adjustment = u
  6054. w := buff.ReadFloat64() // read float64
  6055. target.Cost = w
  6056. // field version check
  6057. if uint8(20) <= version {
  6058. x := buff.ReadBool() // read bool
  6059. target.Private = x
  6060. } else {
  6061. target.Private = false // default
  6062. }
  6063. // field version check
  6064. if uint8(21) <= version {
  6065. var aa string
  6066. if ctx.IsStringTable() {
  6067. bb := buff.ReadInt() // read string index
  6068. aa = ctx.Table.At(bb)
  6069. } else {
  6070. aa = buff.ReadString() // read string
  6071. }
  6072. y := aa
  6073. target.Ip = y
  6074. } else {
  6075. target.Ip = "" // default
  6076. }
  6077. return nil
  6078. }
  6079. //--------------------------------------------------------------------------
  6080. // Network
  6081. //--------------------------------------------------------------------------
  6082. // MarshalBinary serializes the internal properties of this Network instance
  6083. // into a byte array
  6084. func (target *Network) MarshalBinary() (data []byte, err error) {
  6085. ctx := &EncodingContext{
  6086. Buffer: util.NewBuffer(),
  6087. Table: nil,
  6088. }
  6089. e := target.MarshalBinaryWithContext(ctx)
  6090. if e != nil {
  6091. return nil, e
  6092. }
  6093. encBytes := ctx.Buffer.Bytes()
  6094. return encBytes, nil
  6095. }
  6096. // MarshalBinaryWithContext serializes the internal properties of this Network instance
  6097. // into a byte array leveraging a predefined context.
  6098. func (target *Network) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  6099. // panics are recovered and propagated as errors
  6100. defer func() {
  6101. if r := recover(); r != nil {
  6102. if e, ok := r.(error); ok {
  6103. err = e
  6104. } else if s, ok := r.(string); ok {
  6105. err = fmt.Errorf("Unexpected panic: %s", s)
  6106. } else {
  6107. err = fmt.Errorf("Unexpected panic: %+v", r)
  6108. }
  6109. }
  6110. }()
  6111. buff := ctx.Buffer
  6112. buff.WriteUInt8(AssetsCodecVersion) // version
  6113. if target.Properties == nil {
  6114. buff.WriteUInt8(uint8(0)) // write nil byte
  6115. } else {
  6116. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6117. // --- [begin][write][struct](AssetProperties) ---
  6118. buff.WriteInt(0) // [compatibility, unused]
  6119. errA := target.Properties.MarshalBinaryWithContext(ctx)
  6120. if errA != nil {
  6121. return errA
  6122. }
  6123. // --- [end][write][struct](AssetProperties) ---
  6124. }
  6125. // --- [begin][write][alias](AssetLabels) ---
  6126. if map[string]string(target.Labels) == nil {
  6127. buff.WriteUInt8(uint8(0)) // write nil byte
  6128. } else {
  6129. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6130. // --- [begin][write][map](map[string]string) ---
  6131. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  6132. for v, z := range map[string]string(target.Labels) {
  6133. if ctx.IsStringTable() {
  6134. a := ctx.Table.AddOrGet(v)
  6135. buff.WriteInt(a) // write table index
  6136. } else {
  6137. buff.WriteString(v) // write string
  6138. }
  6139. if ctx.IsStringTable() {
  6140. b := ctx.Table.AddOrGet(z)
  6141. buff.WriteInt(b) // write table index
  6142. } else {
  6143. buff.WriteString(z) // write string
  6144. }
  6145. }
  6146. // --- [end][write][map](map[string]string) ---
  6147. }
  6148. // --- [end][write][alias](AssetLabels) ---
  6149. // --- [begin][write][reference](time.Time) ---
  6150. c, errB := target.Start.MarshalBinary()
  6151. if errB != nil {
  6152. return errB
  6153. }
  6154. buff.WriteInt(len(c))
  6155. buff.WriteBytes(c)
  6156. // --- [end][write][reference](time.Time) ---
  6157. // --- [begin][write][reference](time.Time) ---
  6158. d, errC := target.End.MarshalBinary()
  6159. if errC != nil {
  6160. return errC
  6161. }
  6162. buff.WriteInt(len(d))
  6163. buff.WriteBytes(d)
  6164. // --- [end][write][reference](time.Time) ---
  6165. // --- [begin][write][struct](Window) ---
  6166. buff.WriteInt(0) // [compatibility, unused]
  6167. errD := target.Window.MarshalBinaryWithContext(ctx)
  6168. if errD != nil {
  6169. return errD
  6170. }
  6171. // --- [end][write][struct](Window) ---
  6172. buff.WriteFloat64(target.Adjustment) // write float64
  6173. buff.WriteFloat64(target.Cost) // write float64
  6174. return nil
  6175. }
  6176. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  6177. // the Network type
  6178. func (target *Network) UnmarshalBinary(data []byte) error {
  6179. ctx := NewDecodingContextFromBytes(data)
  6180. defer ctx.Close()
  6181. err := target.UnmarshalBinaryWithContext(ctx)
  6182. if err != nil {
  6183. return err
  6184. }
  6185. return nil
  6186. }
  6187. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  6188. // the Network type
  6189. func (target *Network) UnmarshalBinaryFromReader(reader io.Reader) error {
  6190. ctx := NewDecodingContextFromReader(reader)
  6191. defer ctx.Close()
  6192. err := target.UnmarshalBinaryWithContext(ctx)
  6193. if err != nil {
  6194. return err
  6195. }
  6196. return nil
  6197. }
  6198. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  6199. // the Network type
  6200. func (target *Network) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  6201. // panics are recovered and propagated as errors
  6202. defer func() {
  6203. if r := recover(); r != nil {
  6204. if e, ok := r.(error); ok {
  6205. err = e
  6206. } else if s, ok := r.(string); ok {
  6207. err = fmt.Errorf("Unexpected panic: %s", s)
  6208. } else {
  6209. err = fmt.Errorf("Unexpected panic: %+v", r)
  6210. }
  6211. }
  6212. }()
  6213. buff := ctx.Buffer
  6214. version := buff.ReadUInt8()
  6215. if version > AssetsCodecVersion {
  6216. return fmt.Errorf("Invalid Version Unmarshaling Network. Expected %d or less, got %d", AssetsCodecVersion, version)
  6217. }
  6218. if buff.ReadUInt8() == uint8(0) {
  6219. target.Properties = nil
  6220. } else {
  6221. // --- [begin][read][struct](AssetProperties) ---
  6222. a := &AssetProperties{}
  6223. buff.ReadInt() // [compatibility, unused]
  6224. errA := a.UnmarshalBinaryWithContext(ctx)
  6225. if errA != nil {
  6226. return errA
  6227. }
  6228. target.Properties = a
  6229. // --- [end][read][struct](AssetProperties) ---
  6230. }
  6231. // --- [begin][read][alias](AssetLabels) ---
  6232. var b map[string]string
  6233. if buff.ReadUInt8() == uint8(0) {
  6234. b = nil
  6235. } else {
  6236. // --- [begin][read][map](map[string]string) ---
  6237. d := buff.ReadInt() // map len
  6238. c := make(map[string]string, d)
  6239. for i := 0; i < d; i++ {
  6240. var v string
  6241. var f string
  6242. if ctx.IsStringTable() {
  6243. g := buff.ReadInt() // read string index
  6244. f = ctx.Table.At(g)
  6245. } else {
  6246. f = buff.ReadString() // read string
  6247. }
  6248. e := f
  6249. v = e
  6250. var z string
  6251. var l string
  6252. if ctx.IsStringTable() {
  6253. m := buff.ReadInt() // read string index
  6254. l = ctx.Table.At(m)
  6255. } else {
  6256. l = buff.ReadString() // read string
  6257. }
  6258. h := l
  6259. z = h
  6260. c[v] = z
  6261. }
  6262. b = c
  6263. // --- [end][read][map](map[string]string) ---
  6264. }
  6265. target.Labels = AssetLabels(b)
  6266. // --- [end][read][alias](AssetLabels) ---
  6267. // --- [begin][read][reference](time.Time) ---
  6268. n := &time.Time{}
  6269. o := buff.ReadInt() // byte array length
  6270. p := buff.ReadBytes(o) // byte array
  6271. errB := n.UnmarshalBinary(p)
  6272. if errB != nil {
  6273. return errB
  6274. }
  6275. target.Start = *n
  6276. // --- [end][read][reference](time.Time) ---
  6277. // --- [begin][read][reference](time.Time) ---
  6278. q := &time.Time{}
  6279. r := buff.ReadInt() // byte array length
  6280. s := buff.ReadBytes(r) // byte array
  6281. errC := q.UnmarshalBinary(s)
  6282. if errC != nil {
  6283. return errC
  6284. }
  6285. target.End = *q
  6286. // --- [end][read][reference](time.Time) ---
  6287. // --- [begin][read][struct](Window) ---
  6288. t := &Window{}
  6289. buff.ReadInt() // [compatibility, unused]
  6290. errD := t.UnmarshalBinaryWithContext(ctx)
  6291. if errD != nil {
  6292. return errD
  6293. }
  6294. target.Window = *t
  6295. // --- [end][read][struct](Window) ---
  6296. u := buff.ReadFloat64() // read float64
  6297. target.Adjustment = u
  6298. w := buff.ReadFloat64() // read float64
  6299. target.Cost = w
  6300. return nil
  6301. }
  6302. //--------------------------------------------------------------------------
  6303. // NetworkDetail
  6304. //--------------------------------------------------------------------------
  6305. // MarshalBinary serializes the internal properties of this NetworkDetail instance
  6306. // into a byte array
  6307. func (target *NetworkDetail) MarshalBinary() (data []byte, err error) {
  6308. ctx := &EncodingContext{
  6309. Buffer: util.NewBuffer(),
  6310. Table: nil,
  6311. }
  6312. e := target.MarshalBinaryWithContext(ctx)
  6313. if e != nil {
  6314. return nil, e
  6315. }
  6316. encBytes := ctx.Buffer.Bytes()
  6317. return encBytes, nil
  6318. }
  6319. // MarshalBinaryWithContext serializes the internal properties of this NetworkDetail instance
  6320. // into a byte array leveraging a predefined context.
  6321. func (target *NetworkDetail) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  6322. // panics are recovered and propagated as errors
  6323. defer func() {
  6324. if r := recover(); r != nil {
  6325. if e, ok := r.(error); ok {
  6326. err = e
  6327. } else if s, ok := r.(string); ok {
  6328. err = fmt.Errorf("Unexpected panic: %s", s)
  6329. } else {
  6330. err = fmt.Errorf("Unexpected panic: %+v", r)
  6331. }
  6332. }
  6333. }()
  6334. buff := ctx.Buffer
  6335. buff.WriteUInt8(NetworkInsightCodecVersion) // version
  6336. buff.WriteFloat64(target.Cost) // write float64
  6337. buff.WriteFloat64(target.Bytes) // write float64
  6338. if ctx.IsStringTable() {
  6339. a := ctx.Table.AddOrGet(target.EndPoint)
  6340. buff.WriteInt(a) // write table index
  6341. } else {
  6342. buff.WriteString(target.EndPoint) // write string
  6343. }
  6344. // --- [begin][write][alias](NetworkTrafficDirection) ---
  6345. if ctx.IsStringTable() {
  6346. b := ctx.Table.AddOrGet(string(target.TrafficDirection))
  6347. buff.WriteInt(b) // write table index
  6348. } else {
  6349. buff.WriteString(string(target.TrafficDirection)) // write string
  6350. }
  6351. // --- [end][write][alias](NetworkTrafficDirection) ---
  6352. // --- [begin][write][alias](NetworkTrafficType) ---
  6353. if ctx.IsStringTable() {
  6354. c := ctx.Table.AddOrGet(string(target.TrafficType))
  6355. buff.WriteInt(c) // write table index
  6356. } else {
  6357. buff.WriteString(string(target.TrafficType)) // write string
  6358. }
  6359. // --- [end][write][alias](NetworkTrafficType) ---
  6360. return nil
  6361. }
  6362. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  6363. // the NetworkDetail type
  6364. func (target *NetworkDetail) UnmarshalBinary(data []byte) error {
  6365. ctx := NewDecodingContextFromBytes(data)
  6366. defer ctx.Close()
  6367. err := target.UnmarshalBinaryWithContext(ctx)
  6368. if err != nil {
  6369. return err
  6370. }
  6371. return nil
  6372. }
  6373. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  6374. // the NetworkDetail type
  6375. func (target *NetworkDetail) UnmarshalBinaryFromReader(reader io.Reader) error {
  6376. ctx := NewDecodingContextFromReader(reader)
  6377. defer ctx.Close()
  6378. err := target.UnmarshalBinaryWithContext(ctx)
  6379. if err != nil {
  6380. return err
  6381. }
  6382. return nil
  6383. }
  6384. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  6385. // the NetworkDetail type
  6386. func (target *NetworkDetail) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  6387. // panics are recovered and propagated as errors
  6388. defer func() {
  6389. if r := recover(); r != nil {
  6390. if e, ok := r.(error); ok {
  6391. err = e
  6392. } else if s, ok := r.(string); ok {
  6393. err = fmt.Errorf("Unexpected panic: %s", s)
  6394. } else {
  6395. err = fmt.Errorf("Unexpected panic: %+v", r)
  6396. }
  6397. }
  6398. }()
  6399. buff := ctx.Buffer
  6400. version := buff.ReadUInt8()
  6401. if version > NetworkInsightCodecVersion {
  6402. return fmt.Errorf("Invalid Version Unmarshaling NetworkDetail. Expected %d or less, got %d", NetworkInsightCodecVersion, version)
  6403. }
  6404. a := buff.ReadFloat64() // read float64
  6405. target.Cost = a
  6406. b := buff.ReadFloat64() // read float64
  6407. target.Bytes = b
  6408. var d string
  6409. if ctx.IsStringTable() {
  6410. e := buff.ReadInt() // read string index
  6411. d = ctx.Table.At(e)
  6412. } else {
  6413. d = buff.ReadString() // read string
  6414. }
  6415. c := d
  6416. target.EndPoint = c
  6417. // --- [begin][read][alias](NetworkTrafficDirection) ---
  6418. var f string
  6419. var h string
  6420. if ctx.IsStringTable() {
  6421. l := buff.ReadInt() // read string index
  6422. h = ctx.Table.At(l)
  6423. } else {
  6424. h = buff.ReadString() // read string
  6425. }
  6426. g := h
  6427. f = g
  6428. target.TrafficDirection = NetworkTrafficDirection(f)
  6429. // --- [end][read][alias](NetworkTrafficDirection) ---
  6430. // --- [begin][read][alias](NetworkTrafficType) ---
  6431. var m string
  6432. var o string
  6433. if ctx.IsStringTable() {
  6434. p := buff.ReadInt() // read string index
  6435. o = ctx.Table.At(p)
  6436. } else {
  6437. o = buff.ReadString() // read string
  6438. }
  6439. n := o
  6440. m = n
  6441. target.TrafficType = NetworkTrafficType(m)
  6442. // --- [end][read][alias](NetworkTrafficType) ---
  6443. return nil
  6444. }
  6445. //--------------------------------------------------------------------------
  6446. // NetworkInsight
  6447. //--------------------------------------------------------------------------
  6448. // MarshalBinary serializes the internal properties of this NetworkInsight instance
  6449. // into a byte array
  6450. func (target *NetworkInsight) MarshalBinary() (data []byte, err error) {
  6451. ctx := &EncodingContext{
  6452. Buffer: util.NewBuffer(),
  6453. Table: nil,
  6454. }
  6455. e := target.MarshalBinaryWithContext(ctx)
  6456. if e != nil {
  6457. return nil, e
  6458. }
  6459. encBytes := ctx.Buffer.Bytes()
  6460. return encBytes, nil
  6461. }
  6462. // MarshalBinaryWithContext serializes the internal properties of this NetworkInsight instance
  6463. // into a byte array leveraging a predefined context.
  6464. func (target *NetworkInsight) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  6465. // panics are recovered and propagated as errors
  6466. defer func() {
  6467. if r := recover(); r != nil {
  6468. if e, ok := r.(error); ok {
  6469. err = e
  6470. } else if s, ok := r.(string); ok {
  6471. err = fmt.Errorf("Unexpected panic: %s", s)
  6472. } else {
  6473. err = fmt.Errorf("Unexpected panic: %+v", r)
  6474. }
  6475. }
  6476. }()
  6477. buff := ctx.Buffer
  6478. buff.WriteUInt8(NetworkInsightCodecVersion) // version
  6479. if ctx.IsStringTable() {
  6480. a := ctx.Table.AddOrGet(target.Cluster)
  6481. buff.WriteInt(a) // write table index
  6482. } else {
  6483. buff.WriteString(target.Cluster) // write string
  6484. }
  6485. if ctx.IsStringTable() {
  6486. b := ctx.Table.AddOrGet(target.Namespace)
  6487. buff.WriteInt(b) // write table index
  6488. } else {
  6489. buff.WriteString(target.Namespace) // write string
  6490. }
  6491. if ctx.IsStringTable() {
  6492. c := ctx.Table.AddOrGet(target.Controller)
  6493. buff.WriteInt(c) // write table index
  6494. } else {
  6495. buff.WriteString(target.Controller) // write string
  6496. }
  6497. if ctx.IsStringTable() {
  6498. d := ctx.Table.AddOrGet(target.Pod)
  6499. buff.WriteInt(d) // write table index
  6500. } else {
  6501. buff.WriteString(target.Pod) // write string
  6502. }
  6503. if ctx.IsStringTable() {
  6504. e := ctx.Table.AddOrGet(target.Node)
  6505. buff.WriteInt(e) // write table index
  6506. } else {
  6507. buff.WriteString(target.Node) // write string
  6508. }
  6509. if target.Labels == nil {
  6510. buff.WriteUInt8(uint8(0)) // write nil byte
  6511. } else {
  6512. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6513. // --- [begin][write][map](map[string]string) ---
  6514. buff.WriteInt(len(target.Labels)) // map length
  6515. for v, z := range target.Labels {
  6516. if ctx.IsStringTable() {
  6517. f := ctx.Table.AddOrGet(v)
  6518. buff.WriteInt(f) // write table index
  6519. } else {
  6520. buff.WriteString(v) // write string
  6521. }
  6522. if ctx.IsStringTable() {
  6523. g := ctx.Table.AddOrGet(z)
  6524. buff.WriteInt(g) // write table index
  6525. } else {
  6526. buff.WriteString(z) // write string
  6527. }
  6528. }
  6529. // --- [end][write][map](map[string]string) ---
  6530. }
  6531. if ctx.IsStringTable() {
  6532. h := ctx.Table.AddOrGet(target.Region)
  6533. buff.WriteInt(h) // write table index
  6534. } else {
  6535. buff.WriteString(target.Region) // write string
  6536. }
  6537. if ctx.IsStringTable() {
  6538. l := ctx.Table.AddOrGet(target.Zone)
  6539. buff.WriteInt(l) // write table index
  6540. } else {
  6541. buff.WriteString(target.Zone) // write string
  6542. }
  6543. buff.WriteFloat64(target.NetworkTotalCost) // write float64
  6544. buff.WriteFloat64(target.NetworkCrossZoneCost) // write float64
  6545. buff.WriteFloat64(target.NetworkCrossRegionCost) // write float64
  6546. buff.WriteFloat64(target.NetworkInternetCost) // write float64
  6547. // --- [begin][write][alias](NetworkDetailsSet) ---
  6548. if map[string]*NetworkDetail(target.NetworkDetails) == nil {
  6549. buff.WriteUInt8(uint8(0)) // write nil byte
  6550. } else {
  6551. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6552. // --- [begin][write][map](map[string]*NetworkDetail) ---
  6553. buff.WriteInt(len(map[string]*NetworkDetail(target.NetworkDetails))) // map length
  6554. for vv, zz := range map[string]*NetworkDetail(target.NetworkDetails) {
  6555. if ctx.IsStringTable() {
  6556. m := ctx.Table.AddOrGet(vv)
  6557. buff.WriteInt(m) // write table index
  6558. } else {
  6559. buff.WriteString(vv) // write string
  6560. }
  6561. if zz == nil {
  6562. buff.WriteUInt8(uint8(0)) // write nil byte
  6563. } else {
  6564. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6565. // --- [begin][write][struct](NetworkDetail) ---
  6566. buff.WriteInt(0) // [compatibility, unused]
  6567. errA := zz.MarshalBinaryWithContext(ctx)
  6568. if errA != nil {
  6569. return errA
  6570. }
  6571. // --- [end][write][struct](NetworkDetail) ---
  6572. }
  6573. }
  6574. // --- [end][write][map](map[string]*NetworkDetail) ---
  6575. }
  6576. // --- [end][write][alias](NetworkDetailsSet) ---
  6577. return nil
  6578. }
  6579. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  6580. // the NetworkInsight type
  6581. func (target *NetworkInsight) UnmarshalBinary(data []byte) error {
  6582. ctx := NewDecodingContextFromBytes(data)
  6583. defer ctx.Close()
  6584. err := target.UnmarshalBinaryWithContext(ctx)
  6585. if err != nil {
  6586. return err
  6587. }
  6588. return nil
  6589. }
  6590. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  6591. // the NetworkInsight type
  6592. func (target *NetworkInsight) UnmarshalBinaryFromReader(reader io.Reader) error {
  6593. ctx := NewDecodingContextFromReader(reader)
  6594. defer ctx.Close()
  6595. err := target.UnmarshalBinaryWithContext(ctx)
  6596. if err != nil {
  6597. return err
  6598. }
  6599. return nil
  6600. }
  6601. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  6602. // the NetworkInsight type
  6603. func (target *NetworkInsight) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  6604. // panics are recovered and propagated as errors
  6605. defer func() {
  6606. if r := recover(); r != nil {
  6607. if e, ok := r.(error); ok {
  6608. err = e
  6609. } else if s, ok := r.(string); ok {
  6610. err = fmt.Errorf("Unexpected panic: %s", s)
  6611. } else {
  6612. err = fmt.Errorf("Unexpected panic: %+v", r)
  6613. }
  6614. }
  6615. }()
  6616. buff := ctx.Buffer
  6617. version := buff.ReadUInt8()
  6618. if version > NetworkInsightCodecVersion {
  6619. return fmt.Errorf("Invalid Version Unmarshaling NetworkInsight. Expected %d or less, got %d", NetworkInsightCodecVersion, version)
  6620. }
  6621. var b string
  6622. if ctx.IsStringTable() {
  6623. c := buff.ReadInt() // read string index
  6624. b = ctx.Table.At(c)
  6625. } else {
  6626. b = buff.ReadString() // read string
  6627. }
  6628. a := b
  6629. target.Cluster = a
  6630. var e string
  6631. if ctx.IsStringTable() {
  6632. f := buff.ReadInt() // read string index
  6633. e = ctx.Table.At(f)
  6634. } else {
  6635. e = buff.ReadString() // read string
  6636. }
  6637. d := e
  6638. target.Namespace = d
  6639. var h string
  6640. if ctx.IsStringTable() {
  6641. l := buff.ReadInt() // read string index
  6642. h = ctx.Table.At(l)
  6643. } else {
  6644. h = buff.ReadString() // read string
  6645. }
  6646. g := h
  6647. target.Controller = g
  6648. var n string
  6649. if ctx.IsStringTable() {
  6650. o := buff.ReadInt() // read string index
  6651. n = ctx.Table.At(o)
  6652. } else {
  6653. n = buff.ReadString() // read string
  6654. }
  6655. m := n
  6656. target.Pod = m
  6657. var q string
  6658. if ctx.IsStringTable() {
  6659. r := buff.ReadInt() // read string index
  6660. q = ctx.Table.At(r)
  6661. } else {
  6662. q = buff.ReadString() // read string
  6663. }
  6664. p := q
  6665. target.Node = p
  6666. if buff.ReadUInt8() == uint8(0) {
  6667. target.Labels = nil
  6668. } else {
  6669. // --- [begin][read][map](map[string]string) ---
  6670. t := buff.ReadInt() // map len
  6671. s := make(map[string]string, t)
  6672. for i := 0; i < t; i++ {
  6673. var v string
  6674. var w string
  6675. if ctx.IsStringTable() {
  6676. x := buff.ReadInt() // read string index
  6677. w = ctx.Table.At(x)
  6678. } else {
  6679. w = buff.ReadString() // read string
  6680. }
  6681. u := w
  6682. v = u
  6683. var z string
  6684. var aa string
  6685. if ctx.IsStringTable() {
  6686. bb := buff.ReadInt() // read string index
  6687. aa = ctx.Table.At(bb)
  6688. } else {
  6689. aa = buff.ReadString() // read string
  6690. }
  6691. y := aa
  6692. z = y
  6693. s[v] = z
  6694. }
  6695. target.Labels = s
  6696. // --- [end][read][map](map[string]string) ---
  6697. }
  6698. var dd string
  6699. if ctx.IsStringTable() {
  6700. ee := buff.ReadInt() // read string index
  6701. dd = ctx.Table.At(ee)
  6702. } else {
  6703. dd = buff.ReadString() // read string
  6704. }
  6705. cc := dd
  6706. target.Region = cc
  6707. var gg string
  6708. if ctx.IsStringTable() {
  6709. hh := buff.ReadInt() // read string index
  6710. gg = ctx.Table.At(hh)
  6711. } else {
  6712. gg = buff.ReadString() // read string
  6713. }
  6714. ff := gg
  6715. target.Zone = ff
  6716. ll := buff.ReadFloat64() // read float64
  6717. target.NetworkTotalCost = ll
  6718. mm := buff.ReadFloat64() // read float64
  6719. target.NetworkCrossZoneCost = mm
  6720. nn := buff.ReadFloat64() // read float64
  6721. target.NetworkCrossRegionCost = nn
  6722. oo := buff.ReadFloat64() // read float64
  6723. target.NetworkInternetCost = oo
  6724. // --- [begin][read][alias](NetworkDetailsSet) ---
  6725. var pp map[string]*NetworkDetail
  6726. if buff.ReadUInt8() == uint8(0) {
  6727. pp = nil
  6728. } else {
  6729. // --- [begin][read][map](map[string]*NetworkDetail) ---
  6730. rr := buff.ReadInt() // map len
  6731. qq := make(map[string]*NetworkDetail, rr)
  6732. for j := 0; j < rr; j++ {
  6733. var vv string
  6734. var tt string
  6735. if ctx.IsStringTable() {
  6736. uu := buff.ReadInt() // read string index
  6737. tt = ctx.Table.At(uu)
  6738. } else {
  6739. tt = buff.ReadString() // read string
  6740. }
  6741. ss := tt
  6742. vv = ss
  6743. var zz *NetworkDetail
  6744. if buff.ReadUInt8() == uint8(0) {
  6745. zz = nil
  6746. } else {
  6747. // --- [begin][read][struct](NetworkDetail) ---
  6748. ww := &NetworkDetail{}
  6749. buff.ReadInt() // [compatibility, unused]
  6750. errA := ww.UnmarshalBinaryWithContext(ctx)
  6751. if errA != nil {
  6752. return errA
  6753. }
  6754. zz = ww
  6755. // --- [end][read][struct](NetworkDetail) ---
  6756. }
  6757. qq[vv] = zz
  6758. }
  6759. pp = qq
  6760. // --- [end][read][map](map[string]*NetworkDetail) ---
  6761. }
  6762. target.NetworkDetails = NetworkDetailsSet(pp)
  6763. // --- [end][read][alias](NetworkDetailsSet) ---
  6764. return nil
  6765. }
  6766. //--------------------------------------------------------------------------
  6767. // NetworkInsightSet
  6768. //--------------------------------------------------------------------------
  6769. // MarshalBinary serializes the internal properties of this NetworkInsightSet instance
  6770. // into a byte array
  6771. func (target *NetworkInsightSet) MarshalBinary() (data []byte, err error) {
  6772. ctx := &EncodingContext{
  6773. Buffer: util.NewBuffer(),
  6774. Table: NewStringTableWriter(),
  6775. }
  6776. e := target.MarshalBinaryWithContext(ctx)
  6777. if e != nil {
  6778. return nil, e
  6779. }
  6780. encBytes := ctx.Buffer.Bytes()
  6781. sTableBytes := ctx.Table.ToBytes()
  6782. merged := appendBytes(sTableBytes, encBytes)
  6783. return merged, nil
  6784. }
  6785. // MarshalBinaryWithContext serializes the internal properties of this NetworkInsightSet instance
  6786. // into a byte array leveraging a predefined context.
  6787. func (target *NetworkInsightSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  6788. // panics are recovered and propagated as errors
  6789. defer func() {
  6790. if r := recover(); r != nil {
  6791. if e, ok := r.(error); ok {
  6792. err = e
  6793. } else if s, ok := r.(string); ok {
  6794. err = fmt.Errorf("Unexpected panic: %s", s)
  6795. } else {
  6796. err = fmt.Errorf("Unexpected panic: %+v", r)
  6797. }
  6798. }
  6799. }()
  6800. buff := ctx.Buffer
  6801. buff.WriteUInt8(NetworkInsightCodecVersion) // version
  6802. if target.NetworkInsights == nil {
  6803. buff.WriteUInt8(uint8(0)) // write nil byte
  6804. } else {
  6805. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6806. // --- [begin][write][map](map[string]*NetworkInsight) ---
  6807. buff.WriteInt(len(target.NetworkInsights)) // map length
  6808. for v, z := range target.NetworkInsights {
  6809. if ctx.IsStringTable() {
  6810. a := ctx.Table.AddOrGet(v)
  6811. buff.WriteInt(a) // write table index
  6812. } else {
  6813. buff.WriteString(v) // write string
  6814. }
  6815. if z == nil {
  6816. buff.WriteUInt8(uint8(0)) // write nil byte
  6817. } else {
  6818. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6819. // --- [begin][write][struct](NetworkInsight) ---
  6820. buff.WriteInt(0) // [compatibility, unused]
  6821. errA := z.MarshalBinaryWithContext(ctx)
  6822. if errA != nil {
  6823. return errA
  6824. }
  6825. // --- [end][write][struct](NetworkInsight) ---
  6826. }
  6827. }
  6828. // --- [end][write][map](map[string]*NetworkInsight) ---
  6829. }
  6830. // --- [begin][write][struct](Window) ---
  6831. buff.WriteInt(0) // [compatibility, unused]
  6832. errB := target.Window.MarshalBinaryWithContext(ctx)
  6833. if errB != nil {
  6834. return errB
  6835. }
  6836. // --- [end][write][struct](Window) ---
  6837. return nil
  6838. }
  6839. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  6840. // the NetworkInsightSet type
  6841. func (target *NetworkInsightSet) UnmarshalBinary(data []byte) error {
  6842. ctx := NewDecodingContextFromBytes(data)
  6843. defer ctx.Close()
  6844. err := target.UnmarshalBinaryWithContext(ctx)
  6845. if err != nil {
  6846. return err
  6847. }
  6848. return nil
  6849. }
  6850. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  6851. // the NetworkInsightSet type
  6852. func (target *NetworkInsightSet) UnmarshalBinaryFromReader(reader io.Reader) error {
  6853. ctx := NewDecodingContextFromReader(reader)
  6854. defer ctx.Close()
  6855. err := target.UnmarshalBinaryWithContext(ctx)
  6856. if err != nil {
  6857. return err
  6858. }
  6859. return nil
  6860. }
  6861. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  6862. // the NetworkInsightSet type
  6863. func (target *NetworkInsightSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  6864. // panics are recovered and propagated as errors
  6865. defer func() {
  6866. if r := recover(); r != nil {
  6867. if e, ok := r.(error); ok {
  6868. err = e
  6869. } else if s, ok := r.(string); ok {
  6870. err = fmt.Errorf("Unexpected panic: %s", s)
  6871. } else {
  6872. err = fmt.Errorf("Unexpected panic: %+v", r)
  6873. }
  6874. }
  6875. }()
  6876. buff := ctx.Buffer
  6877. version := buff.ReadUInt8()
  6878. if version > NetworkInsightCodecVersion {
  6879. return fmt.Errorf("Invalid Version Unmarshaling NetworkInsightSet. Expected %d or less, got %d", NetworkInsightCodecVersion, version)
  6880. }
  6881. if buff.ReadUInt8() == uint8(0) {
  6882. target.NetworkInsights = nil
  6883. } else {
  6884. // --- [begin][read][map](map[string]*NetworkInsight) ---
  6885. b := buff.ReadInt() // map len
  6886. a := make(map[string]*NetworkInsight, b)
  6887. for i := 0; i < b; i++ {
  6888. var v string
  6889. var d string
  6890. if ctx.IsStringTable() {
  6891. e := buff.ReadInt() // read string index
  6892. d = ctx.Table.At(e)
  6893. } else {
  6894. d = buff.ReadString() // read string
  6895. }
  6896. c := d
  6897. v = c
  6898. var z *NetworkInsight
  6899. if buff.ReadUInt8() == uint8(0) {
  6900. z = nil
  6901. } else {
  6902. // --- [begin][read][struct](NetworkInsight) ---
  6903. f := &NetworkInsight{}
  6904. buff.ReadInt() // [compatibility, unused]
  6905. errA := f.UnmarshalBinaryWithContext(ctx)
  6906. if errA != nil {
  6907. return errA
  6908. }
  6909. z = f
  6910. // --- [end][read][struct](NetworkInsight) ---
  6911. }
  6912. a[v] = z
  6913. }
  6914. target.NetworkInsights = a
  6915. // --- [end][read][map](map[string]*NetworkInsight) ---
  6916. }
  6917. // --- [begin][read][struct](Window) ---
  6918. g := &Window{}
  6919. buff.ReadInt() // [compatibility, unused]
  6920. errB := g.UnmarshalBinaryWithContext(ctx)
  6921. if errB != nil {
  6922. return errB
  6923. }
  6924. target.Window = *g
  6925. // --- [end][read][struct](Window) ---
  6926. return nil
  6927. }
  6928. //--------------------------------------------------------------------------
  6929. // NetworkInsightSetStream
  6930. //--------------------------------------------------------------------------
  6931. // NetworkInsightSetStream is a single use field stream for the contents of an NetworkInsightSet instance. Instead of creating an instance and populating
  6932. // the fields on that instance, we provide a streaming iterator which yields (BingenFieldInfo, *BingenValue) tuples for each
  6933. // stremable element. All slices and maps will be flattened one depth and each element streamed individually.
  6934. type NetworkInsightSetStream struct {
  6935. reader io.Reader
  6936. ctx *DecodingContext
  6937. err error
  6938. }
  6939. // Closes closes the internal io.Reader used to read and parse the NetworkInsightSet fields.
  6940. // This should be called once the stream is no longer needed.
  6941. func (stream *NetworkInsightSetStream) Close() {
  6942. if closer, ok := stream.reader.(io.Closer); ok {
  6943. closer.Close()
  6944. }
  6945. stream.ctx.Close()
  6946. }
  6947. // Error returns an error if one occurred during the process of streaming the NetworkInsightSet
  6948. // This can be checked after iterating through the Stream().
  6949. func (stream *NetworkInsightSetStream) Error() error {
  6950. return stream.err
  6951. }
  6952. // NewNetworkInsightSetStream creates a new NetworkInsightSetStream, which uses the io.Reader data to stream all internal fields of an NetworkInsightSet instance
  6953. func NewNetworkInsightSetStream(reader io.Reader) BingenStream {
  6954. ctx := NewDecodingContextFromReader(reader)
  6955. return &NetworkInsightSetStream{
  6956. ctx: ctx,
  6957. reader: reader,
  6958. }
  6959. }
  6960. // Stream returns the iterator which will stream each field of the target type.
  6961. func (stream *NetworkInsightSetStream) Stream() iter.Seq2[BingenFieldInfo, *BingenValue] {
  6962. return func(yield func(BingenFieldInfo, *BingenValue) bool) {
  6963. var fi BingenFieldInfo
  6964. ctx := stream.ctx
  6965. buff := ctx.Buffer
  6966. version := buff.ReadUInt8()
  6967. if version > NetworkInsightCodecVersion {
  6968. stream.err = fmt.Errorf("Invalid Version Unmarshaling NetworkInsightSet. Expected %d or less, got %d", NetworkInsightCodecVersion, version)
  6969. return
  6970. }
  6971. fi = BingenFieldInfo{
  6972. Type: reflect.TypeFor[map[string]*NetworkInsight](),
  6973. Name: "NetworkInsights",
  6974. }
  6975. if buff.ReadUInt8() == uint8(0) {
  6976. if !yield(fi, nil) {
  6977. return
  6978. }
  6979. } else {
  6980. // --- [begin][read][streaming-map](map[string]*NetworkInsight) ---
  6981. a := buff.ReadInt() // map len
  6982. for i := 0; i < a; i++ {
  6983. var v string
  6984. var c string
  6985. if ctx.IsStringTable() {
  6986. d := buff.ReadInt() // read string index
  6987. c = ctx.Table.At(d)
  6988. } else {
  6989. c = buff.ReadString() // read string
  6990. }
  6991. b := c
  6992. v = b
  6993. var z *NetworkInsight
  6994. if buff.ReadUInt8() == uint8(0) {
  6995. z = nil
  6996. } else {
  6997. // --- [begin][read][struct](NetworkInsight) ---
  6998. e := &NetworkInsight{}
  6999. buff.ReadInt() // [compatibility, unused]
  7000. errA := e.UnmarshalBinaryWithContext(ctx)
  7001. if errA != nil {
  7002. stream.err = errA
  7003. return
  7004. }
  7005. z = e
  7006. // --- [end][read][struct](NetworkInsight) ---
  7007. }
  7008. if !yield(fi, pairV(v, z)) {
  7009. return
  7010. }
  7011. }
  7012. // --- [end][read][streaming-map](map[string]*NetworkInsight) ---
  7013. }
  7014. fi = BingenFieldInfo{
  7015. Type: reflect.TypeFor[Window](),
  7016. Name: "Window",
  7017. }
  7018. // --- [begin][read][struct](Window) ---
  7019. g := &Window{}
  7020. buff.ReadInt() // [compatibility, unused]
  7021. errB := g.UnmarshalBinaryWithContext(ctx)
  7022. if errB != nil {
  7023. stream.err = errB
  7024. return
  7025. }
  7026. f := *g
  7027. // --- [end][read][struct](Window) ---
  7028. if !yield(fi, singleV(f)) {
  7029. return
  7030. }
  7031. }
  7032. }
  7033. //--------------------------------------------------------------------------
  7034. // Node
  7035. //--------------------------------------------------------------------------
  7036. // MarshalBinary serializes the internal properties of this Node instance
  7037. // into a byte array
  7038. func (target *Node) MarshalBinary() (data []byte, err error) {
  7039. ctx := &EncodingContext{
  7040. Buffer: util.NewBuffer(),
  7041. Table: nil,
  7042. }
  7043. e := target.MarshalBinaryWithContext(ctx)
  7044. if e != nil {
  7045. return nil, e
  7046. }
  7047. encBytes := ctx.Buffer.Bytes()
  7048. return encBytes, nil
  7049. }
  7050. // MarshalBinaryWithContext serializes the internal properties of this Node instance
  7051. // into a byte array leveraging a predefined context.
  7052. func (target *Node) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  7053. // panics are recovered and propagated as errors
  7054. defer func() {
  7055. if r := recover(); r != nil {
  7056. if e, ok := r.(error); ok {
  7057. err = e
  7058. } else if s, ok := r.(string); ok {
  7059. err = fmt.Errorf("Unexpected panic: %s", s)
  7060. } else {
  7061. err = fmt.Errorf("Unexpected panic: %+v", r)
  7062. }
  7063. }
  7064. }()
  7065. buff := ctx.Buffer
  7066. buff.WriteUInt8(AssetsCodecVersion) // version
  7067. if target.Properties == nil {
  7068. buff.WriteUInt8(uint8(0)) // write nil byte
  7069. } else {
  7070. buff.WriteUInt8(uint8(1)) // write non-nil byte
  7071. // --- [begin][write][struct](AssetProperties) ---
  7072. buff.WriteInt(0) // [compatibility, unused]
  7073. errA := target.Properties.MarshalBinaryWithContext(ctx)
  7074. if errA != nil {
  7075. return errA
  7076. }
  7077. // --- [end][write][struct](AssetProperties) ---
  7078. }
  7079. // --- [begin][write][alias](AssetLabels) ---
  7080. if map[string]string(target.Labels) == nil {
  7081. buff.WriteUInt8(uint8(0)) // write nil byte
  7082. } else {
  7083. buff.WriteUInt8(uint8(1)) // write non-nil byte
  7084. // --- [begin][write][map](map[string]string) ---
  7085. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  7086. for v, z := range map[string]string(target.Labels) {
  7087. if ctx.IsStringTable() {
  7088. a := ctx.Table.AddOrGet(v)
  7089. buff.WriteInt(a) // write table index
  7090. } else {
  7091. buff.WriteString(v) // write string
  7092. }
  7093. if ctx.IsStringTable() {
  7094. b := ctx.Table.AddOrGet(z)
  7095. buff.WriteInt(b) // write table index
  7096. } else {
  7097. buff.WriteString(z) // write string
  7098. }
  7099. }
  7100. // --- [end][write][map](map[string]string) ---
  7101. }
  7102. // --- [end][write][alias](AssetLabels) ---
  7103. // --- [begin][write][reference](time.Time) ---
  7104. c, errB := target.Start.MarshalBinary()
  7105. if errB != nil {
  7106. return errB
  7107. }
  7108. buff.WriteInt(len(c))
  7109. buff.WriteBytes(c)
  7110. // --- [end][write][reference](time.Time) ---
  7111. // --- [begin][write][reference](time.Time) ---
  7112. d, errC := target.End.MarshalBinary()
  7113. if errC != nil {
  7114. return errC
  7115. }
  7116. buff.WriteInt(len(d))
  7117. buff.WriteBytes(d)
  7118. // --- [end][write][reference](time.Time) ---
  7119. // --- [begin][write][struct](Window) ---
  7120. buff.WriteInt(0) // [compatibility, unused]
  7121. errD := target.Window.MarshalBinaryWithContext(ctx)
  7122. if errD != nil {
  7123. return errD
  7124. }
  7125. // --- [end][write][struct](Window) ---
  7126. buff.WriteFloat64(target.Adjustment) // write float64
  7127. if ctx.IsStringTable() {
  7128. e := ctx.Table.AddOrGet(target.NodeType)
  7129. buff.WriteInt(e) // write table index
  7130. } else {
  7131. buff.WriteString(target.NodeType) // write string
  7132. }
  7133. buff.WriteFloat64(target.CPUCoreHours) // write float64
  7134. buff.WriteFloat64(target.RAMByteHours) // write float64
  7135. buff.WriteFloat64(target.GPUHours) // write float64
  7136. if target.CPUBreakdown == nil {
  7137. buff.WriteUInt8(uint8(0)) // write nil byte
  7138. } else {
  7139. buff.WriteUInt8(uint8(1)) // write non-nil byte
  7140. // --- [begin][write][struct](Breakdown) ---
  7141. buff.WriteInt(0) // [compatibility, unused]
  7142. errE := target.CPUBreakdown.MarshalBinaryWithContext(ctx)
  7143. if errE != nil {
  7144. return errE
  7145. }
  7146. // --- [end][write][struct](Breakdown) ---
  7147. }
  7148. if target.RAMBreakdown == nil {
  7149. buff.WriteUInt8(uint8(0)) // write nil byte
  7150. } else {
  7151. buff.WriteUInt8(uint8(1)) // write non-nil byte
  7152. // --- [begin][write][struct](Breakdown) ---
  7153. buff.WriteInt(0) // [compatibility, unused]
  7154. errF := target.RAMBreakdown.MarshalBinaryWithContext(ctx)
  7155. if errF != nil {
  7156. return errF
  7157. }
  7158. // --- [end][write][struct](Breakdown) ---
  7159. }
  7160. buff.WriteFloat64(target.CPUCost) // write float64
  7161. buff.WriteFloat64(target.GPUCost) // write float64
  7162. buff.WriteFloat64(target.GPUCount) // write float64
  7163. buff.WriteFloat64(target.RAMCost) // write float64
  7164. buff.WriteFloat64(target.Discount) // write float64
  7165. buff.WriteFloat64(target.Preemptible) // write float64
  7166. if target.Overhead == nil {
  7167. buff.WriteUInt8(uint8(0)) // write nil byte
  7168. } else {
  7169. buff.WriteUInt8(uint8(1)) // write non-nil byte
  7170. // --- [begin][write][struct](NodeOverhead) ---
  7171. buff.WriteInt(0) // [compatibility, unused]
  7172. errG := target.Overhead.MarshalBinaryWithContext(ctx)
  7173. if errG != nil {
  7174. return errG
  7175. }
  7176. // --- [end][write][struct](NodeOverhead) ---
  7177. }
  7178. return nil
  7179. }
  7180. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  7181. // the Node type
  7182. func (target *Node) UnmarshalBinary(data []byte) error {
  7183. ctx := NewDecodingContextFromBytes(data)
  7184. defer ctx.Close()
  7185. err := target.UnmarshalBinaryWithContext(ctx)
  7186. if err != nil {
  7187. return err
  7188. }
  7189. return nil
  7190. }
  7191. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  7192. // the Node type
  7193. func (target *Node) UnmarshalBinaryFromReader(reader io.Reader) error {
  7194. ctx := NewDecodingContextFromReader(reader)
  7195. defer ctx.Close()
  7196. err := target.UnmarshalBinaryWithContext(ctx)
  7197. if err != nil {
  7198. return err
  7199. }
  7200. return nil
  7201. }
  7202. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  7203. // the Node type
  7204. func (target *Node) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  7205. // panics are recovered and propagated as errors
  7206. defer func() {
  7207. if r := recover(); r != nil {
  7208. if e, ok := r.(error); ok {
  7209. err = e
  7210. } else if s, ok := r.(string); ok {
  7211. err = fmt.Errorf("Unexpected panic: %s", s)
  7212. } else {
  7213. err = fmt.Errorf("Unexpected panic: %+v", r)
  7214. }
  7215. }
  7216. }()
  7217. buff := ctx.Buffer
  7218. version := buff.ReadUInt8()
  7219. if version > AssetsCodecVersion {
  7220. return fmt.Errorf("Invalid Version Unmarshaling Node. Expected %d or less, got %d", AssetsCodecVersion, version)
  7221. }
  7222. if buff.ReadUInt8() == uint8(0) {
  7223. target.Properties = nil
  7224. } else {
  7225. // --- [begin][read][struct](AssetProperties) ---
  7226. a := &AssetProperties{}
  7227. buff.ReadInt() // [compatibility, unused]
  7228. errA := a.UnmarshalBinaryWithContext(ctx)
  7229. if errA != nil {
  7230. return errA
  7231. }
  7232. target.Properties = a
  7233. // --- [end][read][struct](AssetProperties) ---
  7234. }
  7235. // --- [begin][read][alias](AssetLabels) ---
  7236. var b map[string]string
  7237. if buff.ReadUInt8() == uint8(0) {
  7238. b = nil
  7239. } else {
  7240. // --- [begin][read][map](map[string]string) ---
  7241. d := buff.ReadInt() // map len
  7242. c := make(map[string]string, d)
  7243. for i := 0; i < d; i++ {
  7244. var v string
  7245. var f string
  7246. if ctx.IsStringTable() {
  7247. g := buff.ReadInt() // read string index
  7248. f = ctx.Table.At(g)
  7249. } else {
  7250. f = buff.ReadString() // read string
  7251. }
  7252. e := f
  7253. v = e
  7254. var z string
  7255. var l string
  7256. if ctx.IsStringTable() {
  7257. m := buff.ReadInt() // read string index
  7258. l = ctx.Table.At(m)
  7259. } else {
  7260. l = buff.ReadString() // read string
  7261. }
  7262. h := l
  7263. z = h
  7264. c[v] = z
  7265. }
  7266. b = c
  7267. // --- [end][read][map](map[string]string) ---
  7268. }
  7269. target.Labels = AssetLabels(b)
  7270. // --- [end][read][alias](AssetLabels) ---
  7271. // --- [begin][read][reference](time.Time) ---
  7272. n := &time.Time{}
  7273. o := buff.ReadInt() // byte array length
  7274. p := buff.ReadBytes(o) // byte array
  7275. errB := n.UnmarshalBinary(p)
  7276. if errB != nil {
  7277. return errB
  7278. }
  7279. target.Start = *n
  7280. // --- [end][read][reference](time.Time) ---
  7281. // --- [begin][read][reference](time.Time) ---
  7282. q := &time.Time{}
  7283. r := buff.ReadInt() // byte array length
  7284. s := buff.ReadBytes(r) // byte array
  7285. errC := q.UnmarshalBinary(s)
  7286. if errC != nil {
  7287. return errC
  7288. }
  7289. target.End = *q
  7290. // --- [end][read][reference](time.Time) ---
  7291. // --- [begin][read][struct](Window) ---
  7292. t := &Window{}
  7293. buff.ReadInt() // [compatibility, unused]
  7294. errD := t.UnmarshalBinaryWithContext(ctx)
  7295. if errD != nil {
  7296. return errD
  7297. }
  7298. target.Window = *t
  7299. // --- [end][read][struct](Window) ---
  7300. u := buff.ReadFloat64() // read float64
  7301. target.Adjustment = u
  7302. var x string
  7303. if ctx.IsStringTable() {
  7304. y := buff.ReadInt() // read string index
  7305. x = ctx.Table.At(y)
  7306. } else {
  7307. x = buff.ReadString() // read string
  7308. }
  7309. w := x
  7310. target.NodeType = w
  7311. aa := buff.ReadFloat64() // read float64
  7312. target.CPUCoreHours = aa
  7313. bb := buff.ReadFloat64() // read float64
  7314. target.RAMByteHours = bb
  7315. cc := buff.ReadFloat64() // read float64
  7316. target.GPUHours = cc
  7317. if buff.ReadUInt8() == uint8(0) {
  7318. target.CPUBreakdown = nil
  7319. } else {
  7320. // --- [begin][read][struct](Breakdown) ---
  7321. dd := &Breakdown{}
  7322. buff.ReadInt() // [compatibility, unused]
  7323. errE := dd.UnmarshalBinaryWithContext(ctx)
  7324. if errE != nil {
  7325. return errE
  7326. }
  7327. target.CPUBreakdown = dd
  7328. // --- [end][read][struct](Breakdown) ---
  7329. }
  7330. if buff.ReadUInt8() == uint8(0) {
  7331. target.RAMBreakdown = nil
  7332. } else {
  7333. // --- [begin][read][struct](Breakdown) ---
  7334. ee := &Breakdown{}
  7335. buff.ReadInt() // [compatibility, unused]
  7336. errF := ee.UnmarshalBinaryWithContext(ctx)
  7337. if errF != nil {
  7338. return errF
  7339. }
  7340. target.RAMBreakdown = ee
  7341. // --- [end][read][struct](Breakdown) ---
  7342. }
  7343. ff := buff.ReadFloat64() // read float64
  7344. target.CPUCost = ff
  7345. gg := buff.ReadFloat64() // read float64
  7346. target.GPUCost = gg
  7347. hh := buff.ReadFloat64() // read float64
  7348. target.GPUCount = hh
  7349. ll := buff.ReadFloat64() // read float64
  7350. target.RAMCost = ll
  7351. mm := buff.ReadFloat64() // read float64
  7352. target.Discount = mm
  7353. nn := buff.ReadFloat64() // read float64
  7354. target.Preemptible = nn
  7355. // field version check
  7356. if uint8(19) <= version {
  7357. if buff.ReadUInt8() == uint8(0) {
  7358. target.Overhead = nil
  7359. } else {
  7360. // --- [begin][read][struct](NodeOverhead) ---
  7361. oo := &NodeOverhead{}
  7362. buff.ReadInt() // [compatibility, unused]
  7363. errG := oo.UnmarshalBinaryWithContext(ctx)
  7364. if errG != nil {
  7365. return errG
  7366. }
  7367. target.Overhead = oo
  7368. // --- [end][read][struct](NodeOverhead) ---
  7369. }
  7370. } else {
  7371. target.Overhead = nil
  7372. }
  7373. return nil
  7374. }
  7375. //--------------------------------------------------------------------------
  7376. // NodeOverhead
  7377. //--------------------------------------------------------------------------
  7378. // MarshalBinary serializes the internal properties of this NodeOverhead instance
  7379. // into a byte array
  7380. func (target *NodeOverhead) MarshalBinary() (data []byte, err error) {
  7381. ctx := &EncodingContext{
  7382. Buffer: util.NewBuffer(),
  7383. Table: nil,
  7384. }
  7385. e := target.MarshalBinaryWithContext(ctx)
  7386. if e != nil {
  7387. return nil, e
  7388. }
  7389. encBytes := ctx.Buffer.Bytes()
  7390. return encBytes, nil
  7391. }
  7392. // MarshalBinaryWithContext serializes the internal properties of this NodeOverhead instance
  7393. // into a byte array leveraging a predefined context.
  7394. func (target *NodeOverhead) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  7395. // panics are recovered and propagated as errors
  7396. defer func() {
  7397. if r := recover(); r != nil {
  7398. if e, ok := r.(error); ok {
  7399. err = e
  7400. } else if s, ok := r.(string); ok {
  7401. err = fmt.Errorf("Unexpected panic: %s", s)
  7402. } else {
  7403. err = fmt.Errorf("Unexpected panic: %+v", r)
  7404. }
  7405. }
  7406. }()
  7407. buff := ctx.Buffer
  7408. buff.WriteUInt8(AssetsCodecVersion) // version
  7409. buff.WriteFloat64(target.CpuOverheadFraction) // write float64
  7410. buff.WriteFloat64(target.RamOverheadFraction) // write float64
  7411. buff.WriteFloat64(target.OverheadCostFraction) // write float64
  7412. return nil
  7413. }
  7414. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  7415. // the NodeOverhead type
  7416. func (target *NodeOverhead) UnmarshalBinary(data []byte) error {
  7417. ctx := NewDecodingContextFromBytes(data)
  7418. defer ctx.Close()
  7419. err := target.UnmarshalBinaryWithContext(ctx)
  7420. if err != nil {
  7421. return err
  7422. }
  7423. return nil
  7424. }
  7425. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  7426. // the NodeOverhead type
  7427. func (target *NodeOverhead) UnmarshalBinaryFromReader(reader io.Reader) error {
  7428. ctx := NewDecodingContextFromReader(reader)
  7429. defer ctx.Close()
  7430. err := target.UnmarshalBinaryWithContext(ctx)
  7431. if err != nil {
  7432. return err
  7433. }
  7434. return nil
  7435. }
  7436. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  7437. // the NodeOverhead type
  7438. func (target *NodeOverhead) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  7439. // panics are recovered and propagated as errors
  7440. defer func() {
  7441. if r := recover(); r != nil {
  7442. if e, ok := r.(error); ok {
  7443. err = e
  7444. } else if s, ok := r.(string); ok {
  7445. err = fmt.Errorf("Unexpected panic: %s", s)
  7446. } else {
  7447. err = fmt.Errorf("Unexpected panic: %+v", r)
  7448. }
  7449. }
  7450. }()
  7451. buff := ctx.Buffer
  7452. version := buff.ReadUInt8()
  7453. if version > AssetsCodecVersion {
  7454. return fmt.Errorf("Invalid Version Unmarshaling NodeOverhead. Expected %d or less, got %d", AssetsCodecVersion, version)
  7455. }
  7456. a := buff.ReadFloat64() // read float64
  7457. target.CpuOverheadFraction = a
  7458. b := buff.ReadFloat64() // read float64
  7459. target.RamOverheadFraction = b
  7460. c := buff.ReadFloat64() // read float64
  7461. target.OverheadCostFraction = c
  7462. return nil
  7463. }
  7464. //--------------------------------------------------------------------------
  7465. // PVAllocation
  7466. //--------------------------------------------------------------------------
  7467. // MarshalBinary serializes the internal properties of this PVAllocation instance
  7468. // into a byte array
  7469. func (target *PVAllocation) MarshalBinary() (data []byte, err error) {
  7470. ctx := &EncodingContext{
  7471. Buffer: util.NewBuffer(),
  7472. Table: nil,
  7473. }
  7474. e := target.MarshalBinaryWithContext(ctx)
  7475. if e != nil {
  7476. return nil, e
  7477. }
  7478. encBytes := ctx.Buffer.Bytes()
  7479. return encBytes, nil
  7480. }
  7481. // MarshalBinaryWithContext serializes the internal properties of this PVAllocation instance
  7482. // into a byte array leveraging a predefined context.
  7483. func (target *PVAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  7484. // panics are recovered and propagated as errors
  7485. defer func() {
  7486. if r := recover(); r != nil {
  7487. if e, ok := r.(error); ok {
  7488. err = e
  7489. } else if s, ok := r.(string); ok {
  7490. err = fmt.Errorf("Unexpected panic: %s", s)
  7491. } else {
  7492. err = fmt.Errorf("Unexpected panic: %+v", r)
  7493. }
  7494. }
  7495. }()
  7496. buff := ctx.Buffer
  7497. buff.WriteUInt8(AllocationCodecVersion) // version
  7498. buff.WriteFloat64(target.ByteHours) // write float64
  7499. buff.WriteFloat64(target.Cost) // write float64
  7500. if ctx.IsStringTable() {
  7501. a := ctx.Table.AddOrGet(target.ProviderID)
  7502. buff.WriteInt(a) // write table index
  7503. } else {
  7504. buff.WriteString(target.ProviderID) // write string
  7505. }
  7506. return nil
  7507. }
  7508. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  7509. // the PVAllocation type
  7510. func (target *PVAllocation) UnmarshalBinary(data []byte) error {
  7511. ctx := NewDecodingContextFromBytes(data)
  7512. defer ctx.Close()
  7513. err := target.UnmarshalBinaryWithContext(ctx)
  7514. if err != nil {
  7515. return err
  7516. }
  7517. return nil
  7518. }
  7519. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  7520. // the PVAllocation type
  7521. func (target *PVAllocation) UnmarshalBinaryFromReader(reader io.Reader) error {
  7522. ctx := NewDecodingContextFromReader(reader)
  7523. defer ctx.Close()
  7524. err := target.UnmarshalBinaryWithContext(ctx)
  7525. if err != nil {
  7526. return err
  7527. }
  7528. return nil
  7529. }
  7530. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  7531. // the PVAllocation type
  7532. func (target *PVAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  7533. // panics are recovered and propagated as errors
  7534. defer func() {
  7535. if r := recover(); r != nil {
  7536. if e, ok := r.(error); ok {
  7537. err = e
  7538. } else if s, ok := r.(string); ok {
  7539. err = fmt.Errorf("Unexpected panic: %s", s)
  7540. } else {
  7541. err = fmt.Errorf("Unexpected panic: %+v", r)
  7542. }
  7543. }
  7544. }()
  7545. buff := ctx.Buffer
  7546. version := buff.ReadUInt8()
  7547. if version > AllocationCodecVersion {
  7548. return fmt.Errorf("Invalid Version Unmarshaling PVAllocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  7549. }
  7550. a := buff.ReadFloat64() // read float64
  7551. target.ByteHours = a
  7552. b := buff.ReadFloat64() // read float64
  7553. target.Cost = b
  7554. // field version check
  7555. if uint8(20) <= version {
  7556. var d string
  7557. if ctx.IsStringTable() {
  7558. e := buff.ReadInt() // read string index
  7559. d = ctx.Table.At(e)
  7560. } else {
  7561. d = buff.ReadString() // read string
  7562. }
  7563. c := d
  7564. target.ProviderID = c
  7565. } else {
  7566. target.ProviderID = "" // default
  7567. }
  7568. return nil
  7569. }
  7570. //--------------------------------------------------------------------------
  7571. // PVKey
  7572. //--------------------------------------------------------------------------
  7573. // MarshalBinary serializes the internal properties of this PVKey instance
  7574. // into a byte array
  7575. func (target *PVKey) MarshalBinary() (data []byte, err error) {
  7576. ctx := &EncodingContext{
  7577. Buffer: util.NewBuffer(),
  7578. Table: nil,
  7579. }
  7580. e := target.MarshalBinaryWithContext(ctx)
  7581. if e != nil {
  7582. return nil, e
  7583. }
  7584. encBytes := ctx.Buffer.Bytes()
  7585. return encBytes, nil
  7586. }
  7587. // MarshalBinaryWithContext serializes the internal properties of this PVKey instance
  7588. // into a byte array leveraging a predefined context.
  7589. func (target *PVKey) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  7590. // panics are recovered and propagated as errors
  7591. defer func() {
  7592. if r := recover(); r != nil {
  7593. if e, ok := r.(error); ok {
  7594. err = e
  7595. } else if s, ok := r.(string); ok {
  7596. err = fmt.Errorf("Unexpected panic: %s", s)
  7597. } else {
  7598. err = fmt.Errorf("Unexpected panic: %+v", r)
  7599. }
  7600. }
  7601. }()
  7602. buff := ctx.Buffer
  7603. buff.WriteUInt8(AllocationCodecVersion) // version
  7604. if ctx.IsStringTable() {
  7605. a := ctx.Table.AddOrGet(target.Cluster)
  7606. buff.WriteInt(a) // write table index
  7607. } else {
  7608. buff.WriteString(target.Cluster) // write string
  7609. }
  7610. if ctx.IsStringTable() {
  7611. b := ctx.Table.AddOrGet(target.Name)
  7612. buff.WriteInt(b) // write table index
  7613. } else {
  7614. buff.WriteString(target.Name) // write string
  7615. }
  7616. return nil
  7617. }
  7618. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  7619. // the PVKey type
  7620. func (target *PVKey) UnmarshalBinary(data []byte) error {
  7621. ctx := NewDecodingContextFromBytes(data)
  7622. defer ctx.Close()
  7623. err := target.UnmarshalBinaryWithContext(ctx)
  7624. if err != nil {
  7625. return err
  7626. }
  7627. return nil
  7628. }
  7629. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  7630. // the PVKey type
  7631. func (target *PVKey) UnmarshalBinaryFromReader(reader io.Reader) error {
  7632. ctx := NewDecodingContextFromReader(reader)
  7633. defer ctx.Close()
  7634. err := target.UnmarshalBinaryWithContext(ctx)
  7635. if err != nil {
  7636. return err
  7637. }
  7638. return nil
  7639. }
  7640. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  7641. // the PVKey type
  7642. func (target *PVKey) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  7643. // panics are recovered and propagated as errors
  7644. defer func() {
  7645. if r := recover(); r != nil {
  7646. if e, ok := r.(error); ok {
  7647. err = e
  7648. } else if s, ok := r.(string); ok {
  7649. err = fmt.Errorf("Unexpected panic: %s", s)
  7650. } else {
  7651. err = fmt.Errorf("Unexpected panic: %+v", r)
  7652. }
  7653. }
  7654. }()
  7655. buff := ctx.Buffer
  7656. version := buff.ReadUInt8()
  7657. if version > AllocationCodecVersion {
  7658. return fmt.Errorf("Invalid Version Unmarshaling PVKey. Expected %d or less, got %d", AllocationCodecVersion, version)
  7659. }
  7660. var b string
  7661. if ctx.IsStringTable() {
  7662. c := buff.ReadInt() // read string index
  7663. b = ctx.Table.At(c)
  7664. } else {
  7665. b = buff.ReadString() // read string
  7666. }
  7667. a := b
  7668. target.Cluster = a
  7669. var e string
  7670. if ctx.IsStringTable() {
  7671. f := buff.ReadInt() // read string index
  7672. e = ctx.Table.At(f)
  7673. } else {
  7674. e = buff.ReadString() // read string
  7675. }
  7676. d := e
  7677. target.Name = d
  7678. return nil
  7679. }
  7680. //--------------------------------------------------------------------------
  7681. // RawAllocationOnlyData
  7682. //--------------------------------------------------------------------------
  7683. // MarshalBinary serializes the internal properties of this RawAllocationOnlyData instance
  7684. // into a byte array
  7685. func (target *RawAllocationOnlyData) MarshalBinary() (data []byte, err error) {
  7686. ctx := &EncodingContext{
  7687. Buffer: util.NewBuffer(),
  7688. Table: nil,
  7689. }
  7690. e := target.MarshalBinaryWithContext(ctx)
  7691. if e != nil {
  7692. return nil, e
  7693. }
  7694. encBytes := ctx.Buffer.Bytes()
  7695. return encBytes, nil
  7696. }
  7697. // MarshalBinaryWithContext serializes the internal properties of this RawAllocationOnlyData instance
  7698. // into a byte array leveraging a predefined context.
  7699. func (target *RawAllocationOnlyData) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  7700. // panics are recovered and propagated as errors
  7701. defer func() {
  7702. if r := recover(); r != nil {
  7703. if e, ok := r.(error); ok {
  7704. err = e
  7705. } else if s, ok := r.(string); ok {
  7706. err = fmt.Errorf("Unexpected panic: %s", s)
  7707. } else {
  7708. err = fmt.Errorf("Unexpected panic: %+v", r)
  7709. }
  7710. }
  7711. }()
  7712. buff := ctx.Buffer
  7713. buff.WriteUInt8(AllocationCodecVersion) // version
  7714. buff.WriteFloat64(target.CPUCoreUsageMax) // write float64
  7715. buff.WriteFloat64(target.RAMBytesUsageMax) // write float64
  7716. if target.GPUUsageMax == nil {
  7717. buff.WriteUInt8(uint8(0)) // write nil byte
  7718. } else {
  7719. buff.WriteUInt8(uint8(1)) // write non-nil byte
  7720. buff.WriteFloat64(*target.GPUUsageMax) // write float64
  7721. }
  7722. return nil
  7723. }
  7724. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  7725. // the RawAllocationOnlyData type
  7726. func (target *RawAllocationOnlyData) UnmarshalBinary(data []byte) error {
  7727. ctx := NewDecodingContextFromBytes(data)
  7728. defer ctx.Close()
  7729. err := target.UnmarshalBinaryWithContext(ctx)
  7730. if err != nil {
  7731. return err
  7732. }
  7733. return nil
  7734. }
  7735. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  7736. // the RawAllocationOnlyData type
  7737. func (target *RawAllocationOnlyData) UnmarshalBinaryFromReader(reader io.Reader) error {
  7738. ctx := NewDecodingContextFromReader(reader)
  7739. defer ctx.Close()
  7740. err := target.UnmarshalBinaryWithContext(ctx)
  7741. if err != nil {
  7742. return err
  7743. }
  7744. return nil
  7745. }
  7746. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  7747. // the RawAllocationOnlyData type
  7748. func (target *RawAllocationOnlyData) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  7749. // panics are recovered and propagated as errors
  7750. defer func() {
  7751. if r := recover(); r != nil {
  7752. if e, ok := r.(error); ok {
  7753. err = e
  7754. } else if s, ok := r.(string); ok {
  7755. err = fmt.Errorf("Unexpected panic: %s", s)
  7756. } else {
  7757. err = fmt.Errorf("Unexpected panic: %+v", r)
  7758. }
  7759. }
  7760. }()
  7761. buff := ctx.Buffer
  7762. version := buff.ReadUInt8()
  7763. if version > AllocationCodecVersion {
  7764. return fmt.Errorf("Invalid Version Unmarshaling RawAllocationOnlyData. Expected %d or less, got %d", AllocationCodecVersion, version)
  7765. }
  7766. a := buff.ReadFloat64() // read float64
  7767. target.CPUCoreUsageMax = a
  7768. b := buff.ReadFloat64() // read float64
  7769. target.RAMBytesUsageMax = b
  7770. // field version check
  7771. if uint8(23) <= version {
  7772. if buff.ReadUInt8() == uint8(0) {
  7773. target.GPUUsageMax = nil
  7774. } else {
  7775. c := buff.ReadFloat64() // read float64
  7776. target.GPUUsageMax = &c
  7777. }
  7778. } else {
  7779. target.GPUUsageMax = nil
  7780. }
  7781. return nil
  7782. }
  7783. //--------------------------------------------------------------------------
  7784. // SharedAsset
  7785. //--------------------------------------------------------------------------
  7786. // MarshalBinary serializes the internal properties of this SharedAsset instance
  7787. // into a byte array
  7788. func (target *SharedAsset) MarshalBinary() (data []byte, err error) {
  7789. ctx := &EncodingContext{
  7790. Buffer: util.NewBuffer(),
  7791. Table: nil,
  7792. }
  7793. e := target.MarshalBinaryWithContext(ctx)
  7794. if e != nil {
  7795. return nil, e
  7796. }
  7797. encBytes := ctx.Buffer.Bytes()
  7798. return encBytes, nil
  7799. }
  7800. // MarshalBinaryWithContext serializes the internal properties of this SharedAsset instance
  7801. // into a byte array leveraging a predefined context.
  7802. func (target *SharedAsset) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  7803. // panics are recovered and propagated as errors
  7804. defer func() {
  7805. if r := recover(); r != nil {
  7806. if e, ok := r.(error); ok {
  7807. err = e
  7808. } else if s, ok := r.(string); ok {
  7809. err = fmt.Errorf("Unexpected panic: %s", s)
  7810. } else {
  7811. err = fmt.Errorf("Unexpected panic: %+v", r)
  7812. }
  7813. }
  7814. }()
  7815. buff := ctx.Buffer
  7816. buff.WriteUInt8(AssetsCodecVersion) // version
  7817. if target.Properties == nil {
  7818. buff.WriteUInt8(uint8(0)) // write nil byte
  7819. } else {
  7820. buff.WriteUInt8(uint8(1)) // write non-nil byte
  7821. // --- [begin][write][struct](AssetProperties) ---
  7822. buff.WriteInt(0) // [compatibility, unused]
  7823. errA := target.Properties.MarshalBinaryWithContext(ctx)
  7824. if errA != nil {
  7825. return errA
  7826. }
  7827. // --- [end][write][struct](AssetProperties) ---
  7828. }
  7829. // --- [begin][write][alias](AssetLabels) ---
  7830. if map[string]string(target.Labels) == nil {
  7831. buff.WriteUInt8(uint8(0)) // write nil byte
  7832. } else {
  7833. buff.WriteUInt8(uint8(1)) // write non-nil byte
  7834. // --- [begin][write][map](map[string]string) ---
  7835. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  7836. for v, z := range map[string]string(target.Labels) {
  7837. if ctx.IsStringTable() {
  7838. a := ctx.Table.AddOrGet(v)
  7839. buff.WriteInt(a) // write table index
  7840. } else {
  7841. buff.WriteString(v) // write string
  7842. }
  7843. if ctx.IsStringTable() {
  7844. b := ctx.Table.AddOrGet(z)
  7845. buff.WriteInt(b) // write table index
  7846. } else {
  7847. buff.WriteString(z) // write string
  7848. }
  7849. }
  7850. // --- [end][write][map](map[string]string) ---
  7851. }
  7852. // --- [end][write][alias](AssetLabels) ---
  7853. // --- [begin][write][struct](Window) ---
  7854. buff.WriteInt(0) // [compatibility, unused]
  7855. errB := target.Window.MarshalBinaryWithContext(ctx)
  7856. if errB != nil {
  7857. return errB
  7858. }
  7859. // --- [end][write][struct](Window) ---
  7860. buff.WriteFloat64(target.Cost) // write float64
  7861. return nil
  7862. }
  7863. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  7864. // the SharedAsset type
  7865. func (target *SharedAsset) UnmarshalBinary(data []byte) error {
  7866. ctx := NewDecodingContextFromBytes(data)
  7867. defer ctx.Close()
  7868. err := target.UnmarshalBinaryWithContext(ctx)
  7869. if err != nil {
  7870. return err
  7871. }
  7872. return nil
  7873. }
  7874. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  7875. // the SharedAsset type
  7876. func (target *SharedAsset) UnmarshalBinaryFromReader(reader io.Reader) error {
  7877. ctx := NewDecodingContextFromReader(reader)
  7878. defer ctx.Close()
  7879. err := target.UnmarshalBinaryWithContext(ctx)
  7880. if err != nil {
  7881. return err
  7882. }
  7883. return nil
  7884. }
  7885. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  7886. // the SharedAsset type
  7887. func (target *SharedAsset) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  7888. // panics are recovered and propagated as errors
  7889. defer func() {
  7890. if r := recover(); r != nil {
  7891. if e, ok := r.(error); ok {
  7892. err = e
  7893. } else if s, ok := r.(string); ok {
  7894. err = fmt.Errorf("Unexpected panic: %s", s)
  7895. } else {
  7896. err = fmt.Errorf("Unexpected panic: %+v", r)
  7897. }
  7898. }
  7899. }()
  7900. buff := ctx.Buffer
  7901. version := buff.ReadUInt8()
  7902. if version > AssetsCodecVersion {
  7903. return fmt.Errorf("Invalid Version Unmarshaling SharedAsset. Expected %d or less, got %d", AssetsCodecVersion, version)
  7904. }
  7905. if buff.ReadUInt8() == uint8(0) {
  7906. target.Properties = nil
  7907. } else {
  7908. // --- [begin][read][struct](AssetProperties) ---
  7909. a := &AssetProperties{}
  7910. buff.ReadInt() // [compatibility, unused]
  7911. errA := a.UnmarshalBinaryWithContext(ctx)
  7912. if errA != nil {
  7913. return errA
  7914. }
  7915. target.Properties = a
  7916. // --- [end][read][struct](AssetProperties) ---
  7917. }
  7918. // --- [begin][read][alias](AssetLabels) ---
  7919. var b map[string]string
  7920. if buff.ReadUInt8() == uint8(0) {
  7921. b = nil
  7922. } else {
  7923. // --- [begin][read][map](map[string]string) ---
  7924. d := buff.ReadInt() // map len
  7925. c := make(map[string]string, d)
  7926. for i := 0; i < d; i++ {
  7927. var v string
  7928. var f string
  7929. if ctx.IsStringTable() {
  7930. g := buff.ReadInt() // read string index
  7931. f = ctx.Table.At(g)
  7932. } else {
  7933. f = buff.ReadString() // read string
  7934. }
  7935. e := f
  7936. v = e
  7937. var z string
  7938. var l string
  7939. if ctx.IsStringTable() {
  7940. m := buff.ReadInt() // read string index
  7941. l = ctx.Table.At(m)
  7942. } else {
  7943. l = buff.ReadString() // read string
  7944. }
  7945. h := l
  7946. z = h
  7947. c[v] = z
  7948. }
  7949. b = c
  7950. // --- [end][read][map](map[string]string) ---
  7951. }
  7952. target.Labels = AssetLabels(b)
  7953. // --- [end][read][alias](AssetLabels) ---
  7954. // --- [begin][read][struct](Window) ---
  7955. n := &Window{}
  7956. buff.ReadInt() // [compatibility, unused]
  7957. errB := n.UnmarshalBinaryWithContext(ctx)
  7958. if errB != nil {
  7959. return errB
  7960. }
  7961. target.Window = *n
  7962. // --- [end][read][struct](Window) ---
  7963. o := buff.ReadFloat64() // read float64
  7964. target.Cost = o
  7965. return nil
  7966. }
  7967. //--------------------------------------------------------------------------
  7968. // Window
  7969. //--------------------------------------------------------------------------
  7970. // MarshalBinary serializes the internal properties of this Window instance
  7971. // into a byte array
  7972. func (target *Window) MarshalBinary() (data []byte, err error) {
  7973. ctx := &EncodingContext{
  7974. Buffer: util.NewBuffer(),
  7975. Table: nil,
  7976. }
  7977. e := target.MarshalBinaryWithContext(ctx)
  7978. if e != nil {
  7979. return nil, e
  7980. }
  7981. encBytes := ctx.Buffer.Bytes()
  7982. return encBytes, nil
  7983. }
  7984. // MarshalBinaryWithContext serializes the internal properties of this Window instance
  7985. // into a byte array leveraging a predefined context.
  7986. func (target *Window) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  7987. // panics are recovered and propagated as errors
  7988. defer func() {
  7989. if r := recover(); r != nil {
  7990. if e, ok := r.(error); ok {
  7991. err = e
  7992. } else if s, ok := r.(string); ok {
  7993. err = fmt.Errorf("Unexpected panic: %s", s)
  7994. } else {
  7995. err = fmt.Errorf("Unexpected panic: %+v", r)
  7996. }
  7997. }
  7998. }()
  7999. buff := ctx.Buffer
  8000. buff.WriteUInt8(DefaultCodecVersion) // version
  8001. if target.start == nil {
  8002. buff.WriteUInt8(uint8(0)) // write nil byte
  8003. } else {
  8004. buff.WriteUInt8(uint8(1)) // write non-nil byte
  8005. // --- [begin][write][reference](time.Time) ---
  8006. a, errA := target.start.MarshalBinary()
  8007. if errA != nil {
  8008. return errA
  8009. }
  8010. buff.WriteInt(len(a))
  8011. buff.WriteBytes(a)
  8012. // --- [end][write][reference](time.Time) ---
  8013. }
  8014. if target.end == nil {
  8015. buff.WriteUInt8(uint8(0)) // write nil byte
  8016. } else {
  8017. buff.WriteUInt8(uint8(1)) // write non-nil byte
  8018. // --- [begin][write][reference](time.Time) ---
  8019. b, errB := target.end.MarshalBinary()
  8020. if errB != nil {
  8021. return errB
  8022. }
  8023. buff.WriteInt(len(b))
  8024. buff.WriteBytes(b)
  8025. // --- [end][write][reference](time.Time) ---
  8026. }
  8027. return nil
  8028. }
  8029. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  8030. // the Window type
  8031. func (target *Window) UnmarshalBinary(data []byte) error {
  8032. ctx := NewDecodingContextFromBytes(data)
  8033. defer ctx.Close()
  8034. err := target.UnmarshalBinaryWithContext(ctx)
  8035. if err != nil {
  8036. return err
  8037. }
  8038. return nil
  8039. }
  8040. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  8041. // the Window type
  8042. func (target *Window) UnmarshalBinaryFromReader(reader io.Reader) error {
  8043. ctx := NewDecodingContextFromReader(reader)
  8044. defer ctx.Close()
  8045. err := target.UnmarshalBinaryWithContext(ctx)
  8046. if err != nil {
  8047. return err
  8048. }
  8049. return nil
  8050. }
  8051. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  8052. // the Window type
  8053. func (target *Window) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  8054. // panics are recovered and propagated as errors
  8055. defer func() {
  8056. if r := recover(); r != nil {
  8057. if e, ok := r.(error); ok {
  8058. err = e
  8059. } else if s, ok := r.(string); ok {
  8060. err = fmt.Errorf("Unexpected panic: %s", s)
  8061. } else {
  8062. err = fmt.Errorf("Unexpected panic: %+v", r)
  8063. }
  8064. }
  8065. }()
  8066. buff := ctx.Buffer
  8067. version := buff.ReadUInt8()
  8068. if version > DefaultCodecVersion {
  8069. return fmt.Errorf("Invalid Version Unmarshaling Window. Expected %d or less, got %d", DefaultCodecVersion, version)
  8070. }
  8071. if buff.ReadUInt8() == uint8(0) {
  8072. target.start = nil
  8073. } else {
  8074. // --- [begin][read][reference](time.Time) ---
  8075. a := &time.Time{}
  8076. b := buff.ReadInt() // byte array length
  8077. c := buff.ReadBytes(b) // byte array
  8078. errA := a.UnmarshalBinary(c)
  8079. if errA != nil {
  8080. return errA
  8081. }
  8082. target.start = a
  8083. // --- [end][read][reference](time.Time) ---
  8084. }
  8085. if buff.ReadUInt8() == uint8(0) {
  8086. target.end = nil
  8087. } else {
  8088. // --- [begin][read][reference](time.Time) ---
  8089. d := &time.Time{}
  8090. e := buff.ReadInt() // byte array length
  8091. f := buff.ReadBytes(e) // byte array
  8092. errB := d.UnmarshalBinary(f)
  8093. if errB != nil {
  8094. return errB
  8095. }
  8096. target.end = d
  8097. // --- [end][read][reference](time.Time) ---
  8098. }
  8099. return nil
  8100. }