opencost_codecs.go 187 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369
  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. "reflect"
  15. "strings"
  16. "sync"
  17. "time"
  18. util "github.com/opencost/opencost/core/pkg/util"
  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 = 2
  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.InvoiceEntityID)
  3122. buff.WriteInt(d) // write table index
  3123. } else {
  3124. buff.WriteString(target.InvoiceEntityID) // write string
  3125. }
  3126. if ctx.IsStringTable() {
  3127. e := ctx.Table.AddOrGet(target.Service)
  3128. buff.WriteInt(e) // write table index
  3129. } else {
  3130. buff.WriteString(target.Service) // write string
  3131. }
  3132. if ctx.IsStringTable() {
  3133. f := ctx.Table.AddOrGet(target.Category)
  3134. buff.WriteInt(f) // write table index
  3135. } else {
  3136. buff.WriteString(target.Category) // write string
  3137. }
  3138. // --- [begin][write][alias](CloudCostLabels) ---
  3139. if map[string]string(target.Labels) == nil {
  3140. buff.WriteUInt8(uint8(0)) // write nil byte
  3141. } else {
  3142. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3143. // --- [begin][write][map](map[string]string) ---
  3144. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  3145. for v, z := range map[string]string(target.Labels) {
  3146. if ctx.IsStringTable() {
  3147. g := ctx.Table.AddOrGet(v)
  3148. buff.WriteInt(g) // write table index
  3149. } else {
  3150. buff.WriteString(v) // write string
  3151. }
  3152. if ctx.IsStringTable() {
  3153. h := ctx.Table.AddOrGet(z)
  3154. buff.WriteInt(h) // write table index
  3155. } else {
  3156. buff.WriteString(z) // write string
  3157. }
  3158. }
  3159. // --- [end][write][map](map[string]string) ---
  3160. }
  3161. // --- [end][write][alias](CloudCostLabels) ---
  3162. return nil
  3163. }
  3164. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3165. // the CloudCostProperties type
  3166. func (target *CloudCostProperties) UnmarshalBinary(data []byte) error {
  3167. var table []string
  3168. buff := util.NewBufferFromBytes(data)
  3169. // string table header validation
  3170. if isBinaryTag(data, BinaryTagStringTable) {
  3171. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3172. tl := buff.ReadInt() // table length
  3173. if tl > 0 {
  3174. table = make([]string, tl, tl)
  3175. for i := 0; i < tl; i++ {
  3176. table[i] = buff.ReadString()
  3177. }
  3178. }
  3179. }
  3180. ctx := &DecodingContext{
  3181. Buffer: buff,
  3182. Table: table,
  3183. }
  3184. err := target.UnmarshalBinaryWithContext(ctx)
  3185. if err != nil {
  3186. return err
  3187. }
  3188. return nil
  3189. }
  3190. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3191. // the CloudCostProperties type
  3192. func (target *CloudCostProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3193. // panics are recovered and propagated as errors
  3194. defer func() {
  3195. if r := recover(); r != nil {
  3196. if e, ok := r.(error); ok {
  3197. err = e
  3198. } else if s, ok := r.(string); ok {
  3199. err = fmt.Errorf("Unexpected panic: %s", s)
  3200. } else {
  3201. err = fmt.Errorf("Unexpected panic: %+v", r)
  3202. }
  3203. }
  3204. }()
  3205. buff := ctx.Buffer
  3206. version := buff.ReadUInt8()
  3207. if version > CloudCostCodecVersion {
  3208. return fmt.Errorf("Invalid Version Unmarshaling CloudCostProperties. Expected %d or less, got %d", CloudCostCodecVersion, version)
  3209. }
  3210. var b string
  3211. if ctx.IsStringTable() {
  3212. c := buff.ReadInt() // read string index
  3213. b = ctx.Table[c]
  3214. } else {
  3215. b = buff.ReadString() // read string
  3216. }
  3217. a := b
  3218. target.ProviderID = a
  3219. var e string
  3220. if ctx.IsStringTable() {
  3221. f := buff.ReadInt() // read string index
  3222. e = ctx.Table[f]
  3223. } else {
  3224. e = buff.ReadString() // read string
  3225. }
  3226. d := e
  3227. target.Provider = d
  3228. var h string
  3229. if ctx.IsStringTable() {
  3230. k := buff.ReadInt() // read string index
  3231. h = ctx.Table[k]
  3232. } else {
  3233. h = buff.ReadString() // read string
  3234. }
  3235. g := h
  3236. target.AccountID = g
  3237. var m string
  3238. if ctx.IsStringTable() {
  3239. n := buff.ReadInt() // read string index
  3240. m = ctx.Table[n]
  3241. } else {
  3242. m = buff.ReadString() // read string
  3243. }
  3244. l := m
  3245. target.InvoiceEntityID = l
  3246. var p string
  3247. if ctx.IsStringTable() {
  3248. q := buff.ReadInt() // read string index
  3249. p = ctx.Table[q]
  3250. } else {
  3251. p = buff.ReadString() // read string
  3252. }
  3253. o := p
  3254. target.Service = o
  3255. var s string
  3256. if ctx.IsStringTable() {
  3257. t := buff.ReadInt() // read string index
  3258. s = ctx.Table[t]
  3259. } else {
  3260. s = buff.ReadString() // read string
  3261. }
  3262. r := s
  3263. target.Category = r
  3264. // --- [begin][read][alias](CloudCostLabels) ---
  3265. var u map[string]string
  3266. if buff.ReadUInt8() == uint8(0) {
  3267. u = nil
  3268. } else {
  3269. // --- [begin][read][map](map[string]string) ---
  3270. x := buff.ReadInt() // map len
  3271. w := make(map[string]string, x)
  3272. for i := 0; i < x; i++ {
  3273. var v string
  3274. var aa string
  3275. if ctx.IsStringTable() {
  3276. bb := buff.ReadInt() // read string index
  3277. aa = ctx.Table[bb]
  3278. } else {
  3279. aa = buff.ReadString() // read string
  3280. }
  3281. y := aa
  3282. v = y
  3283. var z string
  3284. var dd string
  3285. if ctx.IsStringTable() {
  3286. ee := buff.ReadInt() // read string index
  3287. dd = ctx.Table[ee]
  3288. } else {
  3289. dd = buff.ReadString() // read string
  3290. }
  3291. cc := dd
  3292. z = cc
  3293. w[v] = z
  3294. }
  3295. u = w
  3296. // --- [end][read][map](map[string]string) ---
  3297. }
  3298. target.Labels = CloudCostLabels(u)
  3299. // --- [end][read][alias](CloudCostLabels) ---
  3300. return nil
  3301. }
  3302. //--------------------------------------------------------------------------
  3303. // CloudCostSet
  3304. //--------------------------------------------------------------------------
  3305. // MarshalBinary serializes the internal properties of this CloudCostSet instance
  3306. // into a byte array
  3307. func (target *CloudCostSet) MarshalBinary() (data []byte, err error) {
  3308. ctx := &EncodingContext{
  3309. Buffer: util.NewBuffer(),
  3310. Table: NewStringTable(),
  3311. }
  3312. e := target.MarshalBinaryWithContext(ctx)
  3313. if e != nil {
  3314. return nil, e
  3315. }
  3316. encBytes := ctx.Buffer.Bytes()
  3317. sTableBytes := ctx.Table.ToBytes()
  3318. merged := appendBytes(sTableBytes, encBytes)
  3319. return merged, nil
  3320. }
  3321. // MarshalBinaryWithContext serializes the internal properties of this CloudCostSet instance
  3322. // into a byte array leveraging a predefined context.
  3323. func (target *CloudCostSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3324. // panics are recovered and propagated as errors
  3325. defer func() {
  3326. if r := recover(); r != nil {
  3327. if e, ok := r.(error); ok {
  3328. err = e
  3329. } else if s, ok := r.(string); ok {
  3330. err = fmt.Errorf("Unexpected panic: %s", s)
  3331. } else {
  3332. err = fmt.Errorf("Unexpected panic: %+v", r)
  3333. }
  3334. }
  3335. }()
  3336. buff := ctx.Buffer
  3337. buff.WriteUInt8(CloudCostCodecVersion) // version
  3338. if target.CloudCosts == nil {
  3339. buff.WriteUInt8(uint8(0)) // write nil byte
  3340. } else {
  3341. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3342. // --- [begin][write][map](map[string]*CloudCost) ---
  3343. buff.WriteInt(len(target.CloudCosts)) // map length
  3344. for v, z := range target.CloudCosts {
  3345. if ctx.IsStringTable() {
  3346. a := ctx.Table.AddOrGet(v)
  3347. buff.WriteInt(a) // write table index
  3348. } else {
  3349. buff.WriteString(v) // write string
  3350. }
  3351. if z == nil {
  3352. buff.WriteUInt8(uint8(0)) // write nil byte
  3353. } else {
  3354. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3355. // --- [begin][write][struct](CloudCost) ---
  3356. buff.WriteInt(0) // [compatibility, unused]
  3357. errA := z.MarshalBinaryWithContext(ctx)
  3358. if errA != nil {
  3359. return errA
  3360. }
  3361. // --- [end][write][struct](CloudCost) ---
  3362. }
  3363. }
  3364. // --- [end][write][map](map[string]*CloudCost) ---
  3365. }
  3366. // --- [begin][write][struct](Window) ---
  3367. buff.WriteInt(0) // [compatibility, unused]
  3368. errB := target.Window.MarshalBinaryWithContext(ctx)
  3369. if errB != nil {
  3370. return errB
  3371. }
  3372. // --- [end][write][struct](Window) ---
  3373. if ctx.IsStringTable() {
  3374. b := ctx.Table.AddOrGet(target.Integration)
  3375. buff.WriteInt(b) // write table index
  3376. } else {
  3377. buff.WriteString(target.Integration) // write string
  3378. }
  3379. if target.AggregationProperties == nil {
  3380. buff.WriteUInt8(uint8(0)) // write nil byte
  3381. } else {
  3382. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3383. // --- [begin][write][slice]([]string) ---
  3384. buff.WriteInt(len(target.AggregationProperties)) // array length
  3385. for i := 0; i < len(target.AggregationProperties); i++ {
  3386. if ctx.IsStringTable() {
  3387. c := ctx.Table.AddOrGet(target.AggregationProperties[i])
  3388. buff.WriteInt(c) // write table index
  3389. } else {
  3390. buff.WriteString(target.AggregationProperties[i]) // write string
  3391. }
  3392. }
  3393. // --- [end][write][slice]([]string) ---
  3394. }
  3395. return nil
  3396. }
  3397. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3398. // the CloudCostSet type
  3399. func (target *CloudCostSet) UnmarshalBinary(data []byte) error {
  3400. var table []string
  3401. buff := util.NewBufferFromBytes(data)
  3402. // string table header validation
  3403. if isBinaryTag(data, BinaryTagStringTable) {
  3404. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3405. tl := buff.ReadInt() // table length
  3406. if tl > 0 {
  3407. table = make([]string, tl, tl)
  3408. for i := 0; i < tl; i++ {
  3409. table[i] = buff.ReadString()
  3410. }
  3411. }
  3412. }
  3413. ctx := &DecodingContext{
  3414. Buffer: buff,
  3415. Table: table,
  3416. }
  3417. err := target.UnmarshalBinaryWithContext(ctx)
  3418. if err != nil {
  3419. return err
  3420. }
  3421. return nil
  3422. }
  3423. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3424. // the CloudCostSet type
  3425. func (target *CloudCostSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3426. // panics are recovered and propagated as errors
  3427. defer func() {
  3428. if r := recover(); r != nil {
  3429. if e, ok := r.(error); ok {
  3430. err = e
  3431. } else if s, ok := r.(string); ok {
  3432. err = fmt.Errorf("Unexpected panic: %s", s)
  3433. } else {
  3434. err = fmt.Errorf("Unexpected panic: %+v", r)
  3435. }
  3436. }
  3437. }()
  3438. buff := ctx.Buffer
  3439. version := buff.ReadUInt8()
  3440. if version > CloudCostCodecVersion {
  3441. return fmt.Errorf("Invalid Version Unmarshaling CloudCostSet. Expected %d or less, got %d", CloudCostCodecVersion, version)
  3442. }
  3443. if buff.ReadUInt8() == uint8(0) {
  3444. target.CloudCosts = nil
  3445. } else {
  3446. // --- [begin][read][map](map[string]*CloudCost) ---
  3447. b := buff.ReadInt() // map len
  3448. a := make(map[string]*CloudCost, b)
  3449. for i := 0; i < b; i++ {
  3450. var v string
  3451. var d string
  3452. if ctx.IsStringTable() {
  3453. e := buff.ReadInt() // read string index
  3454. d = ctx.Table[e]
  3455. } else {
  3456. d = buff.ReadString() // read string
  3457. }
  3458. c := d
  3459. v = c
  3460. var z *CloudCost
  3461. if buff.ReadUInt8() == uint8(0) {
  3462. z = nil
  3463. } else {
  3464. // --- [begin][read][struct](CloudCost) ---
  3465. f := &CloudCost{}
  3466. buff.ReadInt() // [compatibility, unused]
  3467. errA := f.UnmarshalBinaryWithContext(ctx)
  3468. if errA != nil {
  3469. return errA
  3470. }
  3471. z = f
  3472. // --- [end][read][struct](CloudCost) ---
  3473. }
  3474. a[v] = z
  3475. }
  3476. target.CloudCosts = a
  3477. // --- [end][read][map](map[string]*CloudCost) ---
  3478. }
  3479. // --- [begin][read][struct](Window) ---
  3480. g := &Window{}
  3481. buff.ReadInt() // [compatibility, unused]
  3482. errB := g.UnmarshalBinaryWithContext(ctx)
  3483. if errB != nil {
  3484. return errB
  3485. }
  3486. target.Window = *g
  3487. // --- [end][read][struct](Window) ---
  3488. var k string
  3489. if ctx.IsStringTable() {
  3490. l := buff.ReadInt() // read string index
  3491. k = ctx.Table[l]
  3492. } else {
  3493. k = buff.ReadString() // read string
  3494. }
  3495. h := k
  3496. target.Integration = h
  3497. if buff.ReadUInt8() == uint8(0) {
  3498. target.AggregationProperties = nil
  3499. } else {
  3500. // --- [begin][read][slice]([]string) ---
  3501. n := buff.ReadInt() // array len
  3502. m := make([]string, n)
  3503. for j := 0; j < n; j++ {
  3504. var o string
  3505. var q string
  3506. if ctx.IsStringTable() {
  3507. r := buff.ReadInt() // read string index
  3508. q = ctx.Table[r]
  3509. } else {
  3510. q = buff.ReadString() // read string
  3511. }
  3512. p := q
  3513. o = p
  3514. m[j] = o
  3515. }
  3516. target.AggregationProperties = m
  3517. // --- [end][read][slice]([]string) ---
  3518. }
  3519. return nil
  3520. }
  3521. //--------------------------------------------------------------------------
  3522. // CloudCostSetRange
  3523. //--------------------------------------------------------------------------
  3524. // MarshalBinary serializes the internal properties of this CloudCostSetRange instance
  3525. // into a byte array
  3526. func (target *CloudCostSetRange) MarshalBinary() (data []byte, err error) {
  3527. ctx := &EncodingContext{
  3528. Buffer: util.NewBuffer(),
  3529. Table: nil,
  3530. }
  3531. e := target.MarshalBinaryWithContext(ctx)
  3532. if e != nil {
  3533. return nil, e
  3534. }
  3535. encBytes := ctx.Buffer.Bytes()
  3536. return encBytes, nil
  3537. }
  3538. // MarshalBinaryWithContext serializes the internal properties of this CloudCostSetRange instance
  3539. // into a byte array leveraging a predefined context.
  3540. func (target *CloudCostSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3541. // panics are recovered and propagated as errors
  3542. defer func() {
  3543. if r := recover(); r != nil {
  3544. if e, ok := r.(error); ok {
  3545. err = e
  3546. } else if s, ok := r.(string); ok {
  3547. err = fmt.Errorf("Unexpected panic: %s", s)
  3548. } else {
  3549. err = fmt.Errorf("Unexpected panic: %+v", r)
  3550. }
  3551. }
  3552. }()
  3553. buff := ctx.Buffer
  3554. buff.WriteUInt8(CloudCostCodecVersion) // version
  3555. if target.CloudCostSets == nil {
  3556. buff.WriteUInt8(uint8(0)) // write nil byte
  3557. } else {
  3558. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3559. // --- [begin][write][slice]([]*CloudCostSet) ---
  3560. buff.WriteInt(len(target.CloudCostSets)) // array length
  3561. for i := 0; i < len(target.CloudCostSets); i++ {
  3562. if target.CloudCostSets[i] == nil {
  3563. buff.WriteUInt8(uint8(0)) // write nil byte
  3564. } else {
  3565. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3566. // --- [begin][write][struct](CloudCostSet) ---
  3567. buff.WriteInt(0) // [compatibility, unused]
  3568. errA := target.CloudCostSets[i].MarshalBinaryWithContext(ctx)
  3569. if errA != nil {
  3570. return errA
  3571. }
  3572. // --- [end][write][struct](CloudCostSet) ---
  3573. }
  3574. }
  3575. // --- [end][write][slice]([]*CloudCostSet) ---
  3576. }
  3577. // --- [begin][write][struct](Window) ---
  3578. buff.WriteInt(0) // [compatibility, unused]
  3579. errB := target.Window.MarshalBinaryWithContext(ctx)
  3580. if errB != nil {
  3581. return errB
  3582. }
  3583. // --- [end][write][struct](Window) ---
  3584. return nil
  3585. }
  3586. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3587. // the CloudCostSetRange type
  3588. func (target *CloudCostSetRange) UnmarshalBinary(data []byte) error {
  3589. var table []string
  3590. buff := util.NewBufferFromBytes(data)
  3591. // string table header validation
  3592. if isBinaryTag(data, BinaryTagStringTable) {
  3593. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3594. tl := buff.ReadInt() // table length
  3595. if tl > 0 {
  3596. table = make([]string, tl, tl)
  3597. for i := 0; i < tl; i++ {
  3598. table[i] = buff.ReadString()
  3599. }
  3600. }
  3601. }
  3602. ctx := &DecodingContext{
  3603. Buffer: buff,
  3604. Table: table,
  3605. }
  3606. err := target.UnmarshalBinaryWithContext(ctx)
  3607. if err != nil {
  3608. return err
  3609. }
  3610. return nil
  3611. }
  3612. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3613. // the CloudCostSetRange type
  3614. func (target *CloudCostSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3615. // panics are recovered and propagated as errors
  3616. defer func() {
  3617. if r := recover(); r != nil {
  3618. if e, ok := r.(error); ok {
  3619. err = e
  3620. } else if s, ok := r.(string); ok {
  3621. err = fmt.Errorf("Unexpected panic: %s", s)
  3622. } else {
  3623. err = fmt.Errorf("Unexpected panic: %+v", r)
  3624. }
  3625. }
  3626. }()
  3627. buff := ctx.Buffer
  3628. version := buff.ReadUInt8()
  3629. if version > CloudCostCodecVersion {
  3630. return fmt.Errorf("Invalid Version Unmarshaling CloudCostSetRange. Expected %d or less, got %d", CloudCostCodecVersion, version)
  3631. }
  3632. if buff.ReadUInt8() == uint8(0) {
  3633. target.CloudCostSets = nil
  3634. } else {
  3635. // --- [begin][read][slice]([]*CloudCostSet) ---
  3636. b := buff.ReadInt() // array len
  3637. a := make([]*CloudCostSet, b)
  3638. for i := 0; i < b; i++ {
  3639. var c *CloudCostSet
  3640. if buff.ReadUInt8() == uint8(0) {
  3641. c = nil
  3642. } else {
  3643. // --- [begin][read][struct](CloudCostSet) ---
  3644. d := &CloudCostSet{}
  3645. buff.ReadInt() // [compatibility, unused]
  3646. errA := d.UnmarshalBinaryWithContext(ctx)
  3647. if errA != nil {
  3648. return errA
  3649. }
  3650. c = d
  3651. // --- [end][read][struct](CloudCostSet) ---
  3652. }
  3653. a[i] = c
  3654. }
  3655. target.CloudCostSets = a
  3656. // --- [end][read][slice]([]*CloudCostSet) ---
  3657. }
  3658. // --- [begin][read][struct](Window) ---
  3659. e := &Window{}
  3660. buff.ReadInt() // [compatibility, unused]
  3661. errB := e.UnmarshalBinaryWithContext(ctx)
  3662. if errB != nil {
  3663. return errB
  3664. }
  3665. target.Window = *e
  3666. // --- [end][read][struct](Window) ---
  3667. return nil
  3668. }
  3669. //--------------------------------------------------------------------------
  3670. // ClusterManagement
  3671. //--------------------------------------------------------------------------
  3672. // MarshalBinary serializes the internal properties of this ClusterManagement instance
  3673. // into a byte array
  3674. func (target *ClusterManagement) MarshalBinary() (data []byte, err error) {
  3675. ctx := &EncodingContext{
  3676. Buffer: util.NewBuffer(),
  3677. Table: nil,
  3678. }
  3679. e := target.MarshalBinaryWithContext(ctx)
  3680. if e != nil {
  3681. return nil, e
  3682. }
  3683. encBytes := ctx.Buffer.Bytes()
  3684. return encBytes, nil
  3685. }
  3686. // MarshalBinaryWithContext serializes the internal properties of this ClusterManagement instance
  3687. // into a byte array leveraging a predefined context.
  3688. func (target *ClusterManagement) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3689. // panics are recovered and propagated as errors
  3690. defer func() {
  3691. if r := recover(); r != nil {
  3692. if e, ok := r.(error); ok {
  3693. err = e
  3694. } else if s, ok := r.(string); ok {
  3695. err = fmt.Errorf("Unexpected panic: %s", s)
  3696. } else {
  3697. err = fmt.Errorf("Unexpected panic: %+v", r)
  3698. }
  3699. }
  3700. }()
  3701. buff := ctx.Buffer
  3702. buff.WriteUInt8(AssetsCodecVersion) // version
  3703. // --- [begin][write][alias](AssetLabels) ---
  3704. if map[string]string(target.Labels) == nil {
  3705. buff.WriteUInt8(uint8(0)) // write nil byte
  3706. } else {
  3707. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3708. // --- [begin][write][map](map[string]string) ---
  3709. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  3710. for v, z := range map[string]string(target.Labels) {
  3711. if ctx.IsStringTable() {
  3712. a := ctx.Table.AddOrGet(v)
  3713. buff.WriteInt(a) // write table index
  3714. } else {
  3715. buff.WriteString(v) // write string
  3716. }
  3717. if ctx.IsStringTable() {
  3718. b := ctx.Table.AddOrGet(z)
  3719. buff.WriteInt(b) // write table index
  3720. } else {
  3721. buff.WriteString(z) // write string
  3722. }
  3723. }
  3724. // --- [end][write][map](map[string]string) ---
  3725. }
  3726. // --- [end][write][alias](AssetLabels) ---
  3727. if target.Properties == nil {
  3728. buff.WriteUInt8(uint8(0)) // write nil byte
  3729. } else {
  3730. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3731. // --- [begin][write][struct](AssetProperties) ---
  3732. buff.WriteInt(0) // [compatibility, unused]
  3733. errA := target.Properties.MarshalBinaryWithContext(ctx)
  3734. if errA != nil {
  3735. return errA
  3736. }
  3737. // --- [end][write][struct](AssetProperties) ---
  3738. }
  3739. // --- [begin][write][struct](Window) ---
  3740. buff.WriteInt(0) // [compatibility, unused]
  3741. errB := target.Window.MarshalBinaryWithContext(ctx)
  3742. if errB != nil {
  3743. return errB
  3744. }
  3745. // --- [end][write][struct](Window) ---
  3746. buff.WriteFloat64(target.Cost) // write float64
  3747. buff.WriteFloat64(target.Adjustment) // write float64
  3748. return nil
  3749. }
  3750. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3751. // the ClusterManagement type
  3752. func (target *ClusterManagement) UnmarshalBinary(data []byte) error {
  3753. var table []string
  3754. buff := util.NewBufferFromBytes(data)
  3755. // string table header validation
  3756. if isBinaryTag(data, BinaryTagStringTable) {
  3757. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3758. tl := buff.ReadInt() // table length
  3759. if tl > 0 {
  3760. table = make([]string, tl, tl)
  3761. for i := 0; i < tl; i++ {
  3762. table[i] = buff.ReadString()
  3763. }
  3764. }
  3765. }
  3766. ctx := &DecodingContext{
  3767. Buffer: buff,
  3768. Table: table,
  3769. }
  3770. err := target.UnmarshalBinaryWithContext(ctx)
  3771. if err != nil {
  3772. return err
  3773. }
  3774. return nil
  3775. }
  3776. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3777. // the ClusterManagement type
  3778. func (target *ClusterManagement) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3779. // panics are recovered and propagated as errors
  3780. defer func() {
  3781. if r := recover(); r != nil {
  3782. if e, ok := r.(error); ok {
  3783. err = e
  3784. } else if s, ok := r.(string); ok {
  3785. err = fmt.Errorf("Unexpected panic: %s", s)
  3786. } else {
  3787. err = fmt.Errorf("Unexpected panic: %+v", r)
  3788. }
  3789. }
  3790. }()
  3791. buff := ctx.Buffer
  3792. version := buff.ReadUInt8()
  3793. if version > AssetsCodecVersion {
  3794. return fmt.Errorf("Invalid Version Unmarshaling ClusterManagement. Expected %d or less, got %d", AssetsCodecVersion, version)
  3795. }
  3796. // --- [begin][read][alias](AssetLabels) ---
  3797. var a map[string]string
  3798. if buff.ReadUInt8() == uint8(0) {
  3799. a = nil
  3800. } else {
  3801. // --- [begin][read][map](map[string]string) ---
  3802. c := buff.ReadInt() // map len
  3803. b := make(map[string]string, c)
  3804. for i := 0; i < c; i++ {
  3805. var v string
  3806. var e string
  3807. if ctx.IsStringTable() {
  3808. f := buff.ReadInt() // read string index
  3809. e = ctx.Table[f]
  3810. } else {
  3811. e = buff.ReadString() // read string
  3812. }
  3813. d := e
  3814. v = d
  3815. var z string
  3816. var h string
  3817. if ctx.IsStringTable() {
  3818. k := buff.ReadInt() // read string index
  3819. h = ctx.Table[k]
  3820. } else {
  3821. h = buff.ReadString() // read string
  3822. }
  3823. g := h
  3824. z = g
  3825. b[v] = z
  3826. }
  3827. a = b
  3828. // --- [end][read][map](map[string]string) ---
  3829. }
  3830. target.Labels = AssetLabels(a)
  3831. // --- [end][read][alias](AssetLabels) ---
  3832. if buff.ReadUInt8() == uint8(0) {
  3833. target.Properties = nil
  3834. } else {
  3835. // --- [begin][read][struct](AssetProperties) ---
  3836. l := &AssetProperties{}
  3837. buff.ReadInt() // [compatibility, unused]
  3838. errA := l.UnmarshalBinaryWithContext(ctx)
  3839. if errA != nil {
  3840. return errA
  3841. }
  3842. target.Properties = l
  3843. // --- [end][read][struct](AssetProperties) ---
  3844. }
  3845. // --- [begin][read][struct](Window) ---
  3846. m := &Window{}
  3847. buff.ReadInt() // [compatibility, unused]
  3848. errB := m.UnmarshalBinaryWithContext(ctx)
  3849. if errB != nil {
  3850. return errB
  3851. }
  3852. target.Window = *m
  3853. // --- [end][read][struct](Window) ---
  3854. n := buff.ReadFloat64() // read float64
  3855. target.Cost = n
  3856. // field version check
  3857. if uint8(16) <= version {
  3858. o := buff.ReadFloat64() // read float64
  3859. target.Adjustment = o
  3860. } else {
  3861. target.Adjustment = float64(0) // default
  3862. }
  3863. return nil
  3864. }
  3865. //--------------------------------------------------------------------------
  3866. // CostMetric
  3867. //--------------------------------------------------------------------------
  3868. // MarshalBinary serializes the internal properties of this CostMetric instance
  3869. // into a byte array
  3870. func (target *CostMetric) MarshalBinary() (data []byte, err error) {
  3871. ctx := &EncodingContext{
  3872. Buffer: util.NewBuffer(),
  3873. Table: nil,
  3874. }
  3875. e := target.MarshalBinaryWithContext(ctx)
  3876. if e != nil {
  3877. return nil, e
  3878. }
  3879. encBytes := ctx.Buffer.Bytes()
  3880. return encBytes, nil
  3881. }
  3882. // MarshalBinaryWithContext serializes the internal properties of this CostMetric instance
  3883. // into a byte array leveraging a predefined context.
  3884. func (target *CostMetric) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3885. // panics are recovered and propagated as errors
  3886. defer func() {
  3887. if r := recover(); r != nil {
  3888. if e, ok := r.(error); ok {
  3889. err = e
  3890. } else if s, ok := r.(string); ok {
  3891. err = fmt.Errorf("Unexpected panic: %s", s)
  3892. } else {
  3893. err = fmt.Errorf("Unexpected panic: %+v", r)
  3894. }
  3895. }
  3896. }()
  3897. buff := ctx.Buffer
  3898. buff.WriteUInt8(CloudCostCodecVersion) // version
  3899. buff.WriteFloat64(target.Cost) // write float64
  3900. buff.WriteFloat64(target.KubernetesPercent) // write float64
  3901. return nil
  3902. }
  3903. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3904. // the CostMetric type
  3905. func (target *CostMetric) UnmarshalBinary(data []byte) error {
  3906. var table []string
  3907. buff := util.NewBufferFromBytes(data)
  3908. // string table header validation
  3909. if isBinaryTag(data, BinaryTagStringTable) {
  3910. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3911. tl := buff.ReadInt() // table length
  3912. if tl > 0 {
  3913. table = make([]string, tl, tl)
  3914. for i := 0; i < tl; i++ {
  3915. table[i] = buff.ReadString()
  3916. }
  3917. }
  3918. }
  3919. ctx := &DecodingContext{
  3920. Buffer: buff,
  3921. Table: table,
  3922. }
  3923. err := target.UnmarshalBinaryWithContext(ctx)
  3924. if err != nil {
  3925. return err
  3926. }
  3927. return nil
  3928. }
  3929. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3930. // the CostMetric type
  3931. func (target *CostMetric) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3932. // panics are recovered and propagated as errors
  3933. defer func() {
  3934. if r := recover(); r != nil {
  3935. if e, ok := r.(error); ok {
  3936. err = e
  3937. } else if s, ok := r.(string); ok {
  3938. err = fmt.Errorf("Unexpected panic: %s", s)
  3939. } else {
  3940. err = fmt.Errorf("Unexpected panic: %+v", r)
  3941. }
  3942. }
  3943. }()
  3944. buff := ctx.Buffer
  3945. version := buff.ReadUInt8()
  3946. if version > CloudCostCodecVersion {
  3947. return fmt.Errorf("Invalid Version Unmarshaling CostMetric. Expected %d or less, got %d", CloudCostCodecVersion, version)
  3948. }
  3949. a := buff.ReadFloat64() // read float64
  3950. target.Cost = a
  3951. b := buff.ReadFloat64() // read float64
  3952. target.KubernetesPercent = b
  3953. return nil
  3954. }
  3955. //--------------------------------------------------------------------------
  3956. // Coverage
  3957. //--------------------------------------------------------------------------
  3958. // MarshalBinary serializes the internal properties of this Coverage instance
  3959. // into a byte array
  3960. func (target *Coverage) MarshalBinary() (data []byte, err error) {
  3961. ctx := &EncodingContext{
  3962. Buffer: util.NewBuffer(),
  3963. Table: nil,
  3964. }
  3965. e := target.MarshalBinaryWithContext(ctx)
  3966. if e != nil {
  3967. return nil, e
  3968. }
  3969. encBytes := ctx.Buffer.Bytes()
  3970. return encBytes, nil
  3971. }
  3972. // MarshalBinaryWithContext serializes the internal properties of this Coverage instance
  3973. // into a byte array leveraging a predefined context.
  3974. func (target *Coverage) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3975. // panics are recovered and propagated as errors
  3976. defer func() {
  3977. if r := recover(); r != nil {
  3978. if e, ok := r.(error); ok {
  3979. err = e
  3980. } else if s, ok := r.(string); ok {
  3981. err = fmt.Errorf("Unexpected panic: %s", s)
  3982. } else {
  3983. err = fmt.Errorf("Unexpected panic: %+v", r)
  3984. }
  3985. }
  3986. }()
  3987. buff := ctx.Buffer
  3988. buff.WriteUInt8(DefaultCodecVersion) // version
  3989. // --- [begin][write][struct](Window) ---
  3990. buff.WriteInt(0) // [compatibility, unused]
  3991. errA := target.Window.MarshalBinaryWithContext(ctx)
  3992. if errA != nil {
  3993. return errA
  3994. }
  3995. // --- [end][write][struct](Window) ---
  3996. if ctx.IsStringTable() {
  3997. a := ctx.Table.AddOrGet(target.Type)
  3998. buff.WriteInt(a) // write table index
  3999. } else {
  4000. buff.WriteString(target.Type) // write string
  4001. }
  4002. buff.WriteInt(target.Count) // write int
  4003. // --- [begin][write][reference](time.Time) ---
  4004. b, errB := target.Updated.MarshalBinary()
  4005. if errB != nil {
  4006. return errB
  4007. }
  4008. buff.WriteInt(len(b))
  4009. buff.WriteBytes(b)
  4010. // --- [end][write][reference](time.Time) ---
  4011. if target.Errors == nil {
  4012. buff.WriteUInt8(uint8(0)) // write nil byte
  4013. } else {
  4014. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4015. // --- [begin][write][slice]([]string) ---
  4016. buff.WriteInt(len(target.Errors)) // array length
  4017. for i := 0; i < len(target.Errors); i++ {
  4018. if ctx.IsStringTable() {
  4019. c := ctx.Table.AddOrGet(target.Errors[i])
  4020. buff.WriteInt(c) // write table index
  4021. } else {
  4022. buff.WriteString(target.Errors[i]) // write string
  4023. }
  4024. }
  4025. // --- [end][write][slice]([]string) ---
  4026. }
  4027. if target.Warnings == nil {
  4028. buff.WriteUInt8(uint8(0)) // write nil byte
  4029. } else {
  4030. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4031. // --- [begin][write][slice]([]string) ---
  4032. buff.WriteInt(len(target.Warnings)) // array length
  4033. for j := 0; j < len(target.Warnings); j++ {
  4034. if ctx.IsStringTable() {
  4035. d := ctx.Table.AddOrGet(target.Warnings[j])
  4036. buff.WriteInt(d) // write table index
  4037. } else {
  4038. buff.WriteString(target.Warnings[j]) // write string
  4039. }
  4040. }
  4041. // --- [end][write][slice]([]string) ---
  4042. }
  4043. return nil
  4044. }
  4045. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4046. // the Coverage type
  4047. func (target *Coverage) UnmarshalBinary(data []byte) error {
  4048. var table []string
  4049. buff := util.NewBufferFromBytes(data)
  4050. // string table header validation
  4051. if isBinaryTag(data, BinaryTagStringTable) {
  4052. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4053. tl := buff.ReadInt() // table length
  4054. if tl > 0 {
  4055. table = make([]string, tl, tl)
  4056. for i := 0; i < tl; i++ {
  4057. table[i] = buff.ReadString()
  4058. }
  4059. }
  4060. }
  4061. ctx := &DecodingContext{
  4062. Buffer: buff,
  4063. Table: table,
  4064. }
  4065. err := target.UnmarshalBinaryWithContext(ctx)
  4066. if err != nil {
  4067. return err
  4068. }
  4069. return nil
  4070. }
  4071. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4072. // the Coverage type
  4073. func (target *Coverage) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4074. // panics are recovered and propagated as errors
  4075. defer func() {
  4076. if r := recover(); r != nil {
  4077. if e, ok := r.(error); ok {
  4078. err = e
  4079. } else if s, ok := r.(string); ok {
  4080. err = fmt.Errorf("Unexpected panic: %s", s)
  4081. } else {
  4082. err = fmt.Errorf("Unexpected panic: %+v", r)
  4083. }
  4084. }
  4085. }()
  4086. buff := ctx.Buffer
  4087. version := buff.ReadUInt8()
  4088. if version > DefaultCodecVersion {
  4089. return fmt.Errorf("Invalid Version Unmarshaling Coverage. Expected %d or less, got %d", DefaultCodecVersion, version)
  4090. }
  4091. // --- [begin][read][struct](Window) ---
  4092. a := &Window{}
  4093. buff.ReadInt() // [compatibility, unused]
  4094. errA := a.UnmarshalBinaryWithContext(ctx)
  4095. if errA != nil {
  4096. return errA
  4097. }
  4098. target.Window = *a
  4099. // --- [end][read][struct](Window) ---
  4100. var c string
  4101. if ctx.IsStringTable() {
  4102. d := buff.ReadInt() // read string index
  4103. c = ctx.Table[d]
  4104. } else {
  4105. c = buff.ReadString() // read string
  4106. }
  4107. b := c
  4108. target.Type = b
  4109. e := buff.ReadInt() // read int
  4110. target.Count = e
  4111. // --- [begin][read][reference](time.Time) ---
  4112. f := &time.Time{}
  4113. g := buff.ReadInt() // byte array length
  4114. h := buff.ReadBytes(g) // byte array
  4115. errB := f.UnmarshalBinary(h)
  4116. if errB != nil {
  4117. return errB
  4118. }
  4119. target.Updated = *f
  4120. // --- [end][read][reference](time.Time) ---
  4121. if buff.ReadUInt8() == uint8(0) {
  4122. target.Errors = nil
  4123. } else {
  4124. // --- [begin][read][slice]([]string) ---
  4125. l := buff.ReadInt() // array len
  4126. k := make([]string, l)
  4127. for i := 0; i < l; i++ {
  4128. var m string
  4129. var o string
  4130. if ctx.IsStringTable() {
  4131. p := buff.ReadInt() // read string index
  4132. o = ctx.Table[p]
  4133. } else {
  4134. o = buff.ReadString() // read string
  4135. }
  4136. n := o
  4137. m = n
  4138. k[i] = m
  4139. }
  4140. target.Errors = k
  4141. // --- [end][read][slice]([]string) ---
  4142. }
  4143. if buff.ReadUInt8() == uint8(0) {
  4144. target.Warnings = nil
  4145. } else {
  4146. // --- [begin][read][slice]([]string) ---
  4147. r := buff.ReadInt() // array len
  4148. q := make([]string, r)
  4149. for j := 0; j < r; j++ {
  4150. var s string
  4151. var u string
  4152. if ctx.IsStringTable() {
  4153. w := buff.ReadInt() // read string index
  4154. u = ctx.Table[w]
  4155. } else {
  4156. u = buff.ReadString() // read string
  4157. }
  4158. t := u
  4159. s = t
  4160. q[j] = s
  4161. }
  4162. target.Warnings = q
  4163. // --- [end][read][slice]([]string) ---
  4164. }
  4165. return nil
  4166. }
  4167. //--------------------------------------------------------------------------
  4168. // CoverageSet
  4169. //--------------------------------------------------------------------------
  4170. // MarshalBinary serializes the internal properties of this CoverageSet instance
  4171. // into a byte array
  4172. func (target *CoverageSet) MarshalBinary() (data []byte, err error) {
  4173. ctx := &EncodingContext{
  4174. Buffer: util.NewBuffer(),
  4175. Table: nil,
  4176. }
  4177. e := target.MarshalBinaryWithContext(ctx)
  4178. if e != nil {
  4179. return nil, e
  4180. }
  4181. encBytes := ctx.Buffer.Bytes()
  4182. return encBytes, nil
  4183. }
  4184. // MarshalBinaryWithContext serializes the internal properties of this CoverageSet instance
  4185. // into a byte array leveraging a predefined context.
  4186. func (target *CoverageSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4187. // panics are recovered and propagated as errors
  4188. defer func() {
  4189. if r := recover(); r != nil {
  4190. if e, ok := r.(error); ok {
  4191. err = e
  4192. } else if s, ok := r.(string); ok {
  4193. err = fmt.Errorf("Unexpected panic: %s", s)
  4194. } else {
  4195. err = fmt.Errorf("Unexpected panic: %+v", r)
  4196. }
  4197. }
  4198. }()
  4199. buff := ctx.Buffer
  4200. buff.WriteUInt8(DefaultCodecVersion) // version
  4201. // --- [begin][write][struct](Window) ---
  4202. buff.WriteInt(0) // [compatibility, unused]
  4203. errA := target.Window.MarshalBinaryWithContext(ctx)
  4204. if errA != nil {
  4205. return errA
  4206. }
  4207. // --- [end][write][struct](Window) ---
  4208. if target.Items == nil {
  4209. buff.WriteUInt8(uint8(0)) // write nil byte
  4210. } else {
  4211. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4212. // --- [begin][write][map](map[string]*Coverage) ---
  4213. buff.WriteInt(len(target.Items)) // map length
  4214. for v, z := range target.Items {
  4215. if ctx.IsStringTable() {
  4216. a := ctx.Table.AddOrGet(v)
  4217. buff.WriteInt(a) // write table index
  4218. } else {
  4219. buff.WriteString(v) // write string
  4220. }
  4221. if z == nil {
  4222. buff.WriteUInt8(uint8(0)) // write nil byte
  4223. } else {
  4224. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4225. // --- [begin][write][struct](Coverage) ---
  4226. buff.WriteInt(0) // [compatibility, unused]
  4227. errB := z.MarshalBinaryWithContext(ctx)
  4228. if errB != nil {
  4229. return errB
  4230. }
  4231. // --- [end][write][struct](Coverage) ---
  4232. }
  4233. }
  4234. // --- [end][write][map](map[string]*Coverage) ---
  4235. }
  4236. return nil
  4237. }
  4238. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4239. // the CoverageSet type
  4240. func (target *CoverageSet) UnmarshalBinary(data []byte) error {
  4241. var table []string
  4242. buff := util.NewBufferFromBytes(data)
  4243. // string table header validation
  4244. if isBinaryTag(data, BinaryTagStringTable) {
  4245. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4246. tl := buff.ReadInt() // table length
  4247. if tl > 0 {
  4248. table = make([]string, tl, tl)
  4249. for i := 0; i < tl; i++ {
  4250. table[i] = buff.ReadString()
  4251. }
  4252. }
  4253. }
  4254. ctx := &DecodingContext{
  4255. Buffer: buff,
  4256. Table: table,
  4257. }
  4258. err := target.UnmarshalBinaryWithContext(ctx)
  4259. if err != nil {
  4260. return err
  4261. }
  4262. return nil
  4263. }
  4264. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4265. // the CoverageSet type
  4266. func (target *CoverageSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (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. version := buff.ReadUInt8()
  4281. if version > DefaultCodecVersion {
  4282. return fmt.Errorf("Invalid Version Unmarshaling CoverageSet. Expected %d or less, got %d", DefaultCodecVersion, version)
  4283. }
  4284. // --- [begin][read][struct](Window) ---
  4285. a := &Window{}
  4286. buff.ReadInt() // [compatibility, unused]
  4287. errA := a.UnmarshalBinaryWithContext(ctx)
  4288. if errA != nil {
  4289. return errA
  4290. }
  4291. target.Window = *a
  4292. // --- [end][read][struct](Window) ---
  4293. if buff.ReadUInt8() == uint8(0) {
  4294. target.Items = nil
  4295. } else {
  4296. // --- [begin][read][map](map[string]*Coverage) ---
  4297. c := buff.ReadInt() // map len
  4298. b := make(map[string]*Coverage, c)
  4299. for i := 0; i < c; i++ {
  4300. var v string
  4301. var e string
  4302. if ctx.IsStringTable() {
  4303. f := buff.ReadInt() // read string index
  4304. e = ctx.Table[f]
  4305. } else {
  4306. e = buff.ReadString() // read string
  4307. }
  4308. d := e
  4309. v = d
  4310. var z *Coverage
  4311. if buff.ReadUInt8() == uint8(0) {
  4312. z = nil
  4313. } else {
  4314. // --- [begin][read][struct](Coverage) ---
  4315. g := &Coverage{}
  4316. buff.ReadInt() // [compatibility, unused]
  4317. errB := g.UnmarshalBinaryWithContext(ctx)
  4318. if errB != nil {
  4319. return errB
  4320. }
  4321. z = g
  4322. // --- [end][read][struct](Coverage) ---
  4323. }
  4324. b[v] = z
  4325. }
  4326. target.Items = b
  4327. // --- [end][read][map](map[string]*Coverage) ---
  4328. }
  4329. return nil
  4330. }
  4331. //--------------------------------------------------------------------------
  4332. // Disk
  4333. //--------------------------------------------------------------------------
  4334. // MarshalBinary serializes the internal properties of this Disk instance
  4335. // into a byte array
  4336. func (target *Disk) MarshalBinary() (data []byte, err error) {
  4337. ctx := &EncodingContext{
  4338. Buffer: util.NewBuffer(),
  4339. Table: nil,
  4340. }
  4341. e := target.MarshalBinaryWithContext(ctx)
  4342. if e != nil {
  4343. return nil, e
  4344. }
  4345. encBytes := ctx.Buffer.Bytes()
  4346. return encBytes, nil
  4347. }
  4348. // MarshalBinaryWithContext serializes the internal properties of this Disk instance
  4349. // into a byte array leveraging a predefined context.
  4350. func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4351. // panics are recovered and propagated as errors
  4352. defer func() {
  4353. if r := recover(); r != nil {
  4354. if e, ok := r.(error); ok {
  4355. err = e
  4356. } else if s, ok := r.(string); ok {
  4357. err = fmt.Errorf("Unexpected panic: %s", s)
  4358. } else {
  4359. err = fmt.Errorf("Unexpected panic: %+v", r)
  4360. }
  4361. }
  4362. }()
  4363. buff := ctx.Buffer
  4364. buff.WriteUInt8(AssetsCodecVersion) // version
  4365. // --- [begin][write][alias](AssetLabels) ---
  4366. if map[string]string(target.Labels) == nil {
  4367. buff.WriteUInt8(uint8(0)) // write nil byte
  4368. } else {
  4369. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4370. // --- [begin][write][map](map[string]string) ---
  4371. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  4372. for v, z := range map[string]string(target.Labels) {
  4373. if ctx.IsStringTable() {
  4374. a := ctx.Table.AddOrGet(v)
  4375. buff.WriteInt(a) // write table index
  4376. } else {
  4377. buff.WriteString(v) // write string
  4378. }
  4379. if ctx.IsStringTable() {
  4380. b := ctx.Table.AddOrGet(z)
  4381. buff.WriteInt(b) // write table index
  4382. } else {
  4383. buff.WriteString(z) // write string
  4384. }
  4385. }
  4386. // --- [end][write][map](map[string]string) ---
  4387. }
  4388. // --- [end][write][alias](AssetLabels) ---
  4389. if target.Properties == nil {
  4390. buff.WriteUInt8(uint8(0)) // write nil byte
  4391. } else {
  4392. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4393. // --- [begin][write][struct](AssetProperties) ---
  4394. buff.WriteInt(0) // [compatibility, unused]
  4395. errA := target.Properties.MarshalBinaryWithContext(ctx)
  4396. if errA != nil {
  4397. return errA
  4398. }
  4399. // --- [end][write][struct](AssetProperties) ---
  4400. }
  4401. // --- [begin][write][reference](time.Time) ---
  4402. c, errB := target.Start.MarshalBinary()
  4403. if errB != nil {
  4404. return errB
  4405. }
  4406. buff.WriteInt(len(c))
  4407. buff.WriteBytes(c)
  4408. // --- [end][write][reference](time.Time) ---
  4409. // --- [begin][write][reference](time.Time) ---
  4410. d, errC := target.End.MarshalBinary()
  4411. if errC != nil {
  4412. return errC
  4413. }
  4414. buff.WriteInt(len(d))
  4415. buff.WriteBytes(d)
  4416. // --- [end][write][reference](time.Time) ---
  4417. // --- [begin][write][struct](Window) ---
  4418. buff.WriteInt(0) // [compatibility, unused]
  4419. errD := target.Window.MarshalBinaryWithContext(ctx)
  4420. if errD != nil {
  4421. return errD
  4422. }
  4423. // --- [end][write][struct](Window) ---
  4424. buff.WriteFloat64(target.Adjustment) // write float64
  4425. buff.WriteFloat64(target.Cost) // write float64
  4426. buff.WriteFloat64(target.ByteHours) // write float64
  4427. buff.WriteFloat64(target.Local) // write float64
  4428. if target.Breakdown == nil {
  4429. buff.WriteUInt8(uint8(0)) // write nil byte
  4430. } else {
  4431. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4432. // --- [begin][write][struct](Breakdown) ---
  4433. buff.WriteInt(0) // [compatibility, unused]
  4434. errE := target.Breakdown.MarshalBinaryWithContext(ctx)
  4435. if errE != nil {
  4436. return errE
  4437. }
  4438. // --- [end][write][struct](Breakdown) ---
  4439. }
  4440. if ctx.IsStringTable() {
  4441. e := ctx.Table.AddOrGet(target.StorageClass)
  4442. buff.WriteInt(e) // write table index
  4443. } else {
  4444. buff.WriteString(target.StorageClass) // write string
  4445. }
  4446. if target.ByteHoursUsed == nil {
  4447. buff.WriteUInt8(uint8(0)) // write nil byte
  4448. } else {
  4449. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4450. buff.WriteFloat64(*target.ByteHoursUsed) // write float64
  4451. }
  4452. if target.ByteUsageMax == nil {
  4453. buff.WriteUInt8(uint8(0)) // write nil byte
  4454. } else {
  4455. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4456. buff.WriteFloat64(*target.ByteUsageMax) // write float64
  4457. }
  4458. if ctx.IsStringTable() {
  4459. f := ctx.Table.AddOrGet(target.VolumeName)
  4460. buff.WriteInt(f) // write table index
  4461. } else {
  4462. buff.WriteString(target.VolumeName) // write string
  4463. }
  4464. if ctx.IsStringTable() {
  4465. g := ctx.Table.AddOrGet(target.ClaimName)
  4466. buff.WriteInt(g) // write table index
  4467. } else {
  4468. buff.WriteString(target.ClaimName) // write string
  4469. }
  4470. if ctx.IsStringTable() {
  4471. h := ctx.Table.AddOrGet(target.ClaimNamespace)
  4472. buff.WriteInt(h) // write table index
  4473. } else {
  4474. buff.WriteString(target.ClaimNamespace) // write string
  4475. }
  4476. return nil
  4477. }
  4478. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4479. // the Disk type
  4480. func (target *Disk) UnmarshalBinary(data []byte) error {
  4481. var table []string
  4482. buff := util.NewBufferFromBytes(data)
  4483. // string table header validation
  4484. if isBinaryTag(data, BinaryTagStringTable) {
  4485. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4486. tl := buff.ReadInt() // table length
  4487. if tl > 0 {
  4488. table = make([]string, tl, tl)
  4489. for i := 0; i < tl; i++ {
  4490. table[i] = buff.ReadString()
  4491. }
  4492. }
  4493. }
  4494. ctx := &DecodingContext{
  4495. Buffer: buff,
  4496. Table: table,
  4497. }
  4498. err := target.UnmarshalBinaryWithContext(ctx)
  4499. if err != nil {
  4500. return err
  4501. }
  4502. return nil
  4503. }
  4504. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4505. // the Disk type
  4506. func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4507. // panics are recovered and propagated as errors
  4508. defer func() {
  4509. if r := recover(); r != nil {
  4510. if e, ok := r.(error); ok {
  4511. err = e
  4512. } else if s, ok := r.(string); ok {
  4513. err = fmt.Errorf("Unexpected panic: %s", s)
  4514. } else {
  4515. err = fmt.Errorf("Unexpected panic: %+v", r)
  4516. }
  4517. }
  4518. }()
  4519. buff := ctx.Buffer
  4520. version := buff.ReadUInt8()
  4521. if version > AssetsCodecVersion {
  4522. return fmt.Errorf("Invalid Version Unmarshaling Disk. Expected %d or less, got %d", AssetsCodecVersion, version)
  4523. }
  4524. // --- [begin][read][alias](AssetLabels) ---
  4525. var a map[string]string
  4526. if buff.ReadUInt8() == uint8(0) {
  4527. a = nil
  4528. } else {
  4529. // --- [begin][read][map](map[string]string) ---
  4530. c := buff.ReadInt() // map len
  4531. b := make(map[string]string, c)
  4532. for i := 0; i < c; i++ {
  4533. var v string
  4534. var e string
  4535. if ctx.IsStringTable() {
  4536. f := buff.ReadInt() // read string index
  4537. e = ctx.Table[f]
  4538. } else {
  4539. e = buff.ReadString() // read string
  4540. }
  4541. d := e
  4542. v = d
  4543. var z string
  4544. var h string
  4545. if ctx.IsStringTable() {
  4546. k := buff.ReadInt() // read string index
  4547. h = ctx.Table[k]
  4548. } else {
  4549. h = buff.ReadString() // read string
  4550. }
  4551. g := h
  4552. z = g
  4553. b[v] = z
  4554. }
  4555. a = b
  4556. // --- [end][read][map](map[string]string) ---
  4557. }
  4558. target.Labels = AssetLabels(a)
  4559. // --- [end][read][alias](AssetLabels) ---
  4560. if buff.ReadUInt8() == uint8(0) {
  4561. target.Properties = nil
  4562. } else {
  4563. // --- [begin][read][struct](AssetProperties) ---
  4564. l := &AssetProperties{}
  4565. buff.ReadInt() // [compatibility, unused]
  4566. errA := l.UnmarshalBinaryWithContext(ctx)
  4567. if errA != nil {
  4568. return errA
  4569. }
  4570. target.Properties = l
  4571. // --- [end][read][struct](AssetProperties) ---
  4572. }
  4573. // --- [begin][read][reference](time.Time) ---
  4574. m := &time.Time{}
  4575. n := buff.ReadInt() // byte array length
  4576. o := buff.ReadBytes(n) // byte array
  4577. errB := m.UnmarshalBinary(o)
  4578. if errB != nil {
  4579. return errB
  4580. }
  4581. target.Start = *m
  4582. // --- [end][read][reference](time.Time) ---
  4583. // --- [begin][read][reference](time.Time) ---
  4584. p := &time.Time{}
  4585. q := buff.ReadInt() // byte array length
  4586. r := buff.ReadBytes(q) // byte array
  4587. errC := p.UnmarshalBinary(r)
  4588. if errC != nil {
  4589. return errC
  4590. }
  4591. target.End = *p
  4592. // --- [end][read][reference](time.Time) ---
  4593. // --- [begin][read][struct](Window) ---
  4594. s := &Window{}
  4595. buff.ReadInt() // [compatibility, unused]
  4596. errD := s.UnmarshalBinaryWithContext(ctx)
  4597. if errD != nil {
  4598. return errD
  4599. }
  4600. target.Window = *s
  4601. // --- [end][read][struct](Window) ---
  4602. t := buff.ReadFloat64() // read float64
  4603. target.Adjustment = t
  4604. u := buff.ReadFloat64() // read float64
  4605. target.Cost = u
  4606. w := buff.ReadFloat64() // read float64
  4607. target.ByteHours = w
  4608. x := buff.ReadFloat64() // read float64
  4609. target.Local = x
  4610. if buff.ReadUInt8() == uint8(0) {
  4611. target.Breakdown = nil
  4612. } else {
  4613. // --- [begin][read][struct](Breakdown) ---
  4614. y := &Breakdown{}
  4615. buff.ReadInt() // [compatibility, unused]
  4616. errE := y.UnmarshalBinaryWithContext(ctx)
  4617. if errE != nil {
  4618. return errE
  4619. }
  4620. target.Breakdown = y
  4621. // --- [end][read][struct](Breakdown) ---
  4622. }
  4623. // field version check
  4624. if uint8(17) <= version {
  4625. var bb string
  4626. if ctx.IsStringTable() {
  4627. cc := buff.ReadInt() // read string index
  4628. bb = ctx.Table[cc]
  4629. } else {
  4630. bb = buff.ReadString() // read string
  4631. }
  4632. aa := bb
  4633. target.StorageClass = aa
  4634. } else {
  4635. target.StorageClass = "" // default
  4636. }
  4637. // field version check
  4638. if uint8(18) <= version {
  4639. if buff.ReadUInt8() == uint8(0) {
  4640. target.ByteHoursUsed = nil
  4641. } else {
  4642. dd := buff.ReadFloat64() // read float64
  4643. target.ByteHoursUsed = &dd
  4644. }
  4645. } else {
  4646. target.ByteHoursUsed = nil
  4647. }
  4648. // field version check
  4649. if uint8(18) <= version {
  4650. if buff.ReadUInt8() == uint8(0) {
  4651. target.ByteUsageMax = nil
  4652. } else {
  4653. ee := buff.ReadFloat64() // read float64
  4654. target.ByteUsageMax = &ee
  4655. }
  4656. } else {
  4657. target.ByteUsageMax = nil
  4658. }
  4659. // field version check
  4660. if uint8(18) <= version {
  4661. var gg string
  4662. if ctx.IsStringTable() {
  4663. hh := buff.ReadInt() // read string index
  4664. gg = ctx.Table[hh]
  4665. } else {
  4666. gg = buff.ReadString() // read string
  4667. }
  4668. ff := gg
  4669. target.VolumeName = ff
  4670. } else {
  4671. target.VolumeName = "" // default
  4672. }
  4673. // field version check
  4674. if uint8(18) <= version {
  4675. var ll string
  4676. if ctx.IsStringTable() {
  4677. mm := buff.ReadInt() // read string index
  4678. ll = ctx.Table[mm]
  4679. } else {
  4680. ll = buff.ReadString() // read string
  4681. }
  4682. kk := ll
  4683. target.ClaimName = kk
  4684. } else {
  4685. target.ClaimName = "" // default
  4686. }
  4687. // field version check
  4688. if uint8(18) <= version {
  4689. var oo string
  4690. if ctx.IsStringTable() {
  4691. pp := buff.ReadInt() // read string index
  4692. oo = ctx.Table[pp]
  4693. } else {
  4694. oo = buff.ReadString() // read string
  4695. }
  4696. nn := oo
  4697. target.ClaimNamespace = nn
  4698. } else {
  4699. target.ClaimNamespace = "" // default
  4700. }
  4701. return nil
  4702. }
  4703. //--------------------------------------------------------------------------
  4704. // LbAllocation
  4705. //--------------------------------------------------------------------------
  4706. // MarshalBinary serializes the internal properties of this LbAllocation instance
  4707. // into a byte array
  4708. func (target *LbAllocation) MarshalBinary() (data []byte, err error) {
  4709. ctx := &EncodingContext{
  4710. Buffer: util.NewBuffer(),
  4711. Table: nil,
  4712. }
  4713. e := target.MarshalBinaryWithContext(ctx)
  4714. if e != nil {
  4715. return nil, e
  4716. }
  4717. encBytes := ctx.Buffer.Bytes()
  4718. return encBytes, nil
  4719. }
  4720. // MarshalBinaryWithContext serializes the internal properties of this LbAllocation instance
  4721. // into a byte array leveraging a predefined context.
  4722. func (target *LbAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4723. // panics are recovered and propagated as errors
  4724. defer func() {
  4725. if r := recover(); r != nil {
  4726. if e, ok := r.(error); ok {
  4727. err = e
  4728. } else if s, ok := r.(string); ok {
  4729. err = fmt.Errorf("Unexpected panic: %s", s)
  4730. } else {
  4731. err = fmt.Errorf("Unexpected panic: %+v", r)
  4732. }
  4733. }
  4734. }()
  4735. buff := ctx.Buffer
  4736. buff.WriteUInt8(AllocationCodecVersion) // version
  4737. if ctx.IsStringTable() {
  4738. a := ctx.Table.AddOrGet(target.Service)
  4739. buff.WriteInt(a) // write table index
  4740. } else {
  4741. buff.WriteString(target.Service) // write string
  4742. }
  4743. buff.WriteFloat64(target.Cost) // write float64
  4744. buff.WriteBool(target.Private) // write bool
  4745. if ctx.IsStringTable() {
  4746. b := ctx.Table.AddOrGet(target.Ip)
  4747. buff.WriteInt(b) // write table index
  4748. } else {
  4749. buff.WriteString(target.Ip) // write string
  4750. }
  4751. buff.WriteFloat64(target.Hours) // write float64
  4752. return nil
  4753. }
  4754. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4755. // the LbAllocation type
  4756. func (target *LbAllocation) UnmarshalBinary(data []byte) error {
  4757. var table []string
  4758. buff := util.NewBufferFromBytes(data)
  4759. // string table header validation
  4760. if isBinaryTag(data, BinaryTagStringTable) {
  4761. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4762. tl := buff.ReadInt() // table length
  4763. if tl > 0 {
  4764. table = make([]string, tl, tl)
  4765. for i := 0; i < tl; i++ {
  4766. table[i] = buff.ReadString()
  4767. }
  4768. }
  4769. }
  4770. ctx := &DecodingContext{
  4771. Buffer: buff,
  4772. Table: table,
  4773. }
  4774. err := target.UnmarshalBinaryWithContext(ctx)
  4775. if err != nil {
  4776. return err
  4777. }
  4778. return nil
  4779. }
  4780. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4781. // the LbAllocation type
  4782. func (target *LbAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4783. // panics are recovered and propagated as errors
  4784. defer func() {
  4785. if r := recover(); r != nil {
  4786. if e, ok := r.(error); ok {
  4787. err = e
  4788. } else if s, ok := r.(string); ok {
  4789. err = fmt.Errorf("Unexpected panic: %s", s)
  4790. } else {
  4791. err = fmt.Errorf("Unexpected panic: %+v", r)
  4792. }
  4793. }
  4794. }()
  4795. buff := ctx.Buffer
  4796. version := buff.ReadUInt8()
  4797. if version > AllocationCodecVersion {
  4798. return fmt.Errorf("Invalid Version Unmarshaling LbAllocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  4799. }
  4800. var b string
  4801. if ctx.IsStringTable() {
  4802. c := buff.ReadInt() // read string index
  4803. b = ctx.Table[c]
  4804. } else {
  4805. b = buff.ReadString() // read string
  4806. }
  4807. a := b
  4808. target.Service = a
  4809. d := buff.ReadFloat64() // read float64
  4810. target.Cost = d
  4811. e := buff.ReadBool() // read bool
  4812. target.Private = e
  4813. // field version check
  4814. if uint8(19) <= version {
  4815. var g string
  4816. if ctx.IsStringTable() {
  4817. h := buff.ReadInt() // read string index
  4818. g = ctx.Table[h]
  4819. } else {
  4820. g = buff.ReadString() // read string
  4821. }
  4822. f := g
  4823. target.Ip = f
  4824. } else {
  4825. target.Ip = "" // default
  4826. }
  4827. // field version check
  4828. if uint8(21) <= version {
  4829. k := buff.ReadFloat64() // read float64
  4830. target.Hours = k
  4831. } else {
  4832. target.Hours = float64(0) // default
  4833. }
  4834. return nil
  4835. }
  4836. //--------------------------------------------------------------------------
  4837. // LoadBalancer
  4838. //--------------------------------------------------------------------------
  4839. // MarshalBinary serializes the internal properties of this LoadBalancer instance
  4840. // into a byte array
  4841. func (target *LoadBalancer) MarshalBinary() (data []byte, err error) {
  4842. ctx := &EncodingContext{
  4843. Buffer: util.NewBuffer(),
  4844. Table: nil,
  4845. }
  4846. e := target.MarshalBinaryWithContext(ctx)
  4847. if e != nil {
  4848. return nil, e
  4849. }
  4850. encBytes := ctx.Buffer.Bytes()
  4851. return encBytes, nil
  4852. }
  4853. // MarshalBinaryWithContext serializes the internal properties of this LoadBalancer instance
  4854. // into a byte array leveraging a predefined context.
  4855. func (target *LoadBalancer) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4856. // panics are recovered and propagated as errors
  4857. defer func() {
  4858. if r := recover(); r != nil {
  4859. if e, ok := r.(error); ok {
  4860. err = e
  4861. } else if s, ok := r.(string); ok {
  4862. err = fmt.Errorf("Unexpected panic: %s", s)
  4863. } else {
  4864. err = fmt.Errorf("Unexpected panic: %+v", r)
  4865. }
  4866. }
  4867. }()
  4868. buff := ctx.Buffer
  4869. buff.WriteUInt8(AssetsCodecVersion) // version
  4870. if target.Properties == nil {
  4871. buff.WriteUInt8(uint8(0)) // write nil byte
  4872. } else {
  4873. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4874. // --- [begin][write][struct](AssetProperties) ---
  4875. buff.WriteInt(0) // [compatibility, unused]
  4876. errA := target.Properties.MarshalBinaryWithContext(ctx)
  4877. if errA != nil {
  4878. return errA
  4879. }
  4880. // --- [end][write][struct](AssetProperties) ---
  4881. }
  4882. // --- [begin][write][alias](AssetLabels) ---
  4883. if map[string]string(target.Labels) == nil {
  4884. buff.WriteUInt8(uint8(0)) // write nil byte
  4885. } else {
  4886. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4887. // --- [begin][write][map](map[string]string) ---
  4888. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  4889. for v, z := range map[string]string(target.Labels) {
  4890. if ctx.IsStringTable() {
  4891. a := ctx.Table.AddOrGet(v)
  4892. buff.WriteInt(a) // write table index
  4893. } else {
  4894. buff.WriteString(v) // write string
  4895. }
  4896. if ctx.IsStringTable() {
  4897. b := ctx.Table.AddOrGet(z)
  4898. buff.WriteInt(b) // write table index
  4899. } else {
  4900. buff.WriteString(z) // write string
  4901. }
  4902. }
  4903. // --- [end][write][map](map[string]string) ---
  4904. }
  4905. // --- [end][write][alias](AssetLabels) ---
  4906. // --- [begin][write][reference](time.Time) ---
  4907. c, errB := target.Start.MarshalBinary()
  4908. if errB != nil {
  4909. return errB
  4910. }
  4911. buff.WriteInt(len(c))
  4912. buff.WriteBytes(c)
  4913. // --- [end][write][reference](time.Time) ---
  4914. // --- [begin][write][reference](time.Time) ---
  4915. d, errC := target.End.MarshalBinary()
  4916. if errC != nil {
  4917. return errC
  4918. }
  4919. buff.WriteInt(len(d))
  4920. buff.WriteBytes(d)
  4921. // --- [end][write][reference](time.Time) ---
  4922. // --- [begin][write][struct](Window) ---
  4923. buff.WriteInt(0) // [compatibility, unused]
  4924. errD := target.Window.MarshalBinaryWithContext(ctx)
  4925. if errD != nil {
  4926. return errD
  4927. }
  4928. // --- [end][write][struct](Window) ---
  4929. buff.WriteFloat64(target.Adjustment) // write float64
  4930. buff.WriteFloat64(target.Cost) // write float64
  4931. buff.WriteBool(target.Private) // write bool
  4932. if ctx.IsStringTable() {
  4933. e := ctx.Table.AddOrGet(target.Ip)
  4934. buff.WriteInt(e) // write table index
  4935. } else {
  4936. buff.WriteString(target.Ip) // write string
  4937. }
  4938. return nil
  4939. }
  4940. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4941. // the LoadBalancer type
  4942. func (target *LoadBalancer) UnmarshalBinary(data []byte) error {
  4943. var table []string
  4944. buff := util.NewBufferFromBytes(data)
  4945. // string table header validation
  4946. if isBinaryTag(data, BinaryTagStringTable) {
  4947. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4948. tl := buff.ReadInt() // table length
  4949. if tl > 0 {
  4950. table = make([]string, tl, tl)
  4951. for i := 0; i < tl; i++ {
  4952. table[i] = buff.ReadString()
  4953. }
  4954. }
  4955. }
  4956. ctx := &DecodingContext{
  4957. Buffer: buff,
  4958. Table: table,
  4959. }
  4960. err := target.UnmarshalBinaryWithContext(ctx)
  4961. if err != nil {
  4962. return err
  4963. }
  4964. return nil
  4965. }
  4966. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4967. // the LoadBalancer type
  4968. func (target *LoadBalancer) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4969. // panics are recovered and propagated as errors
  4970. defer func() {
  4971. if r := recover(); r != nil {
  4972. if e, ok := r.(error); ok {
  4973. err = e
  4974. } else if s, ok := r.(string); ok {
  4975. err = fmt.Errorf("Unexpected panic: %s", s)
  4976. } else {
  4977. err = fmt.Errorf("Unexpected panic: %+v", r)
  4978. }
  4979. }
  4980. }()
  4981. buff := ctx.Buffer
  4982. version := buff.ReadUInt8()
  4983. if version > AssetsCodecVersion {
  4984. return fmt.Errorf("Invalid Version Unmarshaling LoadBalancer. Expected %d or less, got %d", AssetsCodecVersion, version)
  4985. }
  4986. if buff.ReadUInt8() == uint8(0) {
  4987. target.Properties = nil
  4988. } else {
  4989. // --- [begin][read][struct](AssetProperties) ---
  4990. a := &AssetProperties{}
  4991. buff.ReadInt() // [compatibility, unused]
  4992. errA := a.UnmarshalBinaryWithContext(ctx)
  4993. if errA != nil {
  4994. return errA
  4995. }
  4996. target.Properties = a
  4997. // --- [end][read][struct](AssetProperties) ---
  4998. }
  4999. // --- [begin][read][alias](AssetLabels) ---
  5000. var b map[string]string
  5001. if buff.ReadUInt8() == uint8(0) {
  5002. b = nil
  5003. } else {
  5004. // --- [begin][read][map](map[string]string) ---
  5005. d := buff.ReadInt() // map len
  5006. c := make(map[string]string, d)
  5007. for i := 0; i < d; i++ {
  5008. var v string
  5009. var f string
  5010. if ctx.IsStringTable() {
  5011. g := buff.ReadInt() // read string index
  5012. f = ctx.Table[g]
  5013. } else {
  5014. f = buff.ReadString() // read string
  5015. }
  5016. e := f
  5017. v = e
  5018. var z string
  5019. var k string
  5020. if ctx.IsStringTable() {
  5021. l := buff.ReadInt() // read string index
  5022. k = ctx.Table[l]
  5023. } else {
  5024. k = buff.ReadString() // read string
  5025. }
  5026. h := k
  5027. z = h
  5028. c[v] = z
  5029. }
  5030. b = c
  5031. // --- [end][read][map](map[string]string) ---
  5032. }
  5033. target.Labels = AssetLabels(b)
  5034. // --- [end][read][alias](AssetLabels) ---
  5035. // --- [begin][read][reference](time.Time) ---
  5036. m := &time.Time{}
  5037. n := buff.ReadInt() // byte array length
  5038. o := buff.ReadBytes(n) // byte array
  5039. errB := m.UnmarshalBinary(o)
  5040. if errB != nil {
  5041. return errB
  5042. }
  5043. target.Start = *m
  5044. // --- [end][read][reference](time.Time) ---
  5045. // --- [begin][read][reference](time.Time) ---
  5046. p := &time.Time{}
  5047. q := buff.ReadInt() // byte array length
  5048. r := buff.ReadBytes(q) // byte array
  5049. errC := p.UnmarshalBinary(r)
  5050. if errC != nil {
  5051. return errC
  5052. }
  5053. target.End = *p
  5054. // --- [end][read][reference](time.Time) ---
  5055. // --- [begin][read][struct](Window) ---
  5056. s := &Window{}
  5057. buff.ReadInt() // [compatibility, unused]
  5058. errD := s.UnmarshalBinaryWithContext(ctx)
  5059. if errD != nil {
  5060. return errD
  5061. }
  5062. target.Window = *s
  5063. // --- [end][read][struct](Window) ---
  5064. t := buff.ReadFloat64() // read float64
  5065. target.Adjustment = t
  5066. u := buff.ReadFloat64() // read float64
  5067. target.Cost = u
  5068. // field version check
  5069. if uint8(20) <= version {
  5070. w := buff.ReadBool() // read bool
  5071. target.Private = w
  5072. } else {
  5073. target.Private = false // default
  5074. }
  5075. // field version check
  5076. if uint8(21) <= version {
  5077. var y string
  5078. if ctx.IsStringTable() {
  5079. aa := buff.ReadInt() // read string index
  5080. y = ctx.Table[aa]
  5081. } else {
  5082. y = buff.ReadString() // read string
  5083. }
  5084. x := y
  5085. target.Ip = x
  5086. } else {
  5087. target.Ip = "" // default
  5088. }
  5089. return nil
  5090. }
  5091. //--------------------------------------------------------------------------
  5092. // Network
  5093. //--------------------------------------------------------------------------
  5094. // MarshalBinary serializes the internal properties of this Network instance
  5095. // into a byte array
  5096. func (target *Network) MarshalBinary() (data []byte, err error) {
  5097. ctx := &EncodingContext{
  5098. Buffer: util.NewBuffer(),
  5099. Table: nil,
  5100. }
  5101. e := target.MarshalBinaryWithContext(ctx)
  5102. if e != nil {
  5103. return nil, e
  5104. }
  5105. encBytes := ctx.Buffer.Bytes()
  5106. return encBytes, nil
  5107. }
  5108. // MarshalBinaryWithContext serializes the internal properties of this Network instance
  5109. // into a byte array leveraging a predefined context.
  5110. func (target *Network) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5111. // panics are recovered and propagated as errors
  5112. defer func() {
  5113. if r := recover(); r != nil {
  5114. if e, ok := r.(error); ok {
  5115. err = e
  5116. } else if s, ok := r.(string); ok {
  5117. err = fmt.Errorf("Unexpected panic: %s", s)
  5118. } else {
  5119. err = fmt.Errorf("Unexpected panic: %+v", r)
  5120. }
  5121. }
  5122. }()
  5123. buff := ctx.Buffer
  5124. buff.WriteUInt8(AssetsCodecVersion) // version
  5125. if target.Properties == nil {
  5126. buff.WriteUInt8(uint8(0)) // write nil byte
  5127. } else {
  5128. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5129. // --- [begin][write][struct](AssetProperties) ---
  5130. buff.WriteInt(0) // [compatibility, unused]
  5131. errA := target.Properties.MarshalBinaryWithContext(ctx)
  5132. if errA != nil {
  5133. return errA
  5134. }
  5135. // --- [end][write][struct](AssetProperties) ---
  5136. }
  5137. // --- [begin][write][alias](AssetLabels) ---
  5138. if map[string]string(target.Labels) == nil {
  5139. buff.WriteUInt8(uint8(0)) // write nil byte
  5140. } else {
  5141. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5142. // --- [begin][write][map](map[string]string) ---
  5143. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  5144. for v, z := range map[string]string(target.Labels) {
  5145. if ctx.IsStringTable() {
  5146. a := ctx.Table.AddOrGet(v)
  5147. buff.WriteInt(a) // write table index
  5148. } else {
  5149. buff.WriteString(v) // write string
  5150. }
  5151. if ctx.IsStringTable() {
  5152. b := ctx.Table.AddOrGet(z)
  5153. buff.WriteInt(b) // write table index
  5154. } else {
  5155. buff.WriteString(z) // write string
  5156. }
  5157. }
  5158. // --- [end][write][map](map[string]string) ---
  5159. }
  5160. // --- [end][write][alias](AssetLabels) ---
  5161. // --- [begin][write][reference](time.Time) ---
  5162. c, errB := target.Start.MarshalBinary()
  5163. if errB != nil {
  5164. return errB
  5165. }
  5166. buff.WriteInt(len(c))
  5167. buff.WriteBytes(c)
  5168. // --- [end][write][reference](time.Time) ---
  5169. // --- [begin][write][reference](time.Time) ---
  5170. d, errC := target.End.MarshalBinary()
  5171. if errC != nil {
  5172. return errC
  5173. }
  5174. buff.WriteInt(len(d))
  5175. buff.WriteBytes(d)
  5176. // --- [end][write][reference](time.Time) ---
  5177. // --- [begin][write][struct](Window) ---
  5178. buff.WriteInt(0) // [compatibility, unused]
  5179. errD := target.Window.MarshalBinaryWithContext(ctx)
  5180. if errD != nil {
  5181. return errD
  5182. }
  5183. // --- [end][write][struct](Window) ---
  5184. buff.WriteFloat64(target.Adjustment) // write float64
  5185. buff.WriteFloat64(target.Cost) // write float64
  5186. return nil
  5187. }
  5188. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5189. // the Network type
  5190. func (target *Network) UnmarshalBinary(data []byte) error {
  5191. var table []string
  5192. buff := util.NewBufferFromBytes(data)
  5193. // string table header validation
  5194. if isBinaryTag(data, BinaryTagStringTable) {
  5195. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  5196. tl := buff.ReadInt() // table length
  5197. if tl > 0 {
  5198. table = make([]string, tl, tl)
  5199. for i := 0; i < tl; i++ {
  5200. table[i] = buff.ReadString()
  5201. }
  5202. }
  5203. }
  5204. ctx := &DecodingContext{
  5205. Buffer: buff,
  5206. Table: table,
  5207. }
  5208. err := target.UnmarshalBinaryWithContext(ctx)
  5209. if err != nil {
  5210. return err
  5211. }
  5212. return nil
  5213. }
  5214. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5215. // the Network type
  5216. func (target *Network) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5217. // panics are recovered and propagated as errors
  5218. defer func() {
  5219. if r := recover(); r != nil {
  5220. if e, ok := r.(error); ok {
  5221. err = e
  5222. } else if s, ok := r.(string); ok {
  5223. err = fmt.Errorf("Unexpected panic: %s", s)
  5224. } else {
  5225. err = fmt.Errorf("Unexpected panic: %+v", r)
  5226. }
  5227. }
  5228. }()
  5229. buff := ctx.Buffer
  5230. version := buff.ReadUInt8()
  5231. if version > AssetsCodecVersion {
  5232. return fmt.Errorf("Invalid Version Unmarshaling Network. Expected %d or less, got %d", AssetsCodecVersion, version)
  5233. }
  5234. if buff.ReadUInt8() == uint8(0) {
  5235. target.Properties = nil
  5236. } else {
  5237. // --- [begin][read][struct](AssetProperties) ---
  5238. a := &AssetProperties{}
  5239. buff.ReadInt() // [compatibility, unused]
  5240. errA := a.UnmarshalBinaryWithContext(ctx)
  5241. if errA != nil {
  5242. return errA
  5243. }
  5244. target.Properties = a
  5245. // --- [end][read][struct](AssetProperties) ---
  5246. }
  5247. // --- [begin][read][alias](AssetLabels) ---
  5248. var b map[string]string
  5249. if buff.ReadUInt8() == uint8(0) {
  5250. b = nil
  5251. } else {
  5252. // --- [begin][read][map](map[string]string) ---
  5253. d := buff.ReadInt() // map len
  5254. c := make(map[string]string, d)
  5255. for i := 0; i < d; i++ {
  5256. var v string
  5257. var f string
  5258. if ctx.IsStringTable() {
  5259. g := buff.ReadInt() // read string index
  5260. f = ctx.Table[g]
  5261. } else {
  5262. f = buff.ReadString() // read string
  5263. }
  5264. e := f
  5265. v = e
  5266. var z string
  5267. var k string
  5268. if ctx.IsStringTable() {
  5269. l := buff.ReadInt() // read string index
  5270. k = ctx.Table[l]
  5271. } else {
  5272. k = buff.ReadString() // read string
  5273. }
  5274. h := k
  5275. z = h
  5276. c[v] = z
  5277. }
  5278. b = c
  5279. // --- [end][read][map](map[string]string) ---
  5280. }
  5281. target.Labels = AssetLabels(b)
  5282. // --- [end][read][alias](AssetLabels) ---
  5283. // --- [begin][read][reference](time.Time) ---
  5284. m := &time.Time{}
  5285. n := buff.ReadInt() // byte array length
  5286. o := buff.ReadBytes(n) // byte array
  5287. errB := m.UnmarshalBinary(o)
  5288. if errB != nil {
  5289. return errB
  5290. }
  5291. target.Start = *m
  5292. // --- [end][read][reference](time.Time) ---
  5293. // --- [begin][read][reference](time.Time) ---
  5294. p := &time.Time{}
  5295. q := buff.ReadInt() // byte array length
  5296. r := buff.ReadBytes(q) // byte array
  5297. errC := p.UnmarshalBinary(r)
  5298. if errC != nil {
  5299. return errC
  5300. }
  5301. target.End = *p
  5302. // --- [end][read][reference](time.Time) ---
  5303. // --- [begin][read][struct](Window) ---
  5304. s := &Window{}
  5305. buff.ReadInt() // [compatibility, unused]
  5306. errD := s.UnmarshalBinaryWithContext(ctx)
  5307. if errD != nil {
  5308. return errD
  5309. }
  5310. target.Window = *s
  5311. // --- [end][read][struct](Window) ---
  5312. t := buff.ReadFloat64() // read float64
  5313. target.Adjustment = t
  5314. u := buff.ReadFloat64() // read float64
  5315. target.Cost = u
  5316. return nil
  5317. }
  5318. //--------------------------------------------------------------------------
  5319. // Node
  5320. //--------------------------------------------------------------------------
  5321. // MarshalBinary serializes the internal properties of this Node instance
  5322. // into a byte array
  5323. func (target *Node) MarshalBinary() (data []byte, err error) {
  5324. ctx := &EncodingContext{
  5325. Buffer: util.NewBuffer(),
  5326. Table: nil,
  5327. }
  5328. e := target.MarshalBinaryWithContext(ctx)
  5329. if e != nil {
  5330. return nil, e
  5331. }
  5332. encBytes := ctx.Buffer.Bytes()
  5333. return encBytes, nil
  5334. }
  5335. // MarshalBinaryWithContext serializes the internal properties of this Node instance
  5336. // into a byte array leveraging a predefined context.
  5337. func (target *Node) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5338. // panics are recovered and propagated as errors
  5339. defer func() {
  5340. if r := recover(); r != nil {
  5341. if e, ok := r.(error); ok {
  5342. err = e
  5343. } else if s, ok := r.(string); ok {
  5344. err = fmt.Errorf("Unexpected panic: %s", s)
  5345. } else {
  5346. err = fmt.Errorf("Unexpected panic: %+v", r)
  5347. }
  5348. }
  5349. }()
  5350. buff := ctx.Buffer
  5351. buff.WriteUInt8(AssetsCodecVersion) // version
  5352. if target.Properties == nil {
  5353. buff.WriteUInt8(uint8(0)) // write nil byte
  5354. } else {
  5355. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5356. // --- [begin][write][struct](AssetProperties) ---
  5357. buff.WriteInt(0) // [compatibility, unused]
  5358. errA := target.Properties.MarshalBinaryWithContext(ctx)
  5359. if errA != nil {
  5360. return errA
  5361. }
  5362. // --- [end][write][struct](AssetProperties) ---
  5363. }
  5364. // --- [begin][write][alias](AssetLabels) ---
  5365. if map[string]string(target.Labels) == nil {
  5366. buff.WriteUInt8(uint8(0)) // write nil byte
  5367. } else {
  5368. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5369. // --- [begin][write][map](map[string]string) ---
  5370. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  5371. for v, z := range map[string]string(target.Labels) {
  5372. if ctx.IsStringTable() {
  5373. a := ctx.Table.AddOrGet(v)
  5374. buff.WriteInt(a) // write table index
  5375. } else {
  5376. buff.WriteString(v) // write string
  5377. }
  5378. if ctx.IsStringTable() {
  5379. b := ctx.Table.AddOrGet(z)
  5380. buff.WriteInt(b) // write table index
  5381. } else {
  5382. buff.WriteString(z) // write string
  5383. }
  5384. }
  5385. // --- [end][write][map](map[string]string) ---
  5386. }
  5387. // --- [end][write][alias](AssetLabels) ---
  5388. // --- [begin][write][reference](time.Time) ---
  5389. c, errB := target.Start.MarshalBinary()
  5390. if errB != nil {
  5391. return errB
  5392. }
  5393. buff.WriteInt(len(c))
  5394. buff.WriteBytes(c)
  5395. // --- [end][write][reference](time.Time) ---
  5396. // --- [begin][write][reference](time.Time) ---
  5397. d, errC := target.End.MarshalBinary()
  5398. if errC != nil {
  5399. return errC
  5400. }
  5401. buff.WriteInt(len(d))
  5402. buff.WriteBytes(d)
  5403. // --- [end][write][reference](time.Time) ---
  5404. // --- [begin][write][struct](Window) ---
  5405. buff.WriteInt(0) // [compatibility, unused]
  5406. errD := target.Window.MarshalBinaryWithContext(ctx)
  5407. if errD != nil {
  5408. return errD
  5409. }
  5410. // --- [end][write][struct](Window) ---
  5411. buff.WriteFloat64(target.Adjustment) // write float64
  5412. if ctx.IsStringTable() {
  5413. e := ctx.Table.AddOrGet(target.NodeType)
  5414. buff.WriteInt(e) // write table index
  5415. } else {
  5416. buff.WriteString(target.NodeType) // write string
  5417. }
  5418. buff.WriteFloat64(target.CPUCoreHours) // write float64
  5419. buff.WriteFloat64(target.RAMByteHours) // write float64
  5420. buff.WriteFloat64(target.GPUHours) // write float64
  5421. if target.CPUBreakdown == nil {
  5422. buff.WriteUInt8(uint8(0)) // write nil byte
  5423. } else {
  5424. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5425. // --- [begin][write][struct](Breakdown) ---
  5426. buff.WriteInt(0) // [compatibility, unused]
  5427. errE := target.CPUBreakdown.MarshalBinaryWithContext(ctx)
  5428. if errE != nil {
  5429. return errE
  5430. }
  5431. // --- [end][write][struct](Breakdown) ---
  5432. }
  5433. if target.RAMBreakdown == nil {
  5434. buff.WriteUInt8(uint8(0)) // write nil byte
  5435. } else {
  5436. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5437. // --- [begin][write][struct](Breakdown) ---
  5438. buff.WriteInt(0) // [compatibility, unused]
  5439. errF := target.RAMBreakdown.MarshalBinaryWithContext(ctx)
  5440. if errF != nil {
  5441. return errF
  5442. }
  5443. // --- [end][write][struct](Breakdown) ---
  5444. }
  5445. buff.WriteFloat64(target.CPUCost) // write float64
  5446. buff.WriteFloat64(target.GPUCost) // write float64
  5447. buff.WriteFloat64(target.GPUCount) // write float64
  5448. buff.WriteFloat64(target.RAMCost) // write float64
  5449. buff.WriteFloat64(target.Discount) // write float64
  5450. buff.WriteFloat64(target.Preemptible) // write float64
  5451. if target.Overhead == nil {
  5452. buff.WriteUInt8(uint8(0)) // write nil byte
  5453. } else {
  5454. buff.WriteUInt8(uint8(1)) // write non-nil byte
  5455. // --- [begin][write][struct](NodeOverhead) ---
  5456. buff.WriteInt(0) // [compatibility, unused]
  5457. errG := target.Overhead.MarshalBinaryWithContext(ctx)
  5458. if errG != nil {
  5459. return errG
  5460. }
  5461. // --- [end][write][struct](NodeOverhead) ---
  5462. }
  5463. return nil
  5464. }
  5465. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5466. // the Node type
  5467. func (target *Node) UnmarshalBinary(data []byte) error {
  5468. var table []string
  5469. buff := util.NewBufferFromBytes(data)
  5470. // string table header validation
  5471. if isBinaryTag(data, BinaryTagStringTable) {
  5472. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  5473. tl := buff.ReadInt() // table length
  5474. if tl > 0 {
  5475. table = make([]string, tl, tl)
  5476. for i := 0; i < tl; i++ {
  5477. table[i] = buff.ReadString()
  5478. }
  5479. }
  5480. }
  5481. ctx := &DecodingContext{
  5482. Buffer: buff,
  5483. Table: table,
  5484. }
  5485. err := target.UnmarshalBinaryWithContext(ctx)
  5486. if err != nil {
  5487. return err
  5488. }
  5489. return nil
  5490. }
  5491. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5492. // the Node type
  5493. func (target *Node) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5494. // panics are recovered and propagated as errors
  5495. defer func() {
  5496. if r := recover(); r != nil {
  5497. if e, ok := r.(error); ok {
  5498. err = e
  5499. } else if s, ok := r.(string); ok {
  5500. err = fmt.Errorf("Unexpected panic: %s", s)
  5501. } else {
  5502. err = fmt.Errorf("Unexpected panic: %+v", r)
  5503. }
  5504. }
  5505. }()
  5506. buff := ctx.Buffer
  5507. version := buff.ReadUInt8()
  5508. if version > AssetsCodecVersion {
  5509. return fmt.Errorf("Invalid Version Unmarshaling Node. Expected %d or less, got %d", AssetsCodecVersion, version)
  5510. }
  5511. if buff.ReadUInt8() == uint8(0) {
  5512. target.Properties = nil
  5513. } else {
  5514. // --- [begin][read][struct](AssetProperties) ---
  5515. a := &AssetProperties{}
  5516. buff.ReadInt() // [compatibility, unused]
  5517. errA := a.UnmarshalBinaryWithContext(ctx)
  5518. if errA != nil {
  5519. return errA
  5520. }
  5521. target.Properties = a
  5522. // --- [end][read][struct](AssetProperties) ---
  5523. }
  5524. // --- [begin][read][alias](AssetLabels) ---
  5525. var b map[string]string
  5526. if buff.ReadUInt8() == uint8(0) {
  5527. b = nil
  5528. } else {
  5529. // --- [begin][read][map](map[string]string) ---
  5530. d := buff.ReadInt() // map len
  5531. c := make(map[string]string, d)
  5532. for i := 0; i < d; i++ {
  5533. var v string
  5534. var f string
  5535. if ctx.IsStringTable() {
  5536. g := buff.ReadInt() // read string index
  5537. f = ctx.Table[g]
  5538. } else {
  5539. f = buff.ReadString() // read string
  5540. }
  5541. e := f
  5542. v = e
  5543. var z string
  5544. var k string
  5545. if ctx.IsStringTable() {
  5546. l := buff.ReadInt() // read string index
  5547. k = ctx.Table[l]
  5548. } else {
  5549. k = buff.ReadString() // read string
  5550. }
  5551. h := k
  5552. z = h
  5553. c[v] = z
  5554. }
  5555. b = c
  5556. // --- [end][read][map](map[string]string) ---
  5557. }
  5558. target.Labels = AssetLabels(b)
  5559. // --- [end][read][alias](AssetLabels) ---
  5560. // --- [begin][read][reference](time.Time) ---
  5561. m := &time.Time{}
  5562. n := buff.ReadInt() // byte array length
  5563. o := buff.ReadBytes(n) // byte array
  5564. errB := m.UnmarshalBinary(o)
  5565. if errB != nil {
  5566. return errB
  5567. }
  5568. target.Start = *m
  5569. // --- [end][read][reference](time.Time) ---
  5570. // --- [begin][read][reference](time.Time) ---
  5571. p := &time.Time{}
  5572. q := buff.ReadInt() // byte array length
  5573. r := buff.ReadBytes(q) // byte array
  5574. errC := p.UnmarshalBinary(r)
  5575. if errC != nil {
  5576. return errC
  5577. }
  5578. target.End = *p
  5579. // --- [end][read][reference](time.Time) ---
  5580. // --- [begin][read][struct](Window) ---
  5581. s := &Window{}
  5582. buff.ReadInt() // [compatibility, unused]
  5583. errD := s.UnmarshalBinaryWithContext(ctx)
  5584. if errD != nil {
  5585. return errD
  5586. }
  5587. target.Window = *s
  5588. // --- [end][read][struct](Window) ---
  5589. t := buff.ReadFloat64() // read float64
  5590. target.Adjustment = t
  5591. var w string
  5592. if ctx.IsStringTable() {
  5593. x := buff.ReadInt() // read string index
  5594. w = ctx.Table[x]
  5595. } else {
  5596. w = buff.ReadString() // read string
  5597. }
  5598. u := w
  5599. target.NodeType = u
  5600. y := buff.ReadFloat64() // read float64
  5601. target.CPUCoreHours = y
  5602. aa := buff.ReadFloat64() // read float64
  5603. target.RAMByteHours = aa
  5604. bb := buff.ReadFloat64() // read float64
  5605. target.GPUHours = bb
  5606. if buff.ReadUInt8() == uint8(0) {
  5607. target.CPUBreakdown = nil
  5608. } else {
  5609. // --- [begin][read][struct](Breakdown) ---
  5610. cc := &Breakdown{}
  5611. buff.ReadInt() // [compatibility, unused]
  5612. errE := cc.UnmarshalBinaryWithContext(ctx)
  5613. if errE != nil {
  5614. return errE
  5615. }
  5616. target.CPUBreakdown = cc
  5617. // --- [end][read][struct](Breakdown) ---
  5618. }
  5619. if buff.ReadUInt8() == uint8(0) {
  5620. target.RAMBreakdown = nil
  5621. } else {
  5622. // --- [begin][read][struct](Breakdown) ---
  5623. dd := &Breakdown{}
  5624. buff.ReadInt() // [compatibility, unused]
  5625. errF := dd.UnmarshalBinaryWithContext(ctx)
  5626. if errF != nil {
  5627. return errF
  5628. }
  5629. target.RAMBreakdown = dd
  5630. // --- [end][read][struct](Breakdown) ---
  5631. }
  5632. ee := buff.ReadFloat64() // read float64
  5633. target.CPUCost = ee
  5634. ff := buff.ReadFloat64() // read float64
  5635. target.GPUCost = ff
  5636. gg := buff.ReadFloat64() // read float64
  5637. target.GPUCount = gg
  5638. hh := buff.ReadFloat64() // read float64
  5639. target.RAMCost = hh
  5640. kk := buff.ReadFloat64() // read float64
  5641. target.Discount = kk
  5642. ll := buff.ReadFloat64() // read float64
  5643. target.Preemptible = ll
  5644. // field version check
  5645. if uint8(19) <= version {
  5646. if buff.ReadUInt8() == uint8(0) {
  5647. target.Overhead = nil
  5648. } else {
  5649. // --- [begin][read][struct](NodeOverhead) ---
  5650. mm := &NodeOverhead{}
  5651. buff.ReadInt() // [compatibility, unused]
  5652. errG := mm.UnmarshalBinaryWithContext(ctx)
  5653. if errG != nil {
  5654. return errG
  5655. }
  5656. target.Overhead = mm
  5657. // --- [end][read][struct](NodeOverhead) ---
  5658. }
  5659. } else {
  5660. target.Overhead = nil
  5661. }
  5662. return nil
  5663. }
  5664. //--------------------------------------------------------------------------
  5665. // NodeOverhead
  5666. //--------------------------------------------------------------------------
  5667. // MarshalBinary serializes the internal properties of this NodeOverhead instance
  5668. // into a byte array
  5669. func (target *NodeOverhead) MarshalBinary() (data []byte, err error) {
  5670. ctx := &EncodingContext{
  5671. Buffer: util.NewBuffer(),
  5672. Table: nil,
  5673. }
  5674. e := target.MarshalBinaryWithContext(ctx)
  5675. if e != nil {
  5676. return nil, e
  5677. }
  5678. encBytes := ctx.Buffer.Bytes()
  5679. return encBytes, nil
  5680. }
  5681. // MarshalBinaryWithContext serializes the internal properties of this NodeOverhead instance
  5682. // into a byte array leveraging a predefined context.
  5683. func (target *NodeOverhead) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5684. // panics are recovered and propagated as errors
  5685. defer func() {
  5686. if r := recover(); r != nil {
  5687. if e, ok := r.(error); ok {
  5688. err = e
  5689. } else if s, ok := r.(string); ok {
  5690. err = fmt.Errorf("Unexpected panic: %s", s)
  5691. } else {
  5692. err = fmt.Errorf("Unexpected panic: %+v", r)
  5693. }
  5694. }
  5695. }()
  5696. buff := ctx.Buffer
  5697. buff.WriteUInt8(AssetsCodecVersion) // version
  5698. buff.WriteFloat64(target.CpuOverheadFraction) // write float64
  5699. buff.WriteFloat64(target.RamOverheadFraction) // write float64
  5700. buff.WriteFloat64(target.OverheadCostFraction) // write float64
  5701. return nil
  5702. }
  5703. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5704. // the NodeOverhead type
  5705. func (target *NodeOverhead) UnmarshalBinary(data []byte) error {
  5706. var table []string
  5707. buff := util.NewBufferFromBytes(data)
  5708. // string table header validation
  5709. if isBinaryTag(data, BinaryTagStringTable) {
  5710. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  5711. tl := buff.ReadInt() // table length
  5712. if tl > 0 {
  5713. table = make([]string, tl, tl)
  5714. for i := 0; i < tl; i++ {
  5715. table[i] = buff.ReadString()
  5716. }
  5717. }
  5718. }
  5719. ctx := &DecodingContext{
  5720. Buffer: buff,
  5721. Table: table,
  5722. }
  5723. err := target.UnmarshalBinaryWithContext(ctx)
  5724. if err != nil {
  5725. return err
  5726. }
  5727. return nil
  5728. }
  5729. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5730. // the NodeOverhead type
  5731. func (target *NodeOverhead) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5732. // panics are recovered and propagated as errors
  5733. defer func() {
  5734. if r := recover(); r != nil {
  5735. if e, ok := r.(error); ok {
  5736. err = e
  5737. } else if s, ok := r.(string); ok {
  5738. err = fmt.Errorf("Unexpected panic: %s", s)
  5739. } else {
  5740. err = fmt.Errorf("Unexpected panic: %+v", r)
  5741. }
  5742. }
  5743. }()
  5744. buff := ctx.Buffer
  5745. version := buff.ReadUInt8()
  5746. if version > AssetsCodecVersion {
  5747. return fmt.Errorf("Invalid Version Unmarshaling NodeOverhead. Expected %d or less, got %d", AssetsCodecVersion, version)
  5748. }
  5749. a := buff.ReadFloat64() // read float64
  5750. target.CpuOverheadFraction = a
  5751. b := buff.ReadFloat64() // read float64
  5752. target.RamOverheadFraction = b
  5753. c := buff.ReadFloat64() // read float64
  5754. target.OverheadCostFraction = c
  5755. return nil
  5756. }
  5757. //--------------------------------------------------------------------------
  5758. // PVAllocation
  5759. //--------------------------------------------------------------------------
  5760. // MarshalBinary serializes the internal properties of this PVAllocation instance
  5761. // into a byte array
  5762. func (target *PVAllocation) MarshalBinary() (data []byte, err error) {
  5763. ctx := &EncodingContext{
  5764. Buffer: util.NewBuffer(),
  5765. Table: nil,
  5766. }
  5767. e := target.MarshalBinaryWithContext(ctx)
  5768. if e != nil {
  5769. return nil, e
  5770. }
  5771. encBytes := ctx.Buffer.Bytes()
  5772. return encBytes, nil
  5773. }
  5774. // MarshalBinaryWithContext serializes the internal properties of this PVAllocation instance
  5775. // into a byte array leveraging a predefined context.
  5776. func (target *PVAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5777. // panics are recovered and propagated as errors
  5778. defer func() {
  5779. if r := recover(); r != nil {
  5780. if e, ok := r.(error); ok {
  5781. err = e
  5782. } else if s, ok := r.(string); ok {
  5783. err = fmt.Errorf("Unexpected panic: %s", s)
  5784. } else {
  5785. err = fmt.Errorf("Unexpected panic: %+v", r)
  5786. }
  5787. }
  5788. }()
  5789. buff := ctx.Buffer
  5790. buff.WriteUInt8(AllocationCodecVersion) // version
  5791. buff.WriteFloat64(target.ByteHours) // write float64
  5792. buff.WriteFloat64(target.Cost) // write float64
  5793. if ctx.IsStringTable() {
  5794. a := ctx.Table.AddOrGet(target.ProviderID)
  5795. buff.WriteInt(a) // write table index
  5796. } else {
  5797. buff.WriteString(target.ProviderID) // write string
  5798. }
  5799. return nil
  5800. }
  5801. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5802. // the PVAllocation type
  5803. func (target *PVAllocation) UnmarshalBinary(data []byte) error {
  5804. var table []string
  5805. buff := util.NewBufferFromBytes(data)
  5806. // string table header validation
  5807. if isBinaryTag(data, BinaryTagStringTable) {
  5808. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  5809. tl := buff.ReadInt() // table length
  5810. if tl > 0 {
  5811. table = make([]string, tl, tl)
  5812. for i := 0; i < tl; i++ {
  5813. table[i] = buff.ReadString()
  5814. }
  5815. }
  5816. }
  5817. ctx := &DecodingContext{
  5818. Buffer: buff,
  5819. Table: table,
  5820. }
  5821. err := target.UnmarshalBinaryWithContext(ctx)
  5822. if err != nil {
  5823. return err
  5824. }
  5825. return nil
  5826. }
  5827. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5828. // the PVAllocation type
  5829. func (target *PVAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5830. // panics are recovered and propagated as errors
  5831. defer func() {
  5832. if r := recover(); r != nil {
  5833. if e, ok := r.(error); ok {
  5834. err = e
  5835. } else if s, ok := r.(string); ok {
  5836. err = fmt.Errorf("Unexpected panic: %s", s)
  5837. } else {
  5838. err = fmt.Errorf("Unexpected panic: %+v", r)
  5839. }
  5840. }
  5841. }()
  5842. buff := ctx.Buffer
  5843. version := buff.ReadUInt8()
  5844. if version > AllocationCodecVersion {
  5845. return fmt.Errorf("Invalid Version Unmarshaling PVAllocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  5846. }
  5847. a := buff.ReadFloat64() // read float64
  5848. target.ByteHours = a
  5849. b := buff.ReadFloat64() // read float64
  5850. target.Cost = b
  5851. // field version check
  5852. if uint8(20) <= version {
  5853. var d string
  5854. if ctx.IsStringTable() {
  5855. e := buff.ReadInt() // read string index
  5856. d = ctx.Table[e]
  5857. } else {
  5858. d = buff.ReadString() // read string
  5859. }
  5860. c := d
  5861. target.ProviderID = c
  5862. } else {
  5863. target.ProviderID = "" // default
  5864. }
  5865. return nil
  5866. }
  5867. //--------------------------------------------------------------------------
  5868. // PVKey
  5869. //--------------------------------------------------------------------------
  5870. // MarshalBinary serializes the internal properties of this PVKey instance
  5871. // into a byte array
  5872. func (target *PVKey) MarshalBinary() (data []byte, err error) {
  5873. ctx := &EncodingContext{
  5874. Buffer: util.NewBuffer(),
  5875. Table: nil,
  5876. }
  5877. e := target.MarshalBinaryWithContext(ctx)
  5878. if e != nil {
  5879. return nil, e
  5880. }
  5881. encBytes := ctx.Buffer.Bytes()
  5882. return encBytes, nil
  5883. }
  5884. // MarshalBinaryWithContext serializes the internal properties of this PVKey instance
  5885. // into a byte array leveraging a predefined context.
  5886. func (target *PVKey) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  5887. // panics are recovered and propagated as errors
  5888. defer func() {
  5889. if r := recover(); r != nil {
  5890. if e, ok := r.(error); ok {
  5891. err = e
  5892. } else if s, ok := r.(string); ok {
  5893. err = fmt.Errorf("Unexpected panic: %s", s)
  5894. } else {
  5895. err = fmt.Errorf("Unexpected panic: %+v", r)
  5896. }
  5897. }
  5898. }()
  5899. buff := ctx.Buffer
  5900. buff.WriteUInt8(AllocationCodecVersion) // version
  5901. if ctx.IsStringTable() {
  5902. a := ctx.Table.AddOrGet(target.Cluster)
  5903. buff.WriteInt(a) // write table index
  5904. } else {
  5905. buff.WriteString(target.Cluster) // write string
  5906. }
  5907. if ctx.IsStringTable() {
  5908. b := ctx.Table.AddOrGet(target.Name)
  5909. buff.WriteInt(b) // write table index
  5910. } else {
  5911. buff.WriteString(target.Name) // write string
  5912. }
  5913. return nil
  5914. }
  5915. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  5916. // the PVKey type
  5917. func (target *PVKey) UnmarshalBinary(data []byte) error {
  5918. var table []string
  5919. buff := util.NewBufferFromBytes(data)
  5920. // string table header validation
  5921. if isBinaryTag(data, BinaryTagStringTable) {
  5922. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  5923. tl := buff.ReadInt() // table length
  5924. if tl > 0 {
  5925. table = make([]string, tl, tl)
  5926. for i := 0; i < tl; i++ {
  5927. table[i] = buff.ReadString()
  5928. }
  5929. }
  5930. }
  5931. ctx := &DecodingContext{
  5932. Buffer: buff,
  5933. Table: table,
  5934. }
  5935. err := target.UnmarshalBinaryWithContext(ctx)
  5936. if err != nil {
  5937. return err
  5938. }
  5939. return nil
  5940. }
  5941. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  5942. // the PVKey type
  5943. func (target *PVKey) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  5944. // panics are recovered and propagated as errors
  5945. defer func() {
  5946. if r := recover(); r != nil {
  5947. if e, ok := r.(error); ok {
  5948. err = e
  5949. } else if s, ok := r.(string); ok {
  5950. err = fmt.Errorf("Unexpected panic: %s", s)
  5951. } else {
  5952. err = fmt.Errorf("Unexpected panic: %+v", r)
  5953. }
  5954. }
  5955. }()
  5956. buff := ctx.Buffer
  5957. version := buff.ReadUInt8()
  5958. if version > AllocationCodecVersion {
  5959. return fmt.Errorf("Invalid Version Unmarshaling PVKey. Expected %d or less, got %d", AllocationCodecVersion, version)
  5960. }
  5961. var b string
  5962. if ctx.IsStringTable() {
  5963. c := buff.ReadInt() // read string index
  5964. b = ctx.Table[c]
  5965. } else {
  5966. b = buff.ReadString() // read string
  5967. }
  5968. a := b
  5969. target.Cluster = a
  5970. var e string
  5971. if ctx.IsStringTable() {
  5972. f := buff.ReadInt() // read string index
  5973. e = ctx.Table[f]
  5974. } else {
  5975. e = buff.ReadString() // read string
  5976. }
  5977. d := e
  5978. target.Name = d
  5979. return nil
  5980. }
  5981. //--------------------------------------------------------------------------
  5982. // RawAllocationOnlyData
  5983. //--------------------------------------------------------------------------
  5984. // MarshalBinary serializes the internal properties of this RawAllocationOnlyData instance
  5985. // into a byte array
  5986. func (target *RawAllocationOnlyData) MarshalBinary() (data []byte, err error) {
  5987. ctx := &EncodingContext{
  5988. Buffer: util.NewBuffer(),
  5989. Table: nil,
  5990. }
  5991. e := target.MarshalBinaryWithContext(ctx)
  5992. if e != nil {
  5993. return nil, e
  5994. }
  5995. encBytes := ctx.Buffer.Bytes()
  5996. return encBytes, nil
  5997. }
  5998. // MarshalBinaryWithContext serializes the internal properties of this RawAllocationOnlyData instance
  5999. // into a byte array leveraging a predefined context.
  6000. func (target *RawAllocationOnlyData) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  6001. // panics are recovered and propagated as errors
  6002. defer func() {
  6003. if r := recover(); r != nil {
  6004. if e, ok := r.(error); ok {
  6005. err = e
  6006. } else if s, ok := r.(string); ok {
  6007. err = fmt.Errorf("Unexpected panic: %s", s)
  6008. } else {
  6009. err = fmt.Errorf("Unexpected panic: %+v", r)
  6010. }
  6011. }
  6012. }()
  6013. buff := ctx.Buffer
  6014. buff.WriteUInt8(AllocationCodecVersion) // version
  6015. buff.WriteFloat64(target.CPUCoreUsageMax) // write float64
  6016. buff.WriteFloat64(target.RAMBytesUsageMax) // write float64
  6017. return nil
  6018. }
  6019. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  6020. // the RawAllocationOnlyData type
  6021. func (target *RawAllocationOnlyData) UnmarshalBinary(data []byte) error {
  6022. var table []string
  6023. buff := util.NewBufferFromBytes(data)
  6024. // string table header validation
  6025. if isBinaryTag(data, BinaryTagStringTable) {
  6026. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  6027. tl := buff.ReadInt() // table length
  6028. if tl > 0 {
  6029. table = make([]string, tl, tl)
  6030. for i := 0; i < tl; i++ {
  6031. table[i] = buff.ReadString()
  6032. }
  6033. }
  6034. }
  6035. ctx := &DecodingContext{
  6036. Buffer: buff,
  6037. Table: table,
  6038. }
  6039. err := target.UnmarshalBinaryWithContext(ctx)
  6040. if err != nil {
  6041. return err
  6042. }
  6043. return nil
  6044. }
  6045. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  6046. // the RawAllocationOnlyData type
  6047. func (target *RawAllocationOnlyData) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  6048. // panics are recovered and propagated as errors
  6049. defer func() {
  6050. if r := recover(); r != nil {
  6051. if e, ok := r.(error); ok {
  6052. err = e
  6053. } else if s, ok := r.(string); ok {
  6054. err = fmt.Errorf("Unexpected panic: %s", s)
  6055. } else {
  6056. err = fmt.Errorf("Unexpected panic: %+v", r)
  6057. }
  6058. }
  6059. }()
  6060. buff := ctx.Buffer
  6061. version := buff.ReadUInt8()
  6062. if version > AllocationCodecVersion {
  6063. return fmt.Errorf("Invalid Version Unmarshaling RawAllocationOnlyData. Expected %d or less, got %d", AllocationCodecVersion, version)
  6064. }
  6065. a := buff.ReadFloat64() // read float64
  6066. target.CPUCoreUsageMax = a
  6067. b := buff.ReadFloat64() // read float64
  6068. target.RAMBytesUsageMax = b
  6069. return nil
  6070. }
  6071. //--------------------------------------------------------------------------
  6072. // SharedAsset
  6073. //--------------------------------------------------------------------------
  6074. // MarshalBinary serializes the internal properties of this SharedAsset instance
  6075. // into a byte array
  6076. func (target *SharedAsset) MarshalBinary() (data []byte, err error) {
  6077. ctx := &EncodingContext{
  6078. Buffer: util.NewBuffer(),
  6079. Table: nil,
  6080. }
  6081. e := target.MarshalBinaryWithContext(ctx)
  6082. if e != nil {
  6083. return nil, e
  6084. }
  6085. encBytes := ctx.Buffer.Bytes()
  6086. return encBytes, nil
  6087. }
  6088. // MarshalBinaryWithContext serializes the internal properties of this SharedAsset instance
  6089. // into a byte array leveraging a predefined context.
  6090. func (target *SharedAsset) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  6091. // panics are recovered and propagated as errors
  6092. defer func() {
  6093. if r := recover(); r != nil {
  6094. if e, ok := r.(error); ok {
  6095. err = e
  6096. } else if s, ok := r.(string); ok {
  6097. err = fmt.Errorf("Unexpected panic: %s", s)
  6098. } else {
  6099. err = fmt.Errorf("Unexpected panic: %+v", r)
  6100. }
  6101. }
  6102. }()
  6103. buff := ctx.Buffer
  6104. buff.WriteUInt8(AssetsCodecVersion) // version
  6105. if target.Properties == nil {
  6106. buff.WriteUInt8(uint8(0)) // write nil byte
  6107. } else {
  6108. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6109. // --- [begin][write][struct](AssetProperties) ---
  6110. buff.WriteInt(0) // [compatibility, unused]
  6111. errA := target.Properties.MarshalBinaryWithContext(ctx)
  6112. if errA != nil {
  6113. return errA
  6114. }
  6115. // --- [end][write][struct](AssetProperties) ---
  6116. }
  6117. // --- [begin][write][alias](AssetLabels) ---
  6118. if map[string]string(target.Labels) == nil {
  6119. buff.WriteUInt8(uint8(0)) // write nil byte
  6120. } else {
  6121. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6122. // --- [begin][write][map](map[string]string) ---
  6123. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  6124. for v, z := range map[string]string(target.Labels) {
  6125. if ctx.IsStringTable() {
  6126. a := ctx.Table.AddOrGet(v)
  6127. buff.WriteInt(a) // write table index
  6128. } else {
  6129. buff.WriteString(v) // write string
  6130. }
  6131. if ctx.IsStringTable() {
  6132. b := ctx.Table.AddOrGet(z)
  6133. buff.WriteInt(b) // write table index
  6134. } else {
  6135. buff.WriteString(z) // write string
  6136. }
  6137. }
  6138. // --- [end][write][map](map[string]string) ---
  6139. }
  6140. // --- [end][write][alias](AssetLabels) ---
  6141. // --- [begin][write][struct](Window) ---
  6142. buff.WriteInt(0) // [compatibility, unused]
  6143. errB := target.Window.MarshalBinaryWithContext(ctx)
  6144. if errB != nil {
  6145. return errB
  6146. }
  6147. // --- [end][write][struct](Window) ---
  6148. buff.WriteFloat64(target.Cost) // write float64
  6149. return nil
  6150. }
  6151. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  6152. // the SharedAsset type
  6153. func (target *SharedAsset) UnmarshalBinary(data []byte) error {
  6154. var table []string
  6155. buff := util.NewBufferFromBytes(data)
  6156. // string table header validation
  6157. if isBinaryTag(data, BinaryTagStringTable) {
  6158. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  6159. tl := buff.ReadInt() // table length
  6160. if tl > 0 {
  6161. table = make([]string, tl, tl)
  6162. for i := 0; i < tl; i++ {
  6163. table[i] = buff.ReadString()
  6164. }
  6165. }
  6166. }
  6167. ctx := &DecodingContext{
  6168. Buffer: buff,
  6169. Table: table,
  6170. }
  6171. err := target.UnmarshalBinaryWithContext(ctx)
  6172. if err != nil {
  6173. return err
  6174. }
  6175. return nil
  6176. }
  6177. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  6178. // the SharedAsset type
  6179. func (target *SharedAsset) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  6180. // panics are recovered and propagated as errors
  6181. defer func() {
  6182. if r := recover(); r != nil {
  6183. if e, ok := r.(error); ok {
  6184. err = e
  6185. } else if s, ok := r.(string); ok {
  6186. err = fmt.Errorf("Unexpected panic: %s", s)
  6187. } else {
  6188. err = fmt.Errorf("Unexpected panic: %+v", r)
  6189. }
  6190. }
  6191. }()
  6192. buff := ctx.Buffer
  6193. version := buff.ReadUInt8()
  6194. if version > AssetsCodecVersion {
  6195. return fmt.Errorf("Invalid Version Unmarshaling SharedAsset. Expected %d or less, got %d", AssetsCodecVersion, version)
  6196. }
  6197. if buff.ReadUInt8() == uint8(0) {
  6198. target.Properties = nil
  6199. } else {
  6200. // --- [begin][read][struct](AssetProperties) ---
  6201. a := &AssetProperties{}
  6202. buff.ReadInt() // [compatibility, unused]
  6203. errA := a.UnmarshalBinaryWithContext(ctx)
  6204. if errA != nil {
  6205. return errA
  6206. }
  6207. target.Properties = a
  6208. // --- [end][read][struct](AssetProperties) ---
  6209. }
  6210. // --- [begin][read][alias](AssetLabels) ---
  6211. var b map[string]string
  6212. if buff.ReadUInt8() == uint8(0) {
  6213. b = nil
  6214. } else {
  6215. // --- [begin][read][map](map[string]string) ---
  6216. d := buff.ReadInt() // map len
  6217. c := make(map[string]string, d)
  6218. for i := 0; i < d; i++ {
  6219. var v string
  6220. var f string
  6221. if ctx.IsStringTable() {
  6222. g := buff.ReadInt() // read string index
  6223. f = ctx.Table[g]
  6224. } else {
  6225. f = buff.ReadString() // read string
  6226. }
  6227. e := f
  6228. v = e
  6229. var z string
  6230. var k string
  6231. if ctx.IsStringTable() {
  6232. l := buff.ReadInt() // read string index
  6233. k = ctx.Table[l]
  6234. } else {
  6235. k = buff.ReadString() // read string
  6236. }
  6237. h := k
  6238. z = h
  6239. c[v] = z
  6240. }
  6241. b = c
  6242. // --- [end][read][map](map[string]string) ---
  6243. }
  6244. target.Labels = AssetLabels(b)
  6245. // --- [end][read][alias](AssetLabels) ---
  6246. // --- [begin][read][struct](Window) ---
  6247. m := &Window{}
  6248. buff.ReadInt() // [compatibility, unused]
  6249. errB := m.UnmarshalBinaryWithContext(ctx)
  6250. if errB != nil {
  6251. return errB
  6252. }
  6253. target.Window = *m
  6254. // --- [end][read][struct](Window) ---
  6255. n := buff.ReadFloat64() // read float64
  6256. target.Cost = n
  6257. return nil
  6258. }
  6259. //--------------------------------------------------------------------------
  6260. // Window
  6261. //--------------------------------------------------------------------------
  6262. // MarshalBinary serializes the internal properties of this Window instance
  6263. // into a byte array
  6264. func (target *Window) MarshalBinary() (data []byte, err error) {
  6265. ctx := &EncodingContext{
  6266. Buffer: util.NewBuffer(),
  6267. Table: nil,
  6268. }
  6269. e := target.MarshalBinaryWithContext(ctx)
  6270. if e != nil {
  6271. return nil, e
  6272. }
  6273. encBytes := ctx.Buffer.Bytes()
  6274. return encBytes, nil
  6275. }
  6276. // MarshalBinaryWithContext serializes the internal properties of this Window instance
  6277. // into a byte array leveraging a predefined context.
  6278. func (target *Window) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  6279. // panics are recovered and propagated as errors
  6280. defer func() {
  6281. if r := recover(); r != nil {
  6282. if e, ok := r.(error); ok {
  6283. err = e
  6284. } else if s, ok := r.(string); ok {
  6285. err = fmt.Errorf("Unexpected panic: %s", s)
  6286. } else {
  6287. err = fmt.Errorf("Unexpected panic: %+v", r)
  6288. }
  6289. }
  6290. }()
  6291. buff := ctx.Buffer
  6292. buff.WriteUInt8(DefaultCodecVersion) // version
  6293. if target.start == nil {
  6294. buff.WriteUInt8(uint8(0)) // write nil byte
  6295. } else {
  6296. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6297. // --- [begin][write][reference](time.Time) ---
  6298. a, errA := target.start.MarshalBinary()
  6299. if errA != nil {
  6300. return errA
  6301. }
  6302. buff.WriteInt(len(a))
  6303. buff.WriteBytes(a)
  6304. // --- [end][write][reference](time.Time) ---
  6305. }
  6306. if target.end == nil {
  6307. buff.WriteUInt8(uint8(0)) // write nil byte
  6308. } else {
  6309. buff.WriteUInt8(uint8(1)) // write non-nil byte
  6310. // --- [begin][write][reference](time.Time) ---
  6311. b, errB := target.end.MarshalBinary()
  6312. if errB != nil {
  6313. return errB
  6314. }
  6315. buff.WriteInt(len(b))
  6316. buff.WriteBytes(b)
  6317. // --- [end][write][reference](time.Time) ---
  6318. }
  6319. return nil
  6320. }
  6321. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  6322. // the Window type
  6323. func (target *Window) UnmarshalBinary(data []byte) error {
  6324. var table []string
  6325. buff := util.NewBufferFromBytes(data)
  6326. // string table header validation
  6327. if isBinaryTag(data, BinaryTagStringTable) {
  6328. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  6329. tl := buff.ReadInt() // table length
  6330. if tl > 0 {
  6331. table = make([]string, tl, tl)
  6332. for i := 0; i < tl; i++ {
  6333. table[i] = buff.ReadString()
  6334. }
  6335. }
  6336. }
  6337. ctx := &DecodingContext{
  6338. Buffer: buff,
  6339. Table: table,
  6340. }
  6341. err := target.UnmarshalBinaryWithContext(ctx)
  6342. if err != nil {
  6343. return err
  6344. }
  6345. return nil
  6346. }
  6347. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  6348. // the Window type
  6349. func (target *Window) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  6350. // panics are recovered and propagated as errors
  6351. defer func() {
  6352. if r := recover(); r != nil {
  6353. if e, ok := r.(error); ok {
  6354. err = e
  6355. } else if s, ok := r.(string); ok {
  6356. err = fmt.Errorf("Unexpected panic: %s", s)
  6357. } else {
  6358. err = fmt.Errorf("Unexpected panic: %+v", r)
  6359. }
  6360. }
  6361. }()
  6362. buff := ctx.Buffer
  6363. version := buff.ReadUInt8()
  6364. if version > DefaultCodecVersion {
  6365. return fmt.Errorf("Invalid Version Unmarshaling Window. Expected %d or less, got %d", DefaultCodecVersion, version)
  6366. }
  6367. if buff.ReadUInt8() == uint8(0) {
  6368. target.start = nil
  6369. } else {
  6370. // --- [begin][read][reference](time.Time) ---
  6371. a := &time.Time{}
  6372. b := buff.ReadInt() // byte array length
  6373. c := buff.ReadBytes(b) // byte array
  6374. errA := a.UnmarshalBinary(c)
  6375. if errA != nil {
  6376. return errA
  6377. }
  6378. target.start = a
  6379. // --- [end][read][reference](time.Time) ---
  6380. }
  6381. if buff.ReadUInt8() == uint8(0) {
  6382. target.end = nil
  6383. } else {
  6384. // --- [begin][read][reference](time.Time) ---
  6385. d := &time.Time{}
  6386. e := buff.ReadInt() // byte array length
  6387. f := buff.ReadBytes(e) // byte array
  6388. errB := d.UnmarshalBinary(f)
  6389. if errB != nil {
  6390. return errB
  6391. }
  6392. target.end = d
  6393. // --- [end][read][reference](time.Time) ---
  6394. }
  6395. return nil
  6396. }