kubecost_codecs.go 186 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // DO NOT MODIFY
  4. //
  5. // ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻
  6. //
  7. //
  8. // This source file was automatically generated by bingen.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. package kubecost
  12. import (
  13. "fmt"
  14. util "github.com/opencost/opencost/pkg/util"
  15. "reflect"
  16. "strings"
  17. "sync"
  18. "time"
  19. )
  20. const (
  21. // GeneratorPackageName is the package the generator is targetting
  22. GeneratorPackageName string = "kubecost"
  23. )
  24. // BinaryTags represent the formatting tag used for specific optimization features
  25. const (
  26. // BinaryTagStringTable is written and/or read prior to the existence of a string
  27. // table (where each index is encoded as a string entry in the resource
  28. BinaryTagStringTable string = "BGST"
  29. )
  30. const (
  31. // DefaultCodecVersion is used for any resources listed in the Default version set
  32. DefaultCodecVersion uint8 = 17
  33. // AssetsCodecVersion is used for any resources listed in the Assets version set
  34. AssetsCodecVersion uint8 = 21
  35. // AllocationCodecVersion is used for any resources listed in the Allocation version set
  36. AllocationCodecVersion uint8 = 20
  37. // CloudCostCodecVersion is used for any resources listed in the CloudCost version set
  38. CloudCostCodecVersion uint8 = 2
  39. )
  40. //--------------------------------------------------------------------------
  41. // Type Map
  42. //--------------------------------------------------------------------------
  43. // Generated type map for resolving interface implementations to
  44. // to concrete types
  45. var typeMap map[string]reflect.Type = map[string]reflect.Type{
  46. "Allocation": reflect.TypeOf((*Allocation)(nil)).Elem(),
  47. "AllocationProperties": reflect.TypeOf((*AllocationProperties)(nil)).Elem(),
  48. "AllocationSet": reflect.TypeOf((*AllocationSet)(nil)).Elem(),
  49. "AllocationSetRange": reflect.TypeOf((*AllocationSetRange)(nil)).Elem(),
  50. "Any": reflect.TypeOf((*Any)(nil)).Elem(),
  51. "AssetProperties": reflect.TypeOf((*AssetProperties)(nil)).Elem(),
  52. "AssetSet": reflect.TypeOf((*AssetSet)(nil)).Elem(),
  53. "AssetSetRange": reflect.TypeOf((*AssetSetRange)(nil)).Elem(),
  54. "Breakdown": reflect.TypeOf((*Breakdown)(nil)).Elem(),
  55. "Cloud": reflect.TypeOf((*Cloud)(nil)).Elem(),
  56. "CloudCost": reflect.TypeOf((*CloudCost)(nil)).Elem(),
  57. "CloudCostProperties": reflect.TypeOf((*CloudCostProperties)(nil)).Elem(),
  58. "CloudCostSet": reflect.TypeOf((*CloudCostSet)(nil)).Elem(),
  59. "CloudCostSetRange": reflect.TypeOf((*CloudCostSetRange)(nil)).Elem(),
  60. "ClusterManagement": reflect.TypeOf((*ClusterManagement)(nil)).Elem(),
  61. "CostMetric": reflect.TypeOf((*CostMetric)(nil)).Elem(),
  62. "Coverage": reflect.TypeOf((*Coverage)(nil)).Elem(),
  63. "CoverageSet": reflect.TypeOf((*CoverageSet)(nil)).Elem(),
  64. "Disk": reflect.TypeOf((*Disk)(nil)).Elem(),
  65. "LbAllocation": reflect.TypeOf((*LbAllocation)(nil)).Elem(),
  66. "LoadBalancer": reflect.TypeOf((*LoadBalancer)(nil)).Elem(),
  67. "Network": reflect.TypeOf((*Network)(nil)).Elem(),
  68. "Node": reflect.TypeOf((*Node)(nil)).Elem(),
  69. "NodeOverhead": reflect.TypeOf((*NodeOverhead)(nil)).Elem(),
  70. "PVAllocation": reflect.TypeOf((*PVAllocation)(nil)).Elem(),
  71. "PVKey": reflect.TypeOf((*PVKey)(nil)).Elem(),
  72. "RawAllocationOnlyData": reflect.TypeOf((*RawAllocationOnlyData)(nil)).Elem(),
  73. "SharedAsset": reflect.TypeOf((*SharedAsset)(nil)).Elem(),
  74. "Window": reflect.TypeOf((*Window)(nil)).Elem(),
  75. }
  76. //--------------------------------------------------------------------------
  77. // Type Helpers
  78. //--------------------------------------------------------------------------
  79. // isBinaryTag returns true when the first bytes in the provided binary matches the tag
  80. func isBinaryTag(data []byte, tag string) bool {
  81. return string(data[:len(tag)]) == tag
  82. }
  83. // appendBytes combines a and b into a new byte array
  84. func appendBytes(a []byte, b []byte) []byte {
  85. al := len(a)
  86. bl := len(b)
  87. tl := al + bl
  88. // allocate a new byte array for the combined
  89. // use native copy for speedy byte copying
  90. result := make([]byte, tl, tl)
  91. copy(result, a)
  92. copy(result[al:], b)
  93. return result
  94. }
  95. // typeToString determines the basic properties of the type, the qualifier, package path, and
  96. // type name, and returns the qualified type
  97. func typeToString(f interface{}) string {
  98. qual := ""
  99. t := reflect.TypeOf(f)
  100. if t.Kind() == reflect.Ptr {
  101. t = t.Elem()
  102. qual = "*"
  103. }
  104. return fmt.Sprintf("%s%s.%s", qual, t.PkgPath(), t.Name())
  105. }
  106. // resolveType uses the name of a type and returns the package, base type name, and whether
  107. // or not it's a pointer.
  108. func resolveType(t string) (pkg string, name string, isPtr bool) {
  109. isPtr = t[:1] == "*"
  110. if isPtr {
  111. t = t[1:]
  112. }
  113. slashIndex := strings.LastIndex(t, "/")
  114. if slashIndex >= 0 {
  115. t = t[slashIndex+1:]
  116. }
  117. parts := strings.Split(t, ".")
  118. if parts[0] == GeneratorPackageName {
  119. parts[0] = ""
  120. }
  121. pkg = parts[0]
  122. name = parts[1]
  123. return
  124. }
  125. //--------------------------------------------------------------------------
  126. // StringTable
  127. //--------------------------------------------------------------------------
  128. // StringTable maps strings to specific indices for encoding
  129. type StringTable struct {
  130. l *sync.Mutex
  131. indices map[string]int
  132. next int
  133. }
  134. // NewStringTable Creates a new StringTable instance with provided contents
  135. func NewStringTable(contents ...string) *StringTable {
  136. st := &StringTable{
  137. l: new(sync.Mutex),
  138. indices: make(map[string]int),
  139. next: len(contents),
  140. }
  141. for i, entry := range contents {
  142. st.indices[entry] = i
  143. }
  144. return st
  145. }
  146. // AddOrGet atomically retrieves a string entry's index if it exist. Otherwise, it will
  147. // add the entry and return the index.
  148. func (st *StringTable) AddOrGet(s string) int {
  149. st.l.Lock()
  150. defer st.l.Unlock()
  151. if ind, ok := st.indices[s]; ok {
  152. return ind
  153. }
  154. current := st.next
  155. st.next++
  156. st.indices[s] = current
  157. return current
  158. }
  159. // ToSlice Converts the contents to a string array for encoding.
  160. func (st *StringTable) ToSlice() []string {
  161. st.l.Lock()
  162. defer st.l.Unlock()
  163. if st.next == 0 {
  164. return []string{}
  165. }
  166. sl := make([]string, st.next, st.next)
  167. for s, i := range st.indices {
  168. sl[i] = s
  169. }
  170. return sl
  171. }
  172. // ToBytes Converts the contents to a binary encoded representation
  173. func (st *StringTable) ToBytes() []byte {
  174. buff := util.NewBuffer()
  175. buff.WriteBytes([]byte(BinaryTagStringTable)) // bingen table header
  176. strs := st.ToSlice()
  177. buff.WriteInt(len(strs)) // table length
  178. for _, s := range strs {
  179. buff.WriteString(s)
  180. }
  181. return buff.Bytes()
  182. }
  183. //--------------------------------------------------------------------------
  184. // Codec Context
  185. //--------------------------------------------------------------------------
  186. // EncodingContext is a context object passed to the encoders to ensure reuse of buffer
  187. // and table data
  188. type EncodingContext struct {
  189. Buffer *util.Buffer
  190. Table *StringTable
  191. }
  192. // IsStringTable returns true if the table is available
  193. func (ec *EncodingContext) IsStringTable() bool {
  194. return ec.Table != nil
  195. }
  196. // DecodingContext is a context object passed to the decoders to ensure parent objects
  197. // reuse as much data as possible
  198. type DecodingContext struct {
  199. Buffer *util.Buffer
  200. Table []string
  201. }
  202. // IsStringTable returns true if the table is available
  203. func (dc *DecodingContext) IsStringTable() bool {
  204. return len(dc.Table) > 0
  205. }
  206. //--------------------------------------------------------------------------
  207. // Binary Codec
  208. //--------------------------------------------------------------------------
  209. // BinEncoder is an encoding interface which defines a context based marshal contract.
  210. type BinEncoder interface {
  211. MarshalBinaryWithContext(*EncodingContext) error
  212. }
  213. // BinDecoder is a decoding interface which defines a context based unmarshal contract.
  214. type BinDecoder interface {
  215. UnmarshalBinaryWithContext(*DecodingContext) error
  216. }
  217. //--------------------------------------------------------------------------
  218. // Allocation
  219. //--------------------------------------------------------------------------
  220. // MarshalBinary serializes the internal properties of this Allocation instance
  221. // into a byte array
  222. func (target *Allocation) MarshalBinary() (data []byte, err error) {
  223. ctx := &EncodingContext{
  224. Buffer: util.NewBuffer(),
  225. Table: nil,
  226. }
  227. e := target.MarshalBinaryWithContext(ctx)
  228. if e != nil {
  229. return nil, e
  230. }
  231. encBytes := ctx.Buffer.Bytes()
  232. return encBytes, nil
  233. }
  234. // MarshalBinaryWithContext serializes the internal properties of this Allocation instance
  235. // into a byte array leveraging a predefined context.
  236. func (target *Allocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  237. // panics are recovered and propagated as errors
  238. defer func() {
  239. if r := recover(); r != nil {
  240. if e, ok := r.(error); ok {
  241. err = e
  242. } else if s, ok := r.(string); ok {
  243. err = fmt.Errorf("Unexpected panic: %s", s)
  244. } else {
  245. err = fmt.Errorf("Unexpected panic: %+v", r)
  246. }
  247. }
  248. }()
  249. buff := ctx.Buffer
  250. buff.WriteUInt8(AllocationCodecVersion) // version
  251. if ctx.IsStringTable() {
  252. a := ctx.Table.AddOrGet(target.Name)
  253. buff.WriteInt(a) // write table index
  254. } else {
  255. buff.WriteString(target.Name) // write string
  256. }
  257. if target.Properties == nil {
  258. buff.WriteUInt8(uint8(0)) // write nil byte
  259. } else {
  260. buff.WriteUInt8(uint8(1)) // write non-nil byte
  261. // --- [begin][write][struct](AllocationProperties) ---
  262. buff.WriteInt(0) // [compatibility, unused]
  263. errA := target.Properties.MarshalBinaryWithContext(ctx)
  264. if errA != nil {
  265. return errA
  266. }
  267. // --- [end][write][struct](AllocationProperties) ---
  268. }
  269. // --- [begin][write][struct](Window) ---
  270. buff.WriteInt(0) // [compatibility, unused]
  271. errB := target.Window.MarshalBinaryWithContext(ctx)
  272. if errB != nil {
  273. return errB
  274. }
  275. // --- [end][write][struct](Window) ---
  276. // --- [begin][write][reference](time.Time) ---
  277. b, errC := target.Start.MarshalBinary()
  278. if errC != nil {
  279. return errC
  280. }
  281. buff.WriteInt(len(b))
  282. buff.WriteBytes(b)
  283. // --- [end][write][reference](time.Time) ---
  284. // --- [begin][write][reference](time.Time) ---
  285. c, errD := target.End.MarshalBinary()
  286. if errD != nil {
  287. return errD
  288. }
  289. buff.WriteInt(len(c))
  290. buff.WriteBytes(c)
  291. // --- [end][write][reference](time.Time) ---
  292. buff.WriteFloat64(target.CPUCoreHours) // write float64
  293. buff.WriteFloat64(target.CPUCoreRequestAverage) // write float64
  294. buff.WriteFloat64(target.CPUCoreUsageAverage) // write float64
  295. buff.WriteFloat64(target.CPUCost) // write float64
  296. buff.WriteFloat64(target.CPUCostAdjustment) // write float64
  297. buff.WriteFloat64(target.GPUHours) // write float64
  298. buff.WriteFloat64(target.GPUCost) // write float64
  299. buff.WriteFloat64(target.GPUCostAdjustment) // write float64
  300. buff.WriteFloat64(target.NetworkTransferBytes) // write float64
  301. buff.WriteFloat64(target.NetworkReceiveBytes) // write float64
  302. buff.WriteFloat64(target.NetworkCost) // write float64
  303. buff.WriteFloat64(target.NetworkCrossZoneCost) // write float64
  304. buff.WriteFloat64(target.NetworkCrossRegionCost) // write float64
  305. buff.WriteFloat64(target.NetworkInternetCost) // write float64
  306. buff.WriteFloat64(target.NetworkCostAdjustment) // write float64
  307. buff.WriteFloat64(target.LoadBalancerCost) // write float64
  308. buff.WriteFloat64(target.LoadBalancerCostAdjustment) // write float64
  309. // --- [begin][write][alias](PVAllocations) ---
  310. if map[PVKey]*PVAllocation(target.PVs) == nil {
  311. buff.WriteUInt8(uint8(0)) // write nil byte
  312. } else {
  313. buff.WriteUInt8(uint8(1)) // write non-nil byte
  314. // --- [begin][write][map](map[PVKey]*PVAllocation) ---
  315. buff.WriteInt(len(map[PVKey]*PVAllocation(target.PVs))) // map length
  316. for v, z := range map[PVKey]*PVAllocation(target.PVs) {
  317. // --- [begin][write][struct](PVKey) ---
  318. buff.WriteInt(0) // [compatibility, unused]
  319. errE := v.MarshalBinaryWithContext(ctx)
  320. if errE != nil {
  321. return errE
  322. }
  323. // --- [end][write][struct](PVKey) ---
  324. if z == nil {
  325. buff.WriteUInt8(uint8(0)) // write nil byte
  326. } else {
  327. buff.WriteUInt8(uint8(1)) // write non-nil byte
  328. // --- [begin][write][struct](PVAllocation) ---
  329. buff.WriteInt(0) // [compatibility, unused]
  330. errF := z.MarshalBinaryWithContext(ctx)
  331. if errF != nil {
  332. return errF
  333. }
  334. // --- [end][write][struct](PVAllocation) ---
  335. }
  336. }
  337. // --- [end][write][map](map[PVKey]*PVAllocation) ---
  338. }
  339. // --- [end][write][alias](PVAllocations) ---
  340. buff.WriteFloat64(target.PVCostAdjustment) // write float64
  341. buff.WriteFloat64(target.RAMByteHours) // write float64
  342. buff.WriteFloat64(target.RAMBytesRequestAverage) // write float64
  343. buff.WriteFloat64(target.RAMBytesUsageAverage) // write float64
  344. buff.WriteFloat64(target.RAMCost) // write float64
  345. buff.WriteFloat64(target.RAMCostAdjustment) // write float64
  346. buff.WriteFloat64(target.SharedCost) // write float64
  347. buff.WriteFloat64(target.ExternalCost) // write float64
  348. if target.RawAllocationOnly == nil {
  349. buff.WriteUInt8(uint8(0)) // write nil byte
  350. } else {
  351. buff.WriteUInt8(uint8(1)) // write non-nil byte
  352. // --- [begin][write][struct](RawAllocationOnlyData) ---
  353. buff.WriteInt(0) // [compatibility, unused]
  354. errG := target.RawAllocationOnly.MarshalBinaryWithContext(ctx)
  355. if errG != nil {
  356. return errG
  357. }
  358. // --- [end][write][struct](RawAllocationOnlyData) ---
  359. }
  360. // --- [begin][write][alias](LbAllocations) ---
  361. if map[string]*LbAllocation(target.LoadBalancers) == nil {
  362. buff.WriteUInt8(uint8(0)) // write nil byte
  363. } else {
  364. buff.WriteUInt8(uint8(1)) // write non-nil byte
  365. // --- [begin][write][map](map[string]*LbAllocation) ---
  366. buff.WriteInt(len(map[string]*LbAllocation(target.LoadBalancers))) // map length
  367. for vv, zz := range map[string]*LbAllocation(target.LoadBalancers) {
  368. if ctx.IsStringTable() {
  369. d := ctx.Table.AddOrGet(vv)
  370. buff.WriteInt(d) // write table index
  371. } else {
  372. buff.WriteString(vv) // write string
  373. }
  374. if zz == nil {
  375. buff.WriteUInt8(uint8(0)) // write nil byte
  376. } else {
  377. buff.WriteUInt8(uint8(1)) // write non-nil byte
  378. // --- [begin][write][struct](LbAllocation) ---
  379. buff.WriteInt(0) // [compatibility, unused]
  380. errH := zz.MarshalBinaryWithContext(ctx)
  381. if errH != nil {
  382. return errH
  383. }
  384. // --- [end][write][struct](LbAllocation) ---
  385. }
  386. }
  387. // --- [end][write][map](map[string]*LbAllocation) ---
  388. }
  389. // --- [end][write][alias](LbAllocations) ---
  390. return nil
  391. }
  392. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  393. // the Allocation type
  394. func (target *Allocation) UnmarshalBinary(data []byte) error {
  395. var table []string
  396. buff := util.NewBufferFromBytes(data)
  397. // string table header validation
  398. if isBinaryTag(data, BinaryTagStringTable) {
  399. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  400. tl := buff.ReadInt() // table length
  401. if tl > 0 {
  402. table = make([]string, tl, tl)
  403. for i := 0; i < tl; i++ {
  404. table[i] = buff.ReadString()
  405. }
  406. }
  407. }
  408. ctx := &DecodingContext{
  409. Buffer: buff,
  410. Table: table,
  411. }
  412. err := target.UnmarshalBinaryWithContext(ctx)
  413. if err != nil {
  414. return err
  415. }
  416. return nil
  417. }
  418. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  419. // the Allocation type
  420. func (target *Allocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  421. // panics are recovered and propagated as errors
  422. defer func() {
  423. if r := recover(); r != nil {
  424. if e, ok := r.(error); ok {
  425. err = e
  426. } else if s, ok := r.(string); ok {
  427. err = fmt.Errorf("Unexpected panic: %s", s)
  428. } else {
  429. err = fmt.Errorf("Unexpected panic: %+v", r)
  430. }
  431. }
  432. }()
  433. buff := ctx.Buffer
  434. version := buff.ReadUInt8()
  435. if version > AllocationCodecVersion {
  436. return fmt.Errorf("Invalid Version Unmarshaling Allocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  437. }
  438. var b string
  439. if ctx.IsStringTable() {
  440. c := buff.ReadInt() // read string index
  441. b = ctx.Table[c]
  442. } else {
  443. b = buff.ReadString() // read string
  444. }
  445. a := b
  446. target.Name = a
  447. if buff.ReadUInt8() == uint8(0) {
  448. target.Properties = nil
  449. } else {
  450. // --- [begin][read][struct](AllocationProperties) ---
  451. d := &AllocationProperties{}
  452. buff.ReadInt() // [compatibility, unused]
  453. errA := d.UnmarshalBinaryWithContext(ctx)
  454. if errA != nil {
  455. return errA
  456. }
  457. target.Properties = d
  458. // --- [end][read][struct](AllocationProperties) ---
  459. }
  460. // --- [begin][read][struct](Window) ---
  461. e := &Window{}
  462. buff.ReadInt() // [compatibility, unused]
  463. errB := e.UnmarshalBinaryWithContext(ctx)
  464. if errB != nil {
  465. return errB
  466. }
  467. target.Window = *e
  468. // --- [end][read][struct](Window) ---
  469. // --- [begin][read][reference](time.Time) ---
  470. f := &time.Time{}
  471. g := buff.ReadInt() // byte array length
  472. h := buff.ReadBytes(g) // byte array
  473. errC := f.UnmarshalBinary(h)
  474. if errC != nil {
  475. return errC
  476. }
  477. target.Start = *f
  478. // --- [end][read][reference](time.Time) ---
  479. // --- [begin][read][reference](time.Time) ---
  480. k := &time.Time{}
  481. l := buff.ReadInt() // byte array length
  482. m := buff.ReadBytes(l) // byte array
  483. errD := k.UnmarshalBinary(m)
  484. if errD != nil {
  485. return errD
  486. }
  487. target.End = *k
  488. // --- [end][read][reference](time.Time) ---
  489. n := buff.ReadFloat64() // read float64
  490. target.CPUCoreHours = n
  491. o := buff.ReadFloat64() // read float64
  492. target.CPUCoreRequestAverage = o
  493. p := buff.ReadFloat64() // read float64
  494. target.CPUCoreUsageAverage = p
  495. q := buff.ReadFloat64() // read float64
  496. target.CPUCost = q
  497. r := buff.ReadFloat64() // read float64
  498. target.CPUCostAdjustment = r
  499. s := buff.ReadFloat64() // read float64
  500. target.GPUHours = s
  501. t := buff.ReadFloat64() // read float64
  502. target.GPUCost = t
  503. u := buff.ReadFloat64() // read float64
  504. target.GPUCostAdjustment = u
  505. w := buff.ReadFloat64() // read float64
  506. target.NetworkTransferBytes = w
  507. x := buff.ReadFloat64() // read float64
  508. target.NetworkReceiveBytes = x
  509. y := buff.ReadFloat64() // read float64
  510. target.NetworkCost = y
  511. // field version check
  512. if uint8(16) <= version {
  513. aa := buff.ReadFloat64() // read float64
  514. target.NetworkCrossZoneCost = aa
  515. } else {
  516. target.NetworkCrossZoneCost = float64(0) // default
  517. }
  518. // field version check
  519. if uint8(16) <= version {
  520. bb := buff.ReadFloat64() // read float64
  521. target.NetworkCrossRegionCost = bb
  522. } else {
  523. target.NetworkCrossRegionCost = float64(0) // default
  524. }
  525. // field version check
  526. if uint8(16) <= version {
  527. cc := buff.ReadFloat64() // read float64
  528. target.NetworkInternetCost = cc
  529. } else {
  530. target.NetworkInternetCost = float64(0) // default
  531. }
  532. dd := buff.ReadFloat64() // read float64
  533. target.NetworkCostAdjustment = dd
  534. ee := buff.ReadFloat64() // read float64
  535. target.LoadBalancerCost = ee
  536. ff := buff.ReadFloat64() // read float64
  537. target.LoadBalancerCostAdjustment = ff
  538. // --- [begin][read][alias](PVAllocations) ---
  539. var gg map[PVKey]*PVAllocation
  540. if buff.ReadUInt8() == uint8(0) {
  541. gg = nil
  542. } else {
  543. // --- [begin][read][map](map[PVKey]*PVAllocation) ---
  544. kk := buff.ReadInt() // map len
  545. hh := make(map[PVKey]*PVAllocation, kk)
  546. for i := 0; i < kk; i++ {
  547. // --- [begin][read][struct](PVKey) ---
  548. ll := &PVKey{}
  549. buff.ReadInt() // [compatibility, unused]
  550. errE := ll.UnmarshalBinaryWithContext(ctx)
  551. if errE != nil {
  552. return errE
  553. }
  554. v := *ll
  555. // --- [end][read][struct](PVKey) ---
  556. var z *PVAllocation
  557. if buff.ReadUInt8() == uint8(0) {
  558. z = nil
  559. } else {
  560. // --- [begin][read][struct](PVAllocation) ---
  561. mm := &PVAllocation{}
  562. buff.ReadInt() // [compatibility, unused]
  563. errF := mm.UnmarshalBinaryWithContext(ctx)
  564. if errF != nil {
  565. return errF
  566. }
  567. z = mm
  568. // --- [end][read][struct](PVAllocation) ---
  569. }
  570. hh[v] = z
  571. }
  572. gg = hh
  573. // --- [end][read][map](map[PVKey]*PVAllocation) ---
  574. }
  575. target.PVs = PVAllocations(gg)
  576. // --- [end][read][alias](PVAllocations) ---
  577. nn := buff.ReadFloat64() // read float64
  578. target.PVCostAdjustment = nn
  579. oo := buff.ReadFloat64() // read float64
  580. target.RAMByteHours = oo
  581. pp := buff.ReadFloat64() // read float64
  582. target.RAMBytesRequestAverage = pp
  583. qq := buff.ReadFloat64() // read float64
  584. target.RAMBytesUsageAverage = qq
  585. rr := buff.ReadFloat64() // read float64
  586. target.RAMCost = rr
  587. ss := buff.ReadFloat64() // read float64
  588. target.RAMCostAdjustment = ss
  589. tt := buff.ReadFloat64() // read float64
  590. target.SharedCost = tt
  591. uu := buff.ReadFloat64() // read float64
  592. target.ExternalCost = uu
  593. if buff.ReadUInt8() == uint8(0) {
  594. target.RawAllocationOnly = nil
  595. } else {
  596. // --- [begin][read][struct](RawAllocationOnlyData) ---
  597. ww := &RawAllocationOnlyData{}
  598. buff.ReadInt() // [compatibility, unused]
  599. errG := ww.UnmarshalBinaryWithContext(ctx)
  600. if errG != nil {
  601. return errG
  602. }
  603. target.RawAllocationOnly = ww
  604. // --- [end][read][struct](RawAllocationOnlyData) ---
  605. }
  606. // field version check
  607. if uint8(18) <= version {
  608. // --- [begin][read][alias](LbAllocations) ---
  609. var xx map[string]*LbAllocation
  610. if buff.ReadUInt8() == uint8(0) {
  611. xx = nil
  612. } else {
  613. // --- [begin][read][map](map[string]*LbAllocation) ---
  614. aaa := buff.ReadInt() // map len
  615. yy := make(map[string]*LbAllocation, aaa)
  616. for j := 0; j < aaa; j++ {
  617. var vv string
  618. var ccc string
  619. if ctx.IsStringTable() {
  620. ddd := buff.ReadInt() // read string index
  621. ccc = ctx.Table[ddd]
  622. } else {
  623. ccc = buff.ReadString() // read string
  624. }
  625. bbb := ccc
  626. vv = bbb
  627. var zz *LbAllocation
  628. if buff.ReadUInt8() == uint8(0) {
  629. zz = nil
  630. } else {
  631. // --- [begin][read][struct](LbAllocation) ---
  632. eee := &LbAllocation{}
  633. buff.ReadInt() // [compatibility, unused]
  634. errH := eee.UnmarshalBinaryWithContext(ctx)
  635. if errH != nil {
  636. return errH
  637. }
  638. zz = eee
  639. // --- [end][read][struct](LbAllocation) ---
  640. }
  641. yy[vv] = zz
  642. }
  643. xx = yy
  644. // --- [end][read][map](map[string]*LbAllocation) ---
  645. }
  646. target.LoadBalancers = LbAllocations(xx)
  647. // --- [end][read][alias](LbAllocations) ---
  648. } else {
  649. }
  650. return nil
  651. }
  652. //--------------------------------------------------------------------------
  653. // AllocationProperties
  654. //--------------------------------------------------------------------------
  655. // MarshalBinary serializes the internal properties of this AllocationProperties instance
  656. // into a byte array
  657. func (target *AllocationProperties) MarshalBinary() (data []byte, err error) {
  658. ctx := &EncodingContext{
  659. Buffer: util.NewBuffer(),
  660. Table: nil,
  661. }
  662. e := target.MarshalBinaryWithContext(ctx)
  663. if e != nil {
  664. return nil, e
  665. }
  666. encBytes := ctx.Buffer.Bytes()
  667. return encBytes, nil
  668. }
  669. // MarshalBinaryWithContext serializes the internal properties of this AllocationProperties instance
  670. // into a byte array leveraging a predefined context.
  671. func (target *AllocationProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  672. // panics are recovered and propagated as errors
  673. defer func() {
  674. if r := recover(); r != nil {
  675. if e, ok := r.(error); ok {
  676. err = e
  677. } else if s, ok := r.(string); ok {
  678. err = fmt.Errorf("Unexpected panic: %s", s)
  679. } else {
  680. err = fmt.Errorf("Unexpected panic: %+v", r)
  681. }
  682. }
  683. }()
  684. buff := ctx.Buffer
  685. buff.WriteUInt8(AllocationCodecVersion) // version
  686. if ctx.IsStringTable() {
  687. a := ctx.Table.AddOrGet(target.Cluster)
  688. buff.WriteInt(a) // write table index
  689. } else {
  690. buff.WriteString(target.Cluster) // write string
  691. }
  692. if ctx.IsStringTable() {
  693. b := ctx.Table.AddOrGet(target.Node)
  694. buff.WriteInt(b) // write table index
  695. } else {
  696. buff.WriteString(target.Node) // write string
  697. }
  698. if ctx.IsStringTable() {
  699. c := ctx.Table.AddOrGet(target.Container)
  700. buff.WriteInt(c) // write table index
  701. } else {
  702. buff.WriteString(target.Container) // write string
  703. }
  704. if ctx.IsStringTable() {
  705. d := ctx.Table.AddOrGet(target.Controller)
  706. buff.WriteInt(d) // write table index
  707. } else {
  708. buff.WriteString(target.Controller) // write string
  709. }
  710. if ctx.IsStringTable() {
  711. e := ctx.Table.AddOrGet(target.ControllerKind)
  712. buff.WriteInt(e) // write table index
  713. } else {
  714. buff.WriteString(target.ControllerKind) // write string
  715. }
  716. if ctx.IsStringTable() {
  717. f := ctx.Table.AddOrGet(target.Namespace)
  718. buff.WriteInt(f) // write table index
  719. } else {
  720. buff.WriteString(target.Namespace) // write string
  721. }
  722. if ctx.IsStringTable() {
  723. g := ctx.Table.AddOrGet(target.Pod)
  724. buff.WriteInt(g) // write table index
  725. } else {
  726. buff.WriteString(target.Pod) // write string
  727. }
  728. if target.Services == nil {
  729. buff.WriteUInt8(uint8(0)) // write nil byte
  730. } else {
  731. buff.WriteUInt8(uint8(1)) // write non-nil byte
  732. // --- [begin][write][slice]([]string) ---
  733. buff.WriteInt(len(target.Services)) // array length
  734. for i := 0; i < len(target.Services); i++ {
  735. if ctx.IsStringTable() {
  736. h := ctx.Table.AddOrGet(target.Services[i])
  737. buff.WriteInt(h) // write table index
  738. } else {
  739. buff.WriteString(target.Services[i]) // write string
  740. }
  741. }
  742. // --- [end][write][slice]([]string) ---
  743. }
  744. if ctx.IsStringTable() {
  745. k := ctx.Table.AddOrGet(target.ProviderID)
  746. buff.WriteInt(k) // write table index
  747. } else {
  748. buff.WriteString(target.ProviderID) // write string
  749. }
  750. // --- [begin][write][alias](AllocationLabels) ---
  751. if map[string]string(target.Labels) == nil {
  752. buff.WriteUInt8(uint8(0)) // write nil byte
  753. } else {
  754. buff.WriteUInt8(uint8(1)) // write non-nil byte
  755. // --- [begin][write][map](map[string]string) ---
  756. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  757. for v, z := range map[string]string(target.Labels) {
  758. if ctx.IsStringTable() {
  759. l := ctx.Table.AddOrGet(v)
  760. buff.WriteInt(l) // write table index
  761. } else {
  762. buff.WriteString(v) // write string
  763. }
  764. if ctx.IsStringTable() {
  765. m := ctx.Table.AddOrGet(z)
  766. buff.WriteInt(m) // write table index
  767. } else {
  768. buff.WriteString(z) // write string
  769. }
  770. }
  771. // --- [end][write][map](map[string]string) ---
  772. }
  773. // --- [end][write][alias](AllocationLabels) ---
  774. // --- [begin][write][alias](AllocationAnnotations) ---
  775. if map[string]string(target.Annotations) == nil {
  776. buff.WriteUInt8(uint8(0)) // write nil byte
  777. } else {
  778. buff.WriteUInt8(uint8(1)) // write non-nil byte
  779. // --- [begin][write][map](map[string]string) ---
  780. buff.WriteInt(len(map[string]string(target.Annotations))) // map length
  781. for vv, zz := range map[string]string(target.Annotations) {
  782. if ctx.IsStringTable() {
  783. n := ctx.Table.AddOrGet(vv)
  784. buff.WriteInt(n) // write table index
  785. } else {
  786. buff.WriteString(vv) // write string
  787. }
  788. if ctx.IsStringTable() {
  789. o := ctx.Table.AddOrGet(zz)
  790. buff.WriteInt(o) // write table index
  791. } else {
  792. buff.WriteString(zz) // write string
  793. }
  794. }
  795. // --- [end][write][map](map[string]string) ---
  796. }
  797. // --- [end][write][alias](AllocationAnnotations) ---
  798. // --- [begin][write][alias](AllocationLabels) ---
  799. if map[string]string(target.NamespaceLabels) == nil {
  800. buff.WriteUInt8(uint8(0)) // write nil byte
  801. } else {
  802. buff.WriteUInt8(uint8(1)) // write non-nil byte
  803. // --- [begin][write][map](map[string]string) ---
  804. buff.WriteInt(len(map[string]string(target.NamespaceLabels))) // map length
  805. for vvv, zzz := range map[string]string(target.NamespaceLabels) {
  806. if ctx.IsStringTable() {
  807. p := ctx.Table.AddOrGet(vvv)
  808. buff.WriteInt(p) // write table index
  809. } else {
  810. buff.WriteString(vvv) // write string
  811. }
  812. if ctx.IsStringTable() {
  813. q := ctx.Table.AddOrGet(zzz)
  814. buff.WriteInt(q) // write table index
  815. } else {
  816. buff.WriteString(zzz) // write string
  817. }
  818. }
  819. // --- [end][write][map](map[string]string) ---
  820. }
  821. // --- [end][write][alias](AllocationLabels) ---
  822. // --- [begin][write][alias](AllocationAnnotations) ---
  823. if map[string]string(target.NamespaceAnnotations) == nil {
  824. buff.WriteUInt8(uint8(0)) // write nil byte
  825. } else {
  826. buff.WriteUInt8(uint8(1)) // write non-nil byte
  827. // --- [begin][write][map](map[string]string) ---
  828. buff.WriteInt(len(map[string]string(target.NamespaceAnnotations))) // map length
  829. for vvvv, zzzz := range map[string]string(target.NamespaceAnnotations) {
  830. if ctx.IsStringTable() {
  831. r := ctx.Table.AddOrGet(vvvv)
  832. buff.WriteInt(r) // write table index
  833. } else {
  834. buff.WriteString(vvvv) // write string
  835. }
  836. if ctx.IsStringTable() {
  837. s := ctx.Table.AddOrGet(zzzz)
  838. buff.WriteInt(s) // write table index
  839. } else {
  840. buff.WriteString(zzzz) // write string
  841. }
  842. }
  843. // --- [end][write][map](map[string]string) ---
  844. }
  845. // --- [end][write][alias](AllocationAnnotations) ---
  846. return nil
  847. }
  848. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  849. // the AllocationProperties type
  850. func (target *AllocationProperties) UnmarshalBinary(data []byte) error {
  851. var table []string
  852. buff := util.NewBufferFromBytes(data)
  853. // string table header validation
  854. if isBinaryTag(data, BinaryTagStringTable) {
  855. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  856. tl := buff.ReadInt() // table length
  857. if tl > 0 {
  858. table = make([]string, tl, tl)
  859. for i := 0; i < tl; i++ {
  860. table[i] = buff.ReadString()
  861. }
  862. }
  863. }
  864. ctx := &DecodingContext{
  865. Buffer: buff,
  866. Table: table,
  867. }
  868. err := target.UnmarshalBinaryWithContext(ctx)
  869. if err != nil {
  870. return err
  871. }
  872. return nil
  873. }
  874. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  875. // the AllocationProperties type
  876. func (target *AllocationProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  877. // panics are recovered and propagated as errors
  878. defer func() {
  879. if r := recover(); r != nil {
  880. if e, ok := r.(error); ok {
  881. err = e
  882. } else if s, ok := r.(string); ok {
  883. err = fmt.Errorf("Unexpected panic: %s", s)
  884. } else {
  885. err = fmt.Errorf("Unexpected panic: %+v", r)
  886. }
  887. }
  888. }()
  889. buff := ctx.Buffer
  890. version := buff.ReadUInt8()
  891. if version > AllocationCodecVersion {
  892. return fmt.Errorf("Invalid Version Unmarshaling AllocationProperties. Expected %d or less, got %d", AllocationCodecVersion, version)
  893. }
  894. var b string
  895. if ctx.IsStringTable() {
  896. c := buff.ReadInt() // read string index
  897. b = ctx.Table[c]
  898. } else {
  899. b = buff.ReadString() // read string
  900. }
  901. a := b
  902. target.Cluster = a
  903. var e string
  904. if ctx.IsStringTable() {
  905. f := buff.ReadInt() // read string index
  906. e = ctx.Table[f]
  907. } else {
  908. e = buff.ReadString() // read string
  909. }
  910. d := e
  911. target.Node = d
  912. var h string
  913. if ctx.IsStringTable() {
  914. k := buff.ReadInt() // read string index
  915. h = ctx.Table[k]
  916. } else {
  917. h = buff.ReadString() // read string
  918. }
  919. g := h
  920. target.Container = g
  921. var m string
  922. if ctx.IsStringTable() {
  923. n := buff.ReadInt() // read string index
  924. m = ctx.Table[n]
  925. } else {
  926. m = buff.ReadString() // read string
  927. }
  928. l := m
  929. target.Controller = l
  930. var p string
  931. if ctx.IsStringTable() {
  932. q := buff.ReadInt() // read string index
  933. p = ctx.Table[q]
  934. } else {
  935. p = buff.ReadString() // read string
  936. }
  937. o := p
  938. target.ControllerKind = o
  939. var s string
  940. if ctx.IsStringTable() {
  941. t := buff.ReadInt() // read string index
  942. s = ctx.Table[t]
  943. } else {
  944. s = buff.ReadString() // read string
  945. }
  946. r := s
  947. target.Namespace = r
  948. var w string
  949. if ctx.IsStringTable() {
  950. x := buff.ReadInt() // read string index
  951. w = ctx.Table[x]
  952. } else {
  953. w = buff.ReadString() // read string
  954. }
  955. u := w
  956. target.Pod = u
  957. if buff.ReadUInt8() == uint8(0) {
  958. target.Services = nil
  959. } else {
  960. // --- [begin][read][slice]([]string) ---
  961. aa := buff.ReadInt() // array len
  962. y := make([]string, aa)
  963. for i := 0; i < aa; i++ {
  964. var bb string
  965. var dd string
  966. if ctx.IsStringTable() {
  967. ee := buff.ReadInt() // read string index
  968. dd = ctx.Table[ee]
  969. } else {
  970. dd = buff.ReadString() // read string
  971. }
  972. cc := dd
  973. bb = cc
  974. y[i] = bb
  975. }
  976. target.Services = y
  977. // --- [end][read][slice]([]string) ---
  978. }
  979. var gg string
  980. if ctx.IsStringTable() {
  981. hh := buff.ReadInt() // read string index
  982. gg = ctx.Table[hh]
  983. } else {
  984. gg = buff.ReadString() // read string
  985. }
  986. ff := gg
  987. target.ProviderID = ff
  988. // --- [begin][read][alias](AllocationLabels) ---
  989. var kk map[string]string
  990. if buff.ReadUInt8() == uint8(0) {
  991. kk = nil
  992. } else {
  993. // --- [begin][read][map](map[string]string) ---
  994. mm := buff.ReadInt() // map len
  995. ll := make(map[string]string, mm)
  996. for j := 0; j < mm; j++ {
  997. var v string
  998. var oo string
  999. if ctx.IsStringTable() {
  1000. pp := buff.ReadInt() // read string index
  1001. oo = ctx.Table[pp]
  1002. } else {
  1003. oo = buff.ReadString() // read string
  1004. }
  1005. nn := oo
  1006. v = nn
  1007. var z string
  1008. var rr string
  1009. if ctx.IsStringTable() {
  1010. ss := buff.ReadInt() // read string index
  1011. rr = ctx.Table[ss]
  1012. } else {
  1013. rr = buff.ReadString() // read string
  1014. }
  1015. qq := rr
  1016. z = qq
  1017. ll[v] = z
  1018. }
  1019. kk = ll
  1020. // --- [end][read][map](map[string]string) ---
  1021. }
  1022. target.Labels = AllocationLabels(kk)
  1023. // --- [end][read][alias](AllocationLabels) ---
  1024. // --- [begin][read][alias](AllocationAnnotations) ---
  1025. var tt map[string]string
  1026. if buff.ReadUInt8() == uint8(0) {
  1027. tt = nil
  1028. } else {
  1029. // --- [begin][read][map](map[string]string) ---
  1030. ww := buff.ReadInt() // map len
  1031. uu := make(map[string]string, ww)
  1032. for ii := 0; ii < ww; ii++ {
  1033. var vv string
  1034. var yy string
  1035. if ctx.IsStringTable() {
  1036. aaa := buff.ReadInt() // read string index
  1037. yy = ctx.Table[aaa]
  1038. } else {
  1039. yy = buff.ReadString() // read string
  1040. }
  1041. xx := yy
  1042. vv = xx
  1043. var zz string
  1044. var ccc string
  1045. if ctx.IsStringTable() {
  1046. ddd := buff.ReadInt() // read string index
  1047. ccc = ctx.Table[ddd]
  1048. } else {
  1049. ccc = buff.ReadString() // read string
  1050. }
  1051. bbb := ccc
  1052. zz = bbb
  1053. uu[vv] = zz
  1054. }
  1055. tt = uu
  1056. // --- [end][read][map](map[string]string) ---
  1057. }
  1058. target.Annotations = AllocationAnnotations(tt)
  1059. // --- [end][read][alias](AllocationAnnotations) ---
  1060. // field version check
  1061. if uint8(17) <= version {
  1062. // --- [begin][read][alias](AllocationLabels) ---
  1063. var eee map[string]string
  1064. if buff.ReadUInt8() == uint8(0) {
  1065. eee = nil
  1066. } else {
  1067. // --- [begin][read][map](map[string]string) ---
  1068. ggg := buff.ReadInt() // map len
  1069. fff := make(map[string]string, ggg)
  1070. for jj := 0; jj < ggg; jj++ {
  1071. var vvv string
  1072. var kkk string
  1073. if ctx.IsStringTable() {
  1074. lll := buff.ReadInt() // read string index
  1075. kkk = ctx.Table[lll]
  1076. } else {
  1077. kkk = buff.ReadString() // read string
  1078. }
  1079. hhh := kkk
  1080. vvv = hhh
  1081. var zzz string
  1082. var nnn string
  1083. if ctx.IsStringTable() {
  1084. ooo := buff.ReadInt() // read string index
  1085. nnn = ctx.Table[ooo]
  1086. } else {
  1087. nnn = buff.ReadString() // read string
  1088. }
  1089. mmm := nnn
  1090. zzz = mmm
  1091. fff[vvv] = zzz
  1092. }
  1093. eee = fff
  1094. // --- [end][read][map](map[string]string) ---
  1095. }
  1096. target.NamespaceLabels = AllocationLabels(eee)
  1097. // --- [end][read][alias](AllocationLabels) ---
  1098. } else {
  1099. }
  1100. // field version check
  1101. if uint8(17) <= version {
  1102. // --- [begin][read][alias](AllocationAnnotations) ---
  1103. var ppp map[string]string
  1104. if buff.ReadUInt8() == uint8(0) {
  1105. ppp = nil
  1106. } else {
  1107. // --- [begin][read][map](map[string]string) ---
  1108. rrr := buff.ReadInt() // map len
  1109. qqq := make(map[string]string, rrr)
  1110. for iii := 0; iii < rrr; iii++ {
  1111. var vvvv string
  1112. var ttt string
  1113. if ctx.IsStringTable() {
  1114. uuu := buff.ReadInt() // read string index
  1115. ttt = ctx.Table[uuu]
  1116. } else {
  1117. ttt = buff.ReadString() // read string
  1118. }
  1119. sss := ttt
  1120. vvvv = sss
  1121. var zzzz string
  1122. var xxx string
  1123. if ctx.IsStringTable() {
  1124. yyy := buff.ReadInt() // read string index
  1125. xxx = ctx.Table[yyy]
  1126. } else {
  1127. xxx = buff.ReadString() // read string
  1128. }
  1129. www := xxx
  1130. zzzz = www
  1131. qqq[vvvv] = zzzz
  1132. }
  1133. ppp = qqq
  1134. // --- [end][read][map](map[string]string) ---
  1135. }
  1136. target.NamespaceAnnotations = AllocationAnnotations(ppp)
  1137. // --- [end][read][alias](AllocationAnnotations) ---
  1138. } else {
  1139. }
  1140. return nil
  1141. }
  1142. //--------------------------------------------------------------------------
  1143. // AllocationSet
  1144. //--------------------------------------------------------------------------
  1145. // MarshalBinary serializes the internal properties of this AllocationSet instance
  1146. // into a byte array
  1147. func (target *AllocationSet) MarshalBinary() (data []byte, err error) {
  1148. ctx := &EncodingContext{
  1149. Buffer: util.NewBuffer(),
  1150. Table: NewStringTable(),
  1151. }
  1152. e := target.MarshalBinaryWithContext(ctx)
  1153. if e != nil {
  1154. return nil, e
  1155. }
  1156. encBytes := ctx.Buffer.Bytes()
  1157. sTableBytes := ctx.Table.ToBytes()
  1158. merged := appendBytes(sTableBytes, encBytes)
  1159. return merged, nil
  1160. }
  1161. // MarshalBinaryWithContext serializes the internal properties of this AllocationSet instance
  1162. // into a byte array leveraging a predefined context.
  1163. func (target *AllocationSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1164. // panics are recovered and propagated as errors
  1165. defer func() {
  1166. if r := recover(); r != nil {
  1167. if e, ok := r.(error); ok {
  1168. err = e
  1169. } else if s, ok := r.(string); ok {
  1170. err = fmt.Errorf("Unexpected panic: %s", s)
  1171. } else {
  1172. err = fmt.Errorf("Unexpected panic: %+v", r)
  1173. }
  1174. }
  1175. }()
  1176. buff := ctx.Buffer
  1177. buff.WriteUInt8(AllocationCodecVersion) // version
  1178. if target.Allocations == nil {
  1179. buff.WriteUInt8(uint8(0)) // write nil byte
  1180. } else {
  1181. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1182. // --- [begin][write][map](map[string]*Allocation) ---
  1183. buff.WriteInt(len(target.Allocations)) // map length
  1184. for v, z := range target.Allocations {
  1185. if ctx.IsStringTable() {
  1186. a := ctx.Table.AddOrGet(v)
  1187. buff.WriteInt(a) // write table index
  1188. } else {
  1189. buff.WriteString(v) // write string
  1190. }
  1191. if z == nil {
  1192. buff.WriteUInt8(uint8(0)) // write nil byte
  1193. } else {
  1194. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1195. // --- [begin][write][struct](Allocation) ---
  1196. buff.WriteInt(0) // [compatibility, unused]
  1197. errA := z.MarshalBinaryWithContext(ctx)
  1198. if errA != nil {
  1199. return errA
  1200. }
  1201. // --- [end][write][struct](Allocation) ---
  1202. }
  1203. }
  1204. // --- [end][write][map](map[string]*Allocation) ---
  1205. }
  1206. if target.ExternalKeys == nil {
  1207. buff.WriteUInt8(uint8(0)) // write nil byte
  1208. } else {
  1209. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1210. // --- [begin][write][map](map[string]bool) ---
  1211. buff.WriteInt(len(target.ExternalKeys)) // map length
  1212. for vv, zz := range target.ExternalKeys {
  1213. if ctx.IsStringTable() {
  1214. b := ctx.Table.AddOrGet(vv)
  1215. buff.WriteInt(b) // write table index
  1216. } else {
  1217. buff.WriteString(vv) // write string
  1218. }
  1219. buff.WriteBool(zz) // write bool
  1220. }
  1221. // --- [end][write][map](map[string]bool) ---
  1222. }
  1223. if target.IdleKeys == nil {
  1224. buff.WriteUInt8(uint8(0)) // write nil byte
  1225. } else {
  1226. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1227. // --- [begin][write][map](map[string]bool) ---
  1228. buff.WriteInt(len(target.IdleKeys)) // map length
  1229. for vvv, zzz := range target.IdleKeys {
  1230. if ctx.IsStringTable() {
  1231. c := ctx.Table.AddOrGet(vvv)
  1232. buff.WriteInt(c) // write table index
  1233. } else {
  1234. buff.WriteString(vvv) // write string
  1235. }
  1236. buff.WriteBool(zzz) // write bool
  1237. }
  1238. // --- [end][write][map](map[string]bool) ---
  1239. }
  1240. if ctx.IsStringTable() {
  1241. d := ctx.Table.AddOrGet(target.FromSource)
  1242. buff.WriteInt(d) // write table index
  1243. } else {
  1244. buff.WriteString(target.FromSource) // write string
  1245. }
  1246. // --- [begin][write][struct](Window) ---
  1247. buff.WriteInt(0) // [compatibility, unused]
  1248. errB := target.Window.MarshalBinaryWithContext(ctx)
  1249. if errB != nil {
  1250. return errB
  1251. }
  1252. // --- [end][write][struct](Window) ---
  1253. if target.Warnings == nil {
  1254. buff.WriteUInt8(uint8(0)) // write nil byte
  1255. } else {
  1256. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1257. // --- [begin][write][slice]([]string) ---
  1258. buff.WriteInt(len(target.Warnings)) // array length
  1259. for i := 0; i < len(target.Warnings); i++ {
  1260. if ctx.IsStringTable() {
  1261. e := ctx.Table.AddOrGet(target.Warnings[i])
  1262. buff.WriteInt(e) // write table index
  1263. } else {
  1264. buff.WriteString(target.Warnings[i]) // write string
  1265. }
  1266. }
  1267. // --- [end][write][slice]([]string) ---
  1268. }
  1269. if target.Errors == nil {
  1270. buff.WriteUInt8(uint8(0)) // write nil byte
  1271. } else {
  1272. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1273. // --- [begin][write][slice]([]string) ---
  1274. buff.WriteInt(len(target.Errors)) // array length
  1275. for j := 0; j < len(target.Errors); j++ {
  1276. if ctx.IsStringTable() {
  1277. f := ctx.Table.AddOrGet(target.Errors[j])
  1278. buff.WriteInt(f) // write table index
  1279. } else {
  1280. buff.WriteString(target.Errors[j]) // write string
  1281. }
  1282. }
  1283. // --- [end][write][slice]([]string) ---
  1284. }
  1285. return nil
  1286. }
  1287. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1288. // the AllocationSet type
  1289. func (target *AllocationSet) UnmarshalBinary(data []byte) error {
  1290. var table []string
  1291. buff := util.NewBufferFromBytes(data)
  1292. // string table header validation
  1293. if isBinaryTag(data, BinaryTagStringTable) {
  1294. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1295. tl := buff.ReadInt() // table length
  1296. if tl > 0 {
  1297. table = make([]string, tl, tl)
  1298. for i := 0; i < tl; i++ {
  1299. table[i] = buff.ReadString()
  1300. }
  1301. }
  1302. }
  1303. ctx := &DecodingContext{
  1304. Buffer: buff,
  1305. Table: table,
  1306. }
  1307. err := target.UnmarshalBinaryWithContext(ctx)
  1308. if err != nil {
  1309. return err
  1310. }
  1311. return nil
  1312. }
  1313. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1314. // the AllocationSet type
  1315. func (target *AllocationSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1316. // panics are recovered and propagated as errors
  1317. defer func() {
  1318. if r := recover(); r != nil {
  1319. if e, ok := r.(error); ok {
  1320. err = e
  1321. } else if s, ok := r.(string); ok {
  1322. err = fmt.Errorf("Unexpected panic: %s", s)
  1323. } else {
  1324. err = fmt.Errorf("Unexpected panic: %+v", r)
  1325. }
  1326. }
  1327. }()
  1328. buff := ctx.Buffer
  1329. version := buff.ReadUInt8()
  1330. if version > AllocationCodecVersion {
  1331. return fmt.Errorf("Invalid Version Unmarshaling AllocationSet. Expected %d or less, got %d", AllocationCodecVersion, version)
  1332. }
  1333. if buff.ReadUInt8() == uint8(0) {
  1334. target.Allocations = nil
  1335. } else {
  1336. // --- [begin][read][map](map[string]*Allocation) ---
  1337. b := buff.ReadInt() // map len
  1338. a := make(map[string]*Allocation, b)
  1339. for i := 0; i < b; i++ {
  1340. var v string
  1341. var d string
  1342. if ctx.IsStringTable() {
  1343. e := buff.ReadInt() // read string index
  1344. d = ctx.Table[e]
  1345. } else {
  1346. d = buff.ReadString() // read string
  1347. }
  1348. c := d
  1349. v = c
  1350. var z *Allocation
  1351. if buff.ReadUInt8() == uint8(0) {
  1352. z = nil
  1353. } else {
  1354. // --- [begin][read][struct](Allocation) ---
  1355. f := &Allocation{}
  1356. buff.ReadInt() // [compatibility, unused]
  1357. errA := f.UnmarshalBinaryWithContext(ctx)
  1358. if errA != nil {
  1359. return errA
  1360. }
  1361. z = f
  1362. // --- [end][read][struct](Allocation) ---
  1363. }
  1364. a[v] = z
  1365. }
  1366. target.Allocations = a
  1367. // --- [end][read][map](map[string]*Allocation) ---
  1368. }
  1369. if buff.ReadUInt8() == uint8(0) {
  1370. target.ExternalKeys = nil
  1371. } else {
  1372. // --- [begin][read][map](map[string]bool) ---
  1373. h := buff.ReadInt() // map len
  1374. g := make(map[string]bool, h)
  1375. for j := 0; j < h; j++ {
  1376. var vv string
  1377. var l string
  1378. if ctx.IsStringTable() {
  1379. m := buff.ReadInt() // read string index
  1380. l = ctx.Table[m]
  1381. } else {
  1382. l = buff.ReadString() // read string
  1383. }
  1384. k := l
  1385. vv = k
  1386. var zz bool
  1387. n := buff.ReadBool() // read bool
  1388. zz = n
  1389. g[vv] = zz
  1390. }
  1391. target.ExternalKeys = g
  1392. // --- [end][read][map](map[string]bool) ---
  1393. }
  1394. if buff.ReadUInt8() == uint8(0) {
  1395. target.IdleKeys = nil
  1396. } else {
  1397. // --- [begin][read][map](map[string]bool) ---
  1398. p := buff.ReadInt() // map len
  1399. o := make(map[string]bool, p)
  1400. for ii := 0; ii < p; ii++ {
  1401. var vvv string
  1402. var r string
  1403. if ctx.IsStringTable() {
  1404. s := buff.ReadInt() // read string index
  1405. r = ctx.Table[s]
  1406. } else {
  1407. r = buff.ReadString() // read string
  1408. }
  1409. q := r
  1410. vvv = q
  1411. var zzz bool
  1412. t := buff.ReadBool() // read bool
  1413. zzz = t
  1414. o[vvv] = zzz
  1415. }
  1416. target.IdleKeys = o
  1417. // --- [end][read][map](map[string]bool) ---
  1418. }
  1419. var w string
  1420. if ctx.IsStringTable() {
  1421. x := buff.ReadInt() // read string index
  1422. w = ctx.Table[x]
  1423. } else {
  1424. w = buff.ReadString() // read string
  1425. }
  1426. u := w
  1427. target.FromSource = u
  1428. // --- [begin][read][struct](Window) ---
  1429. y := &Window{}
  1430. buff.ReadInt() // [compatibility, unused]
  1431. errB := y.UnmarshalBinaryWithContext(ctx)
  1432. if errB != nil {
  1433. return errB
  1434. }
  1435. target.Window = *y
  1436. // --- [end][read][struct](Window) ---
  1437. if buff.ReadUInt8() == uint8(0) {
  1438. target.Warnings = nil
  1439. } else {
  1440. // --- [begin][read][slice]([]string) ---
  1441. bb := buff.ReadInt() // array len
  1442. aa := make([]string, bb)
  1443. for jj := 0; jj < bb; jj++ {
  1444. var cc string
  1445. var ee string
  1446. if ctx.IsStringTable() {
  1447. ff := buff.ReadInt() // read string index
  1448. ee = ctx.Table[ff]
  1449. } else {
  1450. ee = buff.ReadString() // read string
  1451. }
  1452. dd := ee
  1453. cc = dd
  1454. aa[jj] = cc
  1455. }
  1456. target.Warnings = aa
  1457. // --- [end][read][slice]([]string) ---
  1458. }
  1459. if buff.ReadUInt8() == uint8(0) {
  1460. target.Errors = nil
  1461. } else {
  1462. // --- [begin][read][slice]([]string) ---
  1463. hh := buff.ReadInt() // array len
  1464. gg := make([]string, hh)
  1465. for iii := 0; iii < hh; iii++ {
  1466. var kk string
  1467. var mm string
  1468. if ctx.IsStringTable() {
  1469. nn := buff.ReadInt() // read string index
  1470. mm = ctx.Table[nn]
  1471. } else {
  1472. mm = buff.ReadString() // read string
  1473. }
  1474. ll := mm
  1475. kk = ll
  1476. gg[iii] = kk
  1477. }
  1478. target.Errors = gg
  1479. // --- [end][read][slice]([]string) ---
  1480. }
  1481. return nil
  1482. }
  1483. //--------------------------------------------------------------------------
  1484. // AllocationSetRange
  1485. //--------------------------------------------------------------------------
  1486. // MarshalBinary serializes the internal properties of this AllocationSetRange instance
  1487. // into a byte array
  1488. func (target *AllocationSetRange) MarshalBinary() (data []byte, err error) {
  1489. ctx := &EncodingContext{
  1490. Buffer: util.NewBuffer(),
  1491. Table: nil,
  1492. }
  1493. e := target.MarshalBinaryWithContext(ctx)
  1494. if e != nil {
  1495. return nil, e
  1496. }
  1497. encBytes := ctx.Buffer.Bytes()
  1498. return encBytes, nil
  1499. }
  1500. // MarshalBinaryWithContext serializes the internal properties of this AllocationSetRange instance
  1501. // into a byte array leveraging a predefined context.
  1502. func (target *AllocationSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1503. // panics are recovered and propagated as errors
  1504. defer func() {
  1505. if r := recover(); r != nil {
  1506. if e, ok := r.(error); ok {
  1507. err = e
  1508. } else if s, ok := r.(string); ok {
  1509. err = fmt.Errorf("Unexpected panic: %s", s)
  1510. } else {
  1511. err = fmt.Errorf("Unexpected panic: %+v", r)
  1512. }
  1513. }
  1514. }()
  1515. buff := ctx.Buffer
  1516. buff.WriteUInt8(AllocationCodecVersion) // version
  1517. if target.Allocations == nil {
  1518. buff.WriteUInt8(uint8(0)) // write nil byte
  1519. } else {
  1520. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1521. // --- [begin][write][slice]([]*AllocationSet) ---
  1522. buff.WriteInt(len(target.Allocations)) // array length
  1523. for i := 0; i < len(target.Allocations); i++ {
  1524. if target.Allocations[i] == nil {
  1525. buff.WriteUInt8(uint8(0)) // write nil byte
  1526. } else {
  1527. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1528. // --- [begin][write][struct](AllocationSet) ---
  1529. buff.WriteInt(0) // [compatibility, unused]
  1530. errA := target.Allocations[i].MarshalBinaryWithContext(ctx)
  1531. if errA != nil {
  1532. return errA
  1533. }
  1534. // --- [end][write][struct](AllocationSet) ---
  1535. }
  1536. }
  1537. // --- [end][write][slice]([]*AllocationSet) ---
  1538. }
  1539. if ctx.IsStringTable() {
  1540. a := ctx.Table.AddOrGet(target.FromStore)
  1541. buff.WriteInt(a) // write table index
  1542. } else {
  1543. buff.WriteString(target.FromStore) // write string
  1544. }
  1545. return nil
  1546. }
  1547. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1548. // the AllocationSetRange type
  1549. func (target *AllocationSetRange) UnmarshalBinary(data []byte) error {
  1550. var table []string
  1551. buff := util.NewBufferFromBytes(data)
  1552. // string table header validation
  1553. if isBinaryTag(data, BinaryTagStringTable) {
  1554. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1555. tl := buff.ReadInt() // table length
  1556. if tl > 0 {
  1557. table = make([]string, tl, tl)
  1558. for i := 0; i < tl; i++ {
  1559. table[i] = buff.ReadString()
  1560. }
  1561. }
  1562. }
  1563. ctx := &DecodingContext{
  1564. Buffer: buff,
  1565. Table: table,
  1566. }
  1567. err := target.UnmarshalBinaryWithContext(ctx)
  1568. if err != nil {
  1569. return err
  1570. }
  1571. return nil
  1572. }
  1573. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1574. // the AllocationSetRange type
  1575. func (target *AllocationSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1576. // panics are recovered and propagated as errors
  1577. defer func() {
  1578. if r := recover(); r != nil {
  1579. if e, ok := r.(error); ok {
  1580. err = e
  1581. } else if s, ok := r.(string); ok {
  1582. err = fmt.Errorf("Unexpected panic: %s", s)
  1583. } else {
  1584. err = fmt.Errorf("Unexpected panic: %+v", r)
  1585. }
  1586. }
  1587. }()
  1588. buff := ctx.Buffer
  1589. version := buff.ReadUInt8()
  1590. if version > AllocationCodecVersion {
  1591. return fmt.Errorf("Invalid Version Unmarshaling AllocationSetRange. Expected %d or less, got %d", AllocationCodecVersion, version)
  1592. }
  1593. if buff.ReadUInt8() == uint8(0) {
  1594. target.Allocations = nil
  1595. } else {
  1596. // --- [begin][read][slice]([]*AllocationSet) ---
  1597. b := buff.ReadInt() // array len
  1598. a := make([]*AllocationSet, b)
  1599. for i := 0; i < b; i++ {
  1600. var c *AllocationSet
  1601. if buff.ReadUInt8() == uint8(0) {
  1602. c = nil
  1603. } else {
  1604. // --- [begin][read][struct](AllocationSet) ---
  1605. d := &AllocationSet{}
  1606. buff.ReadInt() // [compatibility, unused]
  1607. errA := d.UnmarshalBinaryWithContext(ctx)
  1608. if errA != nil {
  1609. return errA
  1610. }
  1611. c = d
  1612. // --- [end][read][struct](AllocationSet) ---
  1613. }
  1614. a[i] = c
  1615. }
  1616. target.Allocations = a
  1617. // --- [end][read][slice]([]*AllocationSet) ---
  1618. }
  1619. var f string
  1620. if ctx.IsStringTable() {
  1621. g := buff.ReadInt() // read string index
  1622. f = ctx.Table[g]
  1623. } else {
  1624. f = buff.ReadString() // read string
  1625. }
  1626. e := f
  1627. target.FromStore = e
  1628. return nil
  1629. }
  1630. //--------------------------------------------------------------------------
  1631. // Any
  1632. //--------------------------------------------------------------------------
  1633. // MarshalBinary serializes the internal properties of this Any instance
  1634. // into a byte array
  1635. func (target *Any) MarshalBinary() (data []byte, err error) {
  1636. ctx := &EncodingContext{
  1637. Buffer: util.NewBuffer(),
  1638. Table: nil,
  1639. }
  1640. e := target.MarshalBinaryWithContext(ctx)
  1641. if e != nil {
  1642. return nil, e
  1643. }
  1644. encBytes := ctx.Buffer.Bytes()
  1645. return encBytes, nil
  1646. }
  1647. // MarshalBinaryWithContext serializes the internal properties of this Any instance
  1648. // into a byte array leveraging a predefined context.
  1649. func (target *Any) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1650. // panics are recovered and propagated as errors
  1651. defer func() {
  1652. if r := recover(); r != nil {
  1653. if e, ok := r.(error); ok {
  1654. err = e
  1655. } else if s, ok := r.(string); ok {
  1656. err = fmt.Errorf("Unexpected panic: %s", s)
  1657. } else {
  1658. err = fmt.Errorf("Unexpected panic: %+v", r)
  1659. }
  1660. }
  1661. }()
  1662. buff := ctx.Buffer
  1663. buff.WriteUInt8(AssetsCodecVersion) // version
  1664. // --- [begin][write][alias](AssetLabels) ---
  1665. if map[string]string(target.Labels) == nil {
  1666. buff.WriteUInt8(uint8(0)) // write nil byte
  1667. } else {
  1668. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1669. // --- [begin][write][map](map[string]string) ---
  1670. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  1671. for v, z := range map[string]string(target.Labels) {
  1672. if ctx.IsStringTable() {
  1673. a := ctx.Table.AddOrGet(v)
  1674. buff.WriteInt(a) // write table index
  1675. } else {
  1676. buff.WriteString(v) // write string
  1677. }
  1678. if ctx.IsStringTable() {
  1679. b := ctx.Table.AddOrGet(z)
  1680. buff.WriteInt(b) // write table index
  1681. } else {
  1682. buff.WriteString(z) // write string
  1683. }
  1684. }
  1685. // --- [end][write][map](map[string]string) ---
  1686. }
  1687. // --- [end][write][alias](AssetLabels) ---
  1688. if target.Properties == nil {
  1689. buff.WriteUInt8(uint8(0)) // write nil byte
  1690. } else {
  1691. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1692. // --- [begin][write][struct](AssetProperties) ---
  1693. buff.WriteInt(0) // [compatibility, unused]
  1694. errA := target.Properties.MarshalBinaryWithContext(ctx)
  1695. if errA != nil {
  1696. return errA
  1697. }
  1698. // --- [end][write][struct](AssetProperties) ---
  1699. }
  1700. // --- [begin][write][reference](time.Time) ---
  1701. c, errB := target.Start.MarshalBinary()
  1702. if errB != nil {
  1703. return errB
  1704. }
  1705. buff.WriteInt(len(c))
  1706. buff.WriteBytes(c)
  1707. // --- [end][write][reference](time.Time) ---
  1708. // --- [begin][write][reference](time.Time) ---
  1709. d, errC := target.End.MarshalBinary()
  1710. if errC != nil {
  1711. return errC
  1712. }
  1713. buff.WriteInt(len(d))
  1714. buff.WriteBytes(d)
  1715. // --- [end][write][reference](time.Time) ---
  1716. // --- [begin][write][struct](Window) ---
  1717. buff.WriteInt(0) // [compatibility, unused]
  1718. errD := target.Window.MarshalBinaryWithContext(ctx)
  1719. if errD != nil {
  1720. return errD
  1721. }
  1722. // --- [end][write][struct](Window) ---
  1723. buff.WriteFloat64(target.Adjustment) // write float64
  1724. buff.WriteFloat64(target.Cost) // write float64
  1725. return nil
  1726. }
  1727. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1728. // the Any type
  1729. func (target *Any) UnmarshalBinary(data []byte) error {
  1730. var table []string
  1731. buff := util.NewBufferFromBytes(data)
  1732. // string table header validation
  1733. if isBinaryTag(data, BinaryTagStringTable) {
  1734. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1735. tl := buff.ReadInt() // table length
  1736. if tl > 0 {
  1737. table = make([]string, tl, tl)
  1738. for i := 0; i < tl; i++ {
  1739. table[i] = buff.ReadString()
  1740. }
  1741. }
  1742. }
  1743. ctx := &DecodingContext{
  1744. Buffer: buff,
  1745. Table: table,
  1746. }
  1747. err := target.UnmarshalBinaryWithContext(ctx)
  1748. if err != nil {
  1749. return err
  1750. }
  1751. return nil
  1752. }
  1753. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1754. // the Any type
  1755. func (target *Any) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1756. // panics are recovered and propagated as errors
  1757. defer func() {
  1758. if r := recover(); r != nil {
  1759. if e, ok := r.(error); ok {
  1760. err = e
  1761. } else if s, ok := r.(string); ok {
  1762. err = fmt.Errorf("Unexpected panic: %s", s)
  1763. } else {
  1764. err = fmt.Errorf("Unexpected panic: %+v", r)
  1765. }
  1766. }
  1767. }()
  1768. buff := ctx.Buffer
  1769. version := buff.ReadUInt8()
  1770. if version > AssetsCodecVersion {
  1771. return fmt.Errorf("Invalid Version Unmarshaling Any. Expected %d or less, got %d", AssetsCodecVersion, version)
  1772. }
  1773. // --- [begin][read][alias](AssetLabels) ---
  1774. var a map[string]string
  1775. if buff.ReadUInt8() == uint8(0) {
  1776. a = nil
  1777. } else {
  1778. // --- [begin][read][map](map[string]string) ---
  1779. c := buff.ReadInt() // map len
  1780. b := make(map[string]string, c)
  1781. for i := 0; i < c; i++ {
  1782. var v string
  1783. var e string
  1784. if ctx.IsStringTable() {
  1785. f := buff.ReadInt() // read string index
  1786. e = ctx.Table[f]
  1787. } else {
  1788. e = buff.ReadString() // read string
  1789. }
  1790. d := e
  1791. v = d
  1792. var z string
  1793. var h string
  1794. if ctx.IsStringTable() {
  1795. k := buff.ReadInt() // read string index
  1796. h = ctx.Table[k]
  1797. } else {
  1798. h = buff.ReadString() // read string
  1799. }
  1800. g := h
  1801. z = g
  1802. b[v] = z
  1803. }
  1804. a = b
  1805. // --- [end][read][map](map[string]string) ---
  1806. }
  1807. target.Labels = AssetLabels(a)
  1808. // --- [end][read][alias](AssetLabels) ---
  1809. if buff.ReadUInt8() == uint8(0) {
  1810. target.Properties = nil
  1811. } else {
  1812. // --- [begin][read][struct](AssetProperties) ---
  1813. l := &AssetProperties{}
  1814. buff.ReadInt() // [compatibility, unused]
  1815. errA := l.UnmarshalBinaryWithContext(ctx)
  1816. if errA != nil {
  1817. return errA
  1818. }
  1819. target.Properties = l
  1820. // --- [end][read][struct](AssetProperties) ---
  1821. }
  1822. // --- [begin][read][reference](time.Time) ---
  1823. m := &time.Time{}
  1824. n := buff.ReadInt() // byte array length
  1825. o := buff.ReadBytes(n) // byte array
  1826. errB := m.UnmarshalBinary(o)
  1827. if errB != nil {
  1828. return errB
  1829. }
  1830. target.Start = *m
  1831. // --- [end][read][reference](time.Time) ---
  1832. // --- [begin][read][reference](time.Time) ---
  1833. p := &time.Time{}
  1834. q := buff.ReadInt() // byte array length
  1835. r := buff.ReadBytes(q) // byte array
  1836. errC := p.UnmarshalBinary(r)
  1837. if errC != nil {
  1838. return errC
  1839. }
  1840. target.End = *p
  1841. // --- [end][read][reference](time.Time) ---
  1842. // --- [begin][read][struct](Window) ---
  1843. s := &Window{}
  1844. buff.ReadInt() // [compatibility, unused]
  1845. errD := s.UnmarshalBinaryWithContext(ctx)
  1846. if errD != nil {
  1847. return errD
  1848. }
  1849. target.Window = *s
  1850. // --- [end][read][struct](Window) ---
  1851. t := buff.ReadFloat64() // read float64
  1852. target.Adjustment = t
  1853. u := buff.ReadFloat64() // read float64
  1854. target.Cost = u
  1855. return nil
  1856. }
  1857. //--------------------------------------------------------------------------
  1858. // AssetProperties
  1859. //--------------------------------------------------------------------------
  1860. // MarshalBinary serializes the internal properties of this AssetProperties instance
  1861. // into a byte array
  1862. func (target *AssetProperties) MarshalBinary() (data []byte, err error) {
  1863. ctx := &EncodingContext{
  1864. Buffer: util.NewBuffer(),
  1865. Table: nil,
  1866. }
  1867. e := target.MarshalBinaryWithContext(ctx)
  1868. if e != nil {
  1869. return nil, e
  1870. }
  1871. encBytes := ctx.Buffer.Bytes()
  1872. return encBytes, nil
  1873. }
  1874. // MarshalBinaryWithContext serializes the internal properties of this AssetProperties instance
  1875. // into a byte array leveraging a predefined context.
  1876. func (target *AssetProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1877. // panics are recovered and propagated as errors
  1878. defer func() {
  1879. if r := recover(); r != nil {
  1880. if e, ok := r.(error); ok {
  1881. err = e
  1882. } else if s, ok := r.(string); ok {
  1883. err = fmt.Errorf("Unexpected panic: %s", s)
  1884. } else {
  1885. err = fmt.Errorf("Unexpected panic: %+v", r)
  1886. }
  1887. }
  1888. }()
  1889. buff := ctx.Buffer
  1890. buff.WriteUInt8(AssetsCodecVersion) // version
  1891. if ctx.IsStringTable() {
  1892. a := ctx.Table.AddOrGet(target.Category)
  1893. buff.WriteInt(a) // write table index
  1894. } else {
  1895. buff.WriteString(target.Category) // write string
  1896. }
  1897. if ctx.IsStringTable() {
  1898. b := ctx.Table.AddOrGet(target.Provider)
  1899. buff.WriteInt(b) // write table index
  1900. } else {
  1901. buff.WriteString(target.Provider) // write string
  1902. }
  1903. if ctx.IsStringTable() {
  1904. c := ctx.Table.AddOrGet(target.Account)
  1905. buff.WriteInt(c) // write table index
  1906. } else {
  1907. buff.WriteString(target.Account) // write string
  1908. }
  1909. if ctx.IsStringTable() {
  1910. d := ctx.Table.AddOrGet(target.Project)
  1911. buff.WriteInt(d) // write table index
  1912. } else {
  1913. buff.WriteString(target.Project) // write string
  1914. }
  1915. if ctx.IsStringTable() {
  1916. e := ctx.Table.AddOrGet(target.Service)
  1917. buff.WriteInt(e) // write table index
  1918. } else {
  1919. buff.WriteString(target.Service) // write string
  1920. }
  1921. if ctx.IsStringTable() {
  1922. f := ctx.Table.AddOrGet(target.Cluster)
  1923. buff.WriteInt(f) // write table index
  1924. } else {
  1925. buff.WriteString(target.Cluster) // write string
  1926. }
  1927. if ctx.IsStringTable() {
  1928. g := ctx.Table.AddOrGet(target.Name)
  1929. buff.WriteInt(g) // write table index
  1930. } else {
  1931. buff.WriteString(target.Name) // write string
  1932. }
  1933. if ctx.IsStringTable() {
  1934. h := ctx.Table.AddOrGet(target.ProviderID)
  1935. buff.WriteInt(h) // write table index
  1936. } else {
  1937. buff.WriteString(target.ProviderID) // write string
  1938. }
  1939. return nil
  1940. }
  1941. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1942. // the AssetProperties type
  1943. func (target *AssetProperties) UnmarshalBinary(data []byte) error {
  1944. var table []string
  1945. buff := util.NewBufferFromBytes(data)
  1946. // string table header validation
  1947. if isBinaryTag(data, BinaryTagStringTable) {
  1948. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1949. tl := buff.ReadInt() // table length
  1950. if tl > 0 {
  1951. table = make([]string, tl, tl)
  1952. for i := 0; i < tl; i++ {
  1953. table[i] = buff.ReadString()
  1954. }
  1955. }
  1956. }
  1957. ctx := &DecodingContext{
  1958. Buffer: buff,
  1959. Table: table,
  1960. }
  1961. err := target.UnmarshalBinaryWithContext(ctx)
  1962. if err != nil {
  1963. return err
  1964. }
  1965. return nil
  1966. }
  1967. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1968. // the AssetProperties type
  1969. func (target *AssetProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1970. // panics are recovered and propagated as errors
  1971. defer func() {
  1972. if r := recover(); r != nil {
  1973. if e, ok := r.(error); ok {
  1974. err = e
  1975. } else if s, ok := r.(string); ok {
  1976. err = fmt.Errorf("Unexpected panic: %s", s)
  1977. } else {
  1978. err = fmt.Errorf("Unexpected panic: %+v", r)
  1979. }
  1980. }
  1981. }()
  1982. buff := ctx.Buffer
  1983. version := buff.ReadUInt8()
  1984. if version > AssetsCodecVersion {
  1985. return fmt.Errorf("Invalid Version Unmarshaling AssetProperties. Expected %d or less, got %d", AssetsCodecVersion, version)
  1986. }
  1987. var b string
  1988. if ctx.IsStringTable() {
  1989. c := buff.ReadInt() // read string index
  1990. b = ctx.Table[c]
  1991. } else {
  1992. b = buff.ReadString() // read string
  1993. }
  1994. a := b
  1995. target.Category = a
  1996. var e string
  1997. if ctx.IsStringTable() {
  1998. f := buff.ReadInt() // read string index
  1999. e = ctx.Table[f]
  2000. } else {
  2001. e = buff.ReadString() // read string
  2002. }
  2003. d := e
  2004. target.Provider = d
  2005. var h string
  2006. if ctx.IsStringTable() {
  2007. k := buff.ReadInt() // read string index
  2008. h = ctx.Table[k]
  2009. } else {
  2010. h = buff.ReadString() // read string
  2011. }
  2012. g := h
  2013. target.Account = g
  2014. var m string
  2015. if ctx.IsStringTable() {
  2016. n := buff.ReadInt() // read string index
  2017. m = ctx.Table[n]
  2018. } else {
  2019. m = buff.ReadString() // read string
  2020. }
  2021. l := m
  2022. target.Project = l
  2023. var p string
  2024. if ctx.IsStringTable() {
  2025. q := buff.ReadInt() // read string index
  2026. p = ctx.Table[q]
  2027. } else {
  2028. p = buff.ReadString() // read string
  2029. }
  2030. o := p
  2031. target.Service = o
  2032. var s string
  2033. if ctx.IsStringTable() {
  2034. t := buff.ReadInt() // read string index
  2035. s = ctx.Table[t]
  2036. } else {
  2037. s = buff.ReadString() // read string
  2038. }
  2039. r := s
  2040. target.Cluster = r
  2041. var w string
  2042. if ctx.IsStringTable() {
  2043. x := buff.ReadInt() // read string index
  2044. w = ctx.Table[x]
  2045. } else {
  2046. w = buff.ReadString() // read string
  2047. }
  2048. u := w
  2049. target.Name = u
  2050. var aa string
  2051. if ctx.IsStringTable() {
  2052. bb := buff.ReadInt() // read string index
  2053. aa = ctx.Table[bb]
  2054. } else {
  2055. aa = buff.ReadString() // read string
  2056. }
  2057. y := aa
  2058. target.ProviderID = y
  2059. return nil
  2060. }
  2061. //--------------------------------------------------------------------------
  2062. // AssetSet
  2063. //--------------------------------------------------------------------------
  2064. // MarshalBinary serializes the internal properties of this AssetSet instance
  2065. // into a byte array
  2066. func (target *AssetSet) MarshalBinary() (data []byte, err error) {
  2067. ctx := &EncodingContext{
  2068. Buffer: util.NewBuffer(),
  2069. Table: NewStringTable(),
  2070. }
  2071. e := target.MarshalBinaryWithContext(ctx)
  2072. if e != nil {
  2073. return nil, e
  2074. }
  2075. encBytes := ctx.Buffer.Bytes()
  2076. sTableBytes := ctx.Table.ToBytes()
  2077. merged := appendBytes(sTableBytes, encBytes)
  2078. return merged, nil
  2079. }
  2080. // MarshalBinaryWithContext serializes the internal properties of this AssetSet instance
  2081. // into a byte array leveraging a predefined context.
  2082. func (target *AssetSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2083. // panics are recovered and propagated as errors
  2084. defer func() {
  2085. if r := recover(); r != nil {
  2086. if e, ok := r.(error); ok {
  2087. err = e
  2088. } else if s, ok := r.(string); ok {
  2089. err = fmt.Errorf("Unexpected panic: %s", s)
  2090. } else {
  2091. err = fmt.Errorf("Unexpected panic: %+v", r)
  2092. }
  2093. }
  2094. }()
  2095. buff := ctx.Buffer
  2096. buff.WriteUInt8(AssetsCodecVersion) // version
  2097. // execute pre-processing func
  2098. preProcessAssetSet(target)
  2099. if target.AggregationKeys == nil {
  2100. buff.WriteUInt8(uint8(0)) // write nil byte
  2101. } else {
  2102. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2103. // --- [begin][write][slice]([]string) ---
  2104. buff.WriteInt(len(target.AggregationKeys)) // array length
  2105. for i := 0; i < len(target.AggregationKeys); i++ {
  2106. if ctx.IsStringTable() {
  2107. a := ctx.Table.AddOrGet(target.AggregationKeys[i])
  2108. buff.WriteInt(a) // write table index
  2109. } else {
  2110. buff.WriteString(target.AggregationKeys[i]) // write string
  2111. }
  2112. }
  2113. // --- [end][write][slice]([]string) ---
  2114. }
  2115. if target.Assets == nil {
  2116. buff.WriteUInt8(uint8(0)) // write nil byte
  2117. } else {
  2118. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2119. // --- [begin][write][map](map[string]Asset) ---
  2120. buff.WriteInt(len(target.Assets)) // map length
  2121. for v, z := range target.Assets {
  2122. if ctx.IsStringTable() {
  2123. b := ctx.Table.AddOrGet(v)
  2124. buff.WriteInt(b) // write table index
  2125. } else {
  2126. buff.WriteString(v) // write string
  2127. }
  2128. if z == nil {
  2129. buff.WriteUInt8(uint8(0)) // write nil byte
  2130. } else {
  2131. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2132. // --- [begin][write][interface](Asset) ---
  2133. c := reflect.ValueOf(z).Interface()
  2134. d, okA := c.(BinEncoder)
  2135. if !okA {
  2136. return fmt.Errorf("Type: %s does not implement %s.BinEncoder", typeToString(z), GeneratorPackageName)
  2137. }
  2138. buff.WriteString(typeToString(z))
  2139. buff.WriteInt(0) // [compatibility, unused]
  2140. errA := d.MarshalBinaryWithContext(ctx)
  2141. if errA != nil {
  2142. return errA
  2143. }
  2144. // --- [end][write][interface](Asset) ---
  2145. }
  2146. }
  2147. // --- [end][write][map](map[string]Asset) ---
  2148. }
  2149. if ctx.IsStringTable() {
  2150. e := ctx.Table.AddOrGet(target.FromSource)
  2151. buff.WriteInt(e) // write table index
  2152. } else {
  2153. buff.WriteString(target.FromSource) // write string
  2154. }
  2155. // --- [begin][write][struct](Window) ---
  2156. buff.WriteInt(0) // [compatibility, unused]
  2157. errB := target.Window.MarshalBinaryWithContext(ctx)
  2158. if errB != nil {
  2159. return errB
  2160. }
  2161. // --- [end][write][struct](Window) ---
  2162. if target.Warnings == nil {
  2163. buff.WriteUInt8(uint8(0)) // write nil byte
  2164. } else {
  2165. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2166. // --- [begin][write][slice]([]string) ---
  2167. buff.WriteInt(len(target.Warnings)) // array length
  2168. for j := 0; j < len(target.Warnings); j++ {
  2169. if ctx.IsStringTable() {
  2170. f := ctx.Table.AddOrGet(target.Warnings[j])
  2171. buff.WriteInt(f) // write table index
  2172. } else {
  2173. buff.WriteString(target.Warnings[j]) // write string
  2174. }
  2175. }
  2176. // --- [end][write][slice]([]string) ---
  2177. }
  2178. if target.Errors == nil {
  2179. buff.WriteUInt8(uint8(0)) // write nil byte
  2180. } else {
  2181. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2182. // --- [begin][write][slice]([]string) ---
  2183. buff.WriteInt(len(target.Errors)) // array length
  2184. for ii := 0; ii < len(target.Errors); ii++ {
  2185. if ctx.IsStringTable() {
  2186. g := ctx.Table.AddOrGet(target.Errors[ii])
  2187. buff.WriteInt(g) // write table index
  2188. } else {
  2189. buff.WriteString(target.Errors[ii]) // write string
  2190. }
  2191. }
  2192. // --- [end][write][slice]([]string) ---
  2193. }
  2194. return nil
  2195. }
  2196. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2197. // the AssetSet type
  2198. func (target *AssetSet) UnmarshalBinary(data []byte) error {
  2199. var table []string
  2200. buff := util.NewBufferFromBytes(data)
  2201. // string table header validation
  2202. if isBinaryTag(data, BinaryTagStringTable) {
  2203. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2204. tl := buff.ReadInt() // table length
  2205. if tl > 0 {
  2206. table = make([]string, tl, tl)
  2207. for i := 0; i < tl; i++ {
  2208. table[i] = buff.ReadString()
  2209. }
  2210. }
  2211. }
  2212. ctx := &DecodingContext{
  2213. Buffer: buff,
  2214. Table: table,
  2215. }
  2216. err := target.UnmarshalBinaryWithContext(ctx)
  2217. if err != nil {
  2218. return err
  2219. }
  2220. return nil
  2221. }
  2222. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2223. // the AssetSet type
  2224. func (target *AssetSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2225. // panics are recovered and propagated as errors
  2226. defer func() {
  2227. if r := recover(); r != nil {
  2228. if e, ok := r.(error); ok {
  2229. err = e
  2230. } else if s, ok := r.(string); ok {
  2231. err = fmt.Errorf("Unexpected panic: %s", s)
  2232. } else {
  2233. err = fmt.Errorf("Unexpected panic: %+v", r)
  2234. }
  2235. }
  2236. }()
  2237. buff := ctx.Buffer
  2238. version := buff.ReadUInt8()
  2239. if version > AssetsCodecVersion {
  2240. return fmt.Errorf("Invalid Version Unmarshaling AssetSet. Expected %d or less, got %d", AssetsCodecVersion, version)
  2241. }
  2242. if buff.ReadUInt8() == uint8(0) {
  2243. target.AggregationKeys = nil
  2244. } else {
  2245. // --- [begin][read][slice]([]string) ---
  2246. b := buff.ReadInt() // array len
  2247. a := make([]string, b)
  2248. for i := 0; i < b; i++ {
  2249. var c string
  2250. var e string
  2251. if ctx.IsStringTable() {
  2252. f := buff.ReadInt() // read string index
  2253. e = ctx.Table[f]
  2254. } else {
  2255. e = buff.ReadString() // read string
  2256. }
  2257. d := e
  2258. c = d
  2259. a[i] = c
  2260. }
  2261. target.AggregationKeys = a
  2262. // --- [end][read][slice]([]string) ---
  2263. }
  2264. if buff.ReadUInt8() == uint8(0) {
  2265. target.Assets = nil
  2266. } else {
  2267. // --- [begin][read][map](map[string]Asset) ---
  2268. h := buff.ReadInt() // map len
  2269. g := make(map[string]Asset, h)
  2270. for j := 0; j < h; j++ {
  2271. var v string
  2272. var l string
  2273. if ctx.IsStringTable() {
  2274. m := buff.ReadInt() // read string index
  2275. l = ctx.Table[m]
  2276. } else {
  2277. l = buff.ReadString() // read string
  2278. }
  2279. k := l
  2280. v = k
  2281. var z Asset
  2282. if buff.ReadUInt8() == uint8(0) {
  2283. z = nil
  2284. } else {
  2285. // --- [begin][read][interface](Asset) ---
  2286. n := buff.ReadString()
  2287. _, o, _ := resolveType(n)
  2288. if _, ok := typeMap[o]; !ok {
  2289. return fmt.Errorf("Unknown Type: %s", o)
  2290. }
  2291. p, okA := reflect.New(typeMap[o]).Interface().(BinDecoder)
  2292. if !okA {
  2293. return fmt.Errorf("Type: %s does not implement %s.BinDecoder.", o, GeneratorPackageName)
  2294. }
  2295. buff.ReadInt() // [compatibility, unused]
  2296. errA := p.UnmarshalBinaryWithContext(ctx)
  2297. if errA != nil {
  2298. return errA
  2299. }
  2300. z = p.(Asset)
  2301. // --- [end][read][interface](Asset) ---
  2302. }
  2303. g[v] = z
  2304. }
  2305. target.Assets = g
  2306. // --- [end][read][map](map[string]Asset) ---
  2307. }
  2308. var r string
  2309. if ctx.IsStringTable() {
  2310. s := buff.ReadInt() // read string index
  2311. r = ctx.Table[s]
  2312. } else {
  2313. r = buff.ReadString() // read string
  2314. }
  2315. q := r
  2316. target.FromSource = q
  2317. // --- [begin][read][struct](Window) ---
  2318. t := &Window{}
  2319. buff.ReadInt() // [compatibility, unused]
  2320. errB := t.UnmarshalBinaryWithContext(ctx)
  2321. if errB != nil {
  2322. return errB
  2323. }
  2324. target.Window = *t
  2325. // --- [end][read][struct](Window) ---
  2326. if buff.ReadUInt8() == uint8(0) {
  2327. target.Warnings = nil
  2328. } else {
  2329. // --- [begin][read][slice]([]string) ---
  2330. w := buff.ReadInt() // array len
  2331. u := make([]string, w)
  2332. for ii := 0; ii < w; ii++ {
  2333. var x string
  2334. var aa string
  2335. if ctx.IsStringTable() {
  2336. bb := buff.ReadInt() // read string index
  2337. aa = ctx.Table[bb]
  2338. } else {
  2339. aa = buff.ReadString() // read string
  2340. }
  2341. y := aa
  2342. x = y
  2343. u[ii] = x
  2344. }
  2345. target.Warnings = u
  2346. // --- [end][read][slice]([]string) ---
  2347. }
  2348. if buff.ReadUInt8() == uint8(0) {
  2349. target.Errors = nil
  2350. } else {
  2351. // --- [begin][read][slice]([]string) ---
  2352. dd := buff.ReadInt() // array len
  2353. cc := make([]string, dd)
  2354. for jj := 0; jj < dd; jj++ {
  2355. var ee string
  2356. var gg string
  2357. if ctx.IsStringTable() {
  2358. hh := buff.ReadInt() // read string index
  2359. gg = ctx.Table[hh]
  2360. } else {
  2361. gg = buff.ReadString() // read string
  2362. }
  2363. ff := gg
  2364. ee = ff
  2365. cc[jj] = ee
  2366. }
  2367. target.Errors = cc
  2368. // --- [end][read][slice]([]string) ---
  2369. }
  2370. // execute post-processing func
  2371. postProcessAssetSet(target)
  2372. return nil
  2373. }
  2374. //--------------------------------------------------------------------------
  2375. // AssetSetRange
  2376. //--------------------------------------------------------------------------
  2377. // MarshalBinary serializes the internal properties of this AssetSetRange instance
  2378. // into a byte array
  2379. func (target *AssetSetRange) MarshalBinary() (data []byte, err error) {
  2380. ctx := &EncodingContext{
  2381. Buffer: util.NewBuffer(),
  2382. Table: nil,
  2383. }
  2384. e := target.MarshalBinaryWithContext(ctx)
  2385. if e != nil {
  2386. return nil, e
  2387. }
  2388. encBytes := ctx.Buffer.Bytes()
  2389. return encBytes, nil
  2390. }
  2391. // MarshalBinaryWithContext serializes the internal properties of this AssetSetRange instance
  2392. // into a byte array leveraging a predefined context.
  2393. func (target *AssetSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2394. // panics are recovered and propagated as errors
  2395. defer func() {
  2396. if r := recover(); r != nil {
  2397. if e, ok := r.(error); ok {
  2398. err = e
  2399. } else if s, ok := r.(string); ok {
  2400. err = fmt.Errorf("Unexpected panic: %s", s)
  2401. } else {
  2402. err = fmt.Errorf("Unexpected panic: %+v", r)
  2403. }
  2404. }
  2405. }()
  2406. buff := ctx.Buffer
  2407. buff.WriteUInt8(AssetsCodecVersion) // version
  2408. if target.Assets == nil {
  2409. buff.WriteUInt8(uint8(0)) // write nil byte
  2410. } else {
  2411. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2412. // --- [begin][write][slice]([]*AssetSet) ---
  2413. buff.WriteInt(len(target.Assets)) // array length
  2414. for i := 0; i < len(target.Assets); i++ {
  2415. if target.Assets[i] == nil {
  2416. buff.WriteUInt8(uint8(0)) // write nil byte
  2417. } else {
  2418. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2419. // --- [begin][write][struct](AssetSet) ---
  2420. buff.WriteInt(0) // [compatibility, unused]
  2421. errA := target.Assets[i].MarshalBinaryWithContext(ctx)
  2422. if errA != nil {
  2423. return errA
  2424. }
  2425. // --- [end][write][struct](AssetSet) ---
  2426. }
  2427. }
  2428. // --- [end][write][slice]([]*AssetSet) ---
  2429. }
  2430. if ctx.IsStringTable() {
  2431. a := ctx.Table.AddOrGet(target.FromStore)
  2432. buff.WriteInt(a) // write table index
  2433. } else {
  2434. buff.WriteString(target.FromStore) // write string
  2435. }
  2436. return nil
  2437. }
  2438. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2439. // the AssetSetRange type
  2440. func (target *AssetSetRange) UnmarshalBinary(data []byte) error {
  2441. var table []string
  2442. buff := util.NewBufferFromBytes(data)
  2443. // string table header validation
  2444. if isBinaryTag(data, BinaryTagStringTable) {
  2445. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2446. tl := buff.ReadInt() // table length
  2447. if tl > 0 {
  2448. table = make([]string, tl, tl)
  2449. for i := 0; i < tl; i++ {
  2450. table[i] = buff.ReadString()
  2451. }
  2452. }
  2453. }
  2454. ctx := &DecodingContext{
  2455. Buffer: buff,
  2456. Table: table,
  2457. }
  2458. err := target.UnmarshalBinaryWithContext(ctx)
  2459. if err != nil {
  2460. return err
  2461. }
  2462. return nil
  2463. }
  2464. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2465. // the AssetSetRange type
  2466. func (target *AssetSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2467. // panics are recovered and propagated as errors
  2468. defer func() {
  2469. if r := recover(); r != nil {
  2470. if e, ok := r.(error); ok {
  2471. err = e
  2472. } else if s, ok := r.(string); ok {
  2473. err = fmt.Errorf("Unexpected panic: %s", s)
  2474. } else {
  2475. err = fmt.Errorf("Unexpected panic: %+v", r)
  2476. }
  2477. }
  2478. }()
  2479. buff := ctx.Buffer
  2480. version := buff.ReadUInt8()
  2481. if version > AssetsCodecVersion {
  2482. return fmt.Errorf("Invalid Version Unmarshaling AssetSetRange. Expected %d or less, got %d", AssetsCodecVersion, version)
  2483. }
  2484. if buff.ReadUInt8() == uint8(0) {
  2485. target.Assets = nil
  2486. } else {
  2487. // --- [begin][read][slice]([]*AssetSet) ---
  2488. b := buff.ReadInt() // array len
  2489. a := make([]*AssetSet, b)
  2490. for i := 0; i < b; i++ {
  2491. var c *AssetSet
  2492. if buff.ReadUInt8() == uint8(0) {
  2493. c = nil
  2494. } else {
  2495. // --- [begin][read][struct](AssetSet) ---
  2496. d := &AssetSet{}
  2497. buff.ReadInt() // [compatibility, unused]
  2498. errA := d.UnmarshalBinaryWithContext(ctx)
  2499. if errA != nil {
  2500. return errA
  2501. }
  2502. c = d
  2503. // --- [end][read][struct](AssetSet) ---
  2504. }
  2505. a[i] = c
  2506. }
  2507. target.Assets = a
  2508. // --- [end][read][slice]([]*AssetSet) ---
  2509. }
  2510. var f string
  2511. if ctx.IsStringTable() {
  2512. g := buff.ReadInt() // read string index
  2513. f = ctx.Table[g]
  2514. } else {
  2515. f = buff.ReadString() // read string
  2516. }
  2517. e := f
  2518. target.FromStore = e
  2519. return nil
  2520. }
  2521. //--------------------------------------------------------------------------
  2522. // Breakdown
  2523. //--------------------------------------------------------------------------
  2524. // MarshalBinary serializes the internal properties of this Breakdown instance
  2525. // into a byte array
  2526. func (target *Breakdown) MarshalBinary() (data []byte, err error) {
  2527. ctx := &EncodingContext{
  2528. Buffer: util.NewBuffer(),
  2529. Table: nil,
  2530. }
  2531. e := target.MarshalBinaryWithContext(ctx)
  2532. if e != nil {
  2533. return nil, e
  2534. }
  2535. encBytes := ctx.Buffer.Bytes()
  2536. return encBytes, nil
  2537. }
  2538. // MarshalBinaryWithContext serializes the internal properties of this Breakdown instance
  2539. // into a byte array leveraging a predefined context.
  2540. func (target *Breakdown) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2541. // panics are recovered and propagated as errors
  2542. defer func() {
  2543. if r := recover(); r != nil {
  2544. if e, ok := r.(error); ok {
  2545. err = e
  2546. } else if s, ok := r.(string); ok {
  2547. err = fmt.Errorf("Unexpected panic: %s", s)
  2548. } else {
  2549. err = fmt.Errorf("Unexpected panic: %+v", r)
  2550. }
  2551. }
  2552. }()
  2553. buff := ctx.Buffer
  2554. buff.WriteUInt8(AssetsCodecVersion) // version
  2555. buff.WriteFloat64(target.Idle) // write float64
  2556. buff.WriteFloat64(target.Other) // write float64
  2557. buff.WriteFloat64(target.System) // write float64
  2558. buff.WriteFloat64(target.User) // write float64
  2559. return nil
  2560. }
  2561. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2562. // the Breakdown type
  2563. func (target *Breakdown) UnmarshalBinary(data []byte) error {
  2564. var table []string
  2565. buff := util.NewBufferFromBytes(data)
  2566. // string table header validation
  2567. if isBinaryTag(data, BinaryTagStringTable) {
  2568. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2569. tl := buff.ReadInt() // table length
  2570. if tl > 0 {
  2571. table = make([]string, tl, tl)
  2572. for i := 0; i < tl; i++ {
  2573. table[i] = buff.ReadString()
  2574. }
  2575. }
  2576. }
  2577. ctx := &DecodingContext{
  2578. Buffer: buff,
  2579. Table: table,
  2580. }
  2581. err := target.UnmarshalBinaryWithContext(ctx)
  2582. if err != nil {
  2583. return err
  2584. }
  2585. return nil
  2586. }
  2587. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2588. // the Breakdown type
  2589. func (target *Breakdown) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2590. // panics are recovered and propagated as errors
  2591. defer func() {
  2592. if r := recover(); r != nil {
  2593. if e, ok := r.(error); ok {
  2594. err = e
  2595. } else if s, ok := r.(string); ok {
  2596. err = fmt.Errorf("Unexpected panic: %s", s)
  2597. } else {
  2598. err = fmt.Errorf("Unexpected panic: %+v", r)
  2599. }
  2600. }
  2601. }()
  2602. buff := ctx.Buffer
  2603. version := buff.ReadUInt8()
  2604. if version > AssetsCodecVersion {
  2605. return fmt.Errorf("Invalid Version Unmarshaling Breakdown. Expected %d or less, got %d", AssetsCodecVersion, version)
  2606. }
  2607. a := buff.ReadFloat64() // read float64
  2608. target.Idle = a
  2609. b := buff.ReadFloat64() // read float64
  2610. target.Other = b
  2611. c := buff.ReadFloat64() // read float64
  2612. target.System = c
  2613. d := buff.ReadFloat64() // read float64
  2614. target.User = d
  2615. return nil
  2616. }
  2617. //--------------------------------------------------------------------------
  2618. // Cloud
  2619. //--------------------------------------------------------------------------
  2620. // MarshalBinary serializes the internal properties of this Cloud instance
  2621. // into a byte array
  2622. func (target *Cloud) MarshalBinary() (data []byte, err error) {
  2623. ctx := &EncodingContext{
  2624. Buffer: util.NewBuffer(),
  2625. Table: nil,
  2626. }
  2627. e := target.MarshalBinaryWithContext(ctx)
  2628. if e != nil {
  2629. return nil, e
  2630. }
  2631. encBytes := ctx.Buffer.Bytes()
  2632. return encBytes, nil
  2633. }
  2634. // MarshalBinaryWithContext serializes the internal properties of this Cloud instance
  2635. // into a byte array leveraging a predefined context.
  2636. func (target *Cloud) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2637. // panics are recovered and propagated as errors
  2638. defer func() {
  2639. if r := recover(); r != nil {
  2640. if e, ok := r.(error); ok {
  2641. err = e
  2642. } else if s, ok := r.(string); ok {
  2643. err = fmt.Errorf("Unexpected panic: %s", s)
  2644. } else {
  2645. err = fmt.Errorf("Unexpected panic: %+v", r)
  2646. }
  2647. }
  2648. }()
  2649. buff := ctx.Buffer
  2650. buff.WriteUInt8(AssetsCodecVersion) // version
  2651. // --- [begin][write][alias](AssetLabels) ---
  2652. if map[string]string(target.Labels) == nil {
  2653. buff.WriteUInt8(uint8(0)) // write nil byte
  2654. } else {
  2655. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2656. // --- [begin][write][map](map[string]string) ---
  2657. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  2658. for v, z := range map[string]string(target.Labels) {
  2659. if ctx.IsStringTable() {
  2660. a := ctx.Table.AddOrGet(v)
  2661. buff.WriteInt(a) // write table index
  2662. } else {
  2663. buff.WriteString(v) // write string
  2664. }
  2665. if ctx.IsStringTable() {
  2666. b := ctx.Table.AddOrGet(z)
  2667. buff.WriteInt(b) // write table index
  2668. } else {
  2669. buff.WriteString(z) // write string
  2670. }
  2671. }
  2672. // --- [end][write][map](map[string]string) ---
  2673. }
  2674. // --- [end][write][alias](AssetLabels) ---
  2675. if target.Properties == nil {
  2676. buff.WriteUInt8(uint8(0)) // write nil byte
  2677. } else {
  2678. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2679. // --- [begin][write][struct](AssetProperties) ---
  2680. buff.WriteInt(0) // [compatibility, unused]
  2681. errA := target.Properties.MarshalBinaryWithContext(ctx)
  2682. if errA != nil {
  2683. return errA
  2684. }
  2685. // --- [end][write][struct](AssetProperties) ---
  2686. }
  2687. // --- [begin][write][reference](time.Time) ---
  2688. c, errB := target.Start.MarshalBinary()
  2689. if errB != nil {
  2690. return errB
  2691. }
  2692. buff.WriteInt(len(c))
  2693. buff.WriteBytes(c)
  2694. // --- [end][write][reference](time.Time) ---
  2695. // --- [begin][write][reference](time.Time) ---
  2696. d, errC := target.End.MarshalBinary()
  2697. if errC != nil {
  2698. return errC
  2699. }
  2700. buff.WriteInt(len(d))
  2701. buff.WriteBytes(d)
  2702. // --- [end][write][reference](time.Time) ---
  2703. // --- [begin][write][struct](Window) ---
  2704. buff.WriteInt(0) // [compatibility, unused]
  2705. errD := target.Window.MarshalBinaryWithContext(ctx)
  2706. if errD != nil {
  2707. return errD
  2708. }
  2709. // --- [end][write][struct](Window) ---
  2710. buff.WriteFloat64(target.Adjustment) // write float64
  2711. buff.WriteFloat64(target.Cost) // write float64
  2712. buff.WriteFloat64(target.Credit) // write float64
  2713. return nil
  2714. }
  2715. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2716. // the Cloud type
  2717. func (target *Cloud) UnmarshalBinary(data []byte) error {
  2718. var table []string
  2719. buff := util.NewBufferFromBytes(data)
  2720. // string table header validation
  2721. if isBinaryTag(data, BinaryTagStringTable) {
  2722. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2723. tl := buff.ReadInt() // table length
  2724. if tl > 0 {
  2725. table = make([]string, tl, tl)
  2726. for i := 0; i < tl; i++ {
  2727. table[i] = buff.ReadString()
  2728. }
  2729. }
  2730. }
  2731. ctx := &DecodingContext{
  2732. Buffer: buff,
  2733. Table: table,
  2734. }
  2735. err := target.UnmarshalBinaryWithContext(ctx)
  2736. if err != nil {
  2737. return err
  2738. }
  2739. return nil
  2740. }
  2741. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2742. // the Cloud type
  2743. func (target *Cloud) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2744. // panics are recovered and propagated as errors
  2745. defer func() {
  2746. if r := recover(); r != nil {
  2747. if e, ok := r.(error); ok {
  2748. err = e
  2749. } else if s, ok := r.(string); ok {
  2750. err = fmt.Errorf("Unexpected panic: %s", s)
  2751. } else {
  2752. err = fmt.Errorf("Unexpected panic: %+v", r)
  2753. }
  2754. }
  2755. }()
  2756. buff := ctx.Buffer
  2757. version := buff.ReadUInt8()
  2758. if version > AssetsCodecVersion {
  2759. return fmt.Errorf("Invalid Version Unmarshaling Cloud. Expected %d or less, got %d", AssetsCodecVersion, version)
  2760. }
  2761. // --- [begin][read][alias](AssetLabels) ---
  2762. var a map[string]string
  2763. if buff.ReadUInt8() == uint8(0) {
  2764. a = nil
  2765. } else {
  2766. // --- [begin][read][map](map[string]string) ---
  2767. c := buff.ReadInt() // map len
  2768. b := make(map[string]string, c)
  2769. for i := 0; i < c; i++ {
  2770. var v string
  2771. var e string
  2772. if ctx.IsStringTable() {
  2773. f := buff.ReadInt() // read string index
  2774. e = ctx.Table[f]
  2775. } else {
  2776. e = buff.ReadString() // read string
  2777. }
  2778. d := e
  2779. v = d
  2780. var z string
  2781. var h string
  2782. if ctx.IsStringTable() {
  2783. k := buff.ReadInt() // read string index
  2784. h = ctx.Table[k]
  2785. } else {
  2786. h = buff.ReadString() // read string
  2787. }
  2788. g := h
  2789. z = g
  2790. b[v] = z
  2791. }
  2792. a = b
  2793. // --- [end][read][map](map[string]string) ---
  2794. }
  2795. target.Labels = AssetLabels(a)
  2796. // --- [end][read][alias](AssetLabels) ---
  2797. if buff.ReadUInt8() == uint8(0) {
  2798. target.Properties = nil
  2799. } else {
  2800. // --- [begin][read][struct](AssetProperties) ---
  2801. l := &AssetProperties{}
  2802. buff.ReadInt() // [compatibility, unused]
  2803. errA := l.UnmarshalBinaryWithContext(ctx)
  2804. if errA != nil {
  2805. return errA
  2806. }
  2807. target.Properties = l
  2808. // --- [end][read][struct](AssetProperties) ---
  2809. }
  2810. // --- [begin][read][reference](time.Time) ---
  2811. m := &time.Time{}
  2812. n := buff.ReadInt() // byte array length
  2813. o := buff.ReadBytes(n) // byte array
  2814. errB := m.UnmarshalBinary(o)
  2815. if errB != nil {
  2816. return errB
  2817. }
  2818. target.Start = *m
  2819. // --- [end][read][reference](time.Time) ---
  2820. // --- [begin][read][reference](time.Time) ---
  2821. p := &time.Time{}
  2822. q := buff.ReadInt() // byte array length
  2823. r := buff.ReadBytes(q) // byte array
  2824. errC := p.UnmarshalBinary(r)
  2825. if errC != nil {
  2826. return errC
  2827. }
  2828. target.End = *p
  2829. // --- [end][read][reference](time.Time) ---
  2830. // --- [begin][read][struct](Window) ---
  2831. s := &Window{}
  2832. buff.ReadInt() // [compatibility, unused]
  2833. errD := s.UnmarshalBinaryWithContext(ctx)
  2834. if errD != nil {
  2835. return errD
  2836. }
  2837. target.Window = *s
  2838. // --- [end][read][struct](Window) ---
  2839. t := buff.ReadFloat64() // read float64
  2840. target.Adjustment = t
  2841. u := buff.ReadFloat64() // read float64
  2842. target.Cost = u
  2843. w := buff.ReadFloat64() // read float64
  2844. target.Credit = w
  2845. return nil
  2846. }
  2847. //--------------------------------------------------------------------------
  2848. // CloudCost
  2849. //--------------------------------------------------------------------------
  2850. // MarshalBinary serializes the internal properties of this CloudCost instance
  2851. // into a byte array
  2852. func (target *CloudCost) MarshalBinary() (data []byte, err error) {
  2853. ctx := &EncodingContext{
  2854. Buffer: util.NewBuffer(),
  2855. Table: nil,
  2856. }
  2857. e := target.MarshalBinaryWithContext(ctx)
  2858. if e != nil {
  2859. return nil, e
  2860. }
  2861. encBytes := ctx.Buffer.Bytes()
  2862. return encBytes, nil
  2863. }
  2864. // MarshalBinaryWithContext serializes the internal properties of this CloudCost instance
  2865. // into a byte array leveraging a predefined context.
  2866. func (target *CloudCost) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2867. // panics are recovered and propagated as errors
  2868. defer func() {
  2869. if r := recover(); r != nil {
  2870. if e, ok := r.(error); ok {
  2871. err = e
  2872. } else if s, ok := r.(string); ok {
  2873. err = fmt.Errorf("Unexpected panic: %s", s)
  2874. } else {
  2875. err = fmt.Errorf("Unexpected panic: %+v", r)
  2876. }
  2877. }
  2878. }()
  2879. buff := ctx.Buffer
  2880. buff.WriteUInt8(CloudCostCodecVersion) // version
  2881. if target.Properties == nil {
  2882. buff.WriteUInt8(uint8(0)) // write nil byte
  2883. } else {
  2884. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2885. // --- [begin][write][struct](CloudCostProperties) ---
  2886. buff.WriteInt(0) // [compatibility, unused]
  2887. errA := target.Properties.MarshalBinaryWithContext(ctx)
  2888. if errA != nil {
  2889. return errA
  2890. }
  2891. // --- [end][write][struct](CloudCostProperties) ---
  2892. }
  2893. // --- [begin][write][struct](Window) ---
  2894. buff.WriteInt(0) // [compatibility, unused]
  2895. errB := target.Window.MarshalBinaryWithContext(ctx)
  2896. if errB != nil {
  2897. return errB
  2898. }
  2899. // --- [end][write][struct](Window) ---
  2900. // --- [begin][write][struct](CostMetric) ---
  2901. buff.WriteInt(0) // [compatibility, unused]
  2902. errC := target.ListCost.MarshalBinaryWithContext(ctx)
  2903. if errC != nil {
  2904. return errC
  2905. }
  2906. // --- [end][write][struct](CostMetric) ---
  2907. // --- [begin][write][struct](CostMetric) ---
  2908. buff.WriteInt(0) // [compatibility, unused]
  2909. errD := target.NetCost.MarshalBinaryWithContext(ctx)
  2910. if errD != nil {
  2911. return errD
  2912. }
  2913. // --- [end][write][struct](CostMetric) ---
  2914. // --- [begin][write][struct](CostMetric) ---
  2915. buff.WriteInt(0) // [compatibility, unused]
  2916. errE := target.AmortizedNetCost.MarshalBinaryWithContext(ctx)
  2917. if errE != nil {
  2918. return errE
  2919. }
  2920. // --- [end][write][struct](CostMetric) ---
  2921. // --- [begin][write][struct](CostMetric) ---
  2922. buff.WriteInt(0) // [compatibility, unused]
  2923. errF := target.InvoicedCost.MarshalBinaryWithContext(ctx)
  2924. if errF != nil {
  2925. return errF
  2926. }
  2927. // --- [end][write][struct](CostMetric) ---
  2928. // --- [begin][write][struct](CostMetric) ---
  2929. buff.WriteInt(0) // [compatibility, unused]
  2930. errG := target.AmortizedCost.MarshalBinaryWithContext(ctx)
  2931. if errG != nil {
  2932. return errG
  2933. }
  2934. // --- [end][write][struct](CostMetric) ---
  2935. return nil
  2936. }
  2937. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2938. // the CloudCost type
  2939. func (target *CloudCost) UnmarshalBinary(data []byte) error {
  2940. var table []string
  2941. buff := util.NewBufferFromBytes(data)
  2942. // string table header validation
  2943. if isBinaryTag(data, BinaryTagStringTable) {
  2944. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2945. tl := buff.ReadInt() // table length
  2946. if tl > 0 {
  2947. table = make([]string, tl, tl)
  2948. for i := 0; i < tl; i++ {
  2949. table[i] = buff.ReadString()
  2950. }
  2951. }
  2952. }
  2953. ctx := &DecodingContext{
  2954. Buffer: buff,
  2955. Table: table,
  2956. }
  2957. err := target.UnmarshalBinaryWithContext(ctx)
  2958. if err != nil {
  2959. return err
  2960. }
  2961. return nil
  2962. }
  2963. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2964. // the CloudCost type
  2965. func (target *CloudCost) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2966. // panics are recovered and propagated as errors
  2967. defer func() {
  2968. if r := recover(); r != nil {
  2969. if e, ok := r.(error); ok {
  2970. err = e
  2971. } else if s, ok := r.(string); ok {
  2972. err = fmt.Errorf("Unexpected panic: %s", s)
  2973. } else {
  2974. err = fmt.Errorf("Unexpected panic: %+v", r)
  2975. }
  2976. }
  2977. }()
  2978. buff := ctx.Buffer
  2979. version := buff.ReadUInt8()
  2980. if version > CloudCostCodecVersion {
  2981. return fmt.Errorf("Invalid Version Unmarshaling CloudCost. Expected %d or less, got %d", CloudCostCodecVersion, version)
  2982. }
  2983. if buff.ReadUInt8() == uint8(0) {
  2984. target.Properties = nil
  2985. } else {
  2986. // --- [begin][read][struct](CloudCostProperties) ---
  2987. a := &CloudCostProperties{}
  2988. buff.ReadInt() // [compatibility, unused]
  2989. errA := a.UnmarshalBinaryWithContext(ctx)
  2990. if errA != nil {
  2991. return errA
  2992. }
  2993. target.Properties = a
  2994. // --- [end][read][struct](CloudCostProperties) ---
  2995. }
  2996. // --- [begin][read][struct](Window) ---
  2997. b := &Window{}
  2998. buff.ReadInt() // [compatibility, unused]
  2999. errB := b.UnmarshalBinaryWithContext(ctx)
  3000. if errB != nil {
  3001. return errB
  3002. }
  3003. target.Window = *b
  3004. // --- [end][read][struct](Window) ---
  3005. // --- [begin][read][struct](CostMetric) ---
  3006. c := &CostMetric{}
  3007. buff.ReadInt() // [compatibility, unused]
  3008. errC := c.UnmarshalBinaryWithContext(ctx)
  3009. if errC != nil {
  3010. return errC
  3011. }
  3012. target.ListCost = *c
  3013. // --- [end][read][struct](CostMetric) ---
  3014. // --- [begin][read][struct](CostMetric) ---
  3015. d := &CostMetric{}
  3016. buff.ReadInt() // [compatibility, unused]
  3017. errD := d.UnmarshalBinaryWithContext(ctx)
  3018. if errD != nil {
  3019. return errD
  3020. }
  3021. target.NetCost = *d
  3022. // --- [end][read][struct](CostMetric) ---
  3023. // --- [begin][read][struct](CostMetric) ---
  3024. e := &CostMetric{}
  3025. buff.ReadInt() // [compatibility, unused]
  3026. errE := e.UnmarshalBinaryWithContext(ctx)
  3027. if errE != nil {
  3028. return errE
  3029. }
  3030. target.AmortizedNetCost = *e
  3031. // --- [end][read][struct](CostMetric) ---
  3032. // --- [begin][read][struct](CostMetric) ---
  3033. f := &CostMetric{}
  3034. buff.ReadInt() // [compatibility, unused]
  3035. errF := f.UnmarshalBinaryWithContext(ctx)
  3036. if errF != nil {
  3037. return errF
  3038. }
  3039. target.InvoicedCost = *f
  3040. // --- [end][read][struct](CostMetric) ---
  3041. // --- [begin][read][struct](CostMetric) ---
  3042. g := &CostMetric{}
  3043. buff.ReadInt() // [compatibility, unused]
  3044. errG := g.UnmarshalBinaryWithContext(ctx)
  3045. if errG != nil {
  3046. return errG
  3047. }
  3048. target.AmortizedCost = *g
  3049. // --- [end][read][struct](CostMetric) ---
  3050. return nil
  3051. }
  3052. //--------------------------------------------------------------------------
  3053. // CloudCostProperties
  3054. //--------------------------------------------------------------------------
  3055. // MarshalBinary serializes the internal properties of this CloudCostProperties instance
  3056. // into a byte array
  3057. func (target *CloudCostProperties) MarshalBinary() (data []byte, err error) {
  3058. ctx := &EncodingContext{
  3059. Buffer: util.NewBuffer(),
  3060. Table: nil,
  3061. }
  3062. e := target.MarshalBinaryWithContext(ctx)
  3063. if e != nil {
  3064. return nil, e
  3065. }
  3066. encBytes := ctx.Buffer.Bytes()
  3067. return encBytes, nil
  3068. }
  3069. // MarshalBinaryWithContext serializes the internal properties of this CloudCostProperties instance
  3070. // into a byte array leveraging a predefined context.
  3071. func (target *CloudCostProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3072. // panics are recovered and propagated as errors
  3073. defer func() {
  3074. if r := recover(); r != nil {
  3075. if e, ok := r.(error); ok {
  3076. err = e
  3077. } else if s, ok := r.(string); ok {
  3078. err = fmt.Errorf("Unexpected panic: %s", s)
  3079. } else {
  3080. err = fmt.Errorf("Unexpected panic: %+v", r)
  3081. }
  3082. }
  3083. }()
  3084. buff := ctx.Buffer
  3085. buff.WriteUInt8(CloudCostCodecVersion) // version
  3086. if ctx.IsStringTable() {
  3087. a := ctx.Table.AddOrGet(target.ProviderID)
  3088. buff.WriteInt(a) // write table index
  3089. } else {
  3090. buff.WriteString(target.ProviderID) // write string
  3091. }
  3092. if ctx.IsStringTable() {
  3093. b := ctx.Table.AddOrGet(target.Provider)
  3094. buff.WriteInt(b) // write table index
  3095. } else {
  3096. buff.WriteString(target.Provider) // write string
  3097. }
  3098. if ctx.IsStringTable() {
  3099. c := ctx.Table.AddOrGet(target.AccountID)
  3100. buff.WriteInt(c) // write table index
  3101. } else {
  3102. buff.WriteString(target.AccountID) // write string
  3103. }
  3104. if ctx.IsStringTable() {
  3105. d := ctx.Table.AddOrGet(target.InvoiceEntityID)
  3106. buff.WriteInt(d) // write table index
  3107. } else {
  3108. buff.WriteString(target.InvoiceEntityID) // write string
  3109. }
  3110. if ctx.IsStringTable() {
  3111. e := ctx.Table.AddOrGet(target.Service)
  3112. buff.WriteInt(e) // write table index
  3113. } else {
  3114. buff.WriteString(target.Service) // write string
  3115. }
  3116. if ctx.IsStringTable() {
  3117. f := ctx.Table.AddOrGet(target.Category)
  3118. buff.WriteInt(f) // write table index
  3119. } else {
  3120. buff.WriteString(target.Category) // write string
  3121. }
  3122. // --- [begin][write][alias](CloudCostLabels) ---
  3123. if map[string]string(target.Labels) == nil {
  3124. buff.WriteUInt8(uint8(0)) // write nil byte
  3125. } else {
  3126. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3127. // --- [begin][write][map](map[string]string) ---
  3128. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  3129. for v, z := range map[string]string(target.Labels) {
  3130. if ctx.IsStringTable() {
  3131. g := ctx.Table.AddOrGet(v)
  3132. buff.WriteInt(g) // write table index
  3133. } else {
  3134. buff.WriteString(v) // write string
  3135. }
  3136. if ctx.IsStringTable() {
  3137. h := ctx.Table.AddOrGet(z)
  3138. buff.WriteInt(h) // write table index
  3139. } else {
  3140. buff.WriteString(z) // write string
  3141. }
  3142. }
  3143. // --- [end][write][map](map[string]string) ---
  3144. }
  3145. // --- [end][write][alias](CloudCostLabels) ---
  3146. return nil
  3147. }
  3148. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3149. // the CloudCostProperties type
  3150. func (target *CloudCostProperties) UnmarshalBinary(data []byte) error {
  3151. var table []string
  3152. buff := util.NewBufferFromBytes(data)
  3153. // string table header validation
  3154. if isBinaryTag(data, BinaryTagStringTable) {
  3155. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3156. tl := buff.ReadInt() // table length
  3157. if tl > 0 {
  3158. table = make([]string, tl, tl)
  3159. for i := 0; i < tl; i++ {
  3160. table[i] = buff.ReadString()
  3161. }
  3162. }
  3163. }
  3164. ctx := &DecodingContext{
  3165. Buffer: buff,
  3166. Table: table,
  3167. }
  3168. err := target.UnmarshalBinaryWithContext(ctx)
  3169. if err != nil {
  3170. return err
  3171. }
  3172. return nil
  3173. }
  3174. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3175. // the CloudCostProperties type
  3176. func (target *CloudCostProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3177. // panics are recovered and propagated as errors
  3178. defer func() {
  3179. if r := recover(); r != nil {
  3180. if e, ok := r.(error); ok {
  3181. err = e
  3182. } else if s, ok := r.(string); ok {
  3183. err = fmt.Errorf("Unexpected panic: %s", s)
  3184. } else {
  3185. err = fmt.Errorf("Unexpected panic: %+v", r)
  3186. }
  3187. }
  3188. }()
  3189. buff := ctx.Buffer
  3190. version := buff.ReadUInt8()
  3191. if version > CloudCostCodecVersion {
  3192. return fmt.Errorf("Invalid Version Unmarshaling CloudCostProperties. Expected %d or less, got %d", CloudCostCodecVersion, version)
  3193. }
  3194. var b string
  3195. if ctx.IsStringTable() {
  3196. c := buff.ReadInt() // read string index
  3197. b = ctx.Table[c]
  3198. } else {
  3199. b = buff.ReadString() // read string
  3200. }
  3201. a := b
  3202. target.ProviderID = a
  3203. var e string
  3204. if ctx.IsStringTable() {
  3205. f := buff.ReadInt() // read string index
  3206. e = ctx.Table[f]
  3207. } else {
  3208. e = buff.ReadString() // read string
  3209. }
  3210. d := e
  3211. target.Provider = d
  3212. var h string
  3213. if ctx.IsStringTable() {
  3214. k := buff.ReadInt() // read string index
  3215. h = ctx.Table[k]
  3216. } else {
  3217. h = buff.ReadString() // read string
  3218. }
  3219. g := h
  3220. target.AccountID = g
  3221. var m string
  3222. if ctx.IsStringTable() {
  3223. n := buff.ReadInt() // read string index
  3224. m = ctx.Table[n]
  3225. } else {
  3226. m = buff.ReadString() // read string
  3227. }
  3228. l := m
  3229. target.InvoiceEntityID = l
  3230. var p string
  3231. if ctx.IsStringTable() {
  3232. q := buff.ReadInt() // read string index
  3233. p = ctx.Table[q]
  3234. } else {
  3235. p = buff.ReadString() // read string
  3236. }
  3237. o := p
  3238. target.Service = o
  3239. var s string
  3240. if ctx.IsStringTable() {
  3241. t := buff.ReadInt() // read string index
  3242. s = ctx.Table[t]
  3243. } else {
  3244. s = buff.ReadString() // read string
  3245. }
  3246. r := s
  3247. target.Category = r
  3248. // --- [begin][read][alias](CloudCostLabels) ---
  3249. var u map[string]string
  3250. if buff.ReadUInt8() == uint8(0) {
  3251. u = nil
  3252. } else {
  3253. // --- [begin][read][map](map[string]string) ---
  3254. x := buff.ReadInt() // map len
  3255. w := make(map[string]string, x)
  3256. for i := 0; i < x; i++ {
  3257. var v string
  3258. var aa string
  3259. if ctx.IsStringTable() {
  3260. bb := buff.ReadInt() // read string index
  3261. aa = ctx.Table[bb]
  3262. } else {
  3263. aa = buff.ReadString() // read string
  3264. }
  3265. y := aa
  3266. v = y
  3267. var z string
  3268. var dd string
  3269. if ctx.IsStringTable() {
  3270. ee := buff.ReadInt() // read string index
  3271. dd = ctx.Table[ee]
  3272. } else {
  3273. dd = buff.ReadString() // read string
  3274. }
  3275. cc := dd
  3276. z = cc
  3277. w[v] = z
  3278. }
  3279. u = w
  3280. // --- [end][read][map](map[string]string) ---
  3281. }
  3282. target.Labels = CloudCostLabels(u)
  3283. // --- [end][read][alias](CloudCostLabels) ---
  3284. return nil
  3285. }
  3286. //--------------------------------------------------------------------------
  3287. // CloudCostSet
  3288. //--------------------------------------------------------------------------
  3289. // MarshalBinary serializes the internal properties of this CloudCostSet instance
  3290. // into a byte array
  3291. func (target *CloudCostSet) MarshalBinary() (data []byte, err error) {
  3292. ctx := &EncodingContext{
  3293. Buffer: util.NewBuffer(),
  3294. Table: NewStringTable(),
  3295. }
  3296. e := target.MarshalBinaryWithContext(ctx)
  3297. if e != nil {
  3298. return nil, e
  3299. }
  3300. encBytes := ctx.Buffer.Bytes()
  3301. sTableBytes := ctx.Table.ToBytes()
  3302. merged := appendBytes(sTableBytes, encBytes)
  3303. return merged, nil
  3304. }
  3305. // MarshalBinaryWithContext serializes the internal properties of this CloudCostSet instance
  3306. // into a byte array leveraging a predefined context.
  3307. func (target *CloudCostSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3308. // panics are recovered and propagated as errors
  3309. defer func() {
  3310. if r := recover(); r != nil {
  3311. if e, ok := r.(error); ok {
  3312. err = e
  3313. } else if s, ok := r.(string); ok {
  3314. err = fmt.Errorf("Unexpected panic: %s", s)
  3315. } else {
  3316. err = fmt.Errorf("Unexpected panic: %+v", r)
  3317. }
  3318. }
  3319. }()
  3320. buff := ctx.Buffer
  3321. buff.WriteUInt8(CloudCostCodecVersion) // version
  3322. if target.CloudCosts == nil {
  3323. buff.WriteUInt8(uint8(0)) // write nil byte
  3324. } else {
  3325. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3326. // --- [begin][write][map](map[string]*CloudCost) ---
  3327. buff.WriteInt(len(target.CloudCosts)) // map length
  3328. for v, z := range target.CloudCosts {
  3329. if ctx.IsStringTable() {
  3330. a := ctx.Table.AddOrGet(v)
  3331. buff.WriteInt(a) // write table index
  3332. } else {
  3333. buff.WriteString(v) // write string
  3334. }
  3335. if z == nil {
  3336. buff.WriteUInt8(uint8(0)) // write nil byte
  3337. } else {
  3338. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3339. // --- [begin][write][struct](CloudCost) ---
  3340. buff.WriteInt(0) // [compatibility, unused]
  3341. errA := z.MarshalBinaryWithContext(ctx)
  3342. if errA != nil {
  3343. return errA
  3344. }
  3345. // --- [end][write][struct](CloudCost) ---
  3346. }
  3347. }
  3348. // --- [end][write][map](map[string]*CloudCost) ---
  3349. }
  3350. // --- [begin][write][struct](Window) ---
  3351. buff.WriteInt(0) // [compatibility, unused]
  3352. errB := target.Window.MarshalBinaryWithContext(ctx)
  3353. if errB != nil {
  3354. return errB
  3355. }
  3356. // --- [end][write][struct](Window) ---
  3357. if ctx.IsStringTable() {
  3358. b := ctx.Table.AddOrGet(target.Integration)
  3359. buff.WriteInt(b) // write table index
  3360. } else {
  3361. buff.WriteString(target.Integration) // write string
  3362. }
  3363. if target.AggregationProperties == nil {
  3364. buff.WriteUInt8(uint8(0)) // write nil byte
  3365. } else {
  3366. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3367. // --- [begin][write][slice]([]string) ---
  3368. buff.WriteInt(len(target.AggregationProperties)) // array length
  3369. for i := 0; i < len(target.AggregationProperties); i++ {
  3370. if ctx.IsStringTable() {
  3371. c := ctx.Table.AddOrGet(target.AggregationProperties[i])
  3372. buff.WriteInt(c) // write table index
  3373. } else {
  3374. buff.WriteString(target.AggregationProperties[i]) // write string
  3375. }
  3376. }
  3377. // --- [end][write][slice]([]string) ---
  3378. }
  3379. return nil
  3380. }
  3381. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3382. // the CloudCostSet type
  3383. func (target *CloudCostSet) UnmarshalBinary(data []byte) error {
  3384. var table []string
  3385. buff := util.NewBufferFromBytes(data)
  3386. // string table header validation
  3387. if isBinaryTag(data, BinaryTagStringTable) {
  3388. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3389. tl := buff.ReadInt() // table length
  3390. if tl > 0 {
  3391. table = make([]string, tl, tl)
  3392. for i := 0; i < tl; i++ {
  3393. table[i] = buff.ReadString()
  3394. }
  3395. }
  3396. }
  3397. ctx := &DecodingContext{
  3398. Buffer: buff,
  3399. Table: table,
  3400. }
  3401. err := target.UnmarshalBinaryWithContext(ctx)
  3402. if err != nil {
  3403. return err
  3404. }
  3405. return nil
  3406. }
  3407. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3408. // the CloudCostSet type
  3409. func (target *CloudCostSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3410. // panics are recovered and propagated as errors
  3411. defer func() {
  3412. if r := recover(); r != nil {
  3413. if e, ok := r.(error); ok {
  3414. err = e
  3415. } else if s, ok := r.(string); ok {
  3416. err = fmt.Errorf("Unexpected panic: %s", s)
  3417. } else {
  3418. err = fmt.Errorf("Unexpected panic: %+v", r)
  3419. }
  3420. }
  3421. }()
  3422. buff := ctx.Buffer
  3423. version := buff.ReadUInt8()
  3424. if version > CloudCostCodecVersion {
  3425. return fmt.Errorf("Invalid Version Unmarshaling CloudCostSet. Expected %d or less, got %d", CloudCostCodecVersion, version)
  3426. }
  3427. if buff.ReadUInt8() == uint8(0) {
  3428. target.CloudCosts = nil
  3429. } else {
  3430. // --- [begin][read][map](map[string]*CloudCost) ---
  3431. b := buff.ReadInt() // map len
  3432. a := make(map[string]*CloudCost, b)
  3433. for i := 0; i < b; i++ {
  3434. var v string
  3435. var d string
  3436. if ctx.IsStringTable() {
  3437. e := buff.ReadInt() // read string index
  3438. d = ctx.Table[e]
  3439. } else {
  3440. d = buff.ReadString() // read string
  3441. }
  3442. c := d
  3443. v = c
  3444. var z *CloudCost
  3445. if buff.ReadUInt8() == uint8(0) {
  3446. z = nil
  3447. } else {
  3448. // --- [begin][read][struct](CloudCost) ---
  3449. f := &CloudCost{}
  3450. buff.ReadInt() // [compatibility, unused]
  3451. errA := f.UnmarshalBinaryWithContext(ctx)
  3452. if errA != nil {
  3453. return errA
  3454. }
  3455. z = f
  3456. // --- [end][read][struct](CloudCost) ---
  3457. }
  3458. a[v] = z
  3459. }
  3460. target.CloudCosts = a
  3461. // --- [end][read][map](map[string]*CloudCost) ---
  3462. }
  3463. // --- [begin][read][struct](Window) ---
  3464. g := &Window{}
  3465. buff.ReadInt() // [compatibility, unused]
  3466. errB := g.UnmarshalBinaryWithContext(ctx)
  3467. if errB != nil {
  3468. return errB
  3469. }
  3470. target.Window = *g
  3471. // --- [end][read][struct](Window) ---
  3472. var k string
  3473. if ctx.IsStringTable() {
  3474. l := buff.ReadInt() // read string index
  3475. k = ctx.Table[l]
  3476. } else {
  3477. k = buff.ReadString() // read string
  3478. }
  3479. h := k
  3480. target.Integration = h
  3481. if buff.ReadUInt8() == uint8(0) {
  3482. target.AggregationProperties = nil
  3483. } else {
  3484. // --- [begin][read][slice]([]string) ---
  3485. n := buff.ReadInt() // array len
  3486. m := make([]string, n)
  3487. for j := 0; j < n; j++ {
  3488. var o string
  3489. var q string
  3490. if ctx.IsStringTable() {
  3491. r := buff.ReadInt() // read string index
  3492. q = ctx.Table[r]
  3493. } else {
  3494. q = buff.ReadString() // read string
  3495. }
  3496. p := q
  3497. o = p
  3498. m[j] = o
  3499. }
  3500. target.AggregationProperties = m
  3501. // --- [end][read][slice]([]string) ---
  3502. }
  3503. return nil
  3504. }
  3505. //--------------------------------------------------------------------------
  3506. // CloudCostSetRange
  3507. //--------------------------------------------------------------------------
  3508. // MarshalBinary serializes the internal properties of this CloudCostSetRange instance
  3509. // into a byte array
  3510. func (target *CloudCostSetRange) MarshalBinary() (data []byte, err error) {
  3511. ctx := &EncodingContext{
  3512. Buffer: util.NewBuffer(),
  3513. Table: nil,
  3514. }
  3515. e := target.MarshalBinaryWithContext(ctx)
  3516. if e != nil {
  3517. return nil, e
  3518. }
  3519. encBytes := ctx.Buffer.Bytes()
  3520. return encBytes, nil
  3521. }
  3522. // MarshalBinaryWithContext serializes the internal properties of this CloudCostSetRange instance
  3523. // into a byte array leveraging a predefined context.
  3524. func (target *CloudCostSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3525. // panics are recovered and propagated as errors
  3526. defer func() {
  3527. if r := recover(); r != nil {
  3528. if e, ok := r.(error); ok {
  3529. err = e
  3530. } else if s, ok := r.(string); ok {
  3531. err = fmt.Errorf("Unexpected panic: %s", s)
  3532. } else {
  3533. err = fmt.Errorf("Unexpected panic: %+v", r)
  3534. }
  3535. }
  3536. }()
  3537. buff := ctx.Buffer
  3538. buff.WriteUInt8(CloudCostCodecVersion) // version
  3539. if target.CloudCostSets == nil {
  3540. buff.WriteUInt8(uint8(0)) // write nil byte
  3541. } else {
  3542. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3543. // --- [begin][write][slice]([]*CloudCostSet) ---
  3544. buff.WriteInt(len(target.CloudCostSets)) // array length
  3545. for i := 0; i < len(target.CloudCostSets); i++ {
  3546. if target.CloudCostSets[i] == nil {
  3547. buff.WriteUInt8(uint8(0)) // write nil byte
  3548. } else {
  3549. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3550. // --- [begin][write][struct](CloudCostSet) ---
  3551. buff.WriteInt(0) // [compatibility, unused]
  3552. errA := target.CloudCostSets[i].MarshalBinaryWithContext(ctx)
  3553. if errA != nil {
  3554. return errA
  3555. }
  3556. // --- [end][write][struct](CloudCostSet) ---
  3557. }
  3558. }
  3559. // --- [end][write][slice]([]*CloudCostSet) ---
  3560. }
  3561. // --- [begin][write][struct](Window) ---
  3562. buff.WriteInt(0) // [compatibility, unused]
  3563. errB := target.Window.MarshalBinaryWithContext(ctx)
  3564. if errB != nil {
  3565. return errB
  3566. }
  3567. // --- [end][write][struct](Window) ---
  3568. return nil
  3569. }
  3570. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3571. // the CloudCostSetRange type
  3572. func (target *CloudCostSetRange) UnmarshalBinary(data []byte) error {
  3573. var table []string
  3574. buff := util.NewBufferFromBytes(data)
  3575. // string table header validation
  3576. if isBinaryTag(data, BinaryTagStringTable) {
  3577. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3578. tl := buff.ReadInt() // table length
  3579. if tl > 0 {
  3580. table = make([]string, tl, tl)
  3581. for i := 0; i < tl; i++ {
  3582. table[i] = buff.ReadString()
  3583. }
  3584. }
  3585. }
  3586. ctx := &DecodingContext{
  3587. Buffer: buff,
  3588. Table: table,
  3589. }
  3590. err := target.UnmarshalBinaryWithContext(ctx)
  3591. if err != nil {
  3592. return err
  3593. }
  3594. return nil
  3595. }
  3596. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3597. // the CloudCostSetRange type
  3598. func (target *CloudCostSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3599. // panics are recovered and propagated as errors
  3600. defer func() {
  3601. if r := recover(); r != nil {
  3602. if e, ok := r.(error); ok {
  3603. err = e
  3604. } else if s, ok := r.(string); ok {
  3605. err = fmt.Errorf("Unexpected panic: %s", s)
  3606. } else {
  3607. err = fmt.Errorf("Unexpected panic: %+v", r)
  3608. }
  3609. }
  3610. }()
  3611. buff := ctx.Buffer
  3612. version := buff.ReadUInt8()
  3613. if version > CloudCostCodecVersion {
  3614. return fmt.Errorf("Invalid Version Unmarshaling CloudCostSetRange. Expected %d or less, got %d", CloudCostCodecVersion, version)
  3615. }
  3616. if buff.ReadUInt8() == uint8(0) {
  3617. target.CloudCostSets = nil
  3618. } else {
  3619. // --- [begin][read][slice]([]*CloudCostSet) ---
  3620. b := buff.ReadInt() // array len
  3621. a := make([]*CloudCostSet, b)
  3622. for i := 0; i < b; i++ {
  3623. var c *CloudCostSet
  3624. if buff.ReadUInt8() == uint8(0) {
  3625. c = nil
  3626. } else {
  3627. // --- [begin][read][struct](CloudCostSet) ---
  3628. d := &CloudCostSet{}
  3629. buff.ReadInt() // [compatibility, unused]
  3630. errA := d.UnmarshalBinaryWithContext(ctx)
  3631. if errA != nil {
  3632. return errA
  3633. }
  3634. c = d
  3635. // --- [end][read][struct](CloudCostSet) ---
  3636. }
  3637. a[i] = c
  3638. }
  3639. target.CloudCostSets = a
  3640. // --- [end][read][slice]([]*CloudCostSet) ---
  3641. }
  3642. // --- [begin][read][struct](Window) ---
  3643. e := &Window{}
  3644. buff.ReadInt() // [compatibility, unused]
  3645. errB := e.UnmarshalBinaryWithContext(ctx)
  3646. if errB != nil {
  3647. return errB
  3648. }
  3649. target.Window = *e
  3650. // --- [end][read][struct](Window) ---
  3651. return nil
  3652. }
  3653. //--------------------------------------------------------------------------
  3654. // ClusterManagement
  3655. //--------------------------------------------------------------------------
  3656. // MarshalBinary serializes the internal properties of this ClusterManagement instance
  3657. // into a byte array
  3658. func (target *ClusterManagement) MarshalBinary() (data []byte, err error) {
  3659. ctx := &EncodingContext{
  3660. Buffer: util.NewBuffer(),
  3661. Table: nil,
  3662. }
  3663. e := target.MarshalBinaryWithContext(ctx)
  3664. if e != nil {
  3665. return nil, e
  3666. }
  3667. encBytes := ctx.Buffer.Bytes()
  3668. return encBytes, nil
  3669. }
  3670. // MarshalBinaryWithContext serializes the internal properties of this ClusterManagement instance
  3671. // into a byte array leveraging a predefined context.
  3672. func (target *ClusterManagement) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3673. // panics are recovered and propagated as errors
  3674. defer func() {
  3675. if r := recover(); r != nil {
  3676. if e, ok := r.(error); ok {
  3677. err = e
  3678. } else if s, ok := r.(string); ok {
  3679. err = fmt.Errorf("Unexpected panic: %s", s)
  3680. } else {
  3681. err = fmt.Errorf("Unexpected panic: %+v", r)
  3682. }
  3683. }
  3684. }()
  3685. buff := ctx.Buffer
  3686. buff.WriteUInt8(AssetsCodecVersion) // version
  3687. // --- [begin][write][alias](AssetLabels) ---
  3688. if map[string]string(target.Labels) == nil {
  3689. buff.WriteUInt8(uint8(0)) // write nil byte
  3690. } else {
  3691. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3692. // --- [begin][write][map](map[string]string) ---
  3693. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  3694. for v, z := range map[string]string(target.Labels) {
  3695. if ctx.IsStringTable() {
  3696. a := ctx.Table.AddOrGet(v)
  3697. buff.WriteInt(a) // write table index
  3698. } else {
  3699. buff.WriteString(v) // write string
  3700. }
  3701. if ctx.IsStringTable() {
  3702. b := ctx.Table.AddOrGet(z)
  3703. buff.WriteInt(b) // write table index
  3704. } else {
  3705. buff.WriteString(z) // write string
  3706. }
  3707. }
  3708. // --- [end][write][map](map[string]string) ---
  3709. }
  3710. // --- [end][write][alias](AssetLabels) ---
  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](AssetProperties) ---
  3716. buff.WriteInt(0) // [compatibility, unused]
  3717. errA := target.Properties.MarshalBinaryWithContext(ctx)
  3718. if errA != nil {
  3719. return errA
  3720. }
  3721. // --- [end][write][struct](AssetProperties) ---
  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. buff.WriteFloat64(target.Cost) // write float64
  3731. buff.WriteFloat64(target.Adjustment) // write float64
  3732. return nil
  3733. }
  3734. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3735. // the ClusterManagement type
  3736. func (target *ClusterManagement) UnmarshalBinary(data []byte) error {
  3737. var table []string
  3738. buff := util.NewBufferFromBytes(data)
  3739. // string table header validation
  3740. if isBinaryTag(data, BinaryTagStringTable) {
  3741. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3742. tl := buff.ReadInt() // table length
  3743. if tl > 0 {
  3744. table = make([]string, tl, tl)
  3745. for i := 0; i < tl; i++ {
  3746. table[i] = buff.ReadString()
  3747. }
  3748. }
  3749. }
  3750. ctx := &DecodingContext{
  3751. Buffer: buff,
  3752. Table: table,
  3753. }
  3754. err := target.UnmarshalBinaryWithContext(ctx)
  3755. if err != nil {
  3756. return err
  3757. }
  3758. return nil
  3759. }
  3760. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3761. // the ClusterManagement type
  3762. func (target *ClusterManagement) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3763. // panics are recovered and propagated as errors
  3764. defer func() {
  3765. if r := recover(); r != nil {
  3766. if e, ok := r.(error); ok {
  3767. err = e
  3768. } else if s, ok := r.(string); ok {
  3769. err = fmt.Errorf("Unexpected panic: %s", s)
  3770. } else {
  3771. err = fmt.Errorf("Unexpected panic: %+v", r)
  3772. }
  3773. }
  3774. }()
  3775. buff := ctx.Buffer
  3776. version := buff.ReadUInt8()
  3777. if version > AssetsCodecVersion {
  3778. return fmt.Errorf("Invalid Version Unmarshaling ClusterManagement. Expected %d or less, got %d", AssetsCodecVersion, version)
  3779. }
  3780. // --- [begin][read][alias](AssetLabels) ---
  3781. var a map[string]string
  3782. if buff.ReadUInt8() == uint8(0) {
  3783. a = nil
  3784. } else {
  3785. // --- [begin][read][map](map[string]string) ---
  3786. c := buff.ReadInt() // map len
  3787. b := make(map[string]string, c)
  3788. for i := 0; i < c; i++ {
  3789. var v string
  3790. var e string
  3791. if ctx.IsStringTable() {
  3792. f := buff.ReadInt() // read string index
  3793. e = ctx.Table[f]
  3794. } else {
  3795. e = buff.ReadString() // read string
  3796. }
  3797. d := e
  3798. v = d
  3799. var z string
  3800. var h string
  3801. if ctx.IsStringTable() {
  3802. k := buff.ReadInt() // read string index
  3803. h = ctx.Table[k]
  3804. } else {
  3805. h = buff.ReadString() // read string
  3806. }
  3807. g := h
  3808. z = g
  3809. b[v] = z
  3810. }
  3811. a = b
  3812. // --- [end][read][map](map[string]string) ---
  3813. }
  3814. target.Labels = AssetLabels(a)
  3815. // --- [end][read][alias](AssetLabels) ---
  3816. if buff.ReadUInt8() == uint8(0) {
  3817. target.Properties = nil
  3818. } else {
  3819. // --- [begin][read][struct](AssetProperties) ---
  3820. l := &AssetProperties{}
  3821. buff.ReadInt() // [compatibility, unused]
  3822. errA := l.UnmarshalBinaryWithContext(ctx)
  3823. if errA != nil {
  3824. return errA
  3825. }
  3826. target.Properties = l
  3827. // --- [end][read][struct](AssetProperties) ---
  3828. }
  3829. // --- [begin][read][struct](Window) ---
  3830. m := &Window{}
  3831. buff.ReadInt() // [compatibility, unused]
  3832. errB := m.UnmarshalBinaryWithContext(ctx)
  3833. if errB != nil {
  3834. return errB
  3835. }
  3836. target.Window = *m
  3837. // --- [end][read][struct](Window) ---
  3838. n := buff.ReadFloat64() // read float64
  3839. target.Cost = n
  3840. // field version check
  3841. if uint8(16) <= version {
  3842. o := buff.ReadFloat64() // read float64
  3843. target.Adjustment = o
  3844. } else {
  3845. target.Adjustment = float64(0) // default
  3846. }
  3847. return nil
  3848. }
  3849. //--------------------------------------------------------------------------
  3850. // CostMetric
  3851. //--------------------------------------------------------------------------
  3852. // MarshalBinary serializes the internal properties of this CostMetric instance
  3853. // into a byte array
  3854. func (target *CostMetric) MarshalBinary() (data []byte, err error) {
  3855. ctx := &EncodingContext{
  3856. Buffer: util.NewBuffer(),
  3857. Table: nil,
  3858. }
  3859. e := target.MarshalBinaryWithContext(ctx)
  3860. if e != nil {
  3861. return nil, e
  3862. }
  3863. encBytes := ctx.Buffer.Bytes()
  3864. return encBytes, nil
  3865. }
  3866. // MarshalBinaryWithContext serializes the internal properties of this CostMetric instance
  3867. // into a byte array leveraging a predefined context.
  3868. func (target *CostMetric) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3869. // panics are recovered and propagated as errors
  3870. defer func() {
  3871. if r := recover(); r != nil {
  3872. if e, ok := r.(error); ok {
  3873. err = e
  3874. } else if s, ok := r.(string); ok {
  3875. err = fmt.Errorf("Unexpected panic: %s", s)
  3876. } else {
  3877. err = fmt.Errorf("Unexpected panic: %+v", r)
  3878. }
  3879. }
  3880. }()
  3881. buff := ctx.Buffer
  3882. buff.WriteUInt8(CloudCostCodecVersion) // version
  3883. buff.WriteFloat64(target.Cost) // write float64
  3884. buff.WriteFloat64(target.KubernetesPercent) // write float64
  3885. return nil
  3886. }
  3887. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3888. // the CostMetric type
  3889. func (target *CostMetric) UnmarshalBinary(data []byte) error {
  3890. var table []string
  3891. buff := util.NewBufferFromBytes(data)
  3892. // string table header validation
  3893. if isBinaryTag(data, BinaryTagStringTable) {
  3894. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3895. tl := buff.ReadInt() // table length
  3896. if tl > 0 {
  3897. table = make([]string, tl, tl)
  3898. for i := 0; i < tl; i++ {
  3899. table[i] = buff.ReadString()
  3900. }
  3901. }
  3902. }
  3903. ctx := &DecodingContext{
  3904. Buffer: buff,
  3905. Table: table,
  3906. }
  3907. err := target.UnmarshalBinaryWithContext(ctx)
  3908. if err != nil {
  3909. return err
  3910. }
  3911. return nil
  3912. }
  3913. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3914. // the CostMetric type
  3915. func (target *CostMetric) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3916. // panics are recovered and propagated as errors
  3917. defer func() {
  3918. if r := recover(); r != nil {
  3919. if e, ok := r.(error); ok {
  3920. err = e
  3921. } else if s, ok := r.(string); ok {
  3922. err = fmt.Errorf("Unexpected panic: %s", s)
  3923. } else {
  3924. err = fmt.Errorf("Unexpected panic: %+v", r)
  3925. }
  3926. }
  3927. }()
  3928. buff := ctx.Buffer
  3929. version := buff.ReadUInt8()
  3930. if version > CloudCostCodecVersion {
  3931. return fmt.Errorf("Invalid Version Unmarshaling CostMetric. Expected %d or less, got %d", CloudCostCodecVersion, version)
  3932. }
  3933. a := buff.ReadFloat64() // read float64
  3934. target.Cost = a
  3935. b := buff.ReadFloat64() // read float64
  3936. target.KubernetesPercent = b
  3937. return nil
  3938. }
  3939. //--------------------------------------------------------------------------
  3940. // Coverage
  3941. //--------------------------------------------------------------------------
  3942. // MarshalBinary serializes the internal properties of this Coverage instance
  3943. // into a byte array
  3944. func (target *Coverage) MarshalBinary() (data []byte, err error) {
  3945. ctx := &EncodingContext{
  3946. Buffer: util.NewBuffer(),
  3947. Table: nil,
  3948. }
  3949. e := target.MarshalBinaryWithContext(ctx)
  3950. if e != nil {
  3951. return nil, e
  3952. }
  3953. encBytes := ctx.Buffer.Bytes()
  3954. return encBytes, nil
  3955. }
  3956. // MarshalBinaryWithContext serializes the internal properties of this Coverage instance
  3957. // into a byte array leveraging a predefined context.
  3958. func (target *Coverage) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3959. // panics are recovered and propagated as errors
  3960. defer func() {
  3961. if r := recover(); r != nil {
  3962. if e, ok := r.(error); ok {
  3963. err = e
  3964. } else if s, ok := r.(string); ok {
  3965. err = fmt.Errorf("Unexpected panic: %s", s)
  3966. } else {
  3967. err = fmt.Errorf("Unexpected panic: %+v", r)
  3968. }
  3969. }
  3970. }()
  3971. buff := ctx.Buffer
  3972. buff.WriteUInt8(DefaultCodecVersion) // version
  3973. // --- [begin][write][struct](Window) ---
  3974. buff.WriteInt(0) // [compatibility, unused]
  3975. errA := target.Window.MarshalBinaryWithContext(ctx)
  3976. if errA != nil {
  3977. return errA
  3978. }
  3979. // --- [end][write][struct](Window) ---
  3980. if ctx.IsStringTable() {
  3981. a := ctx.Table.AddOrGet(target.Type)
  3982. buff.WriteInt(a) // write table index
  3983. } else {
  3984. buff.WriteString(target.Type) // write string
  3985. }
  3986. buff.WriteInt(target.Count) // write int
  3987. // --- [begin][write][reference](time.Time) ---
  3988. b, errB := target.Updated.MarshalBinary()
  3989. if errB != nil {
  3990. return errB
  3991. }
  3992. buff.WriteInt(len(b))
  3993. buff.WriteBytes(b)
  3994. // --- [end][write][reference](time.Time) ---
  3995. if target.Errors == nil {
  3996. buff.WriteUInt8(uint8(0)) // write nil byte
  3997. } else {
  3998. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3999. // --- [begin][write][slice]([]string) ---
  4000. buff.WriteInt(len(target.Errors)) // array length
  4001. for i := 0; i < len(target.Errors); i++ {
  4002. if ctx.IsStringTable() {
  4003. c := ctx.Table.AddOrGet(target.Errors[i])
  4004. buff.WriteInt(c) // write table index
  4005. } else {
  4006. buff.WriteString(target.Errors[i]) // write string
  4007. }
  4008. }
  4009. // --- [end][write][slice]([]string) ---
  4010. }
  4011. if target.Warnings == nil {
  4012. buff.WriteUInt8(uint8(0)) // write nil byte
  4013. } else {
  4014. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4015. // --- [begin][write][slice]([]string) ---
  4016. buff.WriteInt(len(target.Warnings)) // array length
  4017. for j := 0; j < len(target.Warnings); j++ {
  4018. if ctx.IsStringTable() {
  4019. d := ctx.Table.AddOrGet(target.Warnings[j])
  4020. buff.WriteInt(d) // write table index
  4021. } else {
  4022. buff.WriteString(target.Warnings[j]) // write string
  4023. }
  4024. }
  4025. // --- [end][write][slice]([]string) ---
  4026. }
  4027. return nil
  4028. }
  4029. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4030. // the Coverage type
  4031. func (target *Coverage) UnmarshalBinary(data []byte) error {
  4032. var table []string
  4033. buff := util.NewBufferFromBytes(data)
  4034. // string table header validation
  4035. if isBinaryTag(data, BinaryTagStringTable) {
  4036. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4037. tl := buff.ReadInt() // table length
  4038. if tl > 0 {
  4039. table = make([]string, tl, tl)
  4040. for i := 0; i < tl; i++ {
  4041. table[i] = buff.ReadString()
  4042. }
  4043. }
  4044. }
  4045. ctx := &DecodingContext{
  4046. Buffer: buff,
  4047. Table: table,
  4048. }
  4049. err := target.UnmarshalBinaryWithContext(ctx)
  4050. if err != nil {
  4051. return err
  4052. }
  4053. return nil
  4054. }
  4055. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4056. // the Coverage type
  4057. func (target *Coverage) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4058. // panics are recovered and propagated as errors
  4059. defer func() {
  4060. if r := recover(); r != nil {
  4061. if e, ok := r.(error); ok {
  4062. err = e
  4063. } else if s, ok := r.(string); ok {
  4064. err = fmt.Errorf("Unexpected panic: %s", s)
  4065. } else {
  4066. err = fmt.Errorf("Unexpected panic: %+v", r)
  4067. }
  4068. }
  4069. }()
  4070. buff := ctx.Buffer
  4071. version := buff.ReadUInt8()
  4072. if version > DefaultCodecVersion {
  4073. return fmt.Errorf("Invalid Version Unmarshaling Coverage. Expected %d or less, got %d", DefaultCodecVersion, version)
  4074. }
  4075. // --- [begin][read][struct](Window) ---
  4076. a := &Window{}
  4077. buff.ReadInt() // [compatibility, unused]
  4078. errA := a.UnmarshalBinaryWithContext(ctx)
  4079. if errA != nil {
  4080. return errA
  4081. }
  4082. target.Window = *a
  4083. // --- [end][read][struct](Window) ---
  4084. var c string
  4085. if ctx.IsStringTable() {
  4086. d := buff.ReadInt() // read string index
  4087. c = ctx.Table[d]
  4088. } else {
  4089. c = buff.ReadString() // read string
  4090. }
  4091. b := c
  4092. target.Type = b
  4093. e := buff.ReadInt() // read int
  4094. target.Count = e
  4095. // --- [begin][read][reference](time.Time) ---
  4096. f := &time.Time{}
  4097. g := buff.ReadInt() // byte array length
  4098. h := buff.ReadBytes(g) // byte array
  4099. errB := f.UnmarshalBinary(h)
  4100. if errB != nil {
  4101. return errB
  4102. }
  4103. target.Updated = *f
  4104. // --- [end][read][reference](time.Time) ---
  4105. if buff.ReadUInt8() == uint8(0) {
  4106. target.Errors = nil
  4107. } else {
  4108. // --- [begin][read][slice]([]string) ---
  4109. l := buff.ReadInt() // array len
  4110. k := make([]string, l)
  4111. for i := 0; i < l; i++ {
  4112. var m string
  4113. var o string
  4114. if ctx.IsStringTable() {
  4115. p := buff.ReadInt() // read string index
  4116. o = ctx.Table[p]
  4117. } else {
  4118. o = buff.ReadString() // read string
  4119. }
  4120. n := o
  4121. m = n
  4122. k[i] = m
  4123. }
  4124. target.Errors = k
  4125. // --- [end][read][slice]([]string) ---
  4126. }
  4127. if buff.ReadUInt8() == uint8(0) {
  4128. target.Warnings = nil
  4129. } else {
  4130. // --- [begin][read][slice]([]string) ---
  4131. r := buff.ReadInt() // array len
  4132. q := make([]string, r)
  4133. for j := 0; j < r; j++ {
  4134. var s string
  4135. var u string
  4136. if ctx.IsStringTable() {
  4137. w := buff.ReadInt() // read string index
  4138. u = ctx.Table[w]
  4139. } else {
  4140. u = buff.ReadString() // read string
  4141. }
  4142. t := u
  4143. s = t
  4144. q[j] = s
  4145. }
  4146. target.Warnings = q
  4147. // --- [end][read][slice]([]string) ---
  4148. }
  4149. return nil
  4150. }
  4151. //--------------------------------------------------------------------------
  4152. // CoverageSet
  4153. //--------------------------------------------------------------------------
  4154. // MarshalBinary serializes the internal properties of this CoverageSet instance
  4155. // into a byte array
  4156. func (target *CoverageSet) MarshalBinary() (data []byte, err error) {
  4157. ctx := &EncodingContext{
  4158. Buffer: util.NewBuffer(),
  4159. Table: nil,
  4160. }
  4161. e := target.MarshalBinaryWithContext(ctx)
  4162. if e != nil {
  4163. return nil, e
  4164. }
  4165. encBytes := ctx.Buffer.Bytes()
  4166. return encBytes, nil
  4167. }
  4168. // MarshalBinaryWithContext serializes the internal properties of this CoverageSet instance
  4169. // into a byte array leveraging a predefined context.
  4170. func (target *CoverageSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4171. // panics are recovered and propagated as errors
  4172. defer func() {
  4173. if r := recover(); r != nil {
  4174. if e, ok := r.(error); ok {
  4175. err = e
  4176. } else if s, ok := r.(string); ok {
  4177. err = fmt.Errorf("Unexpected panic: %s", s)
  4178. } else {
  4179. err = fmt.Errorf("Unexpected panic: %+v", r)
  4180. }
  4181. }
  4182. }()
  4183. buff := ctx.Buffer
  4184. buff.WriteUInt8(DefaultCodecVersion) // version
  4185. // --- [begin][write][struct](Window) ---
  4186. buff.WriteInt(0) // [compatibility, unused]
  4187. errA := target.Window.MarshalBinaryWithContext(ctx)
  4188. if errA != nil {
  4189. return errA
  4190. }
  4191. // --- [end][write][struct](Window) ---
  4192. if target.Items == nil {
  4193. buff.WriteUInt8(uint8(0)) // write nil byte
  4194. } else {
  4195. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4196. // --- [begin][write][map](map[string]*Coverage) ---
  4197. buff.WriteInt(len(target.Items)) // map length
  4198. for v, z := range target.Items {
  4199. if ctx.IsStringTable() {
  4200. a := ctx.Table.AddOrGet(v)
  4201. buff.WriteInt(a) // write table index
  4202. } else {
  4203. buff.WriteString(v) // write string
  4204. }
  4205. if z == nil {
  4206. buff.WriteUInt8(uint8(0)) // write nil byte
  4207. } else {
  4208. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4209. // --- [begin][write][struct](Coverage) ---
  4210. buff.WriteInt(0) // [compatibility, unused]
  4211. errB := z.MarshalBinaryWithContext(ctx)
  4212. if errB != nil {
  4213. return errB
  4214. }
  4215. // --- [end][write][struct](Coverage) ---
  4216. }
  4217. }
  4218. // --- [end][write][map](map[string]*Coverage) ---
  4219. }
  4220. return nil
  4221. }
  4222. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4223. // the CoverageSet type
  4224. func (target *CoverageSet) UnmarshalBinary(data []byte) error {
  4225. var table []string
  4226. buff := util.NewBufferFromBytes(data)
  4227. // string table header validation
  4228. if isBinaryTag(data, BinaryTagStringTable) {
  4229. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4230. tl := buff.ReadInt() // table length
  4231. if tl > 0 {
  4232. table = make([]string, tl, tl)
  4233. for i := 0; i < tl; i++ {
  4234. table[i] = buff.ReadString()
  4235. }
  4236. }
  4237. }
  4238. ctx := &DecodingContext{
  4239. Buffer: buff,
  4240. Table: table,
  4241. }
  4242. err := target.UnmarshalBinaryWithContext(ctx)
  4243. if err != nil {
  4244. return err
  4245. }
  4246. return nil
  4247. }
  4248. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4249. // the CoverageSet type
  4250. func (target *CoverageSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4251. // panics are recovered and propagated as errors
  4252. defer func() {
  4253. if r := recover(); r != nil {
  4254. if e, ok := r.(error); ok {
  4255. err = e
  4256. } else if s, ok := r.(string); ok {
  4257. err = fmt.Errorf("Unexpected panic: %s", s)
  4258. } else {
  4259. err = fmt.Errorf("Unexpected panic: %+v", r)
  4260. }
  4261. }
  4262. }()
  4263. buff := ctx.Buffer
  4264. version := buff.ReadUInt8()
  4265. if version > DefaultCodecVersion {
  4266. return fmt.Errorf("Invalid Version Unmarshaling CoverageSet. Expected %d or less, got %d", DefaultCodecVersion, version)
  4267. }
  4268. // --- [begin][read][struct](Window) ---
  4269. a := &Window{}
  4270. buff.ReadInt() // [compatibility, unused]
  4271. errA := a.UnmarshalBinaryWithContext(ctx)
  4272. if errA != nil {
  4273. return errA
  4274. }
  4275. target.Window = *a
  4276. // --- [end][read][struct](Window) ---
  4277. if buff.ReadUInt8() == uint8(0) {
  4278. target.Items = nil
  4279. } else {
  4280. // --- [begin][read][map](map[string]*Coverage) ---
  4281. c := buff.ReadInt() // map len
  4282. b := make(map[string]*Coverage, c)
  4283. for i := 0; i < c; i++ {
  4284. var v string
  4285. var e string
  4286. if ctx.IsStringTable() {
  4287. f := buff.ReadInt() // read string index
  4288. e = ctx.Table[f]
  4289. } else {
  4290. e = buff.ReadString() // read string
  4291. }
  4292. d := e
  4293. v = d
  4294. var z *Coverage
  4295. if buff.ReadUInt8() == uint8(0) {
  4296. z = nil
  4297. } else {
  4298. // --- [begin][read][struct](Coverage) ---
  4299. g := &Coverage{}
  4300. buff.ReadInt() // [compatibility, unused]
  4301. errB := g.UnmarshalBinaryWithContext(ctx)
  4302. if errB != nil {
  4303. return errB
  4304. }
  4305. z = g
  4306. // --- [end][read][struct](Coverage) ---
  4307. }
  4308. b[v] = z
  4309. }
  4310. target.Items = b
  4311. // --- [end][read][map](map[string]*Coverage) ---
  4312. }
  4313. return nil
  4314. }
  4315. //--------------------------------------------------------------------------
  4316. // Disk
  4317. //--------------------------------------------------------------------------
  4318. // MarshalBinary serializes the internal properties of this Disk instance
  4319. // into a byte array
  4320. func (target *Disk) MarshalBinary() (data []byte, err error) {
  4321. ctx := &EncodingContext{
  4322. Buffer: util.NewBuffer(),
  4323. Table: nil,
  4324. }
  4325. e := target.MarshalBinaryWithContext(ctx)
  4326. if e != nil {
  4327. return nil, e
  4328. }
  4329. encBytes := ctx.Buffer.Bytes()
  4330. return encBytes, nil
  4331. }
  4332. // MarshalBinaryWithContext serializes the internal properties of this Disk instance
  4333. // into a byte array leveraging a predefined context.
  4334. func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4335. // panics are recovered and propagated as errors
  4336. defer func() {
  4337. if r := recover(); r != nil {
  4338. if e, ok := r.(error); ok {
  4339. err = e
  4340. } else if s, ok := r.(string); ok {
  4341. err = fmt.Errorf("Unexpected panic: %s", s)
  4342. } else {
  4343. err = fmt.Errorf("Unexpected panic: %+v", r)
  4344. }
  4345. }
  4346. }()
  4347. buff := ctx.Buffer
  4348. buff.WriteUInt8(AssetsCodecVersion) // version
  4349. // --- [begin][write][alias](AssetLabels) ---
  4350. if map[string]string(target.Labels) == nil {
  4351. buff.WriteUInt8(uint8(0)) // write nil byte
  4352. } else {
  4353. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4354. // --- [begin][write][map](map[string]string) ---
  4355. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  4356. for v, z := range map[string]string(target.Labels) {
  4357. if ctx.IsStringTable() {
  4358. a := ctx.Table.AddOrGet(v)
  4359. buff.WriteInt(a) // write table index
  4360. } else {
  4361. buff.WriteString(v) // write string
  4362. }
  4363. if ctx.IsStringTable() {
  4364. b := ctx.Table.AddOrGet(z)
  4365. buff.WriteInt(b) // write table index
  4366. } else {
  4367. buff.WriteString(z) // write string
  4368. }
  4369. }
  4370. // --- [end][write][map](map[string]string) ---
  4371. }
  4372. // --- [end][write][alias](AssetLabels) ---
  4373. if target.Properties == nil {
  4374. buff.WriteUInt8(uint8(0)) // write nil byte
  4375. } else {
  4376. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4377. // --- [begin][write][struct](AssetProperties) ---
  4378. buff.WriteInt(0) // [compatibility, unused]
  4379. errA := target.Properties.MarshalBinaryWithContext(ctx)
  4380. if errA != nil {
  4381. return errA
  4382. }
  4383. // --- [end][write][struct](AssetProperties) ---
  4384. }
  4385. // --- [begin][write][reference](time.Time) ---
  4386. c, errB := target.Start.MarshalBinary()
  4387. if errB != nil {
  4388. return errB
  4389. }
  4390. buff.WriteInt(len(c))
  4391. buff.WriteBytes(c)
  4392. // --- [end][write][reference](time.Time) ---
  4393. // --- [begin][write][reference](time.Time) ---
  4394. d, errC := target.End.MarshalBinary()
  4395. if errC != nil {
  4396. return errC
  4397. }
  4398. buff.WriteInt(len(d))
  4399. buff.WriteBytes(d)
  4400. // --- [end][write][reference](time.Time) ---
  4401. // --- [begin][write][struct](Window) ---
  4402. buff.WriteInt(0) // [compatibility, unused]
  4403. errD := target.Window.MarshalBinaryWithContext(ctx)
  4404. if errD != nil {
  4405. return errD
  4406. }
  4407. // --- [end][write][struct](Window) ---
  4408. buff.WriteFloat64(target.Adjustment) // write float64
  4409. buff.WriteFloat64(target.Cost) // write float64
  4410. buff.WriteFloat64(target.ByteHours) // write float64
  4411. buff.WriteFloat64(target.Local) // write float64
  4412. if target.Breakdown == nil {
  4413. buff.WriteUInt8(uint8(0)) // write nil byte
  4414. } else {
  4415. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4416. // --- [begin][write][struct](Breakdown) ---
  4417. buff.WriteInt(0) // [compatibility, unused]
  4418. errE := target.Breakdown.MarshalBinaryWithContext(ctx)
  4419. if errE != nil {
  4420. return errE
  4421. }
  4422. // --- [end][write][struct](Breakdown) ---
  4423. }
  4424. if ctx.IsStringTable() {
  4425. e := ctx.Table.AddOrGet(target.StorageClass)
  4426. buff.WriteInt(e) // write table index
  4427. } else {
  4428. buff.WriteString(target.StorageClass) // write string
  4429. }
  4430. if target.ByteHoursUsed == nil {
  4431. buff.WriteUInt8(uint8(0)) // write nil byte
  4432. } else {
  4433. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4434. buff.WriteFloat64(*target.ByteHoursUsed) // write float64
  4435. }
  4436. if target.ByteUsageMax == nil {
  4437. buff.WriteUInt8(uint8(0)) // write nil byte
  4438. } else {
  4439. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4440. buff.WriteFloat64(*target.ByteUsageMax) // write float64
  4441. }
  4442. if ctx.IsStringTable() {
  4443. f := ctx.Table.AddOrGet(target.VolumeName)
  4444. buff.WriteInt(f) // write table index
  4445. } else {
  4446. buff.WriteString(target.VolumeName) // write string
  4447. }
  4448. if ctx.IsStringTable() {
  4449. g := ctx.Table.AddOrGet(target.ClaimName)
  4450. buff.WriteInt(g) // write table index
  4451. } else {
  4452. buff.WriteString(target.ClaimName) // write string
  4453. }
  4454. if ctx.IsStringTable() {
  4455. h := ctx.Table.AddOrGet(target.ClaimNamespace)
  4456. buff.WriteInt(h) // write table index
  4457. } else {
  4458. buff.WriteString(target.ClaimNamespace) // write string
  4459. }
  4460. return nil
  4461. }
  4462. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4463. // the Disk type
  4464. func (target *Disk) UnmarshalBinary(data []byte) error {
  4465. var table []string
  4466. buff := util.NewBufferFromBytes(data)
  4467. // string table header validation
  4468. if isBinaryTag(data, BinaryTagStringTable) {
  4469. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4470. tl := buff.ReadInt() // table length
  4471. if tl > 0 {
  4472. table = make([]string, tl, tl)
  4473. for i := 0; i < tl; i++ {
  4474. table[i] = buff.ReadString()
  4475. }
  4476. }
  4477. }
  4478. ctx := &DecodingContext{
  4479. Buffer: buff,
  4480. Table: table,
  4481. }
  4482. err := target.UnmarshalBinaryWithContext(ctx)
  4483. if err != nil {
  4484. return err
  4485. }
  4486. return nil
  4487. }
  4488. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4489. // the Disk type
  4490. func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4491. // panics are recovered and propagated as errors
  4492. defer func() {
  4493. if r := recover(); r != nil {
  4494. if e, ok := r.(error); ok {
  4495. err = e
  4496. } else if s, ok := r.(string); ok {
  4497. err = fmt.Errorf("Unexpected panic: %s", s)
  4498. } else {
  4499. err = fmt.Errorf("Unexpected panic: %+v", r)
  4500. }
  4501. }
  4502. }()
  4503. buff := ctx.Buffer
  4504. version := buff.ReadUInt8()
  4505. if version > AssetsCodecVersion {
  4506. return fmt.Errorf("Invalid Version Unmarshaling Disk. Expected %d or less, got %d", AssetsCodecVersion, version)
  4507. }
  4508. // --- [begin][read][alias](AssetLabels) ---
  4509. var a map[string]string
  4510. if buff.ReadUInt8() == uint8(0) {
  4511. a = nil
  4512. } else {
  4513. // --- [begin][read][map](map[string]string) ---
  4514. c := buff.ReadInt() // map len
  4515. b := make(map[string]string, c)
  4516. for i := 0; i < c; i++ {
  4517. var v string
  4518. var e string
  4519. if ctx.IsStringTable() {
  4520. f := buff.ReadInt() // read string index
  4521. e = ctx.Table[f]
  4522. } else {
  4523. e = buff.ReadString() // read string
  4524. }
  4525. d := e
  4526. v = d
  4527. var z string
  4528. var h string
  4529. if ctx.IsStringTable() {
  4530. k := buff.ReadInt() // read string index
  4531. h = ctx.Table[k]
  4532. } else {
  4533. h = buff.ReadString() // read string
  4534. }
  4535. g := h
  4536. z = g
  4537. b[v] = z
  4538. }
  4539. a = b
  4540. // --- [end][read][map](map[string]string) ---
  4541. }
  4542. target.Labels = AssetLabels(a)
  4543. // --- [end][read][alias](AssetLabels) ---
  4544. if buff.ReadUInt8() == uint8(0) {
  4545. target.Properties = nil
  4546. } else {
  4547. // --- [begin][read][struct](AssetProperties) ---
  4548. l := &AssetProperties{}
  4549. buff.ReadInt() // [compatibility, unused]
  4550. errA := l.UnmarshalBinaryWithContext(ctx)
  4551. if errA != nil {
  4552. return errA
  4553. }
  4554. target.Properties = l
  4555. // --- [end][read][struct](AssetProperties) ---
  4556. }
  4557. // --- [begin][read][reference](time.Time) ---
  4558. m := &time.Time{}
  4559. n := buff.ReadInt() // byte array length
  4560. o := buff.ReadBytes(n) // byte array
  4561. errB := m.UnmarshalBinary(o)
  4562. if errB != nil {
  4563. return errB
  4564. }
  4565. target.Start = *m
  4566. // --- [end][read][reference](time.Time) ---
  4567. // --- [begin][read][reference](time.Time) ---
  4568. p := &time.Time{}
  4569. q := buff.ReadInt() // byte array length
  4570. r := buff.ReadBytes(q) // byte array
  4571. errC := p.UnmarshalBinary(r)
  4572. if errC != nil {
  4573. return errC
  4574. }
  4575. target.End = *p
  4576. // --- [end][read][reference](time.Time) ---
  4577. // --- [begin][read][struct](Window) ---
  4578. s := &Window{}
  4579. buff.ReadInt() // [compatibility, unused]
  4580. errD := s.UnmarshalBinaryWithContext(ctx)
  4581. if errD != nil {
  4582. return errD
  4583. }
  4584. target.Window = *s
  4585. // --- [end][read][struct](Window) ---
  4586. t := buff.ReadFloat64() // read float64
  4587. target.Adjustment = t
  4588. u := buff.ReadFloat64() // read float64
  4589. target.Cost = u
  4590. w := buff.ReadFloat64() // read float64
  4591. target.ByteHours = w
  4592. x := buff.ReadFloat64() // read float64
  4593. target.Local = x
  4594. if buff.ReadUInt8() == uint8(0) {
  4595. target.Breakdown = nil
  4596. } else {
  4597. // --- [begin][read][struct](Breakdown) ---
  4598. y := &Breakdown{}
  4599. buff.ReadInt() // [compatibility, unused]
  4600. errE := y.UnmarshalBinaryWithContext(ctx)
  4601. if errE != nil {
  4602. return errE
  4603. }
  4604. target.Breakdown = y
  4605. // --- [end][read][struct](Breakdown) ---
  4606. }
  4607. // field version check
  4608. if uint8(17) <= version {
  4609. var bb string
  4610. if ctx.IsStringTable() {
  4611. cc := buff.ReadInt() // read string index
  4612. bb = ctx.Table[cc]
  4613. } else {
  4614. bb = buff.ReadString() // read string
  4615. }
  4616. aa := bb
  4617. target.StorageClass = aa
  4618. } else {
  4619. target.StorageClass = "" // default
  4620. }
  4621. // field version check
  4622. if uint8(18) <= version {
  4623. if buff.ReadUInt8() == uint8(0) {
  4624. target.ByteHoursUsed = nil
  4625. } else {
  4626. dd := buff.ReadFloat64() // read float64
  4627. target.ByteHoursUsed = &dd
  4628. }
  4629. } else {
  4630. target.ByteHoursUsed = nil
  4631. }
  4632. // field version check
  4633. if uint8(18) <= version {
  4634. if buff.ReadUInt8() == uint8(0) {
  4635. target.ByteUsageMax = nil
  4636. } else {
  4637. ee := buff.ReadFloat64() // read float64
  4638. target.ByteUsageMax = &ee
  4639. }
  4640. } else {
  4641. target.ByteUsageMax = nil
  4642. }
  4643. // field version check
  4644. if uint8(18) <= version {
  4645. var gg string
  4646. if ctx.IsStringTable() {
  4647. hh := buff.ReadInt() // read string index
  4648. gg = ctx.Table[hh]
  4649. } else {
  4650. gg = buff.ReadString() // read string
  4651. }
  4652. ff := gg
  4653. target.VolumeName = ff
  4654. } else {
  4655. target.VolumeName = "" // default
  4656. }
  4657. // field version check
  4658. if uint8(18) <= version {
  4659. var ll string
  4660. if ctx.IsStringTable() {
  4661. mm := buff.ReadInt() // read string index
  4662. ll = ctx.Table[mm]
  4663. } else {
  4664. ll = buff.ReadString() // read string
  4665. }
  4666. kk := ll
  4667. target.ClaimName = kk
  4668. } else {
  4669. target.ClaimName = "" // default
  4670. }
  4671. // field version check
  4672. if uint8(18) <= version {
  4673. var oo string
  4674. if ctx.IsStringTable() {
  4675. pp := buff.ReadInt() // read string index
  4676. oo = ctx.Table[pp]
  4677. } else {
  4678. oo = buff.ReadString() // read string
  4679. }
  4680. nn := oo
  4681. target.ClaimNamespace = nn
  4682. } else {
  4683. target.ClaimNamespace = "" // default
  4684. }
  4685. return nil
  4686. }
  4687. //--------------------------------------------------------------------------
  4688. // LbAllocation
  4689. //--------------------------------------------------------------------------
  4690. // MarshalBinary serializes the internal properties of this LbAllocation instance
  4691. // into a byte array
  4692. func (target *LbAllocation) MarshalBinary() (data []byte, err error) {
  4693. ctx := &EncodingContext{
  4694. Buffer: util.NewBuffer(),
  4695. Table: nil,
  4696. }
  4697. e := target.MarshalBinaryWithContext(ctx)
  4698. if e != nil {
  4699. return nil, e
  4700. }
  4701. encBytes := ctx.Buffer.Bytes()
  4702. return encBytes, nil
  4703. }
  4704. // MarshalBinaryWithContext serializes the internal properties of this LbAllocation instance
  4705. // into a byte array leveraging a predefined context.
  4706. func (target *LbAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4707. // panics are recovered and propagated as errors
  4708. defer func() {
  4709. if r := recover(); r != nil {
  4710. if e, ok := r.(error); ok {
  4711. err = e
  4712. } else if s, ok := r.(string); ok {
  4713. err = fmt.Errorf("Unexpected panic: %s", s)
  4714. } else {
  4715. err = fmt.Errorf("Unexpected panic: %+v", r)
  4716. }
  4717. }
  4718. }()
  4719. buff := ctx.Buffer
  4720. buff.WriteUInt8(AllocationCodecVersion) // version
  4721. if ctx.IsStringTable() {
  4722. a := ctx.Table.AddOrGet(target.Service)
  4723. buff.WriteInt(a) // write table index
  4724. } else {
  4725. buff.WriteString(target.Service) // write string
  4726. }
  4727. buff.WriteFloat64(target.Cost) // write float64
  4728. buff.WriteBool(target.Private) // write bool
  4729. if ctx.IsStringTable() {
  4730. b := ctx.Table.AddOrGet(target.Ip)
  4731. buff.WriteInt(b) // write table index
  4732. } else {
  4733. buff.WriteString(target.Ip) // write string
  4734. }
  4735. return nil
  4736. }
  4737. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4738. // the LbAllocation type
  4739. func (target *LbAllocation) UnmarshalBinary(data []byte) error {
  4740. var table []string
  4741. buff := util.NewBufferFromBytes(data)
  4742. // string table header validation
  4743. if isBinaryTag(data, BinaryTagStringTable) {
  4744. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4745. tl := buff.ReadInt() // table length
  4746. if tl > 0 {
  4747. table = make([]string, tl, tl)
  4748. for i := 0; i < tl; i++ {
  4749. table[i] = buff.ReadString()
  4750. }
  4751. }
  4752. }
  4753. ctx := &DecodingContext{
  4754. Buffer: buff,
  4755. Table: table,
  4756. }
  4757. err := target.UnmarshalBinaryWithContext(ctx)
  4758. if err != nil {
  4759. return err
  4760. }
  4761. return nil
  4762. }
  4763. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4764. // the LbAllocation type
  4765. func (target *LbAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4766. // panics are recovered and propagated as errors
  4767. defer func() {
  4768. if r := recover(); r != nil {
  4769. if e, ok := r.(error); ok {
  4770. err = e
  4771. } else if s, ok := r.(string); ok {
  4772. err = fmt.Errorf("Unexpected panic: %s", s)
  4773. } else {
  4774. err = fmt.Errorf("Unexpected panic: %+v", r)
  4775. }
  4776. }
  4777. }()
  4778. buff := ctx.Buffer
  4779. version := buff.ReadUInt8()
  4780. if version > AllocationCodecVersion {
  4781. return fmt.Errorf("Invalid Version Unmarshaling LbAllocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  4782. }
  4783. var b string
  4784. if ctx.IsStringTable() {
  4785. c := buff.ReadInt() // read string index
  4786. b = ctx.Table[c]
  4787. } else {
  4788. b = buff.ReadString() // read string
  4789. }
  4790. a := b
  4791. target.Service = a
  4792. d := buff.ReadFloat64() // read float64
  4793. target.Cost = d
  4794. e := buff.ReadBool() // read bool
  4795. target.Private = e
  4796. // field version check
  4797. if uint8(19) <= version {
  4798. var g string
  4799. if ctx.IsStringTable() {
  4800. h := buff.ReadInt() // read string index
  4801. g = ctx.Table[h]
  4802. } else {
  4803. g = buff.ReadString() // read string
  4804. }
  4805. f := g
  4806. target.Ip = f
  4807. } else {
  4808. target.Ip = "" // default
  4809. }
  4810. return nil
  4811. }
  4812. //--------------------------------------------------------------------------
  4813. // LoadBalancer
  4814. //--------------------------------------------------------------------------
  4815. // MarshalBinary serializes the internal properties of this LoadBalancer instance
  4816. // into a byte array
  4817. func (target *LoadBalancer) MarshalBinary() (data []byte, err error) {
  4818. ctx := &EncodingContext{
  4819. Buffer: util.NewBuffer(),
  4820. Table: nil,
  4821. }
  4822. e := target.MarshalBinaryWithContext(ctx)
  4823. if e != nil {
  4824. return nil, e
  4825. }
  4826. encBytes := ctx.Buffer.Bytes()
  4827. return encBytes, nil
  4828. }
  4829. // MarshalBinaryWithContext serializes the internal properties of this LoadBalancer instance
  4830. // into a byte array leveraging a predefined context.
  4831. func (target *LoadBalancer) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4832. // panics are recovered and propagated as errors
  4833. defer func() {
  4834. if r := recover(); r != nil {
  4835. if e, ok := r.(error); ok {
  4836. err = e
  4837. } else if s, ok := r.(string); ok {
  4838. err = fmt.Errorf("Unexpected panic: %s", s)
  4839. } else {
  4840. err = fmt.Errorf("Unexpected panic: %+v", r)
  4841. }
  4842. }
  4843. }()
  4844. buff := ctx.Buffer
  4845. buff.WriteUInt8(AssetsCodecVersion) // version
  4846. if target.Properties == nil {
  4847. buff.WriteUInt8(uint8(0)) // write nil byte
  4848. } else {
  4849. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4850. // --- [begin][write][struct](AssetProperties) ---
  4851. buff.WriteInt(0) // [compatibility, unused]
  4852. errA := target.Properties.MarshalBinaryWithContext(ctx)
  4853. if errA != nil {
  4854. return errA
  4855. }
  4856. // --- [end][write][struct](AssetProperties) ---
  4857. }
  4858. // --- [begin][write][alias](AssetLabels) ---
  4859. if map[string]string(target.Labels) == nil {
  4860. buff.WriteUInt8(uint8(0)) // write nil byte
  4861. } else {
  4862. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4863. // --- [begin][write][map](map[string]string) ---
  4864. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  4865. for v, z := range map[string]string(target.Labels) {
  4866. if ctx.IsStringTable() {
  4867. a := ctx.Table.AddOrGet(v)
  4868. buff.WriteInt(a) // write table index
  4869. } else {
  4870. buff.WriteString(v) // write string
  4871. }
  4872. if ctx.IsStringTable() {
  4873. b := ctx.Table.AddOrGet(z)
  4874. buff.WriteInt(b) // write table index
  4875. } else {
  4876. buff.WriteString(z) // write string
  4877. }
  4878. }
  4879. // --- [end][write][map](map[string]string) ---
  4880. }
  4881. // --- [end][write][alias](AssetLabels) ---
  4882. // --- [begin][write][reference](time.Time) ---
  4883. c, errB := target.Start.MarshalBinary()
  4884. if errB != nil {
  4885. return errB
  4886. }
  4887. buff.WriteInt(len(c))
  4888. buff.WriteBytes(c)
  4889. // --- [end][write][reference](time.Time) ---
  4890. // --- [begin][write][reference](time.Time) ---
  4891. d, errC := target.End.MarshalBinary()
  4892. if errC != nil {
  4893. return errC
  4894. }
  4895. buff.WriteInt(len(d))
  4896. buff.WriteBytes(d)
  4897. // --- [end][write][reference](time.Time) ---
  4898. // --- [begin][write][struct](Window) ---
  4899. buff.WriteInt(0) // [compatibility, unused]
  4900. errD := target.Window.MarshalBinaryWithContext(ctx)
  4901. if errD != nil {
  4902. return errD
  4903. }
  4904. // --- [end][write][struct](Window) ---
  4905. buff.WriteFloat64(target.Adjustment) // write float64
  4906. buff.WriteFloat64(target.Cost) // write float64
  4907. buff.WriteBool(target.Private) // write bool
  4908. if ctx.IsStringTable() {
  4909. e := ctx.Table.AddOrGet(target.Ip)
  4910. buff.WriteInt(e) // write table index
  4911. } else {
  4912. buff.WriteString(target.Ip) // write string
  4913. }
  4914. return nil
  4915. }
  4916. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4917. // the LoadBalancer type
  4918. func (target *LoadBalancer) UnmarshalBinary(data []byte) error {
  4919. var table []string
  4920. buff := util.NewBufferFromBytes(data)
  4921. // string table header validation
  4922. if isBinaryTag(data, BinaryTagStringTable) {
  4923. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4924. tl := buff.ReadInt() // table length
  4925. if tl > 0 {
  4926. table = make([]string, tl, tl)
  4927. for i := 0; i < tl; i++ {
  4928. table[i] = buff.ReadString()
  4929. }
  4930. }
  4931. }
  4932. ctx := &DecodingContext{
  4933. Buffer: buff,
  4934. Table: table,
  4935. }
  4936. err := target.UnmarshalBinaryWithContext(ctx)
  4937. if err != nil {
  4938. return err
  4939. }
  4940. return nil
  4941. }
  4942. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4943. // the LoadBalancer type
  4944. func (target *LoadBalancer) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4945. // panics are recovered and propagated as errors
  4946. defer func() {
  4947. if r := recover(); r != nil {
  4948. if e, ok := r.(error); ok {
  4949. err = e
  4950. } else if s, ok := r.(string); ok {
  4951. err = fmt.Errorf("Unexpected panic: %s", s)
  4952. } else {
  4953. err = fmt.Errorf("Unexpected panic: %+v", r)
  4954. }
  4955. }
  4956. }()
  4957. buff := ctx.Buffer
  4958. version := buff.ReadUInt8()
  4959. if version > AssetsCodecVersion {
  4960. return fmt.Errorf("Invalid Version Unmarshaling LoadBalancer. Expected %d or less, got %d", AssetsCodecVersion, version)
  4961. }
  4962. if buff.ReadUInt8() == uint8(0) {
  4963. target.Properties = nil
  4964. } else {
  4965. // --- [begin][read][struct](AssetProperties) ---
  4966. a := &AssetProperties{}
  4967. buff.ReadInt() // [compatibility, unused]
  4968. errA := a.UnmarshalBinaryWithContext(ctx)
  4969. if errA != nil {
  4970. return errA
  4971. }
  4972. target.Properties = a
  4973. // --- [end][read][struct](AssetProperties) ---
  4974. }
  4975. // --- [begin][read][alias](AssetLabels) ---
  4976. var b map[string]string
  4977. if buff.ReadUInt8() == uint8(0) {
  4978. b = nil
  4979. } else {
  4980. // --- [begin][read][map](map[string]string) ---
  4981. d := buff.ReadInt() // map len
  4982. c := make(map[string]string, d)
  4983. for i := 0; i < d; i++ {
  4984. var v string
  4985. var f string
  4986. if ctx.IsStringTable() {
  4987. g := buff.ReadInt() // read string index
  4988. f = ctx.Table[g]
  4989. } else {
  4990. f = buff.ReadString() // read string
  4991. }
  4992. e := f
  4993. v = e
  4994. var z string
  4995. var k string
  4996. if ctx.IsStringTable() {
  4997. l := buff.ReadInt() // read string index
  4998. k = ctx.Table[l]
  4999. } else {
  5000. k = buff.ReadString() // read string
  5001. }
  5002. h := k
  5003. z = h
  5004. c[v] = z
  5005. }
  5006. b = c
  5007. // --- [end][read][map](map[string]string) ---
  5008. }
  5009. target.Labels = AssetLabels(b)
  5010. // --- [end][read][alias](AssetLabels) ---
  5011. // --- [begin][read][reference](time.Time) ---
  5012. m := &time.Time{}
  5013. n := buff.ReadInt() // byte array length
  5014. o := buff.ReadBytes(n) // byte array
  5015. errB := m.UnmarshalBinary(o)
  5016. if errB != nil {
  5017. return errB
  5018. }
  5019. target.Start = *m
  5020. // --- [end][read][reference](time.Time) ---
  5021. // --- [begin][read][reference](time.Time) ---
  5022. p := &time.Time{}
  5023. q := buff.ReadInt() // byte array length
  5024. r := buff.ReadBytes(q) // byte array
  5025. errC := p.UnmarshalBinary(r)
  5026. if errC != nil {
  5027. return errC
  5028. }
  5029. target.End = *p
  5030. // --- [end][read][reference](time.Time) ---
  5031. // --- [begin][read][struct](Window) ---
  5032. s := &Window{}
  5033. buff.ReadInt() // [compatibility, unused]
  5034. errD := s.UnmarshalBinaryWithContext(ctx)
  5035. if errD != nil {
  5036. return errD
  5037. }
  5038. target.Window = *s
  5039. // --- [end][read][struct](Window) ---
  5040. t := buff.ReadFloat64() // read float64
  5041. target.Adjustment = t
  5042. u := buff.ReadFloat64() // read float64
  5043. target.Cost = u
  5044. // field version check
  5045. if uint8(20) <= version {
  5046. w := buff.ReadBool() // read bool
  5047. target.Private = w
  5048. } else {
  5049. target.Private = false // default
  5050. }
  5051. // field version check
  5052. if uint8(21) <= version {
  5053. var y string
  5054. if ctx.IsStringTable() {
  5055. aa := buff.ReadInt() // read string index
  5056. y = ctx.Table[aa]
  5057. } else {
  5058. y = buff.ReadString() // read string
  5059. }
  5060. x := y
  5061. target.Ip = x
  5062. } else {
  5063. target.Ip = "" // default
  5064. }
  5065. return nil
  5066. }
  5067. //--------------------------------------------------------------------------
  5068. // Network
  5069. //--------------------------------------------------------------------------
  5070. // MarshalBinary serializes the internal properties of this Network instance
  5071. // into a byte array
  5072. func (target *Network) MarshalBinary() (data []byte, err error) {
  5073. ctx := &EncodingContext{
  5074. Buffer: util.NewBuffer(),
  5075. Table: nil,
  5076. }
  5077. e := target.MarshalBinaryWithContext(ctx)
  5078. if e != nil {
  5079. return nil, e
  5080. }
  5081. encBytes := ctx.Buffer.Bytes()
  5082. return encBytes, nil
  5083. }
  5084. // MarshalBinaryWithContext serializes the internal properties of this Network instance
  5085. // into a byte array leveraging a predefined context.
  5086. func (target *Network) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5087. // panics are recovered and propagated as errors
  5088. defer func() {
  5089. if r := recover(); r != nil {
  5090. if e, ok := r.(error); ok {
  5091. err = e
  5092. } else if s, ok := r.(string); ok {
  5093. err = fmt.Errorf("Unexpected panic: %s", s)
  5094. } else {
  5095. err = fmt.Errorf("Unexpected panic: %+v", r)
  5096. }
  5097. }
  5098. }()
  5099. buff := ctx.Buffer
  5100. buff.WriteUInt8(AssetsCodecVersion) // version
  5101. if target.Properties == nil {
  5102. buff.WriteUInt8(uint8(0)) // write nil byte
  5103. } else {
  5104. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5105. // --- [begin][write][struct](AssetProperties) ---
  5106. buff.WriteInt(0) // [compatibility, unused]
  5107. errA := target.Properties.MarshalBinaryWithContext(ctx)
  5108. if errA != nil {
  5109. return errA
  5110. }
  5111. // --- [end][write][struct](AssetProperties) ---
  5112. }
  5113. // --- [begin][write][alias](AssetLabels) ---
  5114. if map[string]string(target.Labels) == nil {
  5115. buff.WriteUInt8(uint8(0)) // write nil byte
  5116. } else {
  5117. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5118. // --- [begin][write][map](map[string]string) ---
  5119. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  5120. for v, z := range map[string]string(target.Labels) {
  5121. if ctx.IsStringTable() {
  5122. a := ctx.Table.AddOrGet(v)
  5123. buff.WriteInt(a) // write table index
  5124. } else {
  5125. buff.WriteString(v) // write string
  5126. }
  5127. if ctx.IsStringTable() {
  5128. b := ctx.Table.AddOrGet(z)
  5129. buff.WriteInt(b) // write table index
  5130. } else {
  5131. buff.WriteString(z) // write string
  5132. }
  5133. }
  5134. // --- [end][write][map](map[string]string) ---
  5135. }
  5136. // --- [end][write][alias](AssetLabels) ---
  5137. // --- [begin][write][reference](time.Time) ---
  5138. c, errB := target.Start.MarshalBinary()
  5139. if errB != nil {
  5140. return errB
  5141. }
  5142. buff.WriteInt(len(c))
  5143. buff.WriteBytes(c)
  5144. // --- [end][write][reference](time.Time) ---
  5145. // --- [begin][write][reference](time.Time) ---
  5146. d, errC := target.End.MarshalBinary()
  5147. if errC != nil {
  5148. return errC
  5149. }
  5150. buff.WriteInt(len(d))
  5151. buff.WriteBytes(d)
  5152. // --- [end][write][reference](time.Time) ---
  5153. // --- [begin][write][struct](Window) ---
  5154. buff.WriteInt(0) // [compatibility, unused]
  5155. errD := target.Window.MarshalBinaryWithContext(ctx)
  5156. if errD != nil {
  5157. return errD
  5158. }
  5159. // --- [end][write][struct](Window) ---
  5160. buff.WriteFloat64(target.Adjustment) // write float64
  5161. buff.WriteFloat64(target.Cost) // write float64
  5162. return nil
  5163. }
  5164. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5165. // the Network type
  5166. func (target *Network) UnmarshalBinary(data []byte) error {
  5167. var table []string
  5168. buff := util.NewBufferFromBytes(data)
  5169. // string table header validation
  5170. if isBinaryTag(data, BinaryTagStringTable) {
  5171. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  5172. tl := buff.ReadInt() // table length
  5173. if tl > 0 {
  5174. table = make([]string, tl, tl)
  5175. for i := 0; i < tl; i++ {
  5176. table[i] = buff.ReadString()
  5177. }
  5178. }
  5179. }
  5180. ctx := &DecodingContext{
  5181. Buffer: buff,
  5182. Table: table,
  5183. }
  5184. err := target.UnmarshalBinaryWithContext(ctx)
  5185. if err != nil {
  5186. return err
  5187. }
  5188. return nil
  5189. }
  5190. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5191. // the Network type
  5192. func (target *Network) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5193. // panics are recovered and propagated as errors
  5194. defer func() {
  5195. if r := recover(); r != nil {
  5196. if e, ok := r.(error); ok {
  5197. err = e
  5198. } else if s, ok := r.(string); ok {
  5199. err = fmt.Errorf("Unexpected panic: %s", s)
  5200. } else {
  5201. err = fmt.Errorf("Unexpected panic: %+v", r)
  5202. }
  5203. }
  5204. }()
  5205. buff := ctx.Buffer
  5206. version := buff.ReadUInt8()
  5207. if version > AssetsCodecVersion {
  5208. return fmt.Errorf("Invalid Version Unmarshaling Network. Expected %d or less, got %d", AssetsCodecVersion, version)
  5209. }
  5210. if buff.ReadUInt8() == uint8(0) {
  5211. target.Properties = nil
  5212. } else {
  5213. // --- [begin][read][struct](AssetProperties) ---
  5214. a := &AssetProperties{}
  5215. buff.ReadInt() // [compatibility, unused]
  5216. errA := a.UnmarshalBinaryWithContext(ctx)
  5217. if errA != nil {
  5218. return errA
  5219. }
  5220. target.Properties = a
  5221. // --- [end][read][struct](AssetProperties) ---
  5222. }
  5223. // --- [begin][read][alias](AssetLabels) ---
  5224. var b map[string]string
  5225. if buff.ReadUInt8() == uint8(0) {
  5226. b = nil
  5227. } else {
  5228. // --- [begin][read][map](map[string]string) ---
  5229. d := buff.ReadInt() // map len
  5230. c := make(map[string]string, d)
  5231. for i := 0; i < d; i++ {
  5232. var v string
  5233. var f string
  5234. if ctx.IsStringTable() {
  5235. g := buff.ReadInt() // read string index
  5236. f = ctx.Table[g]
  5237. } else {
  5238. f = buff.ReadString() // read string
  5239. }
  5240. e := f
  5241. v = e
  5242. var z string
  5243. var k string
  5244. if ctx.IsStringTable() {
  5245. l := buff.ReadInt() // read string index
  5246. k = ctx.Table[l]
  5247. } else {
  5248. k = buff.ReadString() // read string
  5249. }
  5250. h := k
  5251. z = h
  5252. c[v] = z
  5253. }
  5254. b = c
  5255. // --- [end][read][map](map[string]string) ---
  5256. }
  5257. target.Labels = AssetLabels(b)
  5258. // --- [end][read][alias](AssetLabels) ---
  5259. // --- [begin][read][reference](time.Time) ---
  5260. m := &time.Time{}
  5261. n := buff.ReadInt() // byte array length
  5262. o := buff.ReadBytes(n) // byte array
  5263. errB := m.UnmarshalBinary(o)
  5264. if errB != nil {
  5265. return errB
  5266. }
  5267. target.Start = *m
  5268. // --- [end][read][reference](time.Time) ---
  5269. // --- [begin][read][reference](time.Time) ---
  5270. p := &time.Time{}
  5271. q := buff.ReadInt() // byte array length
  5272. r := buff.ReadBytes(q) // byte array
  5273. errC := p.UnmarshalBinary(r)
  5274. if errC != nil {
  5275. return errC
  5276. }
  5277. target.End = *p
  5278. // --- [end][read][reference](time.Time) ---
  5279. // --- [begin][read][struct](Window) ---
  5280. s := &Window{}
  5281. buff.ReadInt() // [compatibility, unused]
  5282. errD := s.UnmarshalBinaryWithContext(ctx)
  5283. if errD != nil {
  5284. return errD
  5285. }
  5286. target.Window = *s
  5287. // --- [end][read][struct](Window) ---
  5288. t := buff.ReadFloat64() // read float64
  5289. target.Adjustment = t
  5290. u := buff.ReadFloat64() // read float64
  5291. target.Cost = u
  5292. return nil
  5293. }
  5294. //--------------------------------------------------------------------------
  5295. // Node
  5296. //--------------------------------------------------------------------------
  5297. // MarshalBinary serializes the internal properties of this Node instance
  5298. // into a byte array
  5299. func (target *Node) MarshalBinary() (data []byte, err error) {
  5300. ctx := &EncodingContext{
  5301. Buffer: util.NewBuffer(),
  5302. Table: nil,
  5303. }
  5304. e := target.MarshalBinaryWithContext(ctx)
  5305. if e != nil {
  5306. return nil, e
  5307. }
  5308. encBytes := ctx.Buffer.Bytes()
  5309. return encBytes, nil
  5310. }
  5311. // MarshalBinaryWithContext serializes the internal properties of this Node instance
  5312. // into a byte array leveraging a predefined context.
  5313. func (target *Node) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5314. // panics are recovered and propagated as errors
  5315. defer func() {
  5316. if r := recover(); r != nil {
  5317. if e, ok := r.(error); ok {
  5318. err = e
  5319. } else if s, ok := r.(string); ok {
  5320. err = fmt.Errorf("Unexpected panic: %s", s)
  5321. } else {
  5322. err = fmt.Errorf("Unexpected panic: %+v", r)
  5323. }
  5324. }
  5325. }()
  5326. buff := ctx.Buffer
  5327. buff.WriteUInt8(AssetsCodecVersion) // version
  5328. if target.Properties == nil {
  5329. buff.WriteUInt8(uint8(0)) // write nil byte
  5330. } else {
  5331. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5332. // --- [begin][write][struct](AssetProperties) ---
  5333. buff.WriteInt(0) // [compatibility, unused]
  5334. errA := target.Properties.MarshalBinaryWithContext(ctx)
  5335. if errA != nil {
  5336. return errA
  5337. }
  5338. // --- [end][write][struct](AssetProperties) ---
  5339. }
  5340. // --- [begin][write][alias](AssetLabels) ---
  5341. if map[string]string(target.Labels) == nil {
  5342. buff.WriteUInt8(uint8(0)) // write nil byte
  5343. } else {
  5344. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5345. // --- [begin][write][map](map[string]string) ---
  5346. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  5347. for v, z := range map[string]string(target.Labels) {
  5348. if ctx.IsStringTable() {
  5349. a := ctx.Table.AddOrGet(v)
  5350. buff.WriteInt(a) // write table index
  5351. } else {
  5352. buff.WriteString(v) // write string
  5353. }
  5354. if ctx.IsStringTable() {
  5355. b := ctx.Table.AddOrGet(z)
  5356. buff.WriteInt(b) // write table index
  5357. } else {
  5358. buff.WriteString(z) // write string
  5359. }
  5360. }
  5361. // --- [end][write][map](map[string]string) ---
  5362. }
  5363. // --- [end][write][alias](AssetLabels) ---
  5364. // --- [begin][write][reference](time.Time) ---
  5365. c, errB := target.Start.MarshalBinary()
  5366. if errB != nil {
  5367. return errB
  5368. }
  5369. buff.WriteInt(len(c))
  5370. buff.WriteBytes(c)
  5371. // --- [end][write][reference](time.Time) ---
  5372. // --- [begin][write][reference](time.Time) ---
  5373. d, errC := target.End.MarshalBinary()
  5374. if errC != nil {
  5375. return errC
  5376. }
  5377. buff.WriteInt(len(d))
  5378. buff.WriteBytes(d)
  5379. // --- [end][write][reference](time.Time) ---
  5380. // --- [begin][write][struct](Window) ---
  5381. buff.WriteInt(0) // [compatibility, unused]
  5382. errD := target.Window.MarshalBinaryWithContext(ctx)
  5383. if errD != nil {
  5384. return errD
  5385. }
  5386. // --- [end][write][struct](Window) ---
  5387. buff.WriteFloat64(target.Adjustment) // write float64
  5388. if ctx.IsStringTable() {
  5389. e := ctx.Table.AddOrGet(target.NodeType)
  5390. buff.WriteInt(e) // write table index
  5391. } else {
  5392. buff.WriteString(target.NodeType) // write string
  5393. }
  5394. buff.WriteFloat64(target.CPUCoreHours) // write float64
  5395. buff.WriteFloat64(target.RAMByteHours) // write float64
  5396. buff.WriteFloat64(target.GPUHours) // write float64
  5397. if target.CPUBreakdown == nil {
  5398. buff.WriteUInt8(uint8(0)) // write nil byte
  5399. } else {
  5400. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5401. // --- [begin][write][struct](Breakdown) ---
  5402. buff.WriteInt(0) // [compatibility, unused]
  5403. errE := target.CPUBreakdown.MarshalBinaryWithContext(ctx)
  5404. if errE != nil {
  5405. return errE
  5406. }
  5407. // --- [end][write][struct](Breakdown) ---
  5408. }
  5409. if target.RAMBreakdown == nil {
  5410. buff.WriteUInt8(uint8(0)) // write nil byte
  5411. } else {
  5412. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5413. // --- [begin][write][struct](Breakdown) ---
  5414. buff.WriteInt(0) // [compatibility, unused]
  5415. errF := target.RAMBreakdown.MarshalBinaryWithContext(ctx)
  5416. if errF != nil {
  5417. return errF
  5418. }
  5419. // --- [end][write][struct](Breakdown) ---
  5420. }
  5421. buff.WriteFloat64(target.CPUCost) // write float64
  5422. buff.WriteFloat64(target.GPUCost) // write float64
  5423. buff.WriteFloat64(target.GPUCount) // write float64
  5424. buff.WriteFloat64(target.RAMCost) // write float64
  5425. buff.WriteFloat64(target.Discount) // write float64
  5426. buff.WriteFloat64(target.Preemptible) // write float64
  5427. if target.Overhead == nil {
  5428. buff.WriteUInt8(uint8(0)) // write nil byte
  5429. } else {
  5430. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5431. // --- [begin][write][struct](NodeOverhead) ---
  5432. buff.WriteInt(0) // [compatibility, unused]
  5433. errG := target.Overhead.MarshalBinaryWithContext(ctx)
  5434. if errG != nil {
  5435. return errG
  5436. }
  5437. // --- [end][write][struct](NodeOverhead) ---
  5438. }
  5439. return nil
  5440. }
  5441. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5442. // the Node type
  5443. func (target *Node) UnmarshalBinary(data []byte) error {
  5444. var table []string
  5445. buff := util.NewBufferFromBytes(data)
  5446. // string table header validation
  5447. if isBinaryTag(data, BinaryTagStringTable) {
  5448. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  5449. tl := buff.ReadInt() // table length
  5450. if tl > 0 {
  5451. table = make([]string, tl, tl)
  5452. for i := 0; i < tl; i++ {
  5453. table[i] = buff.ReadString()
  5454. }
  5455. }
  5456. }
  5457. ctx := &DecodingContext{
  5458. Buffer: buff,
  5459. Table: table,
  5460. }
  5461. err := target.UnmarshalBinaryWithContext(ctx)
  5462. if err != nil {
  5463. return err
  5464. }
  5465. return nil
  5466. }
  5467. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5468. // the Node type
  5469. func (target *Node) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5470. // panics are recovered and propagated as errors
  5471. defer func() {
  5472. if r := recover(); r != nil {
  5473. if e, ok := r.(error); ok {
  5474. err = e
  5475. } else if s, ok := r.(string); ok {
  5476. err = fmt.Errorf("Unexpected panic: %s", s)
  5477. } else {
  5478. err = fmt.Errorf("Unexpected panic: %+v", r)
  5479. }
  5480. }
  5481. }()
  5482. buff := ctx.Buffer
  5483. version := buff.ReadUInt8()
  5484. if version > AssetsCodecVersion {
  5485. return fmt.Errorf("Invalid Version Unmarshaling Node. Expected %d or less, got %d", AssetsCodecVersion, version)
  5486. }
  5487. if buff.ReadUInt8() == uint8(0) {
  5488. target.Properties = nil
  5489. } else {
  5490. // --- [begin][read][struct](AssetProperties) ---
  5491. a := &AssetProperties{}
  5492. buff.ReadInt() // [compatibility, unused]
  5493. errA := a.UnmarshalBinaryWithContext(ctx)
  5494. if errA != nil {
  5495. return errA
  5496. }
  5497. target.Properties = a
  5498. // --- [end][read][struct](AssetProperties) ---
  5499. }
  5500. // --- [begin][read][alias](AssetLabels) ---
  5501. var b map[string]string
  5502. if buff.ReadUInt8() == uint8(0) {
  5503. b = nil
  5504. } else {
  5505. // --- [begin][read][map](map[string]string) ---
  5506. d := buff.ReadInt() // map len
  5507. c := make(map[string]string, d)
  5508. for i := 0; i < d; i++ {
  5509. var v string
  5510. var f string
  5511. if ctx.IsStringTable() {
  5512. g := buff.ReadInt() // read string index
  5513. f = ctx.Table[g]
  5514. } else {
  5515. f = buff.ReadString() // read string
  5516. }
  5517. e := f
  5518. v = e
  5519. var z string
  5520. var k string
  5521. if ctx.IsStringTable() {
  5522. l := buff.ReadInt() // read string index
  5523. k = ctx.Table[l]
  5524. } else {
  5525. k = buff.ReadString() // read string
  5526. }
  5527. h := k
  5528. z = h
  5529. c[v] = z
  5530. }
  5531. b = c
  5532. // --- [end][read][map](map[string]string) ---
  5533. }
  5534. target.Labels = AssetLabels(b)
  5535. // --- [end][read][alias](AssetLabels) ---
  5536. // --- [begin][read][reference](time.Time) ---
  5537. m := &time.Time{}
  5538. n := buff.ReadInt() // byte array length
  5539. o := buff.ReadBytes(n) // byte array
  5540. errB := m.UnmarshalBinary(o)
  5541. if errB != nil {
  5542. return errB
  5543. }
  5544. target.Start = *m
  5545. // --- [end][read][reference](time.Time) ---
  5546. // --- [begin][read][reference](time.Time) ---
  5547. p := &time.Time{}
  5548. q := buff.ReadInt() // byte array length
  5549. r := buff.ReadBytes(q) // byte array
  5550. errC := p.UnmarshalBinary(r)
  5551. if errC != nil {
  5552. return errC
  5553. }
  5554. target.End = *p
  5555. // --- [end][read][reference](time.Time) ---
  5556. // --- [begin][read][struct](Window) ---
  5557. s := &Window{}
  5558. buff.ReadInt() // [compatibility, unused]
  5559. errD := s.UnmarshalBinaryWithContext(ctx)
  5560. if errD != nil {
  5561. return errD
  5562. }
  5563. target.Window = *s
  5564. // --- [end][read][struct](Window) ---
  5565. t := buff.ReadFloat64() // read float64
  5566. target.Adjustment = t
  5567. var w string
  5568. if ctx.IsStringTable() {
  5569. x := buff.ReadInt() // read string index
  5570. w = ctx.Table[x]
  5571. } else {
  5572. w = buff.ReadString() // read string
  5573. }
  5574. u := w
  5575. target.NodeType = u
  5576. y := buff.ReadFloat64() // read float64
  5577. target.CPUCoreHours = y
  5578. aa := buff.ReadFloat64() // read float64
  5579. target.RAMByteHours = aa
  5580. bb := buff.ReadFloat64() // read float64
  5581. target.GPUHours = bb
  5582. if buff.ReadUInt8() == uint8(0) {
  5583. target.CPUBreakdown = nil
  5584. } else {
  5585. // --- [begin][read][struct](Breakdown) ---
  5586. cc := &Breakdown{}
  5587. buff.ReadInt() // [compatibility, unused]
  5588. errE := cc.UnmarshalBinaryWithContext(ctx)
  5589. if errE != nil {
  5590. return errE
  5591. }
  5592. target.CPUBreakdown = cc
  5593. // --- [end][read][struct](Breakdown) ---
  5594. }
  5595. if buff.ReadUInt8() == uint8(0) {
  5596. target.RAMBreakdown = nil
  5597. } else {
  5598. // --- [begin][read][struct](Breakdown) ---
  5599. dd := &Breakdown{}
  5600. buff.ReadInt() // [compatibility, unused]
  5601. errF := dd.UnmarshalBinaryWithContext(ctx)
  5602. if errF != nil {
  5603. return errF
  5604. }
  5605. target.RAMBreakdown = dd
  5606. // --- [end][read][struct](Breakdown) ---
  5607. }
  5608. ee := buff.ReadFloat64() // read float64
  5609. target.CPUCost = ee
  5610. ff := buff.ReadFloat64() // read float64
  5611. target.GPUCost = ff
  5612. gg := buff.ReadFloat64() // read float64
  5613. target.GPUCount = gg
  5614. hh := buff.ReadFloat64() // read float64
  5615. target.RAMCost = hh
  5616. kk := buff.ReadFloat64() // read float64
  5617. target.Discount = kk
  5618. ll := buff.ReadFloat64() // read float64
  5619. target.Preemptible = ll
  5620. // field version check
  5621. if uint8(19) <= version {
  5622. if buff.ReadUInt8() == uint8(0) {
  5623. target.Overhead = nil
  5624. } else {
  5625. // --- [begin][read][struct](NodeOverhead) ---
  5626. mm := &NodeOverhead{}
  5627. buff.ReadInt() // [compatibility, unused]
  5628. errG := mm.UnmarshalBinaryWithContext(ctx)
  5629. if errG != nil {
  5630. return errG
  5631. }
  5632. target.Overhead = mm
  5633. // --- [end][read][struct](NodeOverhead) ---
  5634. }
  5635. } else {
  5636. target.Overhead = nil
  5637. }
  5638. return nil
  5639. }
  5640. //--------------------------------------------------------------------------
  5641. // NodeOverhead
  5642. //--------------------------------------------------------------------------
  5643. // MarshalBinary serializes the internal properties of this NodeOverhead instance
  5644. // into a byte array
  5645. func (target *NodeOverhead) MarshalBinary() (data []byte, err error) {
  5646. ctx := &EncodingContext{
  5647. Buffer: util.NewBuffer(),
  5648. Table: nil,
  5649. }
  5650. e := target.MarshalBinaryWithContext(ctx)
  5651. if e != nil {
  5652. return nil, e
  5653. }
  5654. encBytes := ctx.Buffer.Bytes()
  5655. return encBytes, nil
  5656. }
  5657. // MarshalBinaryWithContext serializes the internal properties of this NodeOverhead instance
  5658. // into a byte array leveraging a predefined context.
  5659. func (target *NodeOverhead) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5660. // panics are recovered and propagated as errors
  5661. defer func() {
  5662. if r := recover(); r != nil {
  5663. if e, ok := r.(error); ok {
  5664. err = e
  5665. } else if s, ok := r.(string); ok {
  5666. err = fmt.Errorf("Unexpected panic: %s", s)
  5667. } else {
  5668. err = fmt.Errorf("Unexpected panic: %+v", r)
  5669. }
  5670. }
  5671. }()
  5672. buff := ctx.Buffer
  5673. buff.WriteUInt8(AssetsCodecVersion) // version
  5674. buff.WriteFloat64(target.CpuOverheadFraction) // write float64
  5675. buff.WriteFloat64(target.RamOverheadFraction) // write float64
  5676. buff.WriteFloat64(target.OverheadCostFraction) // write float64
  5677. return nil
  5678. }
  5679. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5680. // the NodeOverhead type
  5681. func (target *NodeOverhead) UnmarshalBinary(data []byte) error {
  5682. var table []string
  5683. buff := util.NewBufferFromBytes(data)
  5684. // string table header validation
  5685. if isBinaryTag(data, BinaryTagStringTable) {
  5686. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  5687. tl := buff.ReadInt() // table length
  5688. if tl > 0 {
  5689. table = make([]string, tl, tl)
  5690. for i := 0; i < tl; i++ {
  5691. table[i] = buff.ReadString()
  5692. }
  5693. }
  5694. }
  5695. ctx := &DecodingContext{
  5696. Buffer: buff,
  5697. Table: table,
  5698. }
  5699. err := target.UnmarshalBinaryWithContext(ctx)
  5700. if err != nil {
  5701. return err
  5702. }
  5703. return nil
  5704. }
  5705. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5706. // the NodeOverhead type
  5707. func (target *NodeOverhead) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5708. // panics are recovered and propagated as errors
  5709. defer func() {
  5710. if r := recover(); r != nil {
  5711. if e, ok := r.(error); ok {
  5712. err = e
  5713. } else if s, ok := r.(string); ok {
  5714. err = fmt.Errorf("Unexpected panic: %s", s)
  5715. } else {
  5716. err = fmt.Errorf("Unexpected panic: %+v", r)
  5717. }
  5718. }
  5719. }()
  5720. buff := ctx.Buffer
  5721. version := buff.ReadUInt8()
  5722. if version > AssetsCodecVersion {
  5723. return fmt.Errorf("Invalid Version Unmarshaling NodeOverhead. Expected %d or less, got %d", AssetsCodecVersion, version)
  5724. }
  5725. a := buff.ReadFloat64() // read float64
  5726. target.CpuOverheadFraction = a
  5727. b := buff.ReadFloat64() // read float64
  5728. target.RamOverheadFraction = b
  5729. c := buff.ReadFloat64() // read float64
  5730. target.OverheadCostFraction = c
  5731. return nil
  5732. }
  5733. //--------------------------------------------------------------------------
  5734. // PVAllocation
  5735. //--------------------------------------------------------------------------
  5736. // MarshalBinary serializes the internal properties of this PVAllocation instance
  5737. // into a byte array
  5738. func (target *PVAllocation) MarshalBinary() (data []byte, err error) {
  5739. ctx := &EncodingContext{
  5740. Buffer: util.NewBuffer(),
  5741. Table: nil,
  5742. }
  5743. e := target.MarshalBinaryWithContext(ctx)
  5744. if e != nil {
  5745. return nil, e
  5746. }
  5747. encBytes := ctx.Buffer.Bytes()
  5748. return encBytes, nil
  5749. }
  5750. // MarshalBinaryWithContext serializes the internal properties of this PVAllocation instance
  5751. // into a byte array leveraging a predefined context.
  5752. func (target *PVAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5753. // panics are recovered and propagated as errors
  5754. defer func() {
  5755. if r := recover(); r != nil {
  5756. if e, ok := r.(error); ok {
  5757. err = e
  5758. } else if s, ok := r.(string); ok {
  5759. err = fmt.Errorf("Unexpected panic: %s", s)
  5760. } else {
  5761. err = fmt.Errorf("Unexpected panic: %+v", r)
  5762. }
  5763. }
  5764. }()
  5765. buff := ctx.Buffer
  5766. buff.WriteUInt8(AllocationCodecVersion) // version
  5767. buff.WriteFloat64(target.ByteHours) // write float64
  5768. buff.WriteFloat64(target.Cost) // write float64
  5769. if ctx.IsStringTable() {
  5770. a := ctx.Table.AddOrGet(target.ProviderID)
  5771. buff.WriteInt(a) // write table index
  5772. } else {
  5773. buff.WriteString(target.ProviderID) // write string
  5774. }
  5775. return nil
  5776. }
  5777. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5778. // the PVAllocation type
  5779. func (target *PVAllocation) UnmarshalBinary(data []byte) error {
  5780. var table []string
  5781. buff := util.NewBufferFromBytes(data)
  5782. // string table header validation
  5783. if isBinaryTag(data, BinaryTagStringTable) {
  5784. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  5785. tl := buff.ReadInt() // table length
  5786. if tl > 0 {
  5787. table = make([]string, tl, tl)
  5788. for i := 0; i < tl; i++ {
  5789. table[i] = buff.ReadString()
  5790. }
  5791. }
  5792. }
  5793. ctx := &DecodingContext{
  5794. Buffer: buff,
  5795. Table: table,
  5796. }
  5797. err := target.UnmarshalBinaryWithContext(ctx)
  5798. if err != nil {
  5799. return err
  5800. }
  5801. return nil
  5802. }
  5803. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5804. // the PVAllocation type
  5805. func (target *PVAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5806. // panics are recovered and propagated as errors
  5807. defer func() {
  5808. if r := recover(); r != nil {
  5809. if e, ok := r.(error); ok {
  5810. err = e
  5811. } else if s, ok := r.(string); ok {
  5812. err = fmt.Errorf("Unexpected panic: %s", s)
  5813. } else {
  5814. err = fmt.Errorf("Unexpected panic: %+v", r)
  5815. }
  5816. }
  5817. }()
  5818. buff := ctx.Buffer
  5819. version := buff.ReadUInt8()
  5820. if version > AllocationCodecVersion {
  5821. return fmt.Errorf("Invalid Version Unmarshaling PVAllocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  5822. }
  5823. a := buff.ReadFloat64() // read float64
  5824. target.ByteHours = a
  5825. b := buff.ReadFloat64() // read float64
  5826. target.Cost = b
  5827. // field version check
  5828. if uint8(20) <= version {
  5829. var d string
  5830. if ctx.IsStringTable() {
  5831. e := buff.ReadInt() // read string index
  5832. d = ctx.Table[e]
  5833. } else {
  5834. d = buff.ReadString() // read string
  5835. }
  5836. c := d
  5837. target.ProviderID = c
  5838. } else {
  5839. target.ProviderID = "" // default
  5840. }
  5841. return nil
  5842. }
  5843. //--------------------------------------------------------------------------
  5844. // PVKey
  5845. //--------------------------------------------------------------------------
  5846. // MarshalBinary serializes the internal properties of this PVKey instance
  5847. // into a byte array
  5848. func (target *PVKey) MarshalBinary() (data []byte, err error) {
  5849. ctx := &EncodingContext{
  5850. Buffer: util.NewBuffer(),
  5851. Table: nil,
  5852. }
  5853. e := target.MarshalBinaryWithContext(ctx)
  5854. if e != nil {
  5855. return nil, e
  5856. }
  5857. encBytes := ctx.Buffer.Bytes()
  5858. return encBytes, nil
  5859. }
  5860. // MarshalBinaryWithContext serializes the internal properties of this PVKey instance
  5861. // into a byte array leveraging a predefined context.
  5862. func (target *PVKey) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5863. // panics are recovered and propagated as errors
  5864. defer func() {
  5865. if r := recover(); r != nil {
  5866. if e, ok := r.(error); ok {
  5867. err = e
  5868. } else if s, ok := r.(string); ok {
  5869. err = fmt.Errorf("Unexpected panic: %s", s)
  5870. } else {
  5871. err = fmt.Errorf("Unexpected panic: %+v", r)
  5872. }
  5873. }
  5874. }()
  5875. buff := ctx.Buffer
  5876. buff.WriteUInt8(AllocationCodecVersion) // version
  5877. if ctx.IsStringTable() {
  5878. a := ctx.Table.AddOrGet(target.Cluster)
  5879. buff.WriteInt(a) // write table index
  5880. } else {
  5881. buff.WriteString(target.Cluster) // write string
  5882. }
  5883. if ctx.IsStringTable() {
  5884. b := ctx.Table.AddOrGet(target.Name)
  5885. buff.WriteInt(b) // write table index
  5886. } else {
  5887. buff.WriteString(target.Name) // write string
  5888. }
  5889. return nil
  5890. }
  5891. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5892. // the PVKey type
  5893. func (target *PVKey) UnmarshalBinary(data []byte) error {
  5894. var table []string
  5895. buff := util.NewBufferFromBytes(data)
  5896. // string table header validation
  5897. if isBinaryTag(data, BinaryTagStringTable) {
  5898. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  5899. tl := buff.ReadInt() // table length
  5900. if tl > 0 {
  5901. table = make([]string, tl, tl)
  5902. for i := 0; i < tl; i++ {
  5903. table[i] = buff.ReadString()
  5904. }
  5905. }
  5906. }
  5907. ctx := &DecodingContext{
  5908. Buffer: buff,
  5909. Table: table,
  5910. }
  5911. err := target.UnmarshalBinaryWithContext(ctx)
  5912. if err != nil {
  5913. return err
  5914. }
  5915. return nil
  5916. }
  5917. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5918. // the PVKey type
  5919. func (target *PVKey) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5920. // panics are recovered and propagated as errors
  5921. defer func() {
  5922. if r := recover(); r != nil {
  5923. if e, ok := r.(error); ok {
  5924. err = e
  5925. } else if s, ok := r.(string); ok {
  5926. err = fmt.Errorf("Unexpected panic: %s", s)
  5927. } else {
  5928. err = fmt.Errorf("Unexpected panic: %+v", r)
  5929. }
  5930. }
  5931. }()
  5932. buff := ctx.Buffer
  5933. version := buff.ReadUInt8()
  5934. if version > AllocationCodecVersion {
  5935. return fmt.Errorf("Invalid Version Unmarshaling PVKey. Expected %d or less, got %d", AllocationCodecVersion, version)
  5936. }
  5937. var b string
  5938. if ctx.IsStringTable() {
  5939. c := buff.ReadInt() // read string index
  5940. b = ctx.Table[c]
  5941. } else {
  5942. b = buff.ReadString() // read string
  5943. }
  5944. a := b
  5945. target.Cluster = a
  5946. var e string
  5947. if ctx.IsStringTable() {
  5948. f := buff.ReadInt() // read string index
  5949. e = ctx.Table[f]
  5950. } else {
  5951. e = buff.ReadString() // read string
  5952. }
  5953. d := e
  5954. target.Name = d
  5955. return nil
  5956. }
  5957. //--------------------------------------------------------------------------
  5958. // RawAllocationOnlyData
  5959. //--------------------------------------------------------------------------
  5960. // MarshalBinary serializes the internal properties of this RawAllocationOnlyData instance
  5961. // into a byte array
  5962. func (target *RawAllocationOnlyData) MarshalBinary() (data []byte, err error) {
  5963. ctx := &EncodingContext{
  5964. Buffer: util.NewBuffer(),
  5965. Table: nil,
  5966. }
  5967. e := target.MarshalBinaryWithContext(ctx)
  5968. if e != nil {
  5969. return nil, e
  5970. }
  5971. encBytes := ctx.Buffer.Bytes()
  5972. return encBytes, nil
  5973. }
  5974. // MarshalBinaryWithContext serializes the internal properties of this RawAllocationOnlyData instance
  5975. // into a byte array leveraging a predefined context.
  5976. func (target *RawAllocationOnlyData) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5977. // panics are recovered and propagated as errors
  5978. defer func() {
  5979. if r := recover(); r != nil {
  5980. if e, ok := r.(error); ok {
  5981. err = e
  5982. } else if s, ok := r.(string); ok {
  5983. err = fmt.Errorf("Unexpected panic: %s", s)
  5984. } else {
  5985. err = fmt.Errorf("Unexpected panic: %+v", r)
  5986. }
  5987. }
  5988. }()
  5989. buff := ctx.Buffer
  5990. buff.WriteUInt8(AllocationCodecVersion) // version
  5991. buff.WriteFloat64(target.CPUCoreUsageMax) // write float64
  5992. buff.WriteFloat64(target.RAMBytesUsageMax) // write float64
  5993. return nil
  5994. }
  5995. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5996. // the RawAllocationOnlyData type
  5997. func (target *RawAllocationOnlyData) UnmarshalBinary(data []byte) error {
  5998. var table []string
  5999. buff := util.NewBufferFromBytes(data)
  6000. // string table header validation
  6001. if isBinaryTag(data, BinaryTagStringTable) {
  6002. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  6003. tl := buff.ReadInt() // table length
  6004. if tl > 0 {
  6005. table = make([]string, tl, tl)
  6006. for i := 0; i < tl; i++ {
  6007. table[i] = buff.ReadString()
  6008. }
  6009. }
  6010. }
  6011. ctx := &DecodingContext{
  6012. Buffer: buff,
  6013. Table: table,
  6014. }
  6015. err := target.UnmarshalBinaryWithContext(ctx)
  6016. if err != nil {
  6017. return err
  6018. }
  6019. return nil
  6020. }
  6021. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  6022. // the RawAllocationOnlyData type
  6023. func (target *RawAllocationOnlyData) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  6024. // panics are recovered and propagated as errors
  6025. defer func() {
  6026. if r := recover(); r != nil {
  6027. if e, ok := r.(error); ok {
  6028. err = e
  6029. } else if s, ok := r.(string); ok {
  6030. err = fmt.Errorf("Unexpected panic: %s", s)
  6031. } else {
  6032. err = fmt.Errorf("Unexpected panic: %+v", r)
  6033. }
  6034. }
  6035. }()
  6036. buff := ctx.Buffer
  6037. version := buff.ReadUInt8()
  6038. if version > AllocationCodecVersion {
  6039. return fmt.Errorf("Invalid Version Unmarshaling RawAllocationOnlyData. Expected %d or less, got %d", AllocationCodecVersion, version)
  6040. }
  6041. a := buff.ReadFloat64() // read float64
  6042. target.CPUCoreUsageMax = a
  6043. b := buff.ReadFloat64() // read float64
  6044. target.RAMBytesUsageMax = b
  6045. return nil
  6046. }
  6047. //--------------------------------------------------------------------------
  6048. // SharedAsset
  6049. //--------------------------------------------------------------------------
  6050. // MarshalBinary serializes the internal properties of this SharedAsset instance
  6051. // into a byte array
  6052. func (target *SharedAsset) MarshalBinary() (data []byte, err error) {
  6053. ctx := &EncodingContext{
  6054. Buffer: util.NewBuffer(),
  6055. Table: nil,
  6056. }
  6057. e := target.MarshalBinaryWithContext(ctx)
  6058. if e != nil {
  6059. return nil, e
  6060. }
  6061. encBytes := ctx.Buffer.Bytes()
  6062. return encBytes, nil
  6063. }
  6064. // MarshalBinaryWithContext serializes the internal properties of this SharedAsset instance
  6065. // into a byte array leveraging a predefined context.
  6066. func (target *SharedAsset) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  6067. // panics are recovered and propagated as errors
  6068. defer func() {
  6069. if r := recover(); r != nil {
  6070. if e, ok := r.(error); ok {
  6071. err = e
  6072. } else if s, ok := r.(string); ok {
  6073. err = fmt.Errorf("Unexpected panic: %s", s)
  6074. } else {
  6075. err = fmt.Errorf("Unexpected panic: %+v", r)
  6076. }
  6077. }
  6078. }()
  6079. buff := ctx.Buffer
  6080. buff.WriteUInt8(AssetsCodecVersion) // version
  6081. if target.Properties == nil {
  6082. buff.WriteUInt8(uint8(0)) // write nil byte
  6083. } else {
  6084. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6085. // --- [begin][write][struct](AssetProperties) ---
  6086. buff.WriteInt(0) // [compatibility, unused]
  6087. errA := target.Properties.MarshalBinaryWithContext(ctx)
  6088. if errA != nil {
  6089. return errA
  6090. }
  6091. // --- [end][write][struct](AssetProperties) ---
  6092. }
  6093. // --- [begin][write][alias](AssetLabels) ---
  6094. if map[string]string(target.Labels) == nil {
  6095. buff.WriteUInt8(uint8(0)) // write nil byte
  6096. } else {
  6097. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6098. // --- [begin][write][map](map[string]string) ---
  6099. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  6100. for v, z := range map[string]string(target.Labels) {
  6101. if ctx.IsStringTable() {
  6102. a := ctx.Table.AddOrGet(v)
  6103. buff.WriteInt(a) // write table index
  6104. } else {
  6105. buff.WriteString(v) // write string
  6106. }
  6107. if ctx.IsStringTable() {
  6108. b := ctx.Table.AddOrGet(z)
  6109. buff.WriteInt(b) // write table index
  6110. } else {
  6111. buff.WriteString(z) // write string
  6112. }
  6113. }
  6114. // --- [end][write][map](map[string]string) ---
  6115. }
  6116. // --- [end][write][alias](AssetLabels) ---
  6117. // --- [begin][write][struct](Window) ---
  6118. buff.WriteInt(0) // [compatibility, unused]
  6119. errB := target.Window.MarshalBinaryWithContext(ctx)
  6120. if errB != nil {
  6121. return errB
  6122. }
  6123. // --- [end][write][struct](Window) ---
  6124. buff.WriteFloat64(target.Cost) // write float64
  6125. return nil
  6126. }
  6127. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  6128. // the SharedAsset type
  6129. func (target *SharedAsset) UnmarshalBinary(data []byte) error {
  6130. var table []string
  6131. buff := util.NewBufferFromBytes(data)
  6132. // string table header validation
  6133. if isBinaryTag(data, BinaryTagStringTable) {
  6134. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  6135. tl := buff.ReadInt() // table length
  6136. if tl > 0 {
  6137. table = make([]string, tl, tl)
  6138. for i := 0; i < tl; i++ {
  6139. table[i] = buff.ReadString()
  6140. }
  6141. }
  6142. }
  6143. ctx := &DecodingContext{
  6144. Buffer: buff,
  6145. Table: table,
  6146. }
  6147. err := target.UnmarshalBinaryWithContext(ctx)
  6148. if err != nil {
  6149. return err
  6150. }
  6151. return nil
  6152. }
  6153. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  6154. // the SharedAsset type
  6155. func (target *SharedAsset) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  6156. // panics are recovered and propagated as errors
  6157. defer func() {
  6158. if r := recover(); r != nil {
  6159. if e, ok := r.(error); ok {
  6160. err = e
  6161. } else if s, ok := r.(string); ok {
  6162. err = fmt.Errorf("Unexpected panic: %s", s)
  6163. } else {
  6164. err = fmt.Errorf("Unexpected panic: %+v", r)
  6165. }
  6166. }
  6167. }()
  6168. buff := ctx.Buffer
  6169. version := buff.ReadUInt8()
  6170. if version > AssetsCodecVersion {
  6171. return fmt.Errorf("Invalid Version Unmarshaling SharedAsset. Expected %d or less, got %d", AssetsCodecVersion, version)
  6172. }
  6173. if buff.ReadUInt8() == uint8(0) {
  6174. target.Properties = nil
  6175. } else {
  6176. // --- [begin][read][struct](AssetProperties) ---
  6177. a := &AssetProperties{}
  6178. buff.ReadInt() // [compatibility, unused]
  6179. errA := a.UnmarshalBinaryWithContext(ctx)
  6180. if errA != nil {
  6181. return errA
  6182. }
  6183. target.Properties = a
  6184. // --- [end][read][struct](AssetProperties) ---
  6185. }
  6186. // --- [begin][read][alias](AssetLabels) ---
  6187. var b map[string]string
  6188. if buff.ReadUInt8() == uint8(0) {
  6189. b = nil
  6190. } else {
  6191. // --- [begin][read][map](map[string]string) ---
  6192. d := buff.ReadInt() // map len
  6193. c := make(map[string]string, d)
  6194. for i := 0; i < d; i++ {
  6195. var v string
  6196. var f string
  6197. if ctx.IsStringTable() {
  6198. g := buff.ReadInt() // read string index
  6199. f = ctx.Table[g]
  6200. } else {
  6201. f = buff.ReadString() // read string
  6202. }
  6203. e := f
  6204. v = e
  6205. var z string
  6206. var k string
  6207. if ctx.IsStringTable() {
  6208. l := buff.ReadInt() // read string index
  6209. k = ctx.Table[l]
  6210. } else {
  6211. k = buff.ReadString() // read string
  6212. }
  6213. h := k
  6214. z = h
  6215. c[v] = z
  6216. }
  6217. b = c
  6218. // --- [end][read][map](map[string]string) ---
  6219. }
  6220. target.Labels = AssetLabels(b)
  6221. // --- [end][read][alias](AssetLabels) ---
  6222. // --- [begin][read][struct](Window) ---
  6223. m := &Window{}
  6224. buff.ReadInt() // [compatibility, unused]
  6225. errB := m.UnmarshalBinaryWithContext(ctx)
  6226. if errB != nil {
  6227. return errB
  6228. }
  6229. target.Window = *m
  6230. // --- [end][read][struct](Window) ---
  6231. n := buff.ReadFloat64() // read float64
  6232. target.Cost = n
  6233. return nil
  6234. }
  6235. //--------------------------------------------------------------------------
  6236. // Window
  6237. //--------------------------------------------------------------------------
  6238. // MarshalBinary serializes the internal properties of this Window instance
  6239. // into a byte array
  6240. func (target *Window) MarshalBinary() (data []byte, err error) {
  6241. ctx := &EncodingContext{
  6242. Buffer: util.NewBuffer(),
  6243. Table: nil,
  6244. }
  6245. e := target.MarshalBinaryWithContext(ctx)
  6246. if e != nil {
  6247. return nil, e
  6248. }
  6249. encBytes := ctx.Buffer.Bytes()
  6250. return encBytes, nil
  6251. }
  6252. // MarshalBinaryWithContext serializes the internal properties of this Window instance
  6253. // into a byte array leveraging a predefined context.
  6254. func (target *Window) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  6255. // panics are recovered and propagated as errors
  6256. defer func() {
  6257. if r := recover(); r != nil {
  6258. if e, ok := r.(error); ok {
  6259. err = e
  6260. } else if s, ok := r.(string); ok {
  6261. err = fmt.Errorf("Unexpected panic: %s", s)
  6262. } else {
  6263. err = fmt.Errorf("Unexpected panic: %+v", r)
  6264. }
  6265. }
  6266. }()
  6267. buff := ctx.Buffer
  6268. buff.WriteUInt8(DefaultCodecVersion) // version
  6269. if target.start == nil {
  6270. buff.WriteUInt8(uint8(0)) // write nil byte
  6271. } else {
  6272. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6273. // --- [begin][write][reference](time.Time) ---
  6274. a, errA := target.start.MarshalBinary()
  6275. if errA != nil {
  6276. return errA
  6277. }
  6278. buff.WriteInt(len(a))
  6279. buff.WriteBytes(a)
  6280. // --- [end][write][reference](time.Time) ---
  6281. }
  6282. if target.end == nil {
  6283. buff.WriteUInt8(uint8(0)) // write nil byte
  6284. } else {
  6285. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6286. // --- [begin][write][reference](time.Time) ---
  6287. b, errB := target.end.MarshalBinary()
  6288. if errB != nil {
  6289. return errB
  6290. }
  6291. buff.WriteInt(len(b))
  6292. buff.WriteBytes(b)
  6293. // --- [end][write][reference](time.Time) ---
  6294. }
  6295. return nil
  6296. }
  6297. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  6298. // the Window type
  6299. func (target *Window) UnmarshalBinary(data []byte) error {
  6300. var table []string
  6301. buff := util.NewBufferFromBytes(data)
  6302. // string table header validation
  6303. if isBinaryTag(data, BinaryTagStringTable) {
  6304. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  6305. tl := buff.ReadInt() // table length
  6306. if tl > 0 {
  6307. table = make([]string, tl, tl)
  6308. for i := 0; i < tl; i++ {
  6309. table[i] = buff.ReadString()
  6310. }
  6311. }
  6312. }
  6313. ctx := &DecodingContext{
  6314. Buffer: buff,
  6315. Table: table,
  6316. }
  6317. err := target.UnmarshalBinaryWithContext(ctx)
  6318. if err != nil {
  6319. return err
  6320. }
  6321. return nil
  6322. }
  6323. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  6324. // the Window type
  6325. func (target *Window) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  6326. // panics are recovered and propagated as errors
  6327. defer func() {
  6328. if r := recover(); r != nil {
  6329. if e, ok := r.(error); ok {
  6330. err = e
  6331. } else if s, ok := r.(string); ok {
  6332. err = fmt.Errorf("Unexpected panic: %s", s)
  6333. } else {
  6334. err = fmt.Errorf("Unexpected panic: %+v", r)
  6335. }
  6336. }
  6337. }()
  6338. buff := ctx.Buffer
  6339. version := buff.ReadUInt8()
  6340. if version > DefaultCodecVersion {
  6341. return fmt.Errorf("Invalid Version Unmarshaling Window. Expected %d or less, got %d", DefaultCodecVersion, version)
  6342. }
  6343. if buff.ReadUInt8() == uint8(0) {
  6344. target.start = nil
  6345. } else {
  6346. // --- [begin][read][reference](time.Time) ---
  6347. a := &time.Time{}
  6348. b := buff.ReadInt() // byte array length
  6349. c := buff.ReadBytes(b) // byte array
  6350. errA := a.UnmarshalBinary(c)
  6351. if errA != nil {
  6352. return errA
  6353. }
  6354. target.start = a
  6355. // --- [end][read][reference](time.Time) ---
  6356. }
  6357. if buff.ReadUInt8() == uint8(0) {
  6358. target.end = nil
  6359. } else {
  6360. // --- [begin][read][reference](time.Time) ---
  6361. d := &time.Time{}
  6362. e := buff.ReadInt() // byte array length
  6363. f := buff.ReadBytes(e) // byte array
  6364. errB := d.UnmarshalBinary(f)
  6365. if errB != nil {
  6366. return errB
  6367. }
  6368. target.end = d
  6369. // --- [end][read][reference](time.Time) ---
  6370. }
  6371. return nil
  6372. }