kubecost_codecs.go 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // DO NOT MODIFY
  4. //
  5. // ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻
  6. //
  7. //
  8. // This source file was automatically generated by bingen.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. package kubecost
  12. import (
  13. "fmt"
  14. "reflect"
  15. "strings"
  16. "sync"
  17. "time"
  18. util "github.com/kubecost/cost-model/pkg/util"
  19. )
  20. const (
  21. // GeneratorPackageName is the package the generator is targetting
  22. GeneratorPackageName string = "kubecost"
  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 = 15
  33. // AssetsCodecVersion is used for any resources listed in the Assets version set
  34. AssetsCodecVersion uint8 = 15
  35. // AllocationCodecVersion is used for any resources listed in the Allocation version set
  36. AllocationCodecVersion uint8 = 15
  37. )
  38. //--------------------------------------------------------------------------
  39. // Type Map
  40. //--------------------------------------------------------------------------
  41. // Generated type map for resolving interface implementations to
  42. // to concrete types
  43. var typeMap map[string]reflect.Type = map[string]reflect.Type{
  44. "Allocation": reflect.TypeOf((*Allocation)(nil)).Elem(),
  45. "AllocationProperties": reflect.TypeOf((*AllocationProperties)(nil)).Elem(),
  46. "AllocationSet": reflect.TypeOf((*AllocationSet)(nil)).Elem(),
  47. "AllocationSetRange": reflect.TypeOf((*AllocationSetRange)(nil)).Elem(),
  48. "Any": reflect.TypeOf((*Any)(nil)).Elem(),
  49. "AssetProperties": reflect.TypeOf((*AssetProperties)(nil)).Elem(),
  50. "AssetSet": reflect.TypeOf((*AssetSet)(nil)).Elem(),
  51. "AssetSetRange": reflect.TypeOf((*AssetSetRange)(nil)).Elem(),
  52. "Breakdown": reflect.TypeOf((*Breakdown)(nil)).Elem(),
  53. "Cloud": reflect.TypeOf((*Cloud)(nil)).Elem(),
  54. "ClusterManagement": reflect.TypeOf((*ClusterManagement)(nil)).Elem(),
  55. "Disk": reflect.TypeOf((*Disk)(nil)).Elem(),
  56. "LoadBalancer": reflect.TypeOf((*LoadBalancer)(nil)).Elem(),
  57. "Network": reflect.TypeOf((*Network)(nil)).Elem(),
  58. "Node": reflect.TypeOf((*Node)(nil)).Elem(),
  59. "PVAllocation": reflect.TypeOf((*PVAllocation)(nil)).Elem(),
  60. "PVKey": reflect.TypeOf((*PVKey)(nil)).Elem(),
  61. "RawAllocationOnlyData": reflect.TypeOf((*RawAllocationOnlyData)(nil)).Elem(),
  62. "SharedAsset": reflect.TypeOf((*SharedAsset)(nil)).Elem(),
  63. "Window": reflect.TypeOf((*Window)(nil)).Elem(),
  64. }
  65. //--------------------------------------------------------------------------
  66. // Type Helpers
  67. //--------------------------------------------------------------------------
  68. // isBinaryTag returns true when the first bytes in the provided binary matches the tag
  69. func isBinaryTag(data []byte, tag string) bool {
  70. return string(data[:len(tag)]) == tag
  71. }
  72. // appendBytes combines a and b into a new byte array
  73. func appendBytes(a []byte, b []byte) []byte {
  74. al := len(a)
  75. bl := len(b)
  76. tl := al + bl
  77. // allocate a new byte array for the combined
  78. // use native copy for speedy byte copying
  79. result := make([]byte, tl, tl)
  80. copy(result, a)
  81. copy(result[al:], b)
  82. return result
  83. }
  84. // typeToString determines the basic properties of the type, the qualifier, package path, and
  85. // type name, and returns the qualified type
  86. func typeToString(f interface{}) string {
  87. qual := ""
  88. t := reflect.TypeOf(f)
  89. if t.Kind() == reflect.Ptr {
  90. t = t.Elem()
  91. qual = "*"
  92. }
  93. return fmt.Sprintf("%s%s.%s", qual, t.PkgPath(), t.Name())
  94. }
  95. // resolveType uses the name of a type and returns the package, base type name, and whether
  96. // or not it's a pointer.
  97. func resolveType(t string) (pkg string, name string, isPtr bool) {
  98. isPtr = t[:1] == "*"
  99. if isPtr {
  100. t = t[1:]
  101. }
  102. slashIndex := strings.LastIndex(t, "/")
  103. if slashIndex >= 0 {
  104. t = t[slashIndex+1:]
  105. }
  106. parts := strings.Split(t, ".")
  107. if parts[0] == GeneratorPackageName {
  108. parts[0] = ""
  109. }
  110. pkg = parts[0]
  111. name = parts[1]
  112. return
  113. }
  114. //--------------------------------------------------------------------------
  115. // StringTable
  116. //--------------------------------------------------------------------------
  117. // StringTable maps strings to specific indices for encoding
  118. type StringTable struct {
  119. l *sync.Mutex
  120. indices map[string]int
  121. next int
  122. }
  123. // NewStringTable Creates a new StringTable instance with provided contents
  124. func NewStringTable(contents ...string) *StringTable {
  125. st := &StringTable{
  126. l: new(sync.Mutex),
  127. indices: make(map[string]int),
  128. next: len(contents),
  129. }
  130. for i, entry := range contents {
  131. st.indices[entry] = i
  132. }
  133. return st
  134. }
  135. // AddOrGet atomically retrieves a string entry's index if it exist. Otherwise, it will
  136. // add the entry and return the index.
  137. func (st *StringTable) AddOrGet(s string) int {
  138. st.l.Lock()
  139. defer st.l.Unlock()
  140. if ind, ok := st.indices[s]; ok {
  141. return ind
  142. }
  143. current := st.next
  144. st.next++
  145. st.indices[s] = current
  146. return current
  147. }
  148. // ToSlice Converts the contents to a string array for encoding.
  149. func (st *StringTable) ToSlice() []string {
  150. st.l.Lock()
  151. defer st.l.Unlock()
  152. if st.next == 0 {
  153. return []string{}
  154. }
  155. sl := make([]string, st.next, st.next)
  156. for s, i := range st.indices {
  157. sl[i] = s
  158. }
  159. return sl
  160. }
  161. // ToBytes Converts the contents to a binary encoded representation
  162. func (st *StringTable) ToBytes() []byte {
  163. buff := util.NewBuffer()
  164. buff.WriteBytes([]byte(BinaryTagStringTable)) // bingen table header
  165. strs := st.ToSlice()
  166. buff.WriteInt(len(strs)) // table length
  167. for _, s := range strs {
  168. buff.WriteString(s)
  169. }
  170. return buff.Bytes()
  171. }
  172. //--------------------------------------------------------------------------
  173. // Codec Context
  174. //--------------------------------------------------------------------------
  175. // EncodingContext is a context object passed to the encoders to ensure reuse of buffer
  176. // and table data
  177. type EncodingContext struct {
  178. Buffer *util.Buffer
  179. Table *StringTable
  180. }
  181. // IsStringTable returns true if the table is available
  182. func (ec *EncodingContext) IsStringTable() bool {
  183. return ec.Table != nil
  184. }
  185. // DecodingContext is a context object passed to the decoders to ensure parent objects
  186. // reuse as much data as possible
  187. type DecodingContext struct {
  188. Buffer *util.Buffer
  189. Table []string
  190. }
  191. // IsStringTable returns true if the table is available
  192. func (dc *DecodingContext) IsStringTable() bool {
  193. return len(dc.Table) > 0
  194. }
  195. //--------------------------------------------------------------------------
  196. // Binary Codec
  197. //--------------------------------------------------------------------------
  198. // BinEncoder is an encoding interface which defines a context based marshal contract.
  199. type BinEncoder interface {
  200. MarshalBinaryWithContext(*EncodingContext) error
  201. }
  202. // BinDecoder is a decoding interface which defines a context based unmarshal contract.
  203. type BinDecoder interface {
  204. UnmarshalBinaryWithContext(*DecodingContext) error
  205. }
  206. //--------------------------------------------------------------------------
  207. // Allocation
  208. //--------------------------------------------------------------------------
  209. // MarshalBinary serializes the internal properties of this Allocation instance
  210. // into a byte array
  211. func (target *Allocation) MarshalBinary() (data []byte, err error) {
  212. ctx := &EncodingContext{
  213. Buffer: util.NewBuffer(),
  214. Table: nil,
  215. }
  216. e := target.MarshalBinaryWithContext(ctx)
  217. if e != nil {
  218. return nil, e
  219. }
  220. encBytes := ctx.Buffer.Bytes()
  221. return encBytes, nil
  222. }
  223. // MarshalBinaryWithContext serializes the internal properties of this Allocation instance
  224. // into a byte array leveraging a predefined context.
  225. func (target *Allocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  226. // panics are recovered and propagated as errors
  227. defer func() {
  228. if r := recover(); r != nil {
  229. if e, ok := r.(error); ok {
  230. err = e
  231. } else if s, ok := r.(string); ok {
  232. err = fmt.Errorf("Unexpected panic: %s", s)
  233. } else {
  234. err = fmt.Errorf("Unexpected panic: %+v", r)
  235. }
  236. }
  237. }()
  238. buff := ctx.Buffer
  239. buff.WriteUInt8(AllocationCodecVersion) // version
  240. if ctx.IsStringTable() {
  241. a := ctx.Table.AddOrGet(target.Name)
  242. buff.WriteInt(a) // write table index
  243. } else {
  244. buff.WriteString(target.Name) // write string
  245. }
  246. if target.Properties == nil {
  247. buff.WriteUInt8(uint8(0)) // write nil byte
  248. } else {
  249. buff.WriteUInt8(uint8(1)) // write non-nil byte
  250. // --- [begin][write][struct](AllocationProperties) ---
  251. buff.WriteInt(0) // [compatibility, unused]
  252. errA := target.Properties.MarshalBinaryWithContext(ctx)
  253. if errA != nil {
  254. return errA
  255. }
  256. // --- [end][write][struct](AllocationProperties) ---
  257. }
  258. // --- [begin][write][struct](Window) ---
  259. buff.WriteInt(0) // [compatibility, unused]
  260. errB := target.Window.MarshalBinaryWithContext(ctx)
  261. if errB != nil {
  262. return errB
  263. }
  264. // --- [end][write][struct](Window) ---
  265. // --- [begin][write][reference](time.Time) ---
  266. b, errC := target.Start.MarshalBinary()
  267. if errC != nil {
  268. return errC
  269. }
  270. buff.WriteInt(len(b))
  271. buff.WriteBytes(b)
  272. // --- [end][write][reference](time.Time) ---
  273. // --- [begin][write][reference](time.Time) ---
  274. c, errD := target.End.MarshalBinary()
  275. if errD != nil {
  276. return errD
  277. }
  278. buff.WriteInt(len(c))
  279. buff.WriteBytes(c)
  280. // --- [end][write][reference](time.Time) ---
  281. buff.WriteFloat64(target.CPUCoreHours) // write float64
  282. buff.WriteFloat64(target.CPUCoreRequestAverage) // write float64
  283. buff.WriteFloat64(target.CPUCoreUsageAverage) // write float64
  284. buff.WriteFloat64(target.CPUCost) // write float64
  285. buff.WriteFloat64(target.CPUCostAdjustment) // write float64
  286. buff.WriteFloat64(target.GPUHours) // write float64
  287. buff.WriteFloat64(target.GPUCost) // write float64
  288. buff.WriteFloat64(target.GPUCostAdjustment) // write float64
  289. buff.WriteFloat64(target.NetworkTransferBytes) // write float64
  290. buff.WriteFloat64(target.NetworkReceiveBytes) // write float64
  291. buff.WriteFloat64(target.NetworkCost) // write float64
  292. buff.WriteFloat64(target.NetworkCostAdjustment) // write float64
  293. buff.WriteFloat64(target.LoadBalancerCost) // write float64
  294. buff.WriteFloat64(target.LoadBalancerCostAdjustment) // write float64
  295. // --- [begin][write][alias](PVAllocations) ---
  296. if map[PVKey]*PVAllocation(target.PVs) == nil {
  297. buff.WriteUInt8(uint8(0)) // write nil byte
  298. } else {
  299. buff.WriteUInt8(uint8(1)) // write non-nil byte
  300. // --- [begin][write][map](map[PVKey]*PVAllocation) ---
  301. buff.WriteInt(len(map[PVKey]*PVAllocation(target.PVs))) // map length
  302. for v, z := range map[PVKey]*PVAllocation(target.PVs) {
  303. // --- [begin][write][struct](PVKey) ---
  304. buff.WriteInt(0) // [compatibility, unused]
  305. errE := v.MarshalBinaryWithContext(ctx)
  306. if errE != nil {
  307. return errE
  308. }
  309. // --- [end][write][struct](PVKey) ---
  310. if z == nil {
  311. buff.WriteUInt8(uint8(0)) // write nil byte
  312. } else {
  313. buff.WriteUInt8(uint8(1)) // write non-nil byte
  314. // --- [begin][write][struct](PVAllocation) ---
  315. buff.WriteInt(0) // [compatibility, unused]
  316. errF := z.MarshalBinaryWithContext(ctx)
  317. if errF != nil {
  318. return errF
  319. }
  320. // --- [end][write][struct](PVAllocation) ---
  321. }
  322. }
  323. // --- [end][write][map](map[PVKey]*PVAllocation) ---
  324. }
  325. // --- [end][write][alias](PVAllocations) ---
  326. buff.WriteFloat64(target.PVCostAdjustment) // write float64
  327. buff.WriteFloat64(target.RAMByteHours) // write float64
  328. buff.WriteFloat64(target.RAMBytesRequestAverage) // write float64
  329. buff.WriteFloat64(target.RAMBytesUsageAverage) // write float64
  330. buff.WriteFloat64(target.RAMCost) // write float64
  331. buff.WriteFloat64(target.RAMCostAdjustment) // write float64
  332. buff.WriteFloat64(target.SharedCost) // write float64
  333. buff.WriteFloat64(target.ExternalCost) // write float64
  334. if target.RawAllocationOnly == nil {
  335. buff.WriteUInt8(uint8(0)) // write nil byte
  336. } else {
  337. buff.WriteUInt8(uint8(1)) // write non-nil byte
  338. // --- [begin][write][struct](RawAllocationOnlyData) ---
  339. buff.WriteInt(0) // [compatibility, unused]
  340. errG := target.RawAllocationOnly.MarshalBinaryWithContext(ctx)
  341. if errG != nil {
  342. return errG
  343. }
  344. // --- [end][write][struct](RawAllocationOnlyData) ---
  345. }
  346. return nil
  347. }
  348. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  349. // the Allocation type
  350. func (target *Allocation) UnmarshalBinary(data []byte) error {
  351. var table []string
  352. buff := util.NewBufferFromBytes(data)
  353. // string table header validation
  354. if isBinaryTag(data, BinaryTagStringTable) {
  355. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  356. tl := buff.ReadInt() // table length
  357. if tl > 0 {
  358. table = make([]string, tl, tl)
  359. for i := 0; i < tl; i++ {
  360. table[i] = buff.ReadString()
  361. }
  362. }
  363. }
  364. ctx := &DecodingContext{
  365. Buffer: buff,
  366. Table: table,
  367. }
  368. err := target.UnmarshalBinaryWithContext(ctx)
  369. if err != nil {
  370. return err
  371. }
  372. return nil
  373. }
  374. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  375. // the Allocation type
  376. func (target *Allocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  377. // panics are recovered and propagated as errors
  378. defer func() {
  379. if r := recover(); r != nil {
  380. if e, ok := r.(error); ok {
  381. err = e
  382. } else if s, ok := r.(string); ok {
  383. err = fmt.Errorf("Unexpected panic: %s", s)
  384. } else {
  385. err = fmt.Errorf("Unexpected panic: %+v", r)
  386. }
  387. }
  388. }()
  389. buff := ctx.Buffer
  390. // Codec Version Check
  391. version := buff.ReadUInt8()
  392. if version != AllocationCodecVersion {
  393. return fmt.Errorf("Invalid Version Unmarshaling Allocation. Expected %d, got %d", AllocationCodecVersion, version)
  394. }
  395. var b string
  396. if ctx.IsStringTable() {
  397. c := buff.ReadInt() // read string index
  398. b = ctx.Table[c]
  399. } else {
  400. b = buff.ReadString() // read string
  401. }
  402. a := b
  403. target.Name = a
  404. if buff.ReadUInt8() == uint8(0) {
  405. target.Properties = nil
  406. } else {
  407. // --- [begin][read][struct](AllocationProperties) ---
  408. d := &AllocationProperties{}
  409. buff.ReadInt() // [compatibility, unused]
  410. errA := d.UnmarshalBinaryWithContext(ctx)
  411. if errA != nil {
  412. return errA
  413. }
  414. target.Properties = d
  415. // --- [end][read][struct](AllocationProperties) ---
  416. }
  417. // --- [begin][read][struct](Window) ---
  418. e := &Window{}
  419. buff.ReadInt() // [compatibility, unused]
  420. errB := e.UnmarshalBinaryWithContext(ctx)
  421. if errB != nil {
  422. return errB
  423. }
  424. target.Window = *e
  425. // --- [end][read][struct](Window) ---
  426. // --- [begin][read][reference](time.Time) ---
  427. f := &time.Time{}
  428. g := buff.ReadInt() // byte array length
  429. h := buff.ReadBytes(g) // byte array
  430. errC := f.UnmarshalBinary(h)
  431. if errC != nil {
  432. return errC
  433. }
  434. target.Start = *f
  435. // --- [end][read][reference](time.Time) ---
  436. // --- [begin][read][reference](time.Time) ---
  437. k := &time.Time{}
  438. l := buff.ReadInt() // byte array length
  439. m := buff.ReadBytes(l) // byte array
  440. errD := k.UnmarshalBinary(m)
  441. if errD != nil {
  442. return errD
  443. }
  444. target.End = *k
  445. // --- [end][read][reference](time.Time) ---
  446. n := buff.ReadFloat64() // read float64
  447. target.CPUCoreHours = n
  448. o := buff.ReadFloat64() // read float64
  449. target.CPUCoreRequestAverage = o
  450. p := buff.ReadFloat64() // read float64
  451. target.CPUCoreUsageAverage = p
  452. q := buff.ReadFloat64() // read float64
  453. target.CPUCost = q
  454. r := buff.ReadFloat64() // read float64
  455. target.CPUCostAdjustment = r
  456. s := buff.ReadFloat64() // read float64
  457. target.GPUHours = s
  458. t := buff.ReadFloat64() // read float64
  459. target.GPUCost = t
  460. u := buff.ReadFloat64() // read float64
  461. target.GPUCostAdjustment = u
  462. w := buff.ReadFloat64() // read float64
  463. target.NetworkTransferBytes = w
  464. x := buff.ReadFloat64() // read float64
  465. target.NetworkReceiveBytes = x
  466. y := buff.ReadFloat64() // read float64
  467. target.NetworkCost = y
  468. aa := buff.ReadFloat64() // read float64
  469. target.NetworkCostAdjustment = aa
  470. bb := buff.ReadFloat64() // read float64
  471. target.LoadBalancerCost = bb
  472. cc := buff.ReadFloat64() // read float64
  473. target.LoadBalancerCostAdjustment = cc
  474. // --- [begin][read][alias](PVAllocations) ---
  475. var dd map[PVKey]*PVAllocation
  476. if buff.ReadUInt8() == uint8(0) {
  477. dd = nil
  478. } else {
  479. // --- [begin][read][map](map[PVKey]*PVAllocation) ---
  480. ff := buff.ReadInt() // map len
  481. ee := make(map[PVKey]*PVAllocation, ff)
  482. for i := 0; i < ff; i++ {
  483. // --- [begin][read][struct](PVKey) ---
  484. gg := &PVKey{}
  485. buff.ReadInt() // [compatibility, unused]
  486. errE := gg.UnmarshalBinaryWithContext(ctx)
  487. if errE != nil {
  488. return errE
  489. }
  490. v := *gg
  491. // --- [end][read][struct](PVKey) ---
  492. var z *PVAllocation
  493. if buff.ReadUInt8() == uint8(0) {
  494. z = nil
  495. } else {
  496. // --- [begin][read][struct](PVAllocation) ---
  497. hh := &PVAllocation{}
  498. buff.ReadInt() // [compatibility, unused]
  499. errF := hh.UnmarshalBinaryWithContext(ctx)
  500. if errF != nil {
  501. return errF
  502. }
  503. z = hh
  504. // --- [end][read][struct](PVAllocation) ---
  505. }
  506. ee[v] = z
  507. }
  508. dd = ee
  509. // --- [end][read][map](map[PVKey]*PVAllocation) ---
  510. }
  511. target.PVs = PVAllocations(dd)
  512. // --- [end][read][alias](PVAllocations) ---
  513. kk := buff.ReadFloat64() // read float64
  514. target.PVCostAdjustment = kk
  515. ll := buff.ReadFloat64() // read float64
  516. target.RAMByteHours = ll
  517. mm := buff.ReadFloat64() // read float64
  518. target.RAMBytesRequestAverage = mm
  519. nn := buff.ReadFloat64() // read float64
  520. target.RAMBytesUsageAverage = nn
  521. oo := buff.ReadFloat64() // read float64
  522. target.RAMCost = oo
  523. pp := buff.ReadFloat64() // read float64
  524. target.RAMCostAdjustment = pp
  525. qq := buff.ReadFloat64() // read float64
  526. target.SharedCost = qq
  527. rr := buff.ReadFloat64() // read float64
  528. target.ExternalCost = rr
  529. if buff.ReadUInt8() == uint8(0) {
  530. target.RawAllocationOnly = nil
  531. } else {
  532. // --- [begin][read][struct](RawAllocationOnlyData) ---
  533. ss := &RawAllocationOnlyData{}
  534. buff.ReadInt() // [compatibility, unused]
  535. errG := ss.UnmarshalBinaryWithContext(ctx)
  536. if errG != nil {
  537. return errG
  538. }
  539. target.RawAllocationOnly = ss
  540. // --- [end][read][struct](RawAllocationOnlyData) ---
  541. }
  542. return nil
  543. }
  544. //--------------------------------------------------------------------------
  545. // AllocationProperties
  546. //--------------------------------------------------------------------------
  547. // MarshalBinary serializes the internal properties of this AllocationProperties instance
  548. // into a byte array
  549. func (target *AllocationProperties) MarshalBinary() (data []byte, err error) {
  550. ctx := &EncodingContext{
  551. Buffer: util.NewBuffer(),
  552. Table: nil,
  553. }
  554. e := target.MarshalBinaryWithContext(ctx)
  555. if e != nil {
  556. return nil, e
  557. }
  558. encBytes := ctx.Buffer.Bytes()
  559. return encBytes, nil
  560. }
  561. // MarshalBinaryWithContext serializes the internal properties of this AllocationProperties instance
  562. // into a byte array leveraging a predefined context.
  563. func (target *AllocationProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  564. // panics are recovered and propagated as errors
  565. defer func() {
  566. if r := recover(); r != nil {
  567. if e, ok := r.(error); ok {
  568. err = e
  569. } else if s, ok := r.(string); ok {
  570. err = fmt.Errorf("Unexpected panic: %s", s)
  571. } else {
  572. err = fmt.Errorf("Unexpected panic: %+v", r)
  573. }
  574. }
  575. }()
  576. buff := ctx.Buffer
  577. buff.WriteUInt8(AllocationCodecVersion) // version
  578. if ctx.IsStringTable() {
  579. a := ctx.Table.AddOrGet(target.Cluster)
  580. buff.WriteInt(a) // write table index
  581. } else {
  582. buff.WriteString(target.Cluster) // write string
  583. }
  584. if ctx.IsStringTable() {
  585. b := ctx.Table.AddOrGet(target.Node)
  586. buff.WriteInt(b) // write table index
  587. } else {
  588. buff.WriteString(target.Node) // write string
  589. }
  590. if ctx.IsStringTable() {
  591. c := ctx.Table.AddOrGet(target.Container)
  592. buff.WriteInt(c) // write table index
  593. } else {
  594. buff.WriteString(target.Container) // write string
  595. }
  596. if ctx.IsStringTable() {
  597. d := ctx.Table.AddOrGet(target.Controller)
  598. buff.WriteInt(d) // write table index
  599. } else {
  600. buff.WriteString(target.Controller) // write string
  601. }
  602. if ctx.IsStringTable() {
  603. e := ctx.Table.AddOrGet(target.ControllerKind)
  604. buff.WriteInt(e) // write table index
  605. } else {
  606. buff.WriteString(target.ControllerKind) // write string
  607. }
  608. if ctx.IsStringTable() {
  609. f := ctx.Table.AddOrGet(target.Namespace)
  610. buff.WriteInt(f) // write table index
  611. } else {
  612. buff.WriteString(target.Namespace) // write string
  613. }
  614. if ctx.IsStringTable() {
  615. g := ctx.Table.AddOrGet(target.Pod)
  616. buff.WriteInt(g) // write table index
  617. } else {
  618. buff.WriteString(target.Pod) // write string
  619. }
  620. if target.Services == nil {
  621. buff.WriteUInt8(uint8(0)) // write nil byte
  622. } else {
  623. buff.WriteUInt8(uint8(1)) // write non-nil byte
  624. // --- [begin][write][slice]([]string) ---
  625. buff.WriteInt(len(target.Services)) // array length
  626. for i := 0; i < len(target.Services); i++ {
  627. if ctx.IsStringTable() {
  628. h := ctx.Table.AddOrGet(target.Services[i])
  629. buff.WriteInt(h) // write table index
  630. } else {
  631. buff.WriteString(target.Services[i]) // write string
  632. }
  633. }
  634. // --- [end][write][slice]([]string) ---
  635. }
  636. if ctx.IsStringTable() {
  637. k := ctx.Table.AddOrGet(target.ProviderID)
  638. buff.WriteInt(k) // write table index
  639. } else {
  640. buff.WriteString(target.ProviderID) // write string
  641. }
  642. // --- [begin][write][alias](AllocationLabels) ---
  643. if map[string]string(target.Labels) == nil {
  644. buff.WriteUInt8(uint8(0)) // write nil byte
  645. } else {
  646. buff.WriteUInt8(uint8(1)) // write non-nil byte
  647. // --- [begin][write][map](map[string]string) ---
  648. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  649. for v, z := range map[string]string(target.Labels) {
  650. if ctx.IsStringTable() {
  651. l := ctx.Table.AddOrGet(v)
  652. buff.WriteInt(l) // write table index
  653. } else {
  654. buff.WriteString(v) // write string
  655. }
  656. if ctx.IsStringTable() {
  657. m := ctx.Table.AddOrGet(z)
  658. buff.WriteInt(m) // write table index
  659. } else {
  660. buff.WriteString(z) // write string
  661. }
  662. }
  663. // --- [end][write][map](map[string]string) ---
  664. }
  665. // --- [end][write][alias](AllocationLabels) ---
  666. // --- [begin][write][alias](AllocationAnnotations) ---
  667. if map[string]string(target.Annotations) == nil {
  668. buff.WriteUInt8(uint8(0)) // write nil byte
  669. } else {
  670. buff.WriteUInt8(uint8(1)) // write non-nil byte
  671. // --- [begin][write][map](map[string]string) ---
  672. buff.WriteInt(len(map[string]string(target.Annotations))) // map length
  673. for vv, zz := range map[string]string(target.Annotations) {
  674. if ctx.IsStringTable() {
  675. n := ctx.Table.AddOrGet(vv)
  676. buff.WriteInt(n) // write table index
  677. } else {
  678. buff.WriteString(vv) // write string
  679. }
  680. if ctx.IsStringTable() {
  681. o := ctx.Table.AddOrGet(zz)
  682. buff.WriteInt(o) // write table index
  683. } else {
  684. buff.WriteString(zz) // write string
  685. }
  686. }
  687. // --- [end][write][map](map[string]string) ---
  688. }
  689. // --- [end][write][alias](AllocationAnnotations) ---
  690. return nil
  691. }
  692. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  693. // the AllocationProperties type
  694. func (target *AllocationProperties) UnmarshalBinary(data []byte) error {
  695. var table []string
  696. buff := util.NewBufferFromBytes(data)
  697. // string table header validation
  698. if isBinaryTag(data, BinaryTagStringTable) {
  699. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  700. tl := buff.ReadInt() // table length
  701. if tl > 0 {
  702. table = make([]string, tl, tl)
  703. for i := 0; i < tl; i++ {
  704. table[i] = buff.ReadString()
  705. }
  706. }
  707. }
  708. ctx := &DecodingContext{
  709. Buffer: buff,
  710. Table: table,
  711. }
  712. err := target.UnmarshalBinaryWithContext(ctx)
  713. if err != nil {
  714. return err
  715. }
  716. return nil
  717. }
  718. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  719. // the AllocationProperties type
  720. func (target *AllocationProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (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. // Codec Version Check
  735. version := buff.ReadUInt8()
  736. if version != AllocationCodecVersion {
  737. return fmt.Errorf("Invalid Version Unmarshaling AllocationProperties. Expected %d, got %d", AllocationCodecVersion, version)
  738. }
  739. var b string
  740. if ctx.IsStringTable() {
  741. c := buff.ReadInt() // read string index
  742. b = ctx.Table[c]
  743. } else {
  744. b = buff.ReadString() // read string
  745. }
  746. a := b
  747. target.Cluster = a
  748. var e string
  749. if ctx.IsStringTable() {
  750. f := buff.ReadInt() // read string index
  751. e = ctx.Table[f]
  752. } else {
  753. e = buff.ReadString() // read string
  754. }
  755. d := e
  756. target.Node = d
  757. var h string
  758. if ctx.IsStringTable() {
  759. k := buff.ReadInt() // read string index
  760. h = ctx.Table[k]
  761. } else {
  762. h = buff.ReadString() // read string
  763. }
  764. g := h
  765. target.Container = g
  766. var m string
  767. if ctx.IsStringTable() {
  768. n := buff.ReadInt() // read string index
  769. m = ctx.Table[n]
  770. } else {
  771. m = buff.ReadString() // read string
  772. }
  773. l := m
  774. target.Controller = l
  775. var p string
  776. if ctx.IsStringTable() {
  777. q := buff.ReadInt() // read string index
  778. p = ctx.Table[q]
  779. } else {
  780. p = buff.ReadString() // read string
  781. }
  782. o := p
  783. target.ControllerKind = o
  784. var s string
  785. if ctx.IsStringTable() {
  786. t := buff.ReadInt() // read string index
  787. s = ctx.Table[t]
  788. } else {
  789. s = buff.ReadString() // read string
  790. }
  791. r := s
  792. target.Namespace = r
  793. var w string
  794. if ctx.IsStringTable() {
  795. x := buff.ReadInt() // read string index
  796. w = ctx.Table[x]
  797. } else {
  798. w = buff.ReadString() // read string
  799. }
  800. u := w
  801. target.Pod = u
  802. if buff.ReadUInt8() == uint8(0) {
  803. target.Services = nil
  804. } else {
  805. // --- [begin][read][slice]([]string) ---
  806. aa := buff.ReadInt() // array len
  807. y := make([]string, aa)
  808. for i := 0; i < aa; i++ {
  809. var bb string
  810. var dd string
  811. if ctx.IsStringTable() {
  812. ee := buff.ReadInt() // read string index
  813. dd = ctx.Table[ee]
  814. } else {
  815. dd = buff.ReadString() // read string
  816. }
  817. cc := dd
  818. bb = cc
  819. y[i] = bb
  820. }
  821. target.Services = y
  822. // --- [end][read][slice]([]string) ---
  823. }
  824. var gg string
  825. if ctx.IsStringTable() {
  826. hh := buff.ReadInt() // read string index
  827. gg = ctx.Table[hh]
  828. } else {
  829. gg = buff.ReadString() // read string
  830. }
  831. ff := gg
  832. target.ProviderID = ff
  833. // --- [begin][read][alias](AllocationLabels) ---
  834. var kk map[string]string
  835. if buff.ReadUInt8() == uint8(0) {
  836. kk = nil
  837. } else {
  838. // --- [begin][read][map](map[string]string) ---
  839. mm := buff.ReadInt() // map len
  840. ll := make(map[string]string, mm)
  841. for j := 0; j < mm; j++ {
  842. var v string
  843. var oo string
  844. if ctx.IsStringTable() {
  845. pp := buff.ReadInt() // read string index
  846. oo = ctx.Table[pp]
  847. } else {
  848. oo = buff.ReadString() // read string
  849. }
  850. nn := oo
  851. v = nn
  852. var z string
  853. var rr string
  854. if ctx.IsStringTable() {
  855. ss := buff.ReadInt() // read string index
  856. rr = ctx.Table[ss]
  857. } else {
  858. rr = buff.ReadString() // read string
  859. }
  860. qq := rr
  861. z = qq
  862. ll[v] = z
  863. }
  864. kk = ll
  865. // --- [end][read][map](map[string]string) ---
  866. }
  867. target.Labels = AllocationLabels(kk)
  868. // --- [end][read][alias](AllocationLabels) ---
  869. // --- [begin][read][alias](AllocationAnnotations) ---
  870. var tt map[string]string
  871. if buff.ReadUInt8() == uint8(0) {
  872. tt = nil
  873. } else {
  874. // --- [begin][read][map](map[string]string) ---
  875. ww := buff.ReadInt() // map len
  876. uu := make(map[string]string, ww)
  877. for ii := 0; ii < ww; ii++ {
  878. var vv string
  879. var yy string
  880. if ctx.IsStringTable() {
  881. aaa := buff.ReadInt() // read string index
  882. yy = ctx.Table[aaa]
  883. } else {
  884. yy = buff.ReadString() // read string
  885. }
  886. xx := yy
  887. vv = xx
  888. var zz string
  889. var ccc string
  890. if ctx.IsStringTable() {
  891. ddd := buff.ReadInt() // read string index
  892. ccc = ctx.Table[ddd]
  893. } else {
  894. ccc = buff.ReadString() // read string
  895. }
  896. bbb := ccc
  897. zz = bbb
  898. uu[vv] = zz
  899. }
  900. tt = uu
  901. // --- [end][read][map](map[string]string) ---
  902. }
  903. target.Annotations = AllocationAnnotations(tt)
  904. // --- [end][read][alias](AllocationAnnotations) ---
  905. return nil
  906. }
  907. //--------------------------------------------------------------------------
  908. // AllocationSet
  909. //--------------------------------------------------------------------------
  910. // MarshalBinary serializes the internal properties of this AllocationSet instance
  911. // into a byte array
  912. func (target *AllocationSet) MarshalBinary() (data []byte, err error) {
  913. ctx := &EncodingContext{
  914. Buffer: util.NewBuffer(),
  915. Table: nil,
  916. }
  917. e := target.MarshalBinaryWithContext(ctx)
  918. if e != nil {
  919. return nil, e
  920. }
  921. encBytes := ctx.Buffer.Bytes()
  922. return encBytes, nil
  923. }
  924. // MarshalBinaryWithContext serializes the internal properties of this AllocationSet instance
  925. // into a byte array leveraging a predefined context.
  926. func (target *AllocationSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  927. // panics are recovered and propagated as errors
  928. defer func() {
  929. if r := recover(); r != nil {
  930. if e, ok := r.(error); ok {
  931. err = e
  932. } else if s, ok := r.(string); ok {
  933. err = fmt.Errorf("Unexpected panic: %s", s)
  934. } else {
  935. err = fmt.Errorf("Unexpected panic: %+v", r)
  936. }
  937. }
  938. }()
  939. buff := ctx.Buffer
  940. buff.WriteUInt8(AllocationCodecVersion) // version
  941. if target.allocations == nil {
  942. buff.WriteUInt8(uint8(0)) // write nil byte
  943. } else {
  944. buff.WriteUInt8(uint8(1)) // write non-nil byte
  945. // --- [begin][write][map](map[string]*Allocation) ---
  946. buff.WriteInt(len(target.allocations)) // map length
  947. for v, z := range target.allocations {
  948. if ctx.IsStringTable() {
  949. a := ctx.Table.AddOrGet(v)
  950. buff.WriteInt(a) // write table index
  951. } else {
  952. buff.WriteString(v) // write string
  953. }
  954. if z == nil {
  955. buff.WriteUInt8(uint8(0)) // write nil byte
  956. } else {
  957. buff.WriteUInt8(uint8(1)) // write non-nil byte
  958. // --- [begin][write][struct](Allocation) ---
  959. buff.WriteInt(0) // [compatibility, unused]
  960. errA := z.MarshalBinaryWithContext(ctx)
  961. if errA != nil {
  962. return errA
  963. }
  964. // --- [end][write][struct](Allocation) ---
  965. }
  966. }
  967. // --- [end][write][map](map[string]*Allocation) ---
  968. }
  969. if target.externalKeys == nil {
  970. buff.WriteUInt8(uint8(0)) // write nil byte
  971. } else {
  972. buff.WriteUInt8(uint8(1)) // write non-nil byte
  973. // --- [begin][write][map](map[string]bool) ---
  974. buff.WriteInt(len(target.externalKeys)) // map length
  975. for vv, zz := range target.externalKeys {
  976. if ctx.IsStringTable() {
  977. b := ctx.Table.AddOrGet(vv)
  978. buff.WriteInt(b) // write table index
  979. } else {
  980. buff.WriteString(vv) // write string
  981. }
  982. buff.WriteBool(zz) // write bool
  983. }
  984. // --- [end][write][map](map[string]bool) ---
  985. }
  986. if target.idleKeys == nil {
  987. buff.WriteUInt8(uint8(0)) // write nil byte
  988. } else {
  989. buff.WriteUInt8(uint8(1)) // write non-nil byte
  990. // --- [begin][write][map](map[string]bool) ---
  991. buff.WriteInt(len(target.idleKeys)) // map length
  992. for vvv, zzz := range target.idleKeys {
  993. if ctx.IsStringTable() {
  994. c := ctx.Table.AddOrGet(vvv)
  995. buff.WriteInt(c) // write table index
  996. } else {
  997. buff.WriteString(vvv) // write string
  998. }
  999. buff.WriteBool(zzz) // write bool
  1000. }
  1001. // --- [end][write][map](map[string]bool) ---
  1002. }
  1003. if ctx.IsStringTable() {
  1004. d := ctx.Table.AddOrGet(target.FromSource)
  1005. buff.WriteInt(d) // write table index
  1006. } else {
  1007. buff.WriteString(target.FromSource) // write string
  1008. }
  1009. // --- [begin][write][struct](Window) ---
  1010. buff.WriteInt(0) // [compatibility, unused]
  1011. errB := target.Window.MarshalBinaryWithContext(ctx)
  1012. if errB != nil {
  1013. return errB
  1014. }
  1015. // --- [end][write][struct](Window) ---
  1016. if target.Warnings == nil {
  1017. buff.WriteUInt8(uint8(0)) // write nil byte
  1018. } else {
  1019. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1020. // --- [begin][write][slice]([]string) ---
  1021. buff.WriteInt(len(target.Warnings)) // array length
  1022. for i := 0; i < len(target.Warnings); i++ {
  1023. if ctx.IsStringTable() {
  1024. e := ctx.Table.AddOrGet(target.Warnings[i])
  1025. buff.WriteInt(e) // write table index
  1026. } else {
  1027. buff.WriteString(target.Warnings[i]) // write string
  1028. }
  1029. }
  1030. // --- [end][write][slice]([]string) ---
  1031. }
  1032. if target.Errors == nil {
  1033. buff.WriteUInt8(uint8(0)) // write nil byte
  1034. } else {
  1035. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1036. // --- [begin][write][slice]([]string) ---
  1037. buff.WriteInt(len(target.Errors)) // array length
  1038. for j := 0; j < len(target.Errors); j++ {
  1039. if ctx.IsStringTable() {
  1040. f := ctx.Table.AddOrGet(target.Errors[j])
  1041. buff.WriteInt(f) // write table index
  1042. } else {
  1043. buff.WriteString(target.Errors[j]) // write string
  1044. }
  1045. }
  1046. // --- [end][write][slice]([]string) ---
  1047. }
  1048. return nil
  1049. }
  1050. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1051. // the AllocationSet type
  1052. func (target *AllocationSet) UnmarshalBinary(data []byte) error {
  1053. var table []string
  1054. buff := util.NewBufferFromBytes(data)
  1055. // string table header validation
  1056. if isBinaryTag(data, BinaryTagStringTable) {
  1057. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1058. tl := buff.ReadInt() // table length
  1059. if tl > 0 {
  1060. table = make([]string, tl, tl)
  1061. for i := 0; i < tl; i++ {
  1062. table[i] = buff.ReadString()
  1063. }
  1064. }
  1065. }
  1066. ctx := &DecodingContext{
  1067. Buffer: buff,
  1068. Table: table,
  1069. }
  1070. err := target.UnmarshalBinaryWithContext(ctx)
  1071. if err != nil {
  1072. return err
  1073. }
  1074. return nil
  1075. }
  1076. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1077. // the AllocationSet type
  1078. func (target *AllocationSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1079. // panics are recovered and propagated as errors
  1080. defer func() {
  1081. if r := recover(); r != nil {
  1082. if e, ok := r.(error); ok {
  1083. err = e
  1084. } else if s, ok := r.(string); ok {
  1085. err = fmt.Errorf("Unexpected panic: %s", s)
  1086. } else {
  1087. err = fmt.Errorf("Unexpected panic: %+v", r)
  1088. }
  1089. }
  1090. }()
  1091. buff := ctx.Buffer
  1092. // Codec Version Check
  1093. version := buff.ReadUInt8()
  1094. if version != AllocationCodecVersion {
  1095. return fmt.Errorf("Invalid Version Unmarshaling AllocationSet. Expected %d, got %d", AllocationCodecVersion, version)
  1096. }
  1097. if buff.ReadUInt8() == uint8(0) {
  1098. target.allocations = nil
  1099. } else {
  1100. // --- [begin][read][map](map[string]*Allocation) ---
  1101. b := buff.ReadInt() // map len
  1102. a := make(map[string]*Allocation, b)
  1103. for i := 0; i < b; i++ {
  1104. var v string
  1105. var d string
  1106. if ctx.IsStringTable() {
  1107. e := buff.ReadInt() // read string index
  1108. d = ctx.Table[e]
  1109. } else {
  1110. d = buff.ReadString() // read string
  1111. }
  1112. c := d
  1113. v = c
  1114. var z *Allocation
  1115. if buff.ReadUInt8() == uint8(0) {
  1116. z = nil
  1117. } else {
  1118. // --- [begin][read][struct](Allocation) ---
  1119. f := &Allocation{}
  1120. buff.ReadInt() // [compatibility, unused]
  1121. errA := f.UnmarshalBinaryWithContext(ctx)
  1122. if errA != nil {
  1123. return errA
  1124. }
  1125. z = f
  1126. // --- [end][read][struct](Allocation) ---
  1127. }
  1128. a[v] = z
  1129. }
  1130. target.allocations = a
  1131. // --- [end][read][map](map[string]*Allocation) ---
  1132. }
  1133. if buff.ReadUInt8() == uint8(0) {
  1134. target.externalKeys = nil
  1135. } else {
  1136. // --- [begin][read][map](map[string]bool) ---
  1137. h := buff.ReadInt() // map len
  1138. g := make(map[string]bool, h)
  1139. for j := 0; j < h; j++ {
  1140. var vv string
  1141. var l string
  1142. if ctx.IsStringTable() {
  1143. m := buff.ReadInt() // read string index
  1144. l = ctx.Table[m]
  1145. } else {
  1146. l = buff.ReadString() // read string
  1147. }
  1148. k := l
  1149. vv = k
  1150. var zz bool
  1151. n := buff.ReadBool() // read bool
  1152. zz = n
  1153. g[vv] = zz
  1154. }
  1155. target.externalKeys = g
  1156. // --- [end][read][map](map[string]bool) ---
  1157. }
  1158. if buff.ReadUInt8() == uint8(0) {
  1159. target.idleKeys = nil
  1160. } else {
  1161. // --- [begin][read][map](map[string]bool) ---
  1162. p := buff.ReadInt() // map len
  1163. o := make(map[string]bool, p)
  1164. for ii := 0; ii < p; ii++ {
  1165. var vvv string
  1166. var r string
  1167. if ctx.IsStringTable() {
  1168. s := buff.ReadInt() // read string index
  1169. r = ctx.Table[s]
  1170. } else {
  1171. r = buff.ReadString() // read string
  1172. }
  1173. q := r
  1174. vvv = q
  1175. var zzz bool
  1176. t := buff.ReadBool() // read bool
  1177. zzz = t
  1178. o[vvv] = zzz
  1179. }
  1180. target.idleKeys = o
  1181. // --- [end][read][map](map[string]bool) ---
  1182. }
  1183. var w string
  1184. if ctx.IsStringTable() {
  1185. x := buff.ReadInt() // read string index
  1186. w = ctx.Table[x]
  1187. } else {
  1188. w = buff.ReadString() // read string
  1189. }
  1190. u := w
  1191. target.FromSource = u
  1192. // --- [begin][read][struct](Window) ---
  1193. y := &Window{}
  1194. buff.ReadInt() // [compatibility, unused]
  1195. errB := y.UnmarshalBinaryWithContext(ctx)
  1196. if errB != nil {
  1197. return errB
  1198. }
  1199. target.Window = *y
  1200. // --- [end][read][struct](Window) ---
  1201. if buff.ReadUInt8() == uint8(0) {
  1202. target.Warnings = nil
  1203. } else {
  1204. // --- [begin][read][slice]([]string) ---
  1205. bb := buff.ReadInt() // array len
  1206. aa := make([]string, bb)
  1207. for jj := 0; jj < bb; jj++ {
  1208. var cc string
  1209. var ee string
  1210. if ctx.IsStringTable() {
  1211. ff := buff.ReadInt() // read string index
  1212. ee = ctx.Table[ff]
  1213. } else {
  1214. ee = buff.ReadString() // read string
  1215. }
  1216. dd := ee
  1217. cc = dd
  1218. aa[jj] = cc
  1219. }
  1220. target.Warnings = aa
  1221. // --- [end][read][slice]([]string) ---
  1222. }
  1223. if buff.ReadUInt8() == uint8(0) {
  1224. target.Errors = nil
  1225. } else {
  1226. // --- [begin][read][slice]([]string) ---
  1227. hh := buff.ReadInt() // array len
  1228. gg := make([]string, hh)
  1229. for iii := 0; iii < hh; iii++ {
  1230. var kk string
  1231. var mm string
  1232. if ctx.IsStringTable() {
  1233. nn := buff.ReadInt() // read string index
  1234. mm = ctx.Table[nn]
  1235. } else {
  1236. mm = buff.ReadString() // read string
  1237. }
  1238. ll := mm
  1239. kk = ll
  1240. gg[iii] = kk
  1241. }
  1242. target.Errors = gg
  1243. // --- [end][read][slice]([]string) ---
  1244. }
  1245. return nil
  1246. }
  1247. //--------------------------------------------------------------------------
  1248. // AllocationSetRange
  1249. //--------------------------------------------------------------------------
  1250. // MarshalBinary serializes the internal properties of this AllocationSetRange instance
  1251. // into a byte array
  1252. func (target *AllocationSetRange) MarshalBinary() (data []byte, err error) {
  1253. ctx := &EncodingContext{
  1254. Buffer: util.NewBuffer(),
  1255. Table: nil,
  1256. }
  1257. e := target.MarshalBinaryWithContext(ctx)
  1258. if e != nil {
  1259. return nil, e
  1260. }
  1261. encBytes := ctx.Buffer.Bytes()
  1262. return encBytes, nil
  1263. }
  1264. // MarshalBinaryWithContext serializes the internal properties of this AllocationSetRange instance
  1265. // into a byte array leveraging a predefined context.
  1266. func (target *AllocationSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1267. // panics are recovered and propagated as errors
  1268. defer func() {
  1269. if r := recover(); r != nil {
  1270. if e, ok := r.(error); ok {
  1271. err = e
  1272. } else if s, ok := r.(string); ok {
  1273. err = fmt.Errorf("Unexpected panic: %s", s)
  1274. } else {
  1275. err = fmt.Errorf("Unexpected panic: %+v", r)
  1276. }
  1277. }
  1278. }()
  1279. buff := ctx.Buffer
  1280. buff.WriteUInt8(AllocationCodecVersion) // version
  1281. if target.allocations == nil {
  1282. buff.WriteUInt8(uint8(0)) // write nil byte
  1283. } else {
  1284. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1285. // --- [begin][write][slice]([]*AllocationSet) ---
  1286. buff.WriteInt(len(target.allocations)) // array length
  1287. for i := 0; i < len(target.allocations); i++ {
  1288. if target.allocations[i] == nil {
  1289. buff.WriteUInt8(uint8(0)) // write nil byte
  1290. } else {
  1291. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1292. // --- [begin][write][struct](AllocationSet) ---
  1293. buff.WriteInt(0) // [compatibility, unused]
  1294. errA := target.allocations[i].MarshalBinaryWithContext(ctx)
  1295. if errA != nil {
  1296. return errA
  1297. }
  1298. // --- [end][write][struct](AllocationSet) ---
  1299. }
  1300. }
  1301. // --- [end][write][slice]([]*AllocationSet) ---
  1302. }
  1303. if ctx.IsStringTable() {
  1304. a := ctx.Table.AddOrGet(target.FromStore)
  1305. buff.WriteInt(a) // write table index
  1306. } else {
  1307. buff.WriteString(target.FromStore) // write string
  1308. }
  1309. return nil
  1310. }
  1311. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1312. // the AllocationSetRange type
  1313. func (target *AllocationSetRange) UnmarshalBinary(data []byte) error {
  1314. var table []string
  1315. buff := util.NewBufferFromBytes(data)
  1316. // string table header validation
  1317. if isBinaryTag(data, BinaryTagStringTable) {
  1318. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1319. tl := buff.ReadInt() // table length
  1320. if tl > 0 {
  1321. table = make([]string, tl, tl)
  1322. for i := 0; i < tl; i++ {
  1323. table[i] = buff.ReadString()
  1324. }
  1325. }
  1326. }
  1327. ctx := &DecodingContext{
  1328. Buffer: buff,
  1329. Table: table,
  1330. }
  1331. err := target.UnmarshalBinaryWithContext(ctx)
  1332. if err != nil {
  1333. return err
  1334. }
  1335. return nil
  1336. }
  1337. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1338. // the AllocationSetRange type
  1339. func (target *AllocationSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1340. // panics are recovered and propagated as errors
  1341. defer func() {
  1342. if r := recover(); r != nil {
  1343. if e, ok := r.(error); ok {
  1344. err = e
  1345. } else if s, ok := r.(string); ok {
  1346. err = fmt.Errorf("Unexpected panic: %s", s)
  1347. } else {
  1348. err = fmt.Errorf("Unexpected panic: %+v", r)
  1349. }
  1350. }
  1351. }()
  1352. buff := ctx.Buffer
  1353. // Codec Version Check
  1354. version := buff.ReadUInt8()
  1355. if version != AllocationCodecVersion {
  1356. return fmt.Errorf("Invalid Version Unmarshaling AllocationSetRange. Expected %d, got %d", AllocationCodecVersion, version)
  1357. }
  1358. if buff.ReadUInt8() == uint8(0) {
  1359. target.allocations = nil
  1360. } else {
  1361. // --- [begin][read][slice]([]*AllocationSet) ---
  1362. b := buff.ReadInt() // array len
  1363. a := make([]*AllocationSet, b)
  1364. for i := 0; i < b; i++ {
  1365. var c *AllocationSet
  1366. if buff.ReadUInt8() == uint8(0) {
  1367. c = nil
  1368. } else {
  1369. // --- [begin][read][struct](AllocationSet) ---
  1370. d := &AllocationSet{}
  1371. buff.ReadInt() // [compatibility, unused]
  1372. errA := d.UnmarshalBinaryWithContext(ctx)
  1373. if errA != nil {
  1374. return errA
  1375. }
  1376. c = d
  1377. // --- [end][read][struct](AllocationSet) ---
  1378. }
  1379. a[i] = c
  1380. }
  1381. target.allocations = a
  1382. // --- [end][read][slice]([]*AllocationSet) ---
  1383. }
  1384. var f string
  1385. if ctx.IsStringTable() {
  1386. g := buff.ReadInt() // read string index
  1387. f = ctx.Table[g]
  1388. } else {
  1389. f = buff.ReadString() // read string
  1390. }
  1391. e := f
  1392. target.FromStore = e
  1393. return nil
  1394. }
  1395. //--------------------------------------------------------------------------
  1396. // Any
  1397. //--------------------------------------------------------------------------
  1398. // MarshalBinary serializes the internal properties of this Any instance
  1399. // into a byte array
  1400. func (target *Any) MarshalBinary() (data []byte, err error) {
  1401. ctx := &EncodingContext{
  1402. Buffer: util.NewBuffer(),
  1403. Table: nil,
  1404. }
  1405. e := target.MarshalBinaryWithContext(ctx)
  1406. if e != nil {
  1407. return nil, e
  1408. }
  1409. encBytes := ctx.Buffer.Bytes()
  1410. return encBytes, nil
  1411. }
  1412. // MarshalBinaryWithContext serializes the internal properties of this Any instance
  1413. // into a byte array leveraging a predefined context.
  1414. func (target *Any) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1415. // panics are recovered and propagated as errors
  1416. defer func() {
  1417. if r := recover(); r != nil {
  1418. if e, ok := r.(error); ok {
  1419. err = e
  1420. } else if s, ok := r.(string); ok {
  1421. err = fmt.Errorf("Unexpected panic: %s", s)
  1422. } else {
  1423. err = fmt.Errorf("Unexpected panic: %+v", r)
  1424. }
  1425. }
  1426. }()
  1427. buff := ctx.Buffer
  1428. buff.WriteUInt8(AssetsCodecVersion) // version
  1429. // --- [begin][write][alias](AssetLabels) ---
  1430. if map[string]string(target.labels) == nil {
  1431. buff.WriteUInt8(uint8(0)) // write nil byte
  1432. } else {
  1433. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1434. // --- [begin][write][map](map[string]string) ---
  1435. buff.WriteInt(len(map[string]string(target.labels))) // map length
  1436. for v, z := range map[string]string(target.labels) {
  1437. if ctx.IsStringTable() {
  1438. a := ctx.Table.AddOrGet(v)
  1439. buff.WriteInt(a) // write table index
  1440. } else {
  1441. buff.WriteString(v) // write string
  1442. }
  1443. if ctx.IsStringTable() {
  1444. b := ctx.Table.AddOrGet(z)
  1445. buff.WriteInt(b) // write table index
  1446. } else {
  1447. buff.WriteString(z) // write string
  1448. }
  1449. }
  1450. // --- [end][write][map](map[string]string) ---
  1451. }
  1452. // --- [end][write][alias](AssetLabels) ---
  1453. if target.properties == nil {
  1454. buff.WriteUInt8(uint8(0)) // write nil byte
  1455. } else {
  1456. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1457. // --- [begin][write][struct](AssetProperties) ---
  1458. buff.WriteInt(0) // [compatibility, unused]
  1459. errA := target.properties.MarshalBinaryWithContext(ctx)
  1460. if errA != nil {
  1461. return errA
  1462. }
  1463. // --- [end][write][struct](AssetProperties) ---
  1464. }
  1465. // --- [begin][write][reference](time.Time) ---
  1466. c, errB := target.start.MarshalBinary()
  1467. if errB != nil {
  1468. return errB
  1469. }
  1470. buff.WriteInt(len(c))
  1471. buff.WriteBytes(c)
  1472. // --- [end][write][reference](time.Time) ---
  1473. // --- [begin][write][reference](time.Time) ---
  1474. d, errC := target.end.MarshalBinary()
  1475. if errC != nil {
  1476. return errC
  1477. }
  1478. buff.WriteInt(len(d))
  1479. buff.WriteBytes(d)
  1480. // --- [end][write][reference](time.Time) ---
  1481. // --- [begin][write][struct](Window) ---
  1482. buff.WriteInt(0) // [compatibility, unused]
  1483. errD := target.window.MarshalBinaryWithContext(ctx)
  1484. if errD != nil {
  1485. return errD
  1486. }
  1487. // --- [end][write][struct](Window) ---
  1488. buff.WriteFloat64(target.adjustment) // write float64
  1489. buff.WriteFloat64(target.Cost) // write float64
  1490. return nil
  1491. }
  1492. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1493. // the Any type
  1494. func (target *Any) UnmarshalBinary(data []byte) error {
  1495. var table []string
  1496. buff := util.NewBufferFromBytes(data)
  1497. // string table header validation
  1498. if isBinaryTag(data, BinaryTagStringTable) {
  1499. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1500. tl := buff.ReadInt() // table length
  1501. if tl > 0 {
  1502. table = make([]string, tl, tl)
  1503. for i := 0; i < tl; i++ {
  1504. table[i] = buff.ReadString()
  1505. }
  1506. }
  1507. }
  1508. ctx := &DecodingContext{
  1509. Buffer: buff,
  1510. Table: table,
  1511. }
  1512. err := target.UnmarshalBinaryWithContext(ctx)
  1513. if err != nil {
  1514. return err
  1515. }
  1516. return nil
  1517. }
  1518. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1519. // the Any type
  1520. func (target *Any) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1521. // panics are recovered and propagated as errors
  1522. defer func() {
  1523. if r := recover(); r != nil {
  1524. if e, ok := r.(error); ok {
  1525. err = e
  1526. } else if s, ok := r.(string); ok {
  1527. err = fmt.Errorf("Unexpected panic: %s", s)
  1528. } else {
  1529. err = fmt.Errorf("Unexpected panic: %+v", r)
  1530. }
  1531. }
  1532. }()
  1533. buff := ctx.Buffer
  1534. // Codec Version Check
  1535. version := buff.ReadUInt8()
  1536. if version != AssetsCodecVersion {
  1537. return fmt.Errorf("Invalid Version Unmarshaling Any. Expected %d, got %d", AssetsCodecVersion, version)
  1538. }
  1539. // --- [begin][read][alias](AssetLabels) ---
  1540. var a map[string]string
  1541. if buff.ReadUInt8() == uint8(0) {
  1542. a = nil
  1543. } else {
  1544. // --- [begin][read][map](map[string]string) ---
  1545. c := buff.ReadInt() // map len
  1546. b := make(map[string]string, c)
  1547. for i := 0; i < c; i++ {
  1548. var v string
  1549. var e string
  1550. if ctx.IsStringTable() {
  1551. f := buff.ReadInt() // read string index
  1552. e = ctx.Table[f]
  1553. } else {
  1554. e = buff.ReadString() // read string
  1555. }
  1556. d := e
  1557. v = d
  1558. var z string
  1559. var h string
  1560. if ctx.IsStringTable() {
  1561. k := buff.ReadInt() // read string index
  1562. h = ctx.Table[k]
  1563. } else {
  1564. h = buff.ReadString() // read string
  1565. }
  1566. g := h
  1567. z = g
  1568. b[v] = z
  1569. }
  1570. a = b
  1571. // --- [end][read][map](map[string]string) ---
  1572. }
  1573. target.labels = AssetLabels(a)
  1574. // --- [end][read][alias](AssetLabels) ---
  1575. if buff.ReadUInt8() == uint8(0) {
  1576. target.properties = nil
  1577. } else {
  1578. // --- [begin][read][struct](AssetProperties) ---
  1579. l := &AssetProperties{}
  1580. buff.ReadInt() // [compatibility, unused]
  1581. errA := l.UnmarshalBinaryWithContext(ctx)
  1582. if errA != nil {
  1583. return errA
  1584. }
  1585. target.properties = l
  1586. // --- [end][read][struct](AssetProperties) ---
  1587. }
  1588. // --- [begin][read][reference](time.Time) ---
  1589. m := &time.Time{}
  1590. n := buff.ReadInt() // byte array length
  1591. o := buff.ReadBytes(n) // byte array
  1592. errB := m.UnmarshalBinary(o)
  1593. if errB != nil {
  1594. return errB
  1595. }
  1596. target.start = *m
  1597. // --- [end][read][reference](time.Time) ---
  1598. // --- [begin][read][reference](time.Time) ---
  1599. p := &time.Time{}
  1600. q := buff.ReadInt() // byte array length
  1601. r := buff.ReadBytes(q) // byte array
  1602. errC := p.UnmarshalBinary(r)
  1603. if errC != nil {
  1604. return errC
  1605. }
  1606. target.end = *p
  1607. // --- [end][read][reference](time.Time) ---
  1608. // --- [begin][read][struct](Window) ---
  1609. s := &Window{}
  1610. buff.ReadInt() // [compatibility, unused]
  1611. errD := s.UnmarshalBinaryWithContext(ctx)
  1612. if errD != nil {
  1613. return errD
  1614. }
  1615. target.window = *s
  1616. // --- [end][read][struct](Window) ---
  1617. t := buff.ReadFloat64() // read float64
  1618. target.adjustment = t
  1619. u := buff.ReadFloat64() // read float64
  1620. target.Cost = u
  1621. return nil
  1622. }
  1623. //--------------------------------------------------------------------------
  1624. // AssetProperties
  1625. //--------------------------------------------------------------------------
  1626. // MarshalBinary serializes the internal properties of this AssetProperties instance
  1627. // into a byte array
  1628. func (target *AssetProperties) MarshalBinary() (data []byte, err error) {
  1629. ctx := &EncodingContext{
  1630. Buffer: util.NewBuffer(),
  1631. Table: nil,
  1632. }
  1633. e := target.MarshalBinaryWithContext(ctx)
  1634. if e != nil {
  1635. return nil, e
  1636. }
  1637. encBytes := ctx.Buffer.Bytes()
  1638. return encBytes, nil
  1639. }
  1640. // MarshalBinaryWithContext serializes the internal properties of this AssetProperties instance
  1641. // into a byte array leveraging a predefined context.
  1642. func (target *AssetProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1643. // panics are recovered and propagated as errors
  1644. defer func() {
  1645. if r := recover(); r != nil {
  1646. if e, ok := r.(error); ok {
  1647. err = e
  1648. } else if s, ok := r.(string); ok {
  1649. err = fmt.Errorf("Unexpected panic: %s", s)
  1650. } else {
  1651. err = fmt.Errorf("Unexpected panic: %+v", r)
  1652. }
  1653. }
  1654. }()
  1655. buff := ctx.Buffer
  1656. buff.WriteUInt8(AssetsCodecVersion) // version
  1657. if ctx.IsStringTable() {
  1658. a := ctx.Table.AddOrGet(target.Category)
  1659. buff.WriteInt(a) // write table index
  1660. } else {
  1661. buff.WriteString(target.Category) // write string
  1662. }
  1663. if ctx.IsStringTable() {
  1664. b := ctx.Table.AddOrGet(target.Provider)
  1665. buff.WriteInt(b) // write table index
  1666. } else {
  1667. buff.WriteString(target.Provider) // write string
  1668. }
  1669. if ctx.IsStringTable() {
  1670. c := ctx.Table.AddOrGet(target.Account)
  1671. buff.WriteInt(c) // write table index
  1672. } else {
  1673. buff.WriteString(target.Account) // write string
  1674. }
  1675. if ctx.IsStringTable() {
  1676. d := ctx.Table.AddOrGet(target.Project)
  1677. buff.WriteInt(d) // write table index
  1678. } else {
  1679. buff.WriteString(target.Project) // write string
  1680. }
  1681. if ctx.IsStringTable() {
  1682. e := ctx.Table.AddOrGet(target.Service)
  1683. buff.WriteInt(e) // write table index
  1684. } else {
  1685. buff.WriteString(target.Service) // write string
  1686. }
  1687. if ctx.IsStringTable() {
  1688. f := ctx.Table.AddOrGet(target.Cluster)
  1689. buff.WriteInt(f) // write table index
  1690. } else {
  1691. buff.WriteString(target.Cluster) // write string
  1692. }
  1693. if ctx.IsStringTable() {
  1694. g := ctx.Table.AddOrGet(target.Name)
  1695. buff.WriteInt(g) // write table index
  1696. } else {
  1697. buff.WriteString(target.Name) // write string
  1698. }
  1699. if ctx.IsStringTable() {
  1700. h := ctx.Table.AddOrGet(target.ProviderID)
  1701. buff.WriteInt(h) // write table index
  1702. } else {
  1703. buff.WriteString(target.ProviderID) // write string
  1704. }
  1705. return nil
  1706. }
  1707. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1708. // the AssetProperties type
  1709. func (target *AssetProperties) UnmarshalBinary(data []byte) error {
  1710. var table []string
  1711. buff := util.NewBufferFromBytes(data)
  1712. // string table header validation
  1713. if isBinaryTag(data, BinaryTagStringTable) {
  1714. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1715. tl := buff.ReadInt() // table length
  1716. if tl > 0 {
  1717. table = make([]string, tl, tl)
  1718. for i := 0; i < tl; i++ {
  1719. table[i] = buff.ReadString()
  1720. }
  1721. }
  1722. }
  1723. ctx := &DecodingContext{
  1724. Buffer: buff,
  1725. Table: table,
  1726. }
  1727. err := target.UnmarshalBinaryWithContext(ctx)
  1728. if err != nil {
  1729. return err
  1730. }
  1731. return nil
  1732. }
  1733. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1734. // the AssetProperties type
  1735. func (target *AssetProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1736. // panics are recovered and propagated as errors
  1737. defer func() {
  1738. if r := recover(); r != nil {
  1739. if e, ok := r.(error); ok {
  1740. err = e
  1741. } else if s, ok := r.(string); ok {
  1742. err = fmt.Errorf("Unexpected panic: %s", s)
  1743. } else {
  1744. err = fmt.Errorf("Unexpected panic: %+v", r)
  1745. }
  1746. }
  1747. }()
  1748. buff := ctx.Buffer
  1749. // Codec Version Check
  1750. version := buff.ReadUInt8()
  1751. if version != AssetsCodecVersion {
  1752. return fmt.Errorf("Invalid Version Unmarshaling AssetProperties. Expected %d, got %d", AssetsCodecVersion, version)
  1753. }
  1754. var b string
  1755. if ctx.IsStringTable() {
  1756. c := buff.ReadInt() // read string index
  1757. b = ctx.Table[c]
  1758. } else {
  1759. b = buff.ReadString() // read string
  1760. }
  1761. a := b
  1762. target.Category = a
  1763. var e string
  1764. if ctx.IsStringTable() {
  1765. f := buff.ReadInt() // read string index
  1766. e = ctx.Table[f]
  1767. } else {
  1768. e = buff.ReadString() // read string
  1769. }
  1770. d := e
  1771. target.Provider = d
  1772. var h string
  1773. if ctx.IsStringTable() {
  1774. k := buff.ReadInt() // read string index
  1775. h = ctx.Table[k]
  1776. } else {
  1777. h = buff.ReadString() // read string
  1778. }
  1779. g := h
  1780. target.Account = g
  1781. var m string
  1782. if ctx.IsStringTable() {
  1783. n := buff.ReadInt() // read string index
  1784. m = ctx.Table[n]
  1785. } else {
  1786. m = buff.ReadString() // read string
  1787. }
  1788. l := m
  1789. target.Project = l
  1790. var p string
  1791. if ctx.IsStringTable() {
  1792. q := buff.ReadInt() // read string index
  1793. p = ctx.Table[q]
  1794. } else {
  1795. p = buff.ReadString() // read string
  1796. }
  1797. o := p
  1798. target.Service = o
  1799. var s string
  1800. if ctx.IsStringTable() {
  1801. t := buff.ReadInt() // read string index
  1802. s = ctx.Table[t]
  1803. } else {
  1804. s = buff.ReadString() // read string
  1805. }
  1806. r := s
  1807. target.Cluster = r
  1808. var w string
  1809. if ctx.IsStringTable() {
  1810. x := buff.ReadInt() // read string index
  1811. w = ctx.Table[x]
  1812. } else {
  1813. w = buff.ReadString() // read string
  1814. }
  1815. u := w
  1816. target.Name = u
  1817. var aa string
  1818. if ctx.IsStringTable() {
  1819. bb := buff.ReadInt() // read string index
  1820. aa = ctx.Table[bb]
  1821. } else {
  1822. aa = buff.ReadString() // read string
  1823. }
  1824. y := aa
  1825. target.ProviderID = y
  1826. return nil
  1827. }
  1828. //--------------------------------------------------------------------------
  1829. // AssetSet
  1830. //--------------------------------------------------------------------------
  1831. // MarshalBinary serializes the internal properties of this AssetSet instance
  1832. // into a byte array
  1833. func (target *AssetSet) MarshalBinary() (data []byte, err error) {
  1834. ctx := &EncodingContext{
  1835. Buffer: util.NewBuffer(),
  1836. Table: nil,
  1837. }
  1838. e := target.MarshalBinaryWithContext(ctx)
  1839. if e != nil {
  1840. return nil, e
  1841. }
  1842. encBytes := ctx.Buffer.Bytes()
  1843. return encBytes, nil
  1844. }
  1845. // MarshalBinaryWithContext serializes the internal properties of this AssetSet instance
  1846. // into a byte array leveraging a predefined context.
  1847. func (target *AssetSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1848. // panics are recovered and propagated as errors
  1849. defer func() {
  1850. if r := recover(); r != nil {
  1851. if e, ok := r.(error); ok {
  1852. err = e
  1853. } else if s, ok := r.(string); ok {
  1854. err = fmt.Errorf("Unexpected panic: %s", s)
  1855. } else {
  1856. err = fmt.Errorf("Unexpected panic: %+v", r)
  1857. }
  1858. }
  1859. }()
  1860. buff := ctx.Buffer
  1861. buff.WriteUInt8(AssetsCodecVersion) // version
  1862. if target.aggregateBy == nil {
  1863. buff.WriteUInt8(uint8(0)) // write nil byte
  1864. } else {
  1865. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1866. // --- [begin][write][slice]([]string) ---
  1867. buff.WriteInt(len(target.aggregateBy)) // array length
  1868. for i := 0; i < len(target.aggregateBy); i++ {
  1869. if ctx.IsStringTable() {
  1870. a := ctx.Table.AddOrGet(target.aggregateBy[i])
  1871. buff.WriteInt(a) // write table index
  1872. } else {
  1873. buff.WriteString(target.aggregateBy[i]) // write string
  1874. }
  1875. }
  1876. // --- [end][write][slice]([]string) ---
  1877. }
  1878. if target.assets == nil {
  1879. buff.WriteUInt8(uint8(0)) // write nil byte
  1880. } else {
  1881. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1882. // --- [begin][write][map](map[string]Asset) ---
  1883. buff.WriteInt(len(target.assets)) // map length
  1884. for v, z := range target.assets {
  1885. if ctx.IsStringTable() {
  1886. b := ctx.Table.AddOrGet(v)
  1887. buff.WriteInt(b) // write table index
  1888. } else {
  1889. buff.WriteString(v) // write string
  1890. }
  1891. if z == nil {
  1892. buff.WriteUInt8(uint8(0)) // write nil byte
  1893. } else {
  1894. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1895. // --- [begin][write][interface](Asset) ---
  1896. c := reflect.ValueOf(z).Interface()
  1897. d, okA := c.(BinEncoder)
  1898. if !okA {
  1899. return fmt.Errorf("Type: %s does not implement %s.BinEncoder", typeToString(z), GeneratorPackageName)
  1900. }
  1901. buff.WriteString(typeToString(z))
  1902. buff.WriteInt(0) // [compatibility, unused]
  1903. errA := d.MarshalBinaryWithContext(ctx)
  1904. if errA != nil {
  1905. return errA
  1906. }
  1907. // --- [end][write][interface](Asset) ---
  1908. }
  1909. }
  1910. // --- [end][write][map](map[string]Asset) ---
  1911. }
  1912. if ctx.IsStringTable() {
  1913. e := ctx.Table.AddOrGet(target.FromSource)
  1914. buff.WriteInt(e) // write table index
  1915. } else {
  1916. buff.WriteString(target.FromSource) // write string
  1917. }
  1918. // --- [begin][write][struct](Window) ---
  1919. buff.WriteInt(0) // [compatibility, unused]
  1920. errB := target.Window.MarshalBinaryWithContext(ctx)
  1921. if errB != nil {
  1922. return errB
  1923. }
  1924. // --- [end][write][struct](Window) ---
  1925. if target.Warnings == nil {
  1926. buff.WriteUInt8(uint8(0)) // write nil byte
  1927. } else {
  1928. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1929. // --- [begin][write][slice]([]string) ---
  1930. buff.WriteInt(len(target.Warnings)) // array length
  1931. for j := 0; j < len(target.Warnings); j++ {
  1932. if ctx.IsStringTable() {
  1933. f := ctx.Table.AddOrGet(target.Warnings[j])
  1934. buff.WriteInt(f) // write table index
  1935. } else {
  1936. buff.WriteString(target.Warnings[j]) // write string
  1937. }
  1938. }
  1939. // --- [end][write][slice]([]string) ---
  1940. }
  1941. if target.Errors == nil {
  1942. buff.WriteUInt8(uint8(0)) // write nil byte
  1943. } else {
  1944. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1945. // --- [begin][write][slice]([]string) ---
  1946. buff.WriteInt(len(target.Errors)) // array length
  1947. for ii := 0; ii < len(target.Errors); ii++ {
  1948. if ctx.IsStringTable() {
  1949. g := ctx.Table.AddOrGet(target.Errors[ii])
  1950. buff.WriteInt(g) // write table index
  1951. } else {
  1952. buff.WriteString(target.Errors[ii]) // write string
  1953. }
  1954. }
  1955. // --- [end][write][slice]([]string) ---
  1956. }
  1957. return nil
  1958. }
  1959. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1960. // the AssetSet type
  1961. func (target *AssetSet) UnmarshalBinary(data []byte) error {
  1962. var table []string
  1963. buff := util.NewBufferFromBytes(data)
  1964. // string table header validation
  1965. if isBinaryTag(data, BinaryTagStringTable) {
  1966. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1967. tl := buff.ReadInt() // table length
  1968. if tl > 0 {
  1969. table = make([]string, tl, tl)
  1970. for i := 0; i < tl; i++ {
  1971. table[i] = buff.ReadString()
  1972. }
  1973. }
  1974. }
  1975. ctx := &DecodingContext{
  1976. Buffer: buff,
  1977. Table: table,
  1978. }
  1979. err := target.UnmarshalBinaryWithContext(ctx)
  1980. if err != nil {
  1981. return err
  1982. }
  1983. return nil
  1984. }
  1985. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1986. // the AssetSet type
  1987. func (target *AssetSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1988. // panics are recovered and propagated as errors
  1989. defer func() {
  1990. if r := recover(); r != nil {
  1991. if e, ok := r.(error); ok {
  1992. err = e
  1993. } else if s, ok := r.(string); ok {
  1994. err = fmt.Errorf("Unexpected panic: %s", s)
  1995. } else {
  1996. err = fmt.Errorf("Unexpected panic: %+v", r)
  1997. }
  1998. }
  1999. }()
  2000. buff := ctx.Buffer
  2001. // Codec Version Check
  2002. version := buff.ReadUInt8()
  2003. if version != AssetsCodecVersion {
  2004. return fmt.Errorf("Invalid Version Unmarshaling AssetSet. Expected %d, got %d", AssetsCodecVersion, version)
  2005. }
  2006. if buff.ReadUInt8() == uint8(0) {
  2007. target.aggregateBy = nil
  2008. } else {
  2009. // --- [begin][read][slice]([]string) ---
  2010. b := buff.ReadInt() // array len
  2011. a := make([]string, b)
  2012. for i := 0; i < b; i++ {
  2013. var c string
  2014. var e string
  2015. if ctx.IsStringTable() {
  2016. f := buff.ReadInt() // read string index
  2017. e = ctx.Table[f]
  2018. } else {
  2019. e = buff.ReadString() // read string
  2020. }
  2021. d := e
  2022. c = d
  2023. a[i] = c
  2024. }
  2025. target.aggregateBy = a
  2026. // --- [end][read][slice]([]string) ---
  2027. }
  2028. if buff.ReadUInt8() == uint8(0) {
  2029. target.assets = nil
  2030. } else {
  2031. // --- [begin][read][map](map[string]Asset) ---
  2032. h := buff.ReadInt() // map len
  2033. g := make(map[string]Asset, h)
  2034. for j := 0; j < h; j++ {
  2035. var v string
  2036. var l string
  2037. if ctx.IsStringTable() {
  2038. m := buff.ReadInt() // read string index
  2039. l = ctx.Table[m]
  2040. } else {
  2041. l = buff.ReadString() // read string
  2042. }
  2043. k := l
  2044. v = k
  2045. var z Asset
  2046. if buff.ReadUInt8() == uint8(0) {
  2047. z = nil
  2048. } else {
  2049. // --- [begin][read][interface](Asset) ---
  2050. n := buff.ReadString()
  2051. _, o, _ := resolveType(n)
  2052. if _, ok := typeMap[o]; !ok {
  2053. return fmt.Errorf("Unknown Type: %s", o)
  2054. }
  2055. p, okA := reflect.New(typeMap[o]).Interface().(BinDecoder)
  2056. if !okA {
  2057. return fmt.Errorf("Type: %s does not implement %s.BinDecoder.", o, GeneratorPackageName)
  2058. }
  2059. buff.ReadInt() // [compatibility, unused]
  2060. errA := p.UnmarshalBinaryWithContext(ctx)
  2061. if errA != nil {
  2062. return errA
  2063. }
  2064. z = p.(Asset)
  2065. // --- [end][read][interface](Asset) ---
  2066. }
  2067. g[v] = z
  2068. }
  2069. target.assets = g
  2070. // --- [end][read][map](map[string]Asset) ---
  2071. }
  2072. var r string
  2073. if ctx.IsStringTable() {
  2074. s := buff.ReadInt() // read string index
  2075. r = ctx.Table[s]
  2076. } else {
  2077. r = buff.ReadString() // read string
  2078. }
  2079. q := r
  2080. target.FromSource = q
  2081. // --- [begin][read][struct](Window) ---
  2082. t := &Window{}
  2083. buff.ReadInt() // [compatibility, unused]
  2084. errB := t.UnmarshalBinaryWithContext(ctx)
  2085. if errB != nil {
  2086. return errB
  2087. }
  2088. target.Window = *t
  2089. // --- [end][read][struct](Window) ---
  2090. if buff.ReadUInt8() == uint8(0) {
  2091. target.Warnings = nil
  2092. } else {
  2093. // --- [begin][read][slice]([]string) ---
  2094. w := buff.ReadInt() // array len
  2095. u := make([]string, w)
  2096. for ii := 0; ii < w; ii++ {
  2097. var x string
  2098. var aa string
  2099. if ctx.IsStringTable() {
  2100. bb := buff.ReadInt() // read string index
  2101. aa = ctx.Table[bb]
  2102. } else {
  2103. aa = buff.ReadString() // read string
  2104. }
  2105. y := aa
  2106. x = y
  2107. u[ii] = x
  2108. }
  2109. target.Warnings = u
  2110. // --- [end][read][slice]([]string) ---
  2111. }
  2112. if buff.ReadUInt8() == uint8(0) {
  2113. target.Errors = nil
  2114. } else {
  2115. // --- [begin][read][slice]([]string) ---
  2116. dd := buff.ReadInt() // array len
  2117. cc := make([]string, dd)
  2118. for jj := 0; jj < dd; jj++ {
  2119. var ee string
  2120. var gg string
  2121. if ctx.IsStringTable() {
  2122. hh := buff.ReadInt() // read string index
  2123. gg = ctx.Table[hh]
  2124. } else {
  2125. gg = buff.ReadString() // read string
  2126. }
  2127. ff := gg
  2128. ee = ff
  2129. cc[jj] = ee
  2130. }
  2131. target.Errors = cc
  2132. // --- [end][read][slice]([]string) ---
  2133. }
  2134. return nil
  2135. }
  2136. //--------------------------------------------------------------------------
  2137. // AssetSetRange
  2138. //--------------------------------------------------------------------------
  2139. // MarshalBinary serializes the internal properties of this AssetSetRange instance
  2140. // into a byte array
  2141. func (target *AssetSetRange) MarshalBinary() (data []byte, err error) {
  2142. ctx := &EncodingContext{
  2143. Buffer: util.NewBuffer(),
  2144. Table: nil,
  2145. }
  2146. e := target.MarshalBinaryWithContext(ctx)
  2147. if e != nil {
  2148. return nil, e
  2149. }
  2150. encBytes := ctx.Buffer.Bytes()
  2151. return encBytes, nil
  2152. }
  2153. // MarshalBinaryWithContext serializes the internal properties of this AssetSetRange instance
  2154. // into a byte array leveraging a predefined context.
  2155. func (target *AssetSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2156. // panics are recovered and propagated as errors
  2157. defer func() {
  2158. if r := recover(); r != nil {
  2159. if e, ok := r.(error); ok {
  2160. err = e
  2161. } else if s, ok := r.(string); ok {
  2162. err = fmt.Errorf("Unexpected panic: %s", s)
  2163. } else {
  2164. err = fmt.Errorf("Unexpected panic: %+v", r)
  2165. }
  2166. }
  2167. }()
  2168. buff := ctx.Buffer
  2169. buff.WriteUInt8(AssetsCodecVersion) // version
  2170. if target.assets == nil {
  2171. buff.WriteUInt8(uint8(0)) // write nil byte
  2172. } else {
  2173. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2174. // --- [begin][write][slice]([]*AssetSet) ---
  2175. buff.WriteInt(len(target.assets)) // array length
  2176. for i := 0; i < len(target.assets); i++ {
  2177. if target.assets[i] == nil {
  2178. buff.WriteUInt8(uint8(0)) // write nil byte
  2179. } else {
  2180. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2181. // --- [begin][write][struct](AssetSet) ---
  2182. buff.WriteInt(0) // [compatibility, unused]
  2183. errA := target.assets[i].MarshalBinaryWithContext(ctx)
  2184. if errA != nil {
  2185. return errA
  2186. }
  2187. // --- [end][write][struct](AssetSet) ---
  2188. }
  2189. }
  2190. // --- [end][write][slice]([]*AssetSet) ---
  2191. }
  2192. if ctx.IsStringTable() {
  2193. a := ctx.Table.AddOrGet(target.FromStore)
  2194. buff.WriteInt(a) // write table index
  2195. } else {
  2196. buff.WriteString(target.FromStore) // write string
  2197. }
  2198. return nil
  2199. }
  2200. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2201. // the AssetSetRange type
  2202. func (target *AssetSetRange) UnmarshalBinary(data []byte) error {
  2203. var table []string
  2204. buff := util.NewBufferFromBytes(data)
  2205. // string table header validation
  2206. if isBinaryTag(data, BinaryTagStringTable) {
  2207. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2208. tl := buff.ReadInt() // table length
  2209. if tl > 0 {
  2210. table = make([]string, tl, tl)
  2211. for i := 0; i < tl; i++ {
  2212. table[i] = buff.ReadString()
  2213. }
  2214. }
  2215. }
  2216. ctx := &DecodingContext{
  2217. Buffer: buff,
  2218. Table: table,
  2219. }
  2220. err := target.UnmarshalBinaryWithContext(ctx)
  2221. if err != nil {
  2222. return err
  2223. }
  2224. return nil
  2225. }
  2226. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2227. // the AssetSetRange type
  2228. func (target *AssetSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2229. // panics are recovered and propagated as errors
  2230. defer func() {
  2231. if r := recover(); r != nil {
  2232. if e, ok := r.(error); ok {
  2233. err = e
  2234. } else if s, ok := r.(string); ok {
  2235. err = fmt.Errorf("Unexpected panic: %s", s)
  2236. } else {
  2237. err = fmt.Errorf("Unexpected panic: %+v", r)
  2238. }
  2239. }
  2240. }()
  2241. buff := ctx.Buffer
  2242. // Codec Version Check
  2243. version := buff.ReadUInt8()
  2244. if version != AssetsCodecVersion {
  2245. return fmt.Errorf("Invalid Version Unmarshaling AssetSetRange. Expected %d, got %d", AssetsCodecVersion, version)
  2246. }
  2247. if buff.ReadUInt8() == uint8(0) {
  2248. target.assets = nil
  2249. } else {
  2250. // --- [begin][read][slice]([]*AssetSet) ---
  2251. b := buff.ReadInt() // array len
  2252. a := make([]*AssetSet, b)
  2253. for i := 0; i < b; i++ {
  2254. var c *AssetSet
  2255. if buff.ReadUInt8() == uint8(0) {
  2256. c = nil
  2257. } else {
  2258. // --- [begin][read][struct](AssetSet) ---
  2259. d := &AssetSet{}
  2260. buff.ReadInt() // [compatibility, unused]
  2261. errA := d.UnmarshalBinaryWithContext(ctx)
  2262. if errA != nil {
  2263. return errA
  2264. }
  2265. c = d
  2266. // --- [end][read][struct](AssetSet) ---
  2267. }
  2268. a[i] = c
  2269. }
  2270. target.assets = a
  2271. // --- [end][read][slice]([]*AssetSet) ---
  2272. }
  2273. var f string
  2274. if ctx.IsStringTable() {
  2275. g := buff.ReadInt() // read string index
  2276. f = ctx.Table[g]
  2277. } else {
  2278. f = buff.ReadString() // read string
  2279. }
  2280. e := f
  2281. target.FromStore = e
  2282. return nil
  2283. }
  2284. //--------------------------------------------------------------------------
  2285. // Breakdown
  2286. //--------------------------------------------------------------------------
  2287. // MarshalBinary serializes the internal properties of this Breakdown instance
  2288. // into a byte array
  2289. func (target *Breakdown) MarshalBinary() (data []byte, err error) {
  2290. ctx := &EncodingContext{
  2291. Buffer: util.NewBuffer(),
  2292. Table: nil,
  2293. }
  2294. e := target.MarshalBinaryWithContext(ctx)
  2295. if e != nil {
  2296. return nil, e
  2297. }
  2298. encBytes := ctx.Buffer.Bytes()
  2299. return encBytes, nil
  2300. }
  2301. // MarshalBinaryWithContext serializes the internal properties of this Breakdown instance
  2302. // into a byte array leveraging a predefined context.
  2303. func (target *Breakdown) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2304. // panics are recovered and propagated as errors
  2305. defer func() {
  2306. if r := recover(); r != nil {
  2307. if e, ok := r.(error); ok {
  2308. err = e
  2309. } else if s, ok := r.(string); ok {
  2310. err = fmt.Errorf("Unexpected panic: %s", s)
  2311. } else {
  2312. err = fmt.Errorf("Unexpected panic: %+v", r)
  2313. }
  2314. }
  2315. }()
  2316. buff := ctx.Buffer
  2317. buff.WriteUInt8(AssetsCodecVersion) // version
  2318. buff.WriteFloat64(target.Idle) // write float64
  2319. buff.WriteFloat64(target.Other) // write float64
  2320. buff.WriteFloat64(target.System) // write float64
  2321. buff.WriteFloat64(target.User) // write float64
  2322. return nil
  2323. }
  2324. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2325. // the Breakdown type
  2326. func (target *Breakdown) UnmarshalBinary(data []byte) error {
  2327. var table []string
  2328. buff := util.NewBufferFromBytes(data)
  2329. // string table header validation
  2330. if isBinaryTag(data, BinaryTagStringTable) {
  2331. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2332. tl := buff.ReadInt() // table length
  2333. if tl > 0 {
  2334. table = make([]string, tl, tl)
  2335. for i := 0; i < tl; i++ {
  2336. table[i] = buff.ReadString()
  2337. }
  2338. }
  2339. }
  2340. ctx := &DecodingContext{
  2341. Buffer: buff,
  2342. Table: table,
  2343. }
  2344. err := target.UnmarshalBinaryWithContext(ctx)
  2345. if err != nil {
  2346. return err
  2347. }
  2348. return nil
  2349. }
  2350. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2351. // the Breakdown type
  2352. func (target *Breakdown) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2353. // panics are recovered and propagated as errors
  2354. defer func() {
  2355. if r := recover(); r != nil {
  2356. if e, ok := r.(error); ok {
  2357. err = e
  2358. } else if s, ok := r.(string); ok {
  2359. err = fmt.Errorf("Unexpected panic: %s", s)
  2360. } else {
  2361. err = fmt.Errorf("Unexpected panic: %+v", r)
  2362. }
  2363. }
  2364. }()
  2365. buff := ctx.Buffer
  2366. // Codec Version Check
  2367. version := buff.ReadUInt8()
  2368. if version != AssetsCodecVersion {
  2369. return fmt.Errorf("Invalid Version Unmarshaling Breakdown. Expected %d, got %d", AssetsCodecVersion, version)
  2370. }
  2371. a := buff.ReadFloat64() // read float64
  2372. target.Idle = a
  2373. b := buff.ReadFloat64() // read float64
  2374. target.Other = b
  2375. c := buff.ReadFloat64() // read float64
  2376. target.System = c
  2377. d := buff.ReadFloat64() // read float64
  2378. target.User = d
  2379. return nil
  2380. }
  2381. //--------------------------------------------------------------------------
  2382. // Cloud
  2383. //--------------------------------------------------------------------------
  2384. // MarshalBinary serializes the internal properties of this Cloud instance
  2385. // into a byte array
  2386. func (target *Cloud) MarshalBinary() (data []byte, err error) {
  2387. ctx := &EncodingContext{
  2388. Buffer: util.NewBuffer(),
  2389. Table: nil,
  2390. }
  2391. e := target.MarshalBinaryWithContext(ctx)
  2392. if e != nil {
  2393. return nil, e
  2394. }
  2395. encBytes := ctx.Buffer.Bytes()
  2396. return encBytes, nil
  2397. }
  2398. // MarshalBinaryWithContext serializes the internal properties of this Cloud instance
  2399. // into a byte array leveraging a predefined context.
  2400. func (target *Cloud) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2401. // panics are recovered and propagated as errors
  2402. defer func() {
  2403. if r := recover(); r != nil {
  2404. if e, ok := r.(error); ok {
  2405. err = e
  2406. } else if s, ok := r.(string); ok {
  2407. err = fmt.Errorf("Unexpected panic: %s", s)
  2408. } else {
  2409. err = fmt.Errorf("Unexpected panic: %+v", r)
  2410. }
  2411. }
  2412. }()
  2413. buff := ctx.Buffer
  2414. buff.WriteUInt8(AssetsCodecVersion) // version
  2415. // --- [begin][write][alias](AssetLabels) ---
  2416. if map[string]string(target.labels) == nil {
  2417. buff.WriteUInt8(uint8(0)) // write nil byte
  2418. } else {
  2419. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2420. // --- [begin][write][map](map[string]string) ---
  2421. buff.WriteInt(len(map[string]string(target.labels))) // map length
  2422. for v, z := range map[string]string(target.labels) {
  2423. if ctx.IsStringTable() {
  2424. a := ctx.Table.AddOrGet(v)
  2425. buff.WriteInt(a) // write table index
  2426. } else {
  2427. buff.WriteString(v) // write string
  2428. }
  2429. if ctx.IsStringTable() {
  2430. b := ctx.Table.AddOrGet(z)
  2431. buff.WriteInt(b) // write table index
  2432. } else {
  2433. buff.WriteString(z) // write string
  2434. }
  2435. }
  2436. // --- [end][write][map](map[string]string) ---
  2437. }
  2438. // --- [end][write][alias](AssetLabels) ---
  2439. if target.properties == nil {
  2440. buff.WriteUInt8(uint8(0)) // write nil byte
  2441. } else {
  2442. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2443. // --- [begin][write][struct](AssetProperties) ---
  2444. buff.WriteInt(0) // [compatibility, unused]
  2445. errA := target.properties.MarshalBinaryWithContext(ctx)
  2446. if errA != nil {
  2447. return errA
  2448. }
  2449. // --- [end][write][struct](AssetProperties) ---
  2450. }
  2451. // --- [begin][write][reference](time.Time) ---
  2452. c, errB := target.start.MarshalBinary()
  2453. if errB != nil {
  2454. return errB
  2455. }
  2456. buff.WriteInt(len(c))
  2457. buff.WriteBytes(c)
  2458. // --- [end][write][reference](time.Time) ---
  2459. // --- [begin][write][reference](time.Time) ---
  2460. d, errC := target.end.MarshalBinary()
  2461. if errC != nil {
  2462. return errC
  2463. }
  2464. buff.WriteInt(len(d))
  2465. buff.WriteBytes(d)
  2466. // --- [end][write][reference](time.Time) ---
  2467. // --- [begin][write][struct](Window) ---
  2468. buff.WriteInt(0) // [compatibility, unused]
  2469. errD := target.window.MarshalBinaryWithContext(ctx)
  2470. if errD != nil {
  2471. return errD
  2472. }
  2473. // --- [end][write][struct](Window) ---
  2474. buff.WriteFloat64(target.adjustment) // write float64
  2475. buff.WriteFloat64(target.Cost) // write float64
  2476. buff.WriteFloat64(target.Credit) // write float64
  2477. return nil
  2478. }
  2479. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2480. // the Cloud type
  2481. func (target *Cloud) UnmarshalBinary(data []byte) error {
  2482. var table []string
  2483. buff := util.NewBufferFromBytes(data)
  2484. // string table header validation
  2485. if isBinaryTag(data, BinaryTagStringTable) {
  2486. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2487. tl := buff.ReadInt() // table length
  2488. if tl > 0 {
  2489. table = make([]string, tl, tl)
  2490. for i := 0; i < tl; i++ {
  2491. table[i] = buff.ReadString()
  2492. }
  2493. }
  2494. }
  2495. ctx := &DecodingContext{
  2496. Buffer: buff,
  2497. Table: table,
  2498. }
  2499. err := target.UnmarshalBinaryWithContext(ctx)
  2500. if err != nil {
  2501. return err
  2502. }
  2503. return nil
  2504. }
  2505. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2506. // the Cloud type
  2507. func (target *Cloud) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2508. // panics are recovered and propagated as errors
  2509. defer func() {
  2510. if r := recover(); r != nil {
  2511. if e, ok := r.(error); ok {
  2512. err = e
  2513. } else if s, ok := r.(string); ok {
  2514. err = fmt.Errorf("Unexpected panic: %s", s)
  2515. } else {
  2516. err = fmt.Errorf("Unexpected panic: %+v", r)
  2517. }
  2518. }
  2519. }()
  2520. buff := ctx.Buffer
  2521. // Codec Version Check
  2522. version := buff.ReadUInt8()
  2523. if version != AssetsCodecVersion {
  2524. return fmt.Errorf("Invalid Version Unmarshaling Cloud. Expected %d, got %d", AssetsCodecVersion, version)
  2525. }
  2526. // --- [begin][read][alias](AssetLabels) ---
  2527. var a map[string]string
  2528. if buff.ReadUInt8() == uint8(0) {
  2529. a = nil
  2530. } else {
  2531. // --- [begin][read][map](map[string]string) ---
  2532. c := buff.ReadInt() // map len
  2533. b := make(map[string]string, c)
  2534. for i := 0; i < c; i++ {
  2535. var v string
  2536. var e string
  2537. if ctx.IsStringTable() {
  2538. f := buff.ReadInt() // read string index
  2539. e = ctx.Table[f]
  2540. } else {
  2541. e = buff.ReadString() // read string
  2542. }
  2543. d := e
  2544. v = d
  2545. var z string
  2546. var h string
  2547. if ctx.IsStringTable() {
  2548. k := buff.ReadInt() // read string index
  2549. h = ctx.Table[k]
  2550. } else {
  2551. h = buff.ReadString() // read string
  2552. }
  2553. g := h
  2554. z = g
  2555. b[v] = z
  2556. }
  2557. a = b
  2558. // --- [end][read][map](map[string]string) ---
  2559. }
  2560. target.labels = AssetLabels(a)
  2561. // --- [end][read][alias](AssetLabels) ---
  2562. if buff.ReadUInt8() == uint8(0) {
  2563. target.properties = nil
  2564. } else {
  2565. // --- [begin][read][struct](AssetProperties) ---
  2566. l := &AssetProperties{}
  2567. buff.ReadInt() // [compatibility, unused]
  2568. errA := l.UnmarshalBinaryWithContext(ctx)
  2569. if errA != nil {
  2570. return errA
  2571. }
  2572. target.properties = l
  2573. // --- [end][read][struct](AssetProperties) ---
  2574. }
  2575. // --- [begin][read][reference](time.Time) ---
  2576. m := &time.Time{}
  2577. n := buff.ReadInt() // byte array length
  2578. o := buff.ReadBytes(n) // byte array
  2579. errB := m.UnmarshalBinary(o)
  2580. if errB != nil {
  2581. return errB
  2582. }
  2583. target.start = *m
  2584. // --- [end][read][reference](time.Time) ---
  2585. // --- [begin][read][reference](time.Time) ---
  2586. p := &time.Time{}
  2587. q := buff.ReadInt() // byte array length
  2588. r := buff.ReadBytes(q) // byte array
  2589. errC := p.UnmarshalBinary(r)
  2590. if errC != nil {
  2591. return errC
  2592. }
  2593. target.end = *p
  2594. // --- [end][read][reference](time.Time) ---
  2595. // --- [begin][read][struct](Window) ---
  2596. s := &Window{}
  2597. buff.ReadInt() // [compatibility, unused]
  2598. errD := s.UnmarshalBinaryWithContext(ctx)
  2599. if errD != nil {
  2600. return errD
  2601. }
  2602. target.window = *s
  2603. // --- [end][read][struct](Window) ---
  2604. t := buff.ReadFloat64() // read float64
  2605. target.adjustment = t
  2606. u := buff.ReadFloat64() // read float64
  2607. target.Cost = u
  2608. w := buff.ReadFloat64() // read float64
  2609. target.Credit = w
  2610. return nil
  2611. }
  2612. //--------------------------------------------------------------------------
  2613. // ClusterManagement
  2614. //--------------------------------------------------------------------------
  2615. // MarshalBinary serializes the internal properties of this ClusterManagement instance
  2616. // into a byte array
  2617. func (target *ClusterManagement) MarshalBinary() (data []byte, err error) {
  2618. ctx := &EncodingContext{
  2619. Buffer: util.NewBuffer(),
  2620. Table: nil,
  2621. }
  2622. e := target.MarshalBinaryWithContext(ctx)
  2623. if e != nil {
  2624. return nil, e
  2625. }
  2626. encBytes := ctx.Buffer.Bytes()
  2627. return encBytes, nil
  2628. }
  2629. // MarshalBinaryWithContext serializes the internal properties of this ClusterManagement instance
  2630. // into a byte array leveraging a predefined context.
  2631. func (target *ClusterManagement) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2632. // panics are recovered and propagated as errors
  2633. defer func() {
  2634. if r := recover(); r != nil {
  2635. if e, ok := r.(error); ok {
  2636. err = e
  2637. } else if s, ok := r.(string); ok {
  2638. err = fmt.Errorf("Unexpected panic: %s", s)
  2639. } else {
  2640. err = fmt.Errorf("Unexpected panic: %+v", r)
  2641. }
  2642. }
  2643. }()
  2644. buff := ctx.Buffer
  2645. buff.WriteUInt8(AssetsCodecVersion) // version
  2646. // --- [begin][write][alias](AssetLabels) ---
  2647. if map[string]string(target.labels) == nil {
  2648. buff.WriteUInt8(uint8(0)) // write nil byte
  2649. } else {
  2650. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2651. // --- [begin][write][map](map[string]string) ---
  2652. buff.WriteInt(len(map[string]string(target.labels))) // map length
  2653. for v, z := range map[string]string(target.labels) {
  2654. if ctx.IsStringTable() {
  2655. a := ctx.Table.AddOrGet(v)
  2656. buff.WriteInt(a) // write table index
  2657. } else {
  2658. buff.WriteString(v) // write string
  2659. }
  2660. if ctx.IsStringTable() {
  2661. b := ctx.Table.AddOrGet(z)
  2662. buff.WriteInt(b) // write table index
  2663. } else {
  2664. buff.WriteString(z) // write string
  2665. }
  2666. }
  2667. // --- [end][write][map](map[string]string) ---
  2668. }
  2669. // --- [end][write][alias](AssetLabels) ---
  2670. if target.properties == nil {
  2671. buff.WriteUInt8(uint8(0)) // write nil byte
  2672. } else {
  2673. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2674. // --- [begin][write][struct](AssetProperties) ---
  2675. buff.WriteInt(0) // [compatibility, unused]
  2676. errA := target.properties.MarshalBinaryWithContext(ctx)
  2677. if errA != nil {
  2678. return errA
  2679. }
  2680. // --- [end][write][struct](AssetProperties) ---
  2681. }
  2682. // --- [begin][write][struct](Window) ---
  2683. buff.WriteInt(0) // [compatibility, unused]
  2684. errB := target.window.MarshalBinaryWithContext(ctx)
  2685. if errB != nil {
  2686. return errB
  2687. }
  2688. // --- [end][write][struct](Window) ---
  2689. buff.WriteFloat64(target.Cost) // write float64
  2690. return nil
  2691. }
  2692. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2693. // the ClusterManagement type
  2694. func (target *ClusterManagement) UnmarshalBinary(data []byte) error {
  2695. var table []string
  2696. buff := util.NewBufferFromBytes(data)
  2697. // string table header validation
  2698. if isBinaryTag(data, BinaryTagStringTable) {
  2699. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2700. tl := buff.ReadInt() // table length
  2701. if tl > 0 {
  2702. table = make([]string, tl, tl)
  2703. for i := 0; i < tl; i++ {
  2704. table[i] = buff.ReadString()
  2705. }
  2706. }
  2707. }
  2708. ctx := &DecodingContext{
  2709. Buffer: buff,
  2710. Table: table,
  2711. }
  2712. err := target.UnmarshalBinaryWithContext(ctx)
  2713. if err != nil {
  2714. return err
  2715. }
  2716. return nil
  2717. }
  2718. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2719. // the ClusterManagement type
  2720. func (target *ClusterManagement) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2721. // panics are recovered and propagated as errors
  2722. defer func() {
  2723. if r := recover(); r != nil {
  2724. if e, ok := r.(error); ok {
  2725. err = e
  2726. } else if s, ok := r.(string); ok {
  2727. err = fmt.Errorf("Unexpected panic: %s", s)
  2728. } else {
  2729. err = fmt.Errorf("Unexpected panic: %+v", r)
  2730. }
  2731. }
  2732. }()
  2733. buff := ctx.Buffer
  2734. // Codec Version Check
  2735. version := buff.ReadUInt8()
  2736. if version != AssetsCodecVersion {
  2737. return fmt.Errorf("Invalid Version Unmarshaling ClusterManagement. Expected %d, got %d", AssetsCodecVersion, version)
  2738. }
  2739. // --- [begin][read][alias](AssetLabels) ---
  2740. var a map[string]string
  2741. if buff.ReadUInt8() == uint8(0) {
  2742. a = nil
  2743. } else {
  2744. // --- [begin][read][map](map[string]string) ---
  2745. c := buff.ReadInt() // map len
  2746. b := make(map[string]string, c)
  2747. for i := 0; i < c; i++ {
  2748. var v string
  2749. var e string
  2750. if ctx.IsStringTable() {
  2751. f := buff.ReadInt() // read string index
  2752. e = ctx.Table[f]
  2753. } else {
  2754. e = buff.ReadString() // read string
  2755. }
  2756. d := e
  2757. v = d
  2758. var z string
  2759. var h string
  2760. if ctx.IsStringTable() {
  2761. k := buff.ReadInt() // read string index
  2762. h = ctx.Table[k]
  2763. } else {
  2764. h = buff.ReadString() // read string
  2765. }
  2766. g := h
  2767. z = g
  2768. b[v] = z
  2769. }
  2770. a = b
  2771. // --- [end][read][map](map[string]string) ---
  2772. }
  2773. target.labels = AssetLabels(a)
  2774. // --- [end][read][alias](AssetLabels) ---
  2775. if buff.ReadUInt8() == uint8(0) {
  2776. target.properties = nil
  2777. } else {
  2778. // --- [begin][read][struct](AssetProperties) ---
  2779. l := &AssetProperties{}
  2780. buff.ReadInt() // [compatibility, unused]
  2781. errA := l.UnmarshalBinaryWithContext(ctx)
  2782. if errA != nil {
  2783. return errA
  2784. }
  2785. target.properties = l
  2786. // --- [end][read][struct](AssetProperties) ---
  2787. }
  2788. // --- [begin][read][struct](Window) ---
  2789. m := &Window{}
  2790. buff.ReadInt() // [compatibility, unused]
  2791. errB := m.UnmarshalBinaryWithContext(ctx)
  2792. if errB != nil {
  2793. return errB
  2794. }
  2795. target.window = *m
  2796. // --- [end][read][struct](Window) ---
  2797. n := buff.ReadFloat64() // read float64
  2798. target.Cost = n
  2799. return nil
  2800. }
  2801. //--------------------------------------------------------------------------
  2802. // Disk
  2803. //--------------------------------------------------------------------------
  2804. // MarshalBinary serializes the internal properties of this Disk instance
  2805. // into a byte array
  2806. func (target *Disk) MarshalBinary() (data []byte, err error) {
  2807. ctx := &EncodingContext{
  2808. Buffer: util.NewBuffer(),
  2809. Table: nil,
  2810. }
  2811. e := target.MarshalBinaryWithContext(ctx)
  2812. if e != nil {
  2813. return nil, e
  2814. }
  2815. encBytes := ctx.Buffer.Bytes()
  2816. return encBytes, nil
  2817. }
  2818. // MarshalBinaryWithContext serializes the internal properties of this Disk instance
  2819. // into a byte array leveraging a predefined context.
  2820. func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2821. // panics are recovered and propagated as errors
  2822. defer func() {
  2823. if r := recover(); r != nil {
  2824. if e, ok := r.(error); ok {
  2825. err = e
  2826. } else if s, ok := r.(string); ok {
  2827. err = fmt.Errorf("Unexpected panic: %s", s)
  2828. } else {
  2829. err = fmt.Errorf("Unexpected panic: %+v", r)
  2830. }
  2831. }
  2832. }()
  2833. buff := ctx.Buffer
  2834. buff.WriteUInt8(AssetsCodecVersion) // version
  2835. // --- [begin][write][alias](AssetLabels) ---
  2836. if map[string]string(target.labels) == nil {
  2837. buff.WriteUInt8(uint8(0)) // write nil byte
  2838. } else {
  2839. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2840. // --- [begin][write][map](map[string]string) ---
  2841. buff.WriteInt(len(map[string]string(target.labels))) // map length
  2842. for v, z := range map[string]string(target.labels) {
  2843. if ctx.IsStringTable() {
  2844. a := ctx.Table.AddOrGet(v)
  2845. buff.WriteInt(a) // write table index
  2846. } else {
  2847. buff.WriteString(v) // write string
  2848. }
  2849. if ctx.IsStringTable() {
  2850. b := ctx.Table.AddOrGet(z)
  2851. buff.WriteInt(b) // write table index
  2852. } else {
  2853. buff.WriteString(z) // write string
  2854. }
  2855. }
  2856. // --- [end][write][map](map[string]string) ---
  2857. }
  2858. // --- [end][write][alias](AssetLabels) ---
  2859. if target.properties == nil {
  2860. buff.WriteUInt8(uint8(0)) // write nil byte
  2861. } else {
  2862. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2863. // --- [begin][write][struct](AssetProperties) ---
  2864. buff.WriteInt(0) // [compatibility, unused]
  2865. errA := target.properties.MarshalBinaryWithContext(ctx)
  2866. if errA != nil {
  2867. return errA
  2868. }
  2869. // --- [end][write][struct](AssetProperties) ---
  2870. }
  2871. // --- [begin][write][reference](time.Time) ---
  2872. c, errB := target.start.MarshalBinary()
  2873. if errB != nil {
  2874. return errB
  2875. }
  2876. buff.WriteInt(len(c))
  2877. buff.WriteBytes(c)
  2878. // --- [end][write][reference](time.Time) ---
  2879. // --- [begin][write][reference](time.Time) ---
  2880. d, errC := target.end.MarshalBinary()
  2881. if errC != nil {
  2882. return errC
  2883. }
  2884. buff.WriteInt(len(d))
  2885. buff.WriteBytes(d)
  2886. // --- [end][write][reference](time.Time) ---
  2887. // --- [begin][write][struct](Window) ---
  2888. buff.WriteInt(0) // [compatibility, unused]
  2889. errD := target.window.MarshalBinaryWithContext(ctx)
  2890. if errD != nil {
  2891. return errD
  2892. }
  2893. // --- [end][write][struct](Window) ---
  2894. buff.WriteFloat64(target.adjustment) // write float64
  2895. buff.WriteFloat64(target.Cost) // write float64
  2896. buff.WriteFloat64(target.ByteHours) // write float64
  2897. buff.WriteFloat64(target.Local) // write float64
  2898. if target.Breakdown == nil {
  2899. buff.WriteUInt8(uint8(0)) // write nil byte
  2900. } else {
  2901. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2902. // --- [begin][write][struct](Breakdown) ---
  2903. buff.WriteInt(0) // [compatibility, unused]
  2904. errE := target.Breakdown.MarshalBinaryWithContext(ctx)
  2905. if errE != nil {
  2906. return errE
  2907. }
  2908. // --- [end][write][struct](Breakdown) ---
  2909. }
  2910. return nil
  2911. }
  2912. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2913. // the Disk type
  2914. func (target *Disk) UnmarshalBinary(data []byte) error {
  2915. var table []string
  2916. buff := util.NewBufferFromBytes(data)
  2917. // string table header validation
  2918. if isBinaryTag(data, BinaryTagStringTable) {
  2919. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2920. tl := buff.ReadInt() // table length
  2921. if tl > 0 {
  2922. table = make([]string, tl, tl)
  2923. for i := 0; i < tl; i++ {
  2924. table[i] = buff.ReadString()
  2925. }
  2926. }
  2927. }
  2928. ctx := &DecodingContext{
  2929. Buffer: buff,
  2930. Table: table,
  2931. }
  2932. err := target.UnmarshalBinaryWithContext(ctx)
  2933. if err != nil {
  2934. return err
  2935. }
  2936. return nil
  2937. }
  2938. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2939. // the Disk type
  2940. func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2941. // panics are recovered and propagated as errors
  2942. defer func() {
  2943. if r := recover(); r != nil {
  2944. if e, ok := r.(error); ok {
  2945. err = e
  2946. } else if s, ok := r.(string); ok {
  2947. err = fmt.Errorf("Unexpected panic: %s", s)
  2948. } else {
  2949. err = fmt.Errorf("Unexpected panic: %+v", r)
  2950. }
  2951. }
  2952. }()
  2953. buff := ctx.Buffer
  2954. // Codec Version Check
  2955. version := buff.ReadUInt8()
  2956. if version != AssetsCodecVersion {
  2957. return fmt.Errorf("Invalid Version Unmarshaling Disk. Expected %d, got %d", AssetsCodecVersion, version)
  2958. }
  2959. // --- [begin][read][alias](AssetLabels) ---
  2960. var a map[string]string
  2961. if buff.ReadUInt8() == uint8(0) {
  2962. a = nil
  2963. } else {
  2964. // --- [begin][read][map](map[string]string) ---
  2965. c := buff.ReadInt() // map len
  2966. b := make(map[string]string, c)
  2967. for i := 0; i < c; i++ {
  2968. var v string
  2969. var e string
  2970. if ctx.IsStringTable() {
  2971. f := buff.ReadInt() // read string index
  2972. e = ctx.Table[f]
  2973. } else {
  2974. e = buff.ReadString() // read string
  2975. }
  2976. d := e
  2977. v = d
  2978. var z string
  2979. var h string
  2980. if ctx.IsStringTable() {
  2981. k := buff.ReadInt() // read string index
  2982. h = ctx.Table[k]
  2983. } else {
  2984. h = buff.ReadString() // read string
  2985. }
  2986. g := h
  2987. z = g
  2988. b[v] = z
  2989. }
  2990. a = b
  2991. // --- [end][read][map](map[string]string) ---
  2992. }
  2993. target.labels = AssetLabels(a)
  2994. // --- [end][read][alias](AssetLabels) ---
  2995. if buff.ReadUInt8() == uint8(0) {
  2996. target.properties = nil
  2997. } else {
  2998. // --- [begin][read][struct](AssetProperties) ---
  2999. l := &AssetProperties{}
  3000. buff.ReadInt() // [compatibility, unused]
  3001. errA := l.UnmarshalBinaryWithContext(ctx)
  3002. if errA != nil {
  3003. return errA
  3004. }
  3005. target.properties = l
  3006. // --- [end][read][struct](AssetProperties) ---
  3007. }
  3008. // --- [begin][read][reference](time.Time) ---
  3009. m := &time.Time{}
  3010. n := buff.ReadInt() // byte array length
  3011. o := buff.ReadBytes(n) // byte array
  3012. errB := m.UnmarshalBinary(o)
  3013. if errB != nil {
  3014. return errB
  3015. }
  3016. target.start = *m
  3017. // --- [end][read][reference](time.Time) ---
  3018. // --- [begin][read][reference](time.Time) ---
  3019. p := &time.Time{}
  3020. q := buff.ReadInt() // byte array length
  3021. r := buff.ReadBytes(q) // byte array
  3022. errC := p.UnmarshalBinary(r)
  3023. if errC != nil {
  3024. return errC
  3025. }
  3026. target.end = *p
  3027. // --- [end][read][reference](time.Time) ---
  3028. // --- [begin][read][struct](Window) ---
  3029. s := &Window{}
  3030. buff.ReadInt() // [compatibility, unused]
  3031. errD := s.UnmarshalBinaryWithContext(ctx)
  3032. if errD != nil {
  3033. return errD
  3034. }
  3035. target.window = *s
  3036. // --- [end][read][struct](Window) ---
  3037. t := buff.ReadFloat64() // read float64
  3038. target.adjustment = t
  3039. u := buff.ReadFloat64() // read float64
  3040. target.Cost = u
  3041. w := buff.ReadFloat64() // read float64
  3042. target.ByteHours = w
  3043. x := buff.ReadFloat64() // read float64
  3044. target.Local = x
  3045. if buff.ReadUInt8() == uint8(0) {
  3046. target.Breakdown = nil
  3047. } else {
  3048. // --- [begin][read][struct](Breakdown) ---
  3049. y := &Breakdown{}
  3050. buff.ReadInt() // [compatibility, unused]
  3051. errE := y.UnmarshalBinaryWithContext(ctx)
  3052. if errE != nil {
  3053. return errE
  3054. }
  3055. target.Breakdown = y
  3056. // --- [end][read][struct](Breakdown) ---
  3057. }
  3058. return nil
  3059. }
  3060. //--------------------------------------------------------------------------
  3061. // LoadBalancer
  3062. //--------------------------------------------------------------------------
  3063. // MarshalBinary serializes the internal properties of this LoadBalancer instance
  3064. // into a byte array
  3065. func (target *LoadBalancer) MarshalBinary() (data []byte, err error) {
  3066. ctx := &EncodingContext{
  3067. Buffer: util.NewBuffer(),
  3068. Table: nil,
  3069. }
  3070. e := target.MarshalBinaryWithContext(ctx)
  3071. if e != nil {
  3072. return nil, e
  3073. }
  3074. encBytes := ctx.Buffer.Bytes()
  3075. return encBytes, nil
  3076. }
  3077. // MarshalBinaryWithContext serializes the internal properties of this LoadBalancer instance
  3078. // into a byte array leveraging a predefined context.
  3079. func (target *LoadBalancer) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3080. // panics are recovered and propagated as errors
  3081. defer func() {
  3082. if r := recover(); r != nil {
  3083. if e, ok := r.(error); ok {
  3084. err = e
  3085. } else if s, ok := r.(string); ok {
  3086. err = fmt.Errorf("Unexpected panic: %s", s)
  3087. } else {
  3088. err = fmt.Errorf("Unexpected panic: %+v", r)
  3089. }
  3090. }
  3091. }()
  3092. buff := ctx.Buffer
  3093. buff.WriteUInt8(AssetsCodecVersion) // version
  3094. if target.properties == nil {
  3095. buff.WriteUInt8(uint8(0)) // write nil byte
  3096. } else {
  3097. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3098. // --- [begin][write][struct](AssetProperties) ---
  3099. buff.WriteInt(0) // [compatibility, unused]
  3100. errA := target.properties.MarshalBinaryWithContext(ctx)
  3101. if errA != nil {
  3102. return errA
  3103. }
  3104. // --- [end][write][struct](AssetProperties) ---
  3105. }
  3106. // --- [begin][write][alias](AssetLabels) ---
  3107. if map[string]string(target.labels) == nil {
  3108. buff.WriteUInt8(uint8(0)) // write nil byte
  3109. } else {
  3110. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3111. // --- [begin][write][map](map[string]string) ---
  3112. buff.WriteInt(len(map[string]string(target.labels))) // map length
  3113. for v, z := range map[string]string(target.labels) {
  3114. if ctx.IsStringTable() {
  3115. a := ctx.Table.AddOrGet(v)
  3116. buff.WriteInt(a) // write table index
  3117. } else {
  3118. buff.WriteString(v) // write string
  3119. }
  3120. if ctx.IsStringTable() {
  3121. b := ctx.Table.AddOrGet(z)
  3122. buff.WriteInt(b) // write table index
  3123. } else {
  3124. buff.WriteString(z) // write string
  3125. }
  3126. }
  3127. // --- [end][write][map](map[string]string) ---
  3128. }
  3129. // --- [end][write][alias](AssetLabels) ---
  3130. // --- [begin][write][reference](time.Time) ---
  3131. c, errB := target.start.MarshalBinary()
  3132. if errB != nil {
  3133. return errB
  3134. }
  3135. buff.WriteInt(len(c))
  3136. buff.WriteBytes(c)
  3137. // --- [end][write][reference](time.Time) ---
  3138. // --- [begin][write][reference](time.Time) ---
  3139. d, errC := target.end.MarshalBinary()
  3140. if errC != nil {
  3141. return errC
  3142. }
  3143. buff.WriteInt(len(d))
  3144. buff.WriteBytes(d)
  3145. // --- [end][write][reference](time.Time) ---
  3146. // --- [begin][write][struct](Window) ---
  3147. buff.WriteInt(0) // [compatibility, unused]
  3148. errD := target.window.MarshalBinaryWithContext(ctx)
  3149. if errD != nil {
  3150. return errD
  3151. }
  3152. // --- [end][write][struct](Window) ---
  3153. buff.WriteFloat64(target.adjustment) // write float64
  3154. buff.WriteFloat64(target.Cost) // write float64
  3155. return nil
  3156. }
  3157. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3158. // the LoadBalancer type
  3159. func (target *LoadBalancer) UnmarshalBinary(data []byte) error {
  3160. var table []string
  3161. buff := util.NewBufferFromBytes(data)
  3162. // string table header validation
  3163. if isBinaryTag(data, BinaryTagStringTable) {
  3164. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3165. tl := buff.ReadInt() // table length
  3166. if tl > 0 {
  3167. table = make([]string, tl, tl)
  3168. for i := 0; i < tl; i++ {
  3169. table[i] = buff.ReadString()
  3170. }
  3171. }
  3172. }
  3173. ctx := &DecodingContext{
  3174. Buffer: buff,
  3175. Table: table,
  3176. }
  3177. err := target.UnmarshalBinaryWithContext(ctx)
  3178. if err != nil {
  3179. return err
  3180. }
  3181. return nil
  3182. }
  3183. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3184. // the LoadBalancer type
  3185. func (target *LoadBalancer) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3186. // panics are recovered and propagated as errors
  3187. defer func() {
  3188. if r := recover(); r != nil {
  3189. if e, ok := r.(error); ok {
  3190. err = e
  3191. } else if s, ok := r.(string); ok {
  3192. err = fmt.Errorf("Unexpected panic: %s", s)
  3193. } else {
  3194. err = fmt.Errorf("Unexpected panic: %+v", r)
  3195. }
  3196. }
  3197. }()
  3198. buff := ctx.Buffer
  3199. // Codec Version Check
  3200. version := buff.ReadUInt8()
  3201. if version != AssetsCodecVersion {
  3202. return fmt.Errorf("Invalid Version Unmarshaling LoadBalancer. Expected %d, got %d", AssetsCodecVersion, version)
  3203. }
  3204. if buff.ReadUInt8() == uint8(0) {
  3205. target.properties = nil
  3206. } else {
  3207. // --- [begin][read][struct](AssetProperties) ---
  3208. a := &AssetProperties{}
  3209. buff.ReadInt() // [compatibility, unused]
  3210. errA := a.UnmarshalBinaryWithContext(ctx)
  3211. if errA != nil {
  3212. return errA
  3213. }
  3214. target.properties = a
  3215. // --- [end][read][struct](AssetProperties) ---
  3216. }
  3217. // --- [begin][read][alias](AssetLabels) ---
  3218. var b map[string]string
  3219. if buff.ReadUInt8() == uint8(0) {
  3220. b = nil
  3221. } else {
  3222. // --- [begin][read][map](map[string]string) ---
  3223. d := buff.ReadInt() // map len
  3224. c := make(map[string]string, d)
  3225. for i := 0; i < d; i++ {
  3226. var v string
  3227. var f string
  3228. if ctx.IsStringTable() {
  3229. g := buff.ReadInt() // read string index
  3230. f = ctx.Table[g]
  3231. } else {
  3232. f = buff.ReadString() // read string
  3233. }
  3234. e := f
  3235. v = e
  3236. var z string
  3237. var k string
  3238. if ctx.IsStringTable() {
  3239. l := buff.ReadInt() // read string index
  3240. k = ctx.Table[l]
  3241. } else {
  3242. k = buff.ReadString() // read string
  3243. }
  3244. h := k
  3245. z = h
  3246. c[v] = z
  3247. }
  3248. b = c
  3249. // --- [end][read][map](map[string]string) ---
  3250. }
  3251. target.labels = AssetLabels(b)
  3252. // --- [end][read][alias](AssetLabels) ---
  3253. // --- [begin][read][reference](time.Time) ---
  3254. m := &time.Time{}
  3255. n := buff.ReadInt() // byte array length
  3256. o := buff.ReadBytes(n) // byte array
  3257. errB := m.UnmarshalBinary(o)
  3258. if errB != nil {
  3259. return errB
  3260. }
  3261. target.start = *m
  3262. // --- [end][read][reference](time.Time) ---
  3263. // --- [begin][read][reference](time.Time) ---
  3264. p := &time.Time{}
  3265. q := buff.ReadInt() // byte array length
  3266. r := buff.ReadBytes(q) // byte array
  3267. errC := p.UnmarshalBinary(r)
  3268. if errC != nil {
  3269. return errC
  3270. }
  3271. target.end = *p
  3272. // --- [end][read][reference](time.Time) ---
  3273. // --- [begin][read][struct](Window) ---
  3274. s := &Window{}
  3275. buff.ReadInt() // [compatibility, unused]
  3276. errD := s.UnmarshalBinaryWithContext(ctx)
  3277. if errD != nil {
  3278. return errD
  3279. }
  3280. target.window = *s
  3281. // --- [end][read][struct](Window) ---
  3282. t := buff.ReadFloat64() // read float64
  3283. target.adjustment = t
  3284. u := buff.ReadFloat64() // read float64
  3285. target.Cost = u
  3286. return nil
  3287. }
  3288. //--------------------------------------------------------------------------
  3289. // Network
  3290. //--------------------------------------------------------------------------
  3291. // MarshalBinary serializes the internal properties of this Network instance
  3292. // into a byte array
  3293. func (target *Network) MarshalBinary() (data []byte, err error) {
  3294. ctx := &EncodingContext{
  3295. Buffer: util.NewBuffer(),
  3296. Table: nil,
  3297. }
  3298. e := target.MarshalBinaryWithContext(ctx)
  3299. if e != nil {
  3300. return nil, e
  3301. }
  3302. encBytes := ctx.Buffer.Bytes()
  3303. return encBytes, nil
  3304. }
  3305. // MarshalBinaryWithContext serializes the internal properties of this Network instance
  3306. // into a byte array leveraging a predefined context.
  3307. func (target *Network) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3308. // panics are recovered and propagated as errors
  3309. defer func() {
  3310. if r := recover(); r != nil {
  3311. if e, ok := r.(error); ok {
  3312. err = e
  3313. } else if s, ok := r.(string); ok {
  3314. err = fmt.Errorf("Unexpected panic: %s", s)
  3315. } else {
  3316. err = fmt.Errorf("Unexpected panic: %+v", r)
  3317. }
  3318. }
  3319. }()
  3320. buff := ctx.Buffer
  3321. buff.WriteUInt8(AssetsCodecVersion) // version
  3322. if target.properties == nil {
  3323. buff.WriteUInt8(uint8(0)) // write nil byte
  3324. } else {
  3325. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3326. // --- [begin][write][struct](AssetProperties) ---
  3327. buff.WriteInt(0) // [compatibility, unused]
  3328. errA := target.properties.MarshalBinaryWithContext(ctx)
  3329. if errA != nil {
  3330. return errA
  3331. }
  3332. // --- [end][write][struct](AssetProperties) ---
  3333. }
  3334. // --- [begin][write][alias](AssetLabels) ---
  3335. if map[string]string(target.labels) == nil {
  3336. buff.WriteUInt8(uint8(0)) // write nil byte
  3337. } else {
  3338. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3339. // --- [begin][write][map](map[string]string) ---
  3340. buff.WriteInt(len(map[string]string(target.labels))) // map length
  3341. for v, z := range map[string]string(target.labels) {
  3342. if ctx.IsStringTable() {
  3343. a := ctx.Table.AddOrGet(v)
  3344. buff.WriteInt(a) // write table index
  3345. } else {
  3346. buff.WriteString(v) // write string
  3347. }
  3348. if ctx.IsStringTable() {
  3349. b := ctx.Table.AddOrGet(z)
  3350. buff.WriteInt(b) // write table index
  3351. } else {
  3352. buff.WriteString(z) // write string
  3353. }
  3354. }
  3355. // --- [end][write][map](map[string]string) ---
  3356. }
  3357. // --- [end][write][alias](AssetLabels) ---
  3358. // --- [begin][write][reference](time.Time) ---
  3359. c, errB := target.start.MarshalBinary()
  3360. if errB != nil {
  3361. return errB
  3362. }
  3363. buff.WriteInt(len(c))
  3364. buff.WriteBytes(c)
  3365. // --- [end][write][reference](time.Time) ---
  3366. // --- [begin][write][reference](time.Time) ---
  3367. d, errC := target.end.MarshalBinary()
  3368. if errC != nil {
  3369. return errC
  3370. }
  3371. buff.WriteInt(len(d))
  3372. buff.WriteBytes(d)
  3373. // --- [end][write][reference](time.Time) ---
  3374. // --- [begin][write][struct](Window) ---
  3375. buff.WriteInt(0) // [compatibility, unused]
  3376. errD := target.window.MarshalBinaryWithContext(ctx)
  3377. if errD != nil {
  3378. return errD
  3379. }
  3380. // --- [end][write][struct](Window) ---
  3381. buff.WriteFloat64(target.adjustment) // write float64
  3382. buff.WriteFloat64(target.Cost) // write float64
  3383. return nil
  3384. }
  3385. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3386. // the Network type
  3387. func (target *Network) UnmarshalBinary(data []byte) error {
  3388. var table []string
  3389. buff := util.NewBufferFromBytes(data)
  3390. // string table header validation
  3391. if isBinaryTag(data, BinaryTagStringTable) {
  3392. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3393. tl := buff.ReadInt() // table length
  3394. if tl > 0 {
  3395. table = make([]string, tl, tl)
  3396. for i := 0; i < tl; i++ {
  3397. table[i] = buff.ReadString()
  3398. }
  3399. }
  3400. }
  3401. ctx := &DecodingContext{
  3402. Buffer: buff,
  3403. Table: table,
  3404. }
  3405. err := target.UnmarshalBinaryWithContext(ctx)
  3406. if err != nil {
  3407. return err
  3408. }
  3409. return nil
  3410. }
  3411. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3412. // the Network type
  3413. func (target *Network) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3414. // panics are recovered and propagated as errors
  3415. defer func() {
  3416. if r := recover(); r != nil {
  3417. if e, ok := r.(error); ok {
  3418. err = e
  3419. } else if s, ok := r.(string); ok {
  3420. err = fmt.Errorf("Unexpected panic: %s", s)
  3421. } else {
  3422. err = fmt.Errorf("Unexpected panic: %+v", r)
  3423. }
  3424. }
  3425. }()
  3426. buff := ctx.Buffer
  3427. // Codec Version Check
  3428. version := buff.ReadUInt8()
  3429. if version != AssetsCodecVersion {
  3430. return fmt.Errorf("Invalid Version Unmarshaling Network. Expected %d, got %d", AssetsCodecVersion, version)
  3431. }
  3432. if buff.ReadUInt8() == uint8(0) {
  3433. target.properties = nil
  3434. } else {
  3435. // --- [begin][read][struct](AssetProperties) ---
  3436. a := &AssetProperties{}
  3437. buff.ReadInt() // [compatibility, unused]
  3438. errA := a.UnmarshalBinaryWithContext(ctx)
  3439. if errA != nil {
  3440. return errA
  3441. }
  3442. target.properties = a
  3443. // --- [end][read][struct](AssetProperties) ---
  3444. }
  3445. // --- [begin][read][alias](AssetLabels) ---
  3446. var b map[string]string
  3447. if buff.ReadUInt8() == uint8(0) {
  3448. b = nil
  3449. } else {
  3450. // --- [begin][read][map](map[string]string) ---
  3451. d := buff.ReadInt() // map len
  3452. c := make(map[string]string, d)
  3453. for i := 0; i < d; i++ {
  3454. var v string
  3455. var f string
  3456. if ctx.IsStringTable() {
  3457. g := buff.ReadInt() // read string index
  3458. f = ctx.Table[g]
  3459. } else {
  3460. f = buff.ReadString() // read string
  3461. }
  3462. e := f
  3463. v = e
  3464. var z string
  3465. var k string
  3466. if ctx.IsStringTable() {
  3467. l := buff.ReadInt() // read string index
  3468. k = ctx.Table[l]
  3469. } else {
  3470. k = buff.ReadString() // read string
  3471. }
  3472. h := k
  3473. z = h
  3474. c[v] = z
  3475. }
  3476. b = c
  3477. // --- [end][read][map](map[string]string) ---
  3478. }
  3479. target.labels = AssetLabels(b)
  3480. // --- [end][read][alias](AssetLabels) ---
  3481. // --- [begin][read][reference](time.Time) ---
  3482. m := &time.Time{}
  3483. n := buff.ReadInt() // byte array length
  3484. o := buff.ReadBytes(n) // byte array
  3485. errB := m.UnmarshalBinary(o)
  3486. if errB != nil {
  3487. return errB
  3488. }
  3489. target.start = *m
  3490. // --- [end][read][reference](time.Time) ---
  3491. // --- [begin][read][reference](time.Time) ---
  3492. p := &time.Time{}
  3493. q := buff.ReadInt() // byte array length
  3494. r := buff.ReadBytes(q) // byte array
  3495. errC := p.UnmarshalBinary(r)
  3496. if errC != nil {
  3497. return errC
  3498. }
  3499. target.end = *p
  3500. // --- [end][read][reference](time.Time) ---
  3501. // --- [begin][read][struct](Window) ---
  3502. s := &Window{}
  3503. buff.ReadInt() // [compatibility, unused]
  3504. errD := s.UnmarshalBinaryWithContext(ctx)
  3505. if errD != nil {
  3506. return errD
  3507. }
  3508. target.window = *s
  3509. // --- [end][read][struct](Window) ---
  3510. t := buff.ReadFloat64() // read float64
  3511. target.adjustment = t
  3512. u := buff.ReadFloat64() // read float64
  3513. target.Cost = u
  3514. return nil
  3515. }
  3516. //--------------------------------------------------------------------------
  3517. // Node
  3518. //--------------------------------------------------------------------------
  3519. // MarshalBinary serializes the internal properties of this Node instance
  3520. // into a byte array
  3521. func (target *Node) MarshalBinary() (data []byte, err error) {
  3522. ctx := &EncodingContext{
  3523. Buffer: util.NewBuffer(),
  3524. Table: nil,
  3525. }
  3526. e := target.MarshalBinaryWithContext(ctx)
  3527. if e != nil {
  3528. return nil, e
  3529. }
  3530. encBytes := ctx.Buffer.Bytes()
  3531. return encBytes, nil
  3532. }
  3533. // MarshalBinaryWithContext serializes the internal properties of this Node instance
  3534. // into a byte array leveraging a predefined context.
  3535. func (target *Node) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3536. // panics are recovered and propagated as errors
  3537. defer func() {
  3538. if r := recover(); r != nil {
  3539. if e, ok := r.(error); ok {
  3540. err = e
  3541. } else if s, ok := r.(string); ok {
  3542. err = fmt.Errorf("Unexpected panic: %s", s)
  3543. } else {
  3544. err = fmt.Errorf("Unexpected panic: %+v", r)
  3545. }
  3546. }
  3547. }()
  3548. buff := ctx.Buffer
  3549. buff.WriteUInt8(AssetsCodecVersion) // version
  3550. if target.properties == nil {
  3551. buff.WriteUInt8(uint8(0)) // write nil byte
  3552. } else {
  3553. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3554. // --- [begin][write][struct](AssetProperties) ---
  3555. buff.WriteInt(0) // [compatibility, unused]
  3556. errA := target.properties.MarshalBinaryWithContext(ctx)
  3557. if errA != nil {
  3558. return errA
  3559. }
  3560. // --- [end][write][struct](AssetProperties) ---
  3561. }
  3562. // --- [begin][write][alias](AssetLabels) ---
  3563. if map[string]string(target.labels) == nil {
  3564. buff.WriteUInt8(uint8(0)) // write nil byte
  3565. } else {
  3566. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3567. // --- [begin][write][map](map[string]string) ---
  3568. buff.WriteInt(len(map[string]string(target.labels))) // map length
  3569. for v, z := range map[string]string(target.labels) {
  3570. if ctx.IsStringTable() {
  3571. a := ctx.Table.AddOrGet(v)
  3572. buff.WriteInt(a) // write table index
  3573. } else {
  3574. buff.WriteString(v) // write string
  3575. }
  3576. if ctx.IsStringTable() {
  3577. b := ctx.Table.AddOrGet(z)
  3578. buff.WriteInt(b) // write table index
  3579. } else {
  3580. buff.WriteString(z) // write string
  3581. }
  3582. }
  3583. // --- [end][write][map](map[string]string) ---
  3584. }
  3585. // --- [end][write][alias](AssetLabels) ---
  3586. // --- [begin][write][reference](time.Time) ---
  3587. c, errB := target.start.MarshalBinary()
  3588. if errB != nil {
  3589. return errB
  3590. }
  3591. buff.WriteInt(len(c))
  3592. buff.WriteBytes(c)
  3593. // --- [end][write][reference](time.Time) ---
  3594. // --- [begin][write][reference](time.Time) ---
  3595. d, errC := target.end.MarshalBinary()
  3596. if errC != nil {
  3597. return errC
  3598. }
  3599. buff.WriteInt(len(d))
  3600. buff.WriteBytes(d)
  3601. // --- [end][write][reference](time.Time) ---
  3602. // --- [begin][write][struct](Window) ---
  3603. buff.WriteInt(0) // [compatibility, unused]
  3604. errD := target.window.MarshalBinaryWithContext(ctx)
  3605. if errD != nil {
  3606. return errD
  3607. }
  3608. // --- [end][write][struct](Window) ---
  3609. buff.WriteFloat64(target.adjustment) // write float64
  3610. if ctx.IsStringTable() {
  3611. e := ctx.Table.AddOrGet(target.NodeType)
  3612. buff.WriteInt(e) // write table index
  3613. } else {
  3614. buff.WriteString(target.NodeType) // write string
  3615. }
  3616. buff.WriteFloat64(target.CPUCoreHours) // write float64
  3617. buff.WriteFloat64(target.RAMByteHours) // write float64
  3618. buff.WriteFloat64(target.GPUHours) // write float64
  3619. if target.CPUBreakdown == nil {
  3620. buff.WriteUInt8(uint8(0)) // write nil byte
  3621. } else {
  3622. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3623. // --- [begin][write][struct](Breakdown) ---
  3624. buff.WriteInt(0) // [compatibility, unused]
  3625. errE := target.CPUBreakdown.MarshalBinaryWithContext(ctx)
  3626. if errE != nil {
  3627. return errE
  3628. }
  3629. // --- [end][write][struct](Breakdown) ---
  3630. }
  3631. if target.RAMBreakdown == nil {
  3632. buff.WriteUInt8(uint8(0)) // write nil byte
  3633. } else {
  3634. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3635. // --- [begin][write][struct](Breakdown) ---
  3636. buff.WriteInt(0) // [compatibility, unused]
  3637. errF := target.RAMBreakdown.MarshalBinaryWithContext(ctx)
  3638. if errF != nil {
  3639. return errF
  3640. }
  3641. // --- [end][write][struct](Breakdown) ---
  3642. }
  3643. buff.WriteFloat64(target.CPUCost) // write float64
  3644. buff.WriteFloat64(target.GPUCost) // write float64
  3645. buff.WriteFloat64(target.GPUCount) // write float64
  3646. buff.WriteFloat64(target.RAMCost) // write float64
  3647. buff.WriteFloat64(target.Discount) // write float64
  3648. buff.WriteFloat64(target.Preemptible) // write float64
  3649. return nil
  3650. }
  3651. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3652. // the Node type
  3653. func (target *Node) UnmarshalBinary(data []byte) error {
  3654. var table []string
  3655. buff := util.NewBufferFromBytes(data)
  3656. // string table header validation
  3657. if isBinaryTag(data, BinaryTagStringTable) {
  3658. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3659. tl := buff.ReadInt() // table length
  3660. if tl > 0 {
  3661. table = make([]string, tl, tl)
  3662. for i := 0; i < tl; i++ {
  3663. table[i] = buff.ReadString()
  3664. }
  3665. }
  3666. }
  3667. ctx := &DecodingContext{
  3668. Buffer: buff,
  3669. Table: table,
  3670. }
  3671. err := target.UnmarshalBinaryWithContext(ctx)
  3672. if err != nil {
  3673. return err
  3674. }
  3675. return nil
  3676. }
  3677. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3678. // the Node type
  3679. func (target *Node) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3680. // panics are recovered and propagated as errors
  3681. defer func() {
  3682. if r := recover(); r != nil {
  3683. if e, ok := r.(error); ok {
  3684. err = e
  3685. } else if s, ok := r.(string); ok {
  3686. err = fmt.Errorf("Unexpected panic: %s", s)
  3687. } else {
  3688. err = fmt.Errorf("Unexpected panic: %+v", r)
  3689. }
  3690. }
  3691. }()
  3692. buff := ctx.Buffer
  3693. // Codec Version Check
  3694. version := buff.ReadUInt8()
  3695. if version != AssetsCodecVersion {
  3696. return fmt.Errorf("Invalid Version Unmarshaling Node. Expected %d, got %d", AssetsCodecVersion, version)
  3697. }
  3698. if buff.ReadUInt8() == uint8(0) {
  3699. target.properties = nil
  3700. } else {
  3701. // --- [begin][read][struct](AssetProperties) ---
  3702. a := &AssetProperties{}
  3703. buff.ReadInt() // [compatibility, unused]
  3704. errA := a.UnmarshalBinaryWithContext(ctx)
  3705. if errA != nil {
  3706. return errA
  3707. }
  3708. target.properties = a
  3709. // --- [end][read][struct](AssetProperties) ---
  3710. }
  3711. // --- [begin][read][alias](AssetLabels) ---
  3712. var b map[string]string
  3713. if buff.ReadUInt8() == uint8(0) {
  3714. b = nil
  3715. } else {
  3716. // --- [begin][read][map](map[string]string) ---
  3717. d := buff.ReadInt() // map len
  3718. c := make(map[string]string, d)
  3719. for i := 0; i < d; i++ {
  3720. var v string
  3721. var f string
  3722. if ctx.IsStringTable() {
  3723. g := buff.ReadInt() // read string index
  3724. f = ctx.Table[g]
  3725. } else {
  3726. f = buff.ReadString() // read string
  3727. }
  3728. e := f
  3729. v = e
  3730. var z string
  3731. var k string
  3732. if ctx.IsStringTable() {
  3733. l := buff.ReadInt() // read string index
  3734. k = ctx.Table[l]
  3735. } else {
  3736. k = buff.ReadString() // read string
  3737. }
  3738. h := k
  3739. z = h
  3740. c[v] = z
  3741. }
  3742. b = c
  3743. // --- [end][read][map](map[string]string) ---
  3744. }
  3745. target.labels = AssetLabels(b)
  3746. // --- [end][read][alias](AssetLabels) ---
  3747. // --- [begin][read][reference](time.Time) ---
  3748. m := &time.Time{}
  3749. n := buff.ReadInt() // byte array length
  3750. o := buff.ReadBytes(n) // byte array
  3751. errB := m.UnmarshalBinary(o)
  3752. if errB != nil {
  3753. return errB
  3754. }
  3755. target.start = *m
  3756. // --- [end][read][reference](time.Time) ---
  3757. // --- [begin][read][reference](time.Time) ---
  3758. p := &time.Time{}
  3759. q := buff.ReadInt() // byte array length
  3760. r := buff.ReadBytes(q) // byte array
  3761. errC := p.UnmarshalBinary(r)
  3762. if errC != nil {
  3763. return errC
  3764. }
  3765. target.end = *p
  3766. // --- [end][read][reference](time.Time) ---
  3767. // --- [begin][read][struct](Window) ---
  3768. s := &Window{}
  3769. buff.ReadInt() // [compatibility, unused]
  3770. errD := s.UnmarshalBinaryWithContext(ctx)
  3771. if errD != nil {
  3772. return errD
  3773. }
  3774. target.window = *s
  3775. // --- [end][read][struct](Window) ---
  3776. t := buff.ReadFloat64() // read float64
  3777. target.adjustment = t
  3778. var w string
  3779. if ctx.IsStringTable() {
  3780. x := buff.ReadInt() // read string index
  3781. w = ctx.Table[x]
  3782. } else {
  3783. w = buff.ReadString() // read string
  3784. }
  3785. u := w
  3786. target.NodeType = u
  3787. y := buff.ReadFloat64() // read float64
  3788. target.CPUCoreHours = y
  3789. aa := buff.ReadFloat64() // read float64
  3790. target.RAMByteHours = aa
  3791. bb := buff.ReadFloat64() // read float64
  3792. target.GPUHours = bb
  3793. if buff.ReadUInt8() == uint8(0) {
  3794. target.CPUBreakdown = nil
  3795. } else {
  3796. // --- [begin][read][struct](Breakdown) ---
  3797. cc := &Breakdown{}
  3798. buff.ReadInt() // [compatibility, unused]
  3799. errE := cc.UnmarshalBinaryWithContext(ctx)
  3800. if errE != nil {
  3801. return errE
  3802. }
  3803. target.CPUBreakdown = cc
  3804. // --- [end][read][struct](Breakdown) ---
  3805. }
  3806. if buff.ReadUInt8() == uint8(0) {
  3807. target.RAMBreakdown = nil
  3808. } else {
  3809. // --- [begin][read][struct](Breakdown) ---
  3810. dd := &Breakdown{}
  3811. buff.ReadInt() // [compatibility, unused]
  3812. errF := dd.UnmarshalBinaryWithContext(ctx)
  3813. if errF != nil {
  3814. return errF
  3815. }
  3816. target.RAMBreakdown = dd
  3817. // --- [end][read][struct](Breakdown) ---
  3818. }
  3819. ee := buff.ReadFloat64() // read float64
  3820. target.CPUCost = ee
  3821. ff := buff.ReadFloat64() // read float64
  3822. target.GPUCost = ff
  3823. gg := buff.ReadFloat64() // read float64
  3824. target.GPUCount = gg
  3825. hh := buff.ReadFloat64() // read float64
  3826. target.RAMCost = hh
  3827. kk := buff.ReadFloat64() // read float64
  3828. target.Discount = kk
  3829. ll := buff.ReadFloat64() // read float64
  3830. target.Preemptible = ll
  3831. return nil
  3832. }
  3833. //--------------------------------------------------------------------------
  3834. // PVAllocation
  3835. //--------------------------------------------------------------------------
  3836. // MarshalBinary serializes the internal properties of this PVAllocation instance
  3837. // into a byte array
  3838. func (target *PVAllocation) MarshalBinary() (data []byte, err error) {
  3839. ctx := &EncodingContext{
  3840. Buffer: util.NewBuffer(),
  3841. Table: nil,
  3842. }
  3843. e := target.MarshalBinaryWithContext(ctx)
  3844. if e != nil {
  3845. return nil, e
  3846. }
  3847. encBytes := ctx.Buffer.Bytes()
  3848. return encBytes, nil
  3849. }
  3850. // MarshalBinaryWithContext serializes the internal properties of this PVAllocation instance
  3851. // into a byte array leveraging a predefined context.
  3852. func (target *PVAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3853. // panics are recovered and propagated as errors
  3854. defer func() {
  3855. if r := recover(); r != nil {
  3856. if e, ok := r.(error); ok {
  3857. err = e
  3858. } else if s, ok := r.(string); ok {
  3859. err = fmt.Errorf("Unexpected panic: %s", s)
  3860. } else {
  3861. err = fmt.Errorf("Unexpected panic: %+v", r)
  3862. }
  3863. }
  3864. }()
  3865. buff := ctx.Buffer
  3866. buff.WriteUInt8(AllocationCodecVersion) // version
  3867. buff.WriteFloat64(target.ByteHours) // write float64
  3868. buff.WriteFloat64(target.Cost) // write float64
  3869. return nil
  3870. }
  3871. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3872. // the PVAllocation type
  3873. func (target *PVAllocation) UnmarshalBinary(data []byte) error {
  3874. var table []string
  3875. buff := util.NewBufferFromBytes(data)
  3876. // string table header validation
  3877. if isBinaryTag(data, BinaryTagStringTable) {
  3878. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3879. tl := buff.ReadInt() // table length
  3880. if tl > 0 {
  3881. table = make([]string, tl, tl)
  3882. for i := 0; i < tl; i++ {
  3883. table[i] = buff.ReadString()
  3884. }
  3885. }
  3886. }
  3887. ctx := &DecodingContext{
  3888. Buffer: buff,
  3889. Table: table,
  3890. }
  3891. err := target.UnmarshalBinaryWithContext(ctx)
  3892. if err != nil {
  3893. return err
  3894. }
  3895. return nil
  3896. }
  3897. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3898. // the PVAllocation type
  3899. func (target *PVAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3900. // panics are recovered and propagated as errors
  3901. defer func() {
  3902. if r := recover(); r != nil {
  3903. if e, ok := r.(error); ok {
  3904. err = e
  3905. } else if s, ok := r.(string); ok {
  3906. err = fmt.Errorf("Unexpected panic: %s", s)
  3907. } else {
  3908. err = fmt.Errorf("Unexpected panic: %+v", r)
  3909. }
  3910. }
  3911. }()
  3912. buff := ctx.Buffer
  3913. // Codec Version Check
  3914. version := buff.ReadUInt8()
  3915. if version != AllocationCodecVersion {
  3916. return fmt.Errorf("Invalid Version Unmarshaling PVAllocation. Expected %d, got %d", AllocationCodecVersion, version)
  3917. }
  3918. a := buff.ReadFloat64() // read float64
  3919. target.ByteHours = a
  3920. b := buff.ReadFloat64() // read float64
  3921. target.Cost = b
  3922. return nil
  3923. }
  3924. //--------------------------------------------------------------------------
  3925. // PVKey
  3926. //--------------------------------------------------------------------------
  3927. // MarshalBinary serializes the internal properties of this PVKey instance
  3928. // into a byte array
  3929. func (target *PVKey) MarshalBinary() (data []byte, err error) {
  3930. ctx := &EncodingContext{
  3931. Buffer: util.NewBuffer(),
  3932. Table: nil,
  3933. }
  3934. e := target.MarshalBinaryWithContext(ctx)
  3935. if e != nil {
  3936. return nil, e
  3937. }
  3938. encBytes := ctx.Buffer.Bytes()
  3939. return encBytes, nil
  3940. }
  3941. // MarshalBinaryWithContext serializes the internal properties of this PVKey instance
  3942. // into a byte array leveraging a predefined context.
  3943. func (target *PVKey) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3944. // panics are recovered and propagated as errors
  3945. defer func() {
  3946. if r := recover(); r != nil {
  3947. if e, ok := r.(error); ok {
  3948. err = e
  3949. } else if s, ok := r.(string); ok {
  3950. err = fmt.Errorf("Unexpected panic: %s", s)
  3951. } else {
  3952. err = fmt.Errorf("Unexpected panic: %+v", r)
  3953. }
  3954. }
  3955. }()
  3956. buff := ctx.Buffer
  3957. buff.WriteUInt8(AllocationCodecVersion) // version
  3958. if ctx.IsStringTable() {
  3959. a := ctx.Table.AddOrGet(target.Cluster)
  3960. buff.WriteInt(a) // write table index
  3961. } else {
  3962. buff.WriteString(target.Cluster) // write string
  3963. }
  3964. if ctx.IsStringTable() {
  3965. b := ctx.Table.AddOrGet(target.Name)
  3966. buff.WriteInt(b) // write table index
  3967. } else {
  3968. buff.WriteString(target.Name) // write string
  3969. }
  3970. return nil
  3971. }
  3972. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3973. // the PVKey type
  3974. func (target *PVKey) UnmarshalBinary(data []byte) error {
  3975. var table []string
  3976. buff := util.NewBufferFromBytes(data)
  3977. // string table header validation
  3978. if isBinaryTag(data, BinaryTagStringTable) {
  3979. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3980. tl := buff.ReadInt() // table length
  3981. if tl > 0 {
  3982. table = make([]string, tl, tl)
  3983. for i := 0; i < tl; i++ {
  3984. table[i] = buff.ReadString()
  3985. }
  3986. }
  3987. }
  3988. ctx := &DecodingContext{
  3989. Buffer: buff,
  3990. Table: table,
  3991. }
  3992. err := target.UnmarshalBinaryWithContext(ctx)
  3993. if err != nil {
  3994. return err
  3995. }
  3996. return nil
  3997. }
  3998. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3999. // the PVKey type
  4000. func (target *PVKey) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4001. // panics are recovered and propagated as errors
  4002. defer func() {
  4003. if r := recover(); r != nil {
  4004. if e, ok := r.(error); ok {
  4005. err = e
  4006. } else if s, ok := r.(string); ok {
  4007. err = fmt.Errorf("Unexpected panic: %s", s)
  4008. } else {
  4009. err = fmt.Errorf("Unexpected panic: %+v", r)
  4010. }
  4011. }
  4012. }()
  4013. buff := ctx.Buffer
  4014. // Codec Version Check
  4015. version := buff.ReadUInt8()
  4016. if version != AllocationCodecVersion {
  4017. return fmt.Errorf("Invalid Version Unmarshaling PVKey. Expected %d, got %d", AllocationCodecVersion, version)
  4018. }
  4019. var b string
  4020. if ctx.IsStringTable() {
  4021. c := buff.ReadInt() // read string index
  4022. b = ctx.Table[c]
  4023. } else {
  4024. b = buff.ReadString() // read string
  4025. }
  4026. a := b
  4027. target.Cluster = a
  4028. var e string
  4029. if ctx.IsStringTable() {
  4030. f := buff.ReadInt() // read string index
  4031. e = ctx.Table[f]
  4032. } else {
  4033. e = buff.ReadString() // read string
  4034. }
  4035. d := e
  4036. target.Name = d
  4037. return nil
  4038. }
  4039. //--------------------------------------------------------------------------
  4040. // RawAllocationOnlyData
  4041. //--------------------------------------------------------------------------
  4042. // MarshalBinary serializes the internal properties of this RawAllocationOnlyData instance
  4043. // into a byte array
  4044. func (target *RawAllocationOnlyData) MarshalBinary() (data []byte, err error) {
  4045. ctx := &EncodingContext{
  4046. Buffer: util.NewBuffer(),
  4047. Table: nil,
  4048. }
  4049. e := target.MarshalBinaryWithContext(ctx)
  4050. if e != nil {
  4051. return nil, e
  4052. }
  4053. encBytes := ctx.Buffer.Bytes()
  4054. return encBytes, nil
  4055. }
  4056. // MarshalBinaryWithContext serializes the internal properties of this RawAllocationOnlyData instance
  4057. // into a byte array leveraging a predefined context.
  4058. func (target *RawAllocationOnlyData) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4059. // panics are recovered and propagated as errors
  4060. defer func() {
  4061. if r := recover(); r != nil {
  4062. if e, ok := r.(error); ok {
  4063. err = e
  4064. } else if s, ok := r.(string); ok {
  4065. err = fmt.Errorf("Unexpected panic: %s", s)
  4066. } else {
  4067. err = fmt.Errorf("Unexpected panic: %+v", r)
  4068. }
  4069. }
  4070. }()
  4071. buff := ctx.Buffer
  4072. buff.WriteUInt8(AllocationCodecVersion) // version
  4073. buff.WriteFloat64(target.CPUCoreUsageMax) // write float64
  4074. buff.WriteFloat64(target.RAMBytesUsageMax) // write float64
  4075. return nil
  4076. }
  4077. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4078. // the RawAllocationOnlyData type
  4079. func (target *RawAllocationOnlyData) UnmarshalBinary(data []byte) error {
  4080. var table []string
  4081. buff := util.NewBufferFromBytes(data)
  4082. // string table header validation
  4083. if isBinaryTag(data, BinaryTagStringTable) {
  4084. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4085. tl := buff.ReadInt() // table length
  4086. if tl > 0 {
  4087. table = make([]string, tl, tl)
  4088. for i := 0; i < tl; i++ {
  4089. table[i] = buff.ReadString()
  4090. }
  4091. }
  4092. }
  4093. ctx := &DecodingContext{
  4094. Buffer: buff,
  4095. Table: table,
  4096. }
  4097. err := target.UnmarshalBinaryWithContext(ctx)
  4098. if err != nil {
  4099. return err
  4100. }
  4101. return nil
  4102. }
  4103. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4104. // the RawAllocationOnlyData type
  4105. func (target *RawAllocationOnlyData) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4106. // panics are recovered and propagated as errors
  4107. defer func() {
  4108. if r := recover(); r != nil {
  4109. if e, ok := r.(error); ok {
  4110. err = e
  4111. } else if s, ok := r.(string); ok {
  4112. err = fmt.Errorf("Unexpected panic: %s", s)
  4113. } else {
  4114. err = fmt.Errorf("Unexpected panic: %+v", r)
  4115. }
  4116. }
  4117. }()
  4118. buff := ctx.Buffer
  4119. // Codec Version Check
  4120. version := buff.ReadUInt8()
  4121. if version != AllocationCodecVersion {
  4122. return fmt.Errorf("Invalid Version Unmarshaling RawAllocationOnlyData. Expected %d, got %d", AllocationCodecVersion, version)
  4123. }
  4124. a := buff.ReadFloat64() // read float64
  4125. target.CPUCoreUsageMax = a
  4126. b := buff.ReadFloat64() // read float64
  4127. target.RAMBytesUsageMax = b
  4128. return nil
  4129. }
  4130. //--------------------------------------------------------------------------
  4131. // SharedAsset
  4132. //--------------------------------------------------------------------------
  4133. // MarshalBinary serializes the internal properties of this SharedAsset instance
  4134. // into a byte array
  4135. func (target *SharedAsset) MarshalBinary() (data []byte, err error) {
  4136. ctx := &EncodingContext{
  4137. Buffer: util.NewBuffer(),
  4138. Table: nil,
  4139. }
  4140. e := target.MarshalBinaryWithContext(ctx)
  4141. if e != nil {
  4142. return nil, e
  4143. }
  4144. encBytes := ctx.Buffer.Bytes()
  4145. return encBytes, nil
  4146. }
  4147. // MarshalBinaryWithContext serializes the internal properties of this SharedAsset instance
  4148. // into a byte array leveraging a predefined context.
  4149. func (target *SharedAsset) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4150. // panics are recovered and propagated as errors
  4151. defer func() {
  4152. if r := recover(); r != nil {
  4153. if e, ok := r.(error); ok {
  4154. err = e
  4155. } else if s, ok := r.(string); ok {
  4156. err = fmt.Errorf("Unexpected panic: %s", s)
  4157. } else {
  4158. err = fmt.Errorf("Unexpected panic: %+v", r)
  4159. }
  4160. }
  4161. }()
  4162. buff := ctx.Buffer
  4163. buff.WriteUInt8(AssetsCodecVersion) // version
  4164. if target.properties == nil {
  4165. buff.WriteUInt8(uint8(0)) // write nil byte
  4166. } else {
  4167. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4168. // --- [begin][write][struct](AssetProperties) ---
  4169. buff.WriteInt(0) // [compatibility, unused]
  4170. errA := target.properties.MarshalBinaryWithContext(ctx)
  4171. if errA != nil {
  4172. return errA
  4173. }
  4174. // --- [end][write][struct](AssetProperties) ---
  4175. }
  4176. // --- [begin][write][alias](AssetLabels) ---
  4177. if map[string]string(target.labels) == nil {
  4178. buff.WriteUInt8(uint8(0)) // write nil byte
  4179. } else {
  4180. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4181. // --- [begin][write][map](map[string]string) ---
  4182. buff.WriteInt(len(map[string]string(target.labels))) // map length
  4183. for v, z := range map[string]string(target.labels) {
  4184. if ctx.IsStringTable() {
  4185. a := ctx.Table.AddOrGet(v)
  4186. buff.WriteInt(a) // write table index
  4187. } else {
  4188. buff.WriteString(v) // write string
  4189. }
  4190. if ctx.IsStringTable() {
  4191. b := ctx.Table.AddOrGet(z)
  4192. buff.WriteInt(b) // write table index
  4193. } else {
  4194. buff.WriteString(z) // write string
  4195. }
  4196. }
  4197. // --- [end][write][map](map[string]string) ---
  4198. }
  4199. // --- [end][write][alias](AssetLabels) ---
  4200. // --- [begin][write][struct](Window) ---
  4201. buff.WriteInt(0) // [compatibility, unused]
  4202. errB := target.window.MarshalBinaryWithContext(ctx)
  4203. if errB != nil {
  4204. return errB
  4205. }
  4206. // --- [end][write][struct](Window) ---
  4207. buff.WriteFloat64(target.Cost) // write float64
  4208. return nil
  4209. }
  4210. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4211. // the SharedAsset type
  4212. func (target *SharedAsset) UnmarshalBinary(data []byte) error {
  4213. var table []string
  4214. buff := util.NewBufferFromBytes(data)
  4215. // string table header validation
  4216. if isBinaryTag(data, BinaryTagStringTable) {
  4217. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4218. tl := buff.ReadInt() // table length
  4219. if tl > 0 {
  4220. table = make([]string, tl, tl)
  4221. for i := 0; i < tl; i++ {
  4222. table[i] = buff.ReadString()
  4223. }
  4224. }
  4225. }
  4226. ctx := &DecodingContext{
  4227. Buffer: buff,
  4228. Table: table,
  4229. }
  4230. err := target.UnmarshalBinaryWithContext(ctx)
  4231. if err != nil {
  4232. return err
  4233. }
  4234. return nil
  4235. }
  4236. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4237. // the SharedAsset type
  4238. func (target *SharedAsset) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4239. // panics are recovered and propagated as errors
  4240. defer func() {
  4241. if r := recover(); r != nil {
  4242. if e, ok := r.(error); ok {
  4243. err = e
  4244. } else if s, ok := r.(string); ok {
  4245. err = fmt.Errorf("Unexpected panic: %s", s)
  4246. } else {
  4247. err = fmt.Errorf("Unexpected panic: %+v", r)
  4248. }
  4249. }
  4250. }()
  4251. buff := ctx.Buffer
  4252. // Codec Version Check
  4253. version := buff.ReadUInt8()
  4254. if version != AssetsCodecVersion {
  4255. return fmt.Errorf("Invalid Version Unmarshaling SharedAsset. Expected %d, got %d", AssetsCodecVersion, version)
  4256. }
  4257. if buff.ReadUInt8() == uint8(0) {
  4258. target.properties = nil
  4259. } else {
  4260. // --- [begin][read][struct](AssetProperties) ---
  4261. a := &AssetProperties{}
  4262. buff.ReadInt() // [compatibility, unused]
  4263. errA := a.UnmarshalBinaryWithContext(ctx)
  4264. if errA != nil {
  4265. return errA
  4266. }
  4267. target.properties = a
  4268. // --- [end][read][struct](AssetProperties) ---
  4269. }
  4270. // --- [begin][read][alias](AssetLabels) ---
  4271. var b map[string]string
  4272. if buff.ReadUInt8() == uint8(0) {
  4273. b = nil
  4274. } else {
  4275. // --- [begin][read][map](map[string]string) ---
  4276. d := buff.ReadInt() // map len
  4277. c := make(map[string]string, d)
  4278. for i := 0; i < d; i++ {
  4279. var v string
  4280. var f string
  4281. if ctx.IsStringTable() {
  4282. g := buff.ReadInt() // read string index
  4283. f = ctx.Table[g]
  4284. } else {
  4285. f = buff.ReadString() // read string
  4286. }
  4287. e := f
  4288. v = e
  4289. var z string
  4290. var k string
  4291. if ctx.IsStringTable() {
  4292. l := buff.ReadInt() // read string index
  4293. k = ctx.Table[l]
  4294. } else {
  4295. k = buff.ReadString() // read string
  4296. }
  4297. h := k
  4298. z = h
  4299. c[v] = z
  4300. }
  4301. b = c
  4302. // --- [end][read][map](map[string]string) ---
  4303. }
  4304. target.labels = AssetLabels(b)
  4305. // --- [end][read][alias](AssetLabels) ---
  4306. // --- [begin][read][struct](Window) ---
  4307. m := &Window{}
  4308. buff.ReadInt() // [compatibility, unused]
  4309. errB := m.UnmarshalBinaryWithContext(ctx)
  4310. if errB != nil {
  4311. return errB
  4312. }
  4313. target.window = *m
  4314. // --- [end][read][struct](Window) ---
  4315. n := buff.ReadFloat64() // read float64
  4316. target.Cost = n
  4317. return nil
  4318. }
  4319. //--------------------------------------------------------------------------
  4320. // Window
  4321. //--------------------------------------------------------------------------
  4322. // MarshalBinary serializes the internal properties of this Window instance
  4323. // into a byte array
  4324. func (target *Window) MarshalBinary() (data []byte, err error) {
  4325. ctx := &EncodingContext{
  4326. Buffer: util.NewBuffer(),
  4327. Table: nil,
  4328. }
  4329. e := target.MarshalBinaryWithContext(ctx)
  4330. if e != nil {
  4331. return nil, e
  4332. }
  4333. encBytes := ctx.Buffer.Bytes()
  4334. return encBytes, nil
  4335. }
  4336. // MarshalBinaryWithContext serializes the internal properties of this Window instance
  4337. // into a byte array leveraging a predefined context.
  4338. func (target *Window) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4339. // panics are recovered and propagated as errors
  4340. defer func() {
  4341. if r := recover(); r != nil {
  4342. if e, ok := r.(error); ok {
  4343. err = e
  4344. } else if s, ok := r.(string); ok {
  4345. err = fmt.Errorf("Unexpected panic: %s", s)
  4346. } else {
  4347. err = fmt.Errorf("Unexpected panic: %+v", r)
  4348. }
  4349. }
  4350. }()
  4351. buff := ctx.Buffer
  4352. buff.WriteUInt8(DefaultCodecVersion) // version
  4353. if target.start == nil {
  4354. buff.WriteUInt8(uint8(0)) // write nil byte
  4355. } else {
  4356. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4357. // --- [begin][write][reference](time.Time) ---
  4358. a, errA := target.start.MarshalBinary()
  4359. if errA != nil {
  4360. return errA
  4361. }
  4362. buff.WriteInt(len(a))
  4363. buff.WriteBytes(a)
  4364. // --- [end][write][reference](time.Time) ---
  4365. }
  4366. if target.end == nil {
  4367. buff.WriteUInt8(uint8(0)) // write nil byte
  4368. } else {
  4369. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4370. // --- [begin][write][reference](time.Time) ---
  4371. b, errB := target.end.MarshalBinary()
  4372. if errB != nil {
  4373. return errB
  4374. }
  4375. buff.WriteInt(len(b))
  4376. buff.WriteBytes(b)
  4377. // --- [end][write][reference](time.Time) ---
  4378. }
  4379. return nil
  4380. }
  4381. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4382. // the Window type
  4383. func (target *Window) UnmarshalBinary(data []byte) error {
  4384. var table []string
  4385. buff := util.NewBufferFromBytes(data)
  4386. // string table header validation
  4387. if isBinaryTag(data, BinaryTagStringTable) {
  4388. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4389. tl := buff.ReadInt() // table length
  4390. if tl > 0 {
  4391. table = make([]string, tl, tl)
  4392. for i := 0; i < tl; i++ {
  4393. table[i] = buff.ReadString()
  4394. }
  4395. }
  4396. }
  4397. ctx := &DecodingContext{
  4398. Buffer: buff,
  4399. Table: table,
  4400. }
  4401. err := target.UnmarshalBinaryWithContext(ctx)
  4402. if err != nil {
  4403. return err
  4404. }
  4405. return nil
  4406. }
  4407. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4408. // the Window type
  4409. func (target *Window) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4410. // panics are recovered and propagated as errors
  4411. defer func() {
  4412. if r := recover(); r != nil {
  4413. if e, ok := r.(error); ok {
  4414. err = e
  4415. } else if s, ok := r.(string); ok {
  4416. err = fmt.Errorf("Unexpected panic: %s", s)
  4417. } else {
  4418. err = fmt.Errorf("Unexpected panic: %+v", r)
  4419. }
  4420. }
  4421. }()
  4422. buff := ctx.Buffer
  4423. // Codec Version Check
  4424. version := buff.ReadUInt8()
  4425. if version != DefaultCodecVersion {
  4426. return fmt.Errorf("Invalid Version Unmarshaling Window. Expected %d, got %d", DefaultCodecVersion, version)
  4427. }
  4428. if buff.ReadUInt8() == uint8(0) {
  4429. target.start = nil
  4430. } else {
  4431. // --- [begin][read][reference](time.Time) ---
  4432. a := &time.Time{}
  4433. b := buff.ReadInt() // byte array length
  4434. c := buff.ReadBytes(b) // byte array
  4435. errA := a.UnmarshalBinary(c)
  4436. if errA != nil {
  4437. return errA
  4438. }
  4439. target.start = a
  4440. // --- [end][read][reference](time.Time) ---
  4441. }
  4442. if buff.ReadUInt8() == uint8(0) {
  4443. target.end = nil
  4444. } else {
  4445. // --- [begin][read][reference](time.Time) ---
  4446. d := &time.Time{}
  4447. e := buff.ReadInt() // byte array length
  4448. f := buff.ReadBytes(e) // byte array
  4449. errB := d.UnmarshalBinary(f)
  4450. if errB != nil {
  4451. return errB
  4452. }
  4453. target.end = d
  4454. // --- [end][read][reference](time.Time) ---
  4455. }
  4456. return nil
  4457. }