opencost_codecs.go 238 KB

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