opencost_codecs.go 249 KB

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