opencost_codecs.go 187 KB

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