opencost_codecs.go 242 KB

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