opencost_codecs.go 176 KB

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