opencost_codecs.go 185 KB

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