opencost_codecs.go 187 KB

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