opencost_codecs.go 235 KB

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