opencost_codecs.go 246 KB

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