opencost_codecs.go 189 KB

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