opencost_codecs.go 227 KB

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