opencost_codecs.go 203 KB

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