kubecost_codecs.go 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119
  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. // AllocationCodecVersion is used for any resources listed in the Allocation version set
  32. AllocationCodecVersion uint8 = 15
  33. // DefaultCodecVersion is used for any resources listed in the Default version set
  34. DefaultCodecVersion uint8 = 15
  35. // AssetsCodecVersion is used for any resources listed in the Assets version set
  36. AssetsCodecVersion 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: NewStringTable(),
  916. }
  917. e := target.MarshalBinaryWithContext(ctx)
  918. if e != nil {
  919. return nil, e
  920. }
  921. encBytes := ctx.Buffer.Bytes()
  922. sTableBytes := ctx.Table.ToBytes()
  923. merged := appendBytes(sTableBytes, encBytes)
  924. return merged, nil
  925. }
  926. // MarshalBinaryWithContext serializes the internal properties of this AllocationSet instance
  927. // into a byte array leveraging a predefined context.
  928. func (target *AllocationSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  929. // panics are recovered and propagated as errors
  930. defer func() {
  931. if r := recover(); r != nil {
  932. if e, ok := r.(error); ok {
  933. err = e
  934. } else if s, ok := r.(string); ok {
  935. err = fmt.Errorf("Unexpected panic: %s", s)
  936. } else {
  937. err = fmt.Errorf("Unexpected panic: %+v", r)
  938. }
  939. }
  940. }()
  941. buff := ctx.Buffer
  942. buff.WriteUInt8(AllocationCodecVersion) // version
  943. if target.allocations == nil {
  944. buff.WriteUInt8(uint8(0)) // write nil byte
  945. } else {
  946. buff.WriteUInt8(uint8(1)) // write non-nil byte
  947. // --- [begin][write][map](map[string]*Allocation) ---
  948. buff.WriteInt(len(target.allocations)) // map length
  949. for v, z := range target.allocations {
  950. if ctx.IsStringTable() {
  951. a := ctx.Table.AddOrGet(v)
  952. buff.WriteInt(a) // write table index
  953. } else {
  954. buff.WriteString(v) // write string
  955. }
  956. if z == nil {
  957. buff.WriteUInt8(uint8(0)) // write nil byte
  958. } else {
  959. buff.WriteUInt8(uint8(1)) // write non-nil byte
  960. // --- [begin][write][struct](Allocation) ---
  961. buff.WriteInt(0) // [compatibility, unused]
  962. errA := z.MarshalBinaryWithContext(ctx)
  963. if errA != nil {
  964. return errA
  965. }
  966. // --- [end][write][struct](Allocation) ---
  967. }
  968. }
  969. // --- [end][write][map](map[string]*Allocation) ---
  970. }
  971. if target.externalKeys == nil {
  972. buff.WriteUInt8(uint8(0)) // write nil byte
  973. } else {
  974. buff.WriteUInt8(uint8(1)) // write non-nil byte
  975. // --- [begin][write][map](map[string]bool) ---
  976. buff.WriteInt(len(target.externalKeys)) // map length
  977. for vv, zz := range target.externalKeys {
  978. if ctx.IsStringTable() {
  979. b := ctx.Table.AddOrGet(vv)
  980. buff.WriteInt(b) // write table index
  981. } else {
  982. buff.WriteString(vv) // write string
  983. }
  984. buff.WriteBool(zz) // write bool
  985. }
  986. // --- [end][write][map](map[string]bool) ---
  987. }
  988. if target.idleKeys == nil {
  989. buff.WriteUInt8(uint8(0)) // write nil byte
  990. } else {
  991. buff.WriteUInt8(uint8(1)) // write non-nil byte
  992. // --- [begin][write][map](map[string]bool) ---
  993. buff.WriteInt(len(target.idleKeys)) // map length
  994. for vvv, zzz := range target.idleKeys {
  995. if ctx.IsStringTable() {
  996. c := ctx.Table.AddOrGet(vvv)
  997. buff.WriteInt(c) // write table index
  998. } else {
  999. buff.WriteString(vvv) // write string
  1000. }
  1001. buff.WriteBool(zzz) // write bool
  1002. }
  1003. // --- [end][write][map](map[string]bool) ---
  1004. }
  1005. if ctx.IsStringTable() {
  1006. d := ctx.Table.AddOrGet(target.FromSource)
  1007. buff.WriteInt(d) // write table index
  1008. } else {
  1009. buff.WriteString(target.FromSource) // write string
  1010. }
  1011. // --- [begin][write][struct](Window) ---
  1012. buff.WriteInt(0) // [compatibility, unused]
  1013. errB := target.Window.MarshalBinaryWithContext(ctx)
  1014. if errB != nil {
  1015. return errB
  1016. }
  1017. // --- [end][write][struct](Window) ---
  1018. if target.Warnings == nil {
  1019. buff.WriteUInt8(uint8(0)) // write nil byte
  1020. } else {
  1021. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1022. // --- [begin][write][slice]([]string) ---
  1023. buff.WriteInt(len(target.Warnings)) // array length
  1024. for i := 0; i < len(target.Warnings); i++ {
  1025. if ctx.IsStringTable() {
  1026. e := ctx.Table.AddOrGet(target.Warnings[i])
  1027. buff.WriteInt(e) // write table index
  1028. } else {
  1029. buff.WriteString(target.Warnings[i]) // write string
  1030. }
  1031. }
  1032. // --- [end][write][slice]([]string) ---
  1033. }
  1034. if target.Errors == nil {
  1035. buff.WriteUInt8(uint8(0)) // write nil byte
  1036. } else {
  1037. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1038. // --- [begin][write][slice]([]string) ---
  1039. buff.WriteInt(len(target.Errors)) // array length
  1040. for j := 0; j < len(target.Errors); j++ {
  1041. if ctx.IsStringTable() {
  1042. f := ctx.Table.AddOrGet(target.Errors[j])
  1043. buff.WriteInt(f) // write table index
  1044. } else {
  1045. buff.WriteString(target.Errors[j]) // write string
  1046. }
  1047. }
  1048. // --- [end][write][slice]([]string) ---
  1049. }
  1050. return nil
  1051. }
  1052. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1053. // the AllocationSet type
  1054. func (target *AllocationSet) UnmarshalBinary(data []byte) error {
  1055. var table []string
  1056. buff := util.NewBufferFromBytes(data)
  1057. // string table header validation
  1058. if isBinaryTag(data, BinaryTagStringTable) {
  1059. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1060. tl := buff.ReadInt() // table length
  1061. if tl > 0 {
  1062. table = make([]string, tl, tl)
  1063. for i := 0; i < tl; i++ {
  1064. table[i] = buff.ReadString()
  1065. }
  1066. }
  1067. }
  1068. ctx := &DecodingContext{
  1069. Buffer: buff,
  1070. Table: table,
  1071. }
  1072. err := target.UnmarshalBinaryWithContext(ctx)
  1073. if err != nil {
  1074. return err
  1075. }
  1076. return nil
  1077. }
  1078. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1079. // the AllocationSet type
  1080. func (target *AllocationSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1081. // panics are recovered and propagated as errors
  1082. defer func() {
  1083. if r := recover(); r != nil {
  1084. if e, ok := r.(error); ok {
  1085. err = e
  1086. } else if s, ok := r.(string); ok {
  1087. err = fmt.Errorf("Unexpected panic: %s", s)
  1088. } else {
  1089. err = fmt.Errorf("Unexpected panic: %+v", r)
  1090. }
  1091. }
  1092. }()
  1093. buff := ctx.Buffer
  1094. // Codec Version Check
  1095. version := buff.ReadUInt8()
  1096. if version != AllocationCodecVersion {
  1097. return fmt.Errorf("Invalid Version Unmarshaling AllocationSet. Expected %d, got %d", AllocationCodecVersion, version)
  1098. }
  1099. if buff.ReadUInt8() == uint8(0) {
  1100. target.allocations = nil
  1101. } else {
  1102. // --- [begin][read][map](map[string]*Allocation) ---
  1103. b := buff.ReadInt() // map len
  1104. a := make(map[string]*Allocation, b)
  1105. for i := 0; i < b; i++ {
  1106. var v string
  1107. var d string
  1108. if ctx.IsStringTable() {
  1109. e := buff.ReadInt() // read string index
  1110. d = ctx.Table[e]
  1111. } else {
  1112. d = buff.ReadString() // read string
  1113. }
  1114. c := d
  1115. v = c
  1116. var z *Allocation
  1117. if buff.ReadUInt8() == uint8(0) {
  1118. z = nil
  1119. } else {
  1120. // --- [begin][read][struct](Allocation) ---
  1121. f := &Allocation{}
  1122. buff.ReadInt() // [compatibility, unused]
  1123. errA := f.UnmarshalBinaryWithContext(ctx)
  1124. if errA != nil {
  1125. return errA
  1126. }
  1127. z = f
  1128. // --- [end][read][struct](Allocation) ---
  1129. }
  1130. a[v] = z
  1131. }
  1132. target.allocations = a
  1133. // --- [end][read][map](map[string]*Allocation) ---
  1134. }
  1135. if buff.ReadUInt8() == uint8(0) {
  1136. target.externalKeys = nil
  1137. } else {
  1138. // --- [begin][read][map](map[string]bool) ---
  1139. h := buff.ReadInt() // map len
  1140. g := make(map[string]bool, h)
  1141. for j := 0; j < h; j++ {
  1142. var vv string
  1143. var l string
  1144. if ctx.IsStringTable() {
  1145. m := buff.ReadInt() // read string index
  1146. l = ctx.Table[m]
  1147. } else {
  1148. l = buff.ReadString() // read string
  1149. }
  1150. k := l
  1151. vv = k
  1152. var zz bool
  1153. n := buff.ReadBool() // read bool
  1154. zz = n
  1155. g[vv] = zz
  1156. }
  1157. target.externalKeys = g
  1158. // --- [end][read][map](map[string]bool) ---
  1159. }
  1160. if buff.ReadUInt8() == uint8(0) {
  1161. target.idleKeys = nil
  1162. } else {
  1163. // --- [begin][read][map](map[string]bool) ---
  1164. p := buff.ReadInt() // map len
  1165. o := make(map[string]bool, p)
  1166. for ii := 0; ii < p; ii++ {
  1167. var vvv string
  1168. var r string
  1169. if ctx.IsStringTable() {
  1170. s := buff.ReadInt() // read string index
  1171. r = ctx.Table[s]
  1172. } else {
  1173. r = buff.ReadString() // read string
  1174. }
  1175. q := r
  1176. vvv = q
  1177. var zzz bool
  1178. t := buff.ReadBool() // read bool
  1179. zzz = t
  1180. o[vvv] = zzz
  1181. }
  1182. target.idleKeys = o
  1183. // --- [end][read][map](map[string]bool) ---
  1184. }
  1185. var w string
  1186. if ctx.IsStringTable() {
  1187. x := buff.ReadInt() // read string index
  1188. w = ctx.Table[x]
  1189. } else {
  1190. w = buff.ReadString() // read string
  1191. }
  1192. u := w
  1193. target.FromSource = u
  1194. // --- [begin][read][struct](Window) ---
  1195. y := &Window{}
  1196. buff.ReadInt() // [compatibility, unused]
  1197. errB := y.UnmarshalBinaryWithContext(ctx)
  1198. if errB != nil {
  1199. return errB
  1200. }
  1201. target.Window = *y
  1202. // --- [end][read][struct](Window) ---
  1203. if buff.ReadUInt8() == uint8(0) {
  1204. target.Warnings = nil
  1205. } else {
  1206. // --- [begin][read][slice]([]string) ---
  1207. bb := buff.ReadInt() // array len
  1208. aa := make([]string, bb)
  1209. for jj := 0; jj < bb; jj++ {
  1210. var cc string
  1211. var ee string
  1212. if ctx.IsStringTable() {
  1213. ff := buff.ReadInt() // read string index
  1214. ee = ctx.Table[ff]
  1215. } else {
  1216. ee = buff.ReadString() // read string
  1217. }
  1218. dd := ee
  1219. cc = dd
  1220. aa[jj] = cc
  1221. }
  1222. target.Warnings = aa
  1223. // --- [end][read][slice]([]string) ---
  1224. }
  1225. if buff.ReadUInt8() == uint8(0) {
  1226. target.Errors = nil
  1227. } else {
  1228. // --- [begin][read][slice]([]string) ---
  1229. hh := buff.ReadInt() // array len
  1230. gg := make([]string, hh)
  1231. for iii := 0; iii < hh; iii++ {
  1232. var kk string
  1233. var mm string
  1234. if ctx.IsStringTable() {
  1235. nn := buff.ReadInt() // read string index
  1236. mm = ctx.Table[nn]
  1237. } else {
  1238. mm = buff.ReadString() // read string
  1239. }
  1240. ll := mm
  1241. kk = ll
  1242. gg[iii] = kk
  1243. }
  1244. target.Errors = gg
  1245. // --- [end][read][slice]([]string) ---
  1246. }
  1247. return nil
  1248. }
  1249. //--------------------------------------------------------------------------
  1250. // AllocationSetRange
  1251. //--------------------------------------------------------------------------
  1252. // MarshalBinary serializes the internal properties of this AllocationSetRange instance
  1253. // into a byte array
  1254. func (target *AllocationSetRange) MarshalBinary() (data []byte, err error) {
  1255. ctx := &EncodingContext{
  1256. Buffer: util.NewBuffer(),
  1257. Table: nil,
  1258. }
  1259. e := target.MarshalBinaryWithContext(ctx)
  1260. if e != nil {
  1261. return nil, e
  1262. }
  1263. encBytes := ctx.Buffer.Bytes()
  1264. return encBytes, nil
  1265. }
  1266. // MarshalBinaryWithContext serializes the internal properties of this AllocationSetRange instance
  1267. // into a byte array leveraging a predefined context.
  1268. func (target *AllocationSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1269. // panics are recovered and propagated as errors
  1270. defer func() {
  1271. if r := recover(); r != nil {
  1272. if e, ok := r.(error); ok {
  1273. err = e
  1274. } else if s, ok := r.(string); ok {
  1275. err = fmt.Errorf("Unexpected panic: %s", s)
  1276. } else {
  1277. err = fmt.Errorf("Unexpected panic: %+v", r)
  1278. }
  1279. }
  1280. }()
  1281. buff := ctx.Buffer
  1282. buff.WriteUInt8(AllocationCodecVersion) // version
  1283. if target.allocations == nil {
  1284. buff.WriteUInt8(uint8(0)) // write nil byte
  1285. } else {
  1286. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1287. // --- [begin][write][slice]([]*AllocationSet) ---
  1288. buff.WriteInt(len(target.allocations)) // array length
  1289. for i := 0; i < len(target.allocations); i++ {
  1290. if target.allocations[i] == nil {
  1291. buff.WriteUInt8(uint8(0)) // write nil byte
  1292. } else {
  1293. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1294. // --- [begin][write][struct](AllocationSet) ---
  1295. buff.WriteInt(0) // [compatibility, unused]
  1296. errA := target.allocations[i].MarshalBinaryWithContext(ctx)
  1297. if errA != nil {
  1298. return errA
  1299. }
  1300. // --- [end][write][struct](AllocationSet) ---
  1301. }
  1302. }
  1303. // --- [end][write][slice]([]*AllocationSet) ---
  1304. }
  1305. if ctx.IsStringTable() {
  1306. a := ctx.Table.AddOrGet(target.FromStore)
  1307. buff.WriteInt(a) // write table index
  1308. } else {
  1309. buff.WriteString(target.FromStore) // write string
  1310. }
  1311. return nil
  1312. }
  1313. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1314. // the AllocationSetRange type
  1315. func (target *AllocationSetRange) UnmarshalBinary(data []byte) error {
  1316. var table []string
  1317. buff := util.NewBufferFromBytes(data)
  1318. // string table header validation
  1319. if isBinaryTag(data, BinaryTagStringTable) {
  1320. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1321. tl := buff.ReadInt() // table length
  1322. if tl > 0 {
  1323. table = make([]string, tl, tl)
  1324. for i := 0; i < tl; i++ {
  1325. table[i] = buff.ReadString()
  1326. }
  1327. }
  1328. }
  1329. ctx := &DecodingContext{
  1330. Buffer: buff,
  1331. Table: table,
  1332. }
  1333. err := target.UnmarshalBinaryWithContext(ctx)
  1334. if err != nil {
  1335. return err
  1336. }
  1337. return nil
  1338. }
  1339. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1340. // the AllocationSetRange type
  1341. func (target *AllocationSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1342. // panics are recovered and propagated as errors
  1343. defer func() {
  1344. if r := recover(); r != nil {
  1345. if e, ok := r.(error); ok {
  1346. err = e
  1347. } else if s, ok := r.(string); ok {
  1348. err = fmt.Errorf("Unexpected panic: %s", s)
  1349. } else {
  1350. err = fmt.Errorf("Unexpected panic: %+v", r)
  1351. }
  1352. }
  1353. }()
  1354. buff := ctx.Buffer
  1355. // Codec Version Check
  1356. version := buff.ReadUInt8()
  1357. if version != AllocationCodecVersion {
  1358. return fmt.Errorf("Invalid Version Unmarshaling AllocationSetRange. Expected %d, got %d", AllocationCodecVersion, version)
  1359. }
  1360. if buff.ReadUInt8() == uint8(0) {
  1361. target.allocations = nil
  1362. } else {
  1363. // --- [begin][read][slice]([]*AllocationSet) ---
  1364. b := buff.ReadInt() // array len
  1365. a := make([]*AllocationSet, b)
  1366. for i := 0; i < b; i++ {
  1367. var c *AllocationSet
  1368. if buff.ReadUInt8() == uint8(0) {
  1369. c = nil
  1370. } else {
  1371. // --- [begin][read][struct](AllocationSet) ---
  1372. d := &AllocationSet{}
  1373. buff.ReadInt() // [compatibility, unused]
  1374. errA := d.UnmarshalBinaryWithContext(ctx)
  1375. if errA != nil {
  1376. return errA
  1377. }
  1378. c = d
  1379. // --- [end][read][struct](AllocationSet) ---
  1380. }
  1381. a[i] = c
  1382. }
  1383. target.allocations = a
  1384. // --- [end][read][slice]([]*AllocationSet) ---
  1385. }
  1386. var f string
  1387. if ctx.IsStringTable() {
  1388. g := buff.ReadInt() // read string index
  1389. f = ctx.Table[g]
  1390. } else {
  1391. f = buff.ReadString() // read string
  1392. }
  1393. e := f
  1394. target.FromStore = e
  1395. return nil
  1396. }
  1397. //--------------------------------------------------------------------------
  1398. // Any
  1399. //--------------------------------------------------------------------------
  1400. // MarshalBinary serializes the internal properties of this Any instance
  1401. // into a byte array
  1402. func (target *Any) MarshalBinary() (data []byte, err error) {
  1403. ctx := &EncodingContext{
  1404. Buffer: util.NewBuffer(),
  1405. Table: nil,
  1406. }
  1407. e := target.MarshalBinaryWithContext(ctx)
  1408. if e != nil {
  1409. return nil, e
  1410. }
  1411. encBytes := ctx.Buffer.Bytes()
  1412. return encBytes, nil
  1413. }
  1414. // MarshalBinaryWithContext serializes the internal properties of this Any instance
  1415. // into a byte array leveraging a predefined context.
  1416. func (target *Any) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1417. // panics are recovered and propagated as errors
  1418. defer func() {
  1419. if r := recover(); r != nil {
  1420. if e, ok := r.(error); ok {
  1421. err = e
  1422. } else if s, ok := r.(string); ok {
  1423. err = fmt.Errorf("Unexpected panic: %s", s)
  1424. } else {
  1425. err = fmt.Errorf("Unexpected panic: %+v", r)
  1426. }
  1427. }
  1428. }()
  1429. buff := ctx.Buffer
  1430. buff.WriteUInt8(AssetsCodecVersion) // version
  1431. // --- [begin][write][alias](AssetLabels) ---
  1432. if map[string]string(target.labels) == nil {
  1433. buff.WriteUInt8(uint8(0)) // write nil byte
  1434. } else {
  1435. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1436. // --- [begin][write][map](map[string]string) ---
  1437. buff.WriteInt(len(map[string]string(target.labels))) // map length
  1438. for v, z := range map[string]string(target.labels) {
  1439. if ctx.IsStringTable() {
  1440. a := ctx.Table.AddOrGet(v)
  1441. buff.WriteInt(a) // write table index
  1442. } else {
  1443. buff.WriteString(v) // write string
  1444. }
  1445. if ctx.IsStringTable() {
  1446. b := ctx.Table.AddOrGet(z)
  1447. buff.WriteInt(b) // write table index
  1448. } else {
  1449. buff.WriteString(z) // write string
  1450. }
  1451. }
  1452. // --- [end][write][map](map[string]string) ---
  1453. }
  1454. // --- [end][write][alias](AssetLabels) ---
  1455. if target.properties == nil {
  1456. buff.WriteUInt8(uint8(0)) // write nil byte
  1457. } else {
  1458. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1459. // --- [begin][write][struct](AssetProperties) ---
  1460. buff.WriteInt(0) // [compatibility, unused]
  1461. errA := target.properties.MarshalBinaryWithContext(ctx)
  1462. if errA != nil {
  1463. return errA
  1464. }
  1465. // --- [end][write][struct](AssetProperties) ---
  1466. }
  1467. // --- [begin][write][reference](time.Time) ---
  1468. c, errB := target.start.MarshalBinary()
  1469. if errB != nil {
  1470. return errB
  1471. }
  1472. buff.WriteInt(len(c))
  1473. buff.WriteBytes(c)
  1474. // --- [end][write][reference](time.Time) ---
  1475. // --- [begin][write][reference](time.Time) ---
  1476. d, errC := target.end.MarshalBinary()
  1477. if errC != nil {
  1478. return errC
  1479. }
  1480. buff.WriteInt(len(d))
  1481. buff.WriteBytes(d)
  1482. // --- [end][write][reference](time.Time) ---
  1483. // --- [begin][write][struct](Window) ---
  1484. buff.WriteInt(0) // [compatibility, unused]
  1485. errD := target.window.MarshalBinaryWithContext(ctx)
  1486. if errD != nil {
  1487. return errD
  1488. }
  1489. // --- [end][write][struct](Window) ---
  1490. buff.WriteFloat64(target.adjustment) // write float64
  1491. buff.WriteFloat64(target.Cost) // write float64
  1492. return nil
  1493. }
  1494. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1495. // the Any type
  1496. func (target *Any) UnmarshalBinary(data []byte) error {
  1497. var table []string
  1498. buff := util.NewBufferFromBytes(data)
  1499. // string table header validation
  1500. if isBinaryTag(data, BinaryTagStringTable) {
  1501. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1502. tl := buff.ReadInt() // table length
  1503. if tl > 0 {
  1504. table = make([]string, tl, tl)
  1505. for i := 0; i < tl; i++ {
  1506. table[i] = buff.ReadString()
  1507. }
  1508. }
  1509. }
  1510. ctx := &DecodingContext{
  1511. Buffer: buff,
  1512. Table: table,
  1513. }
  1514. err := target.UnmarshalBinaryWithContext(ctx)
  1515. if err != nil {
  1516. return err
  1517. }
  1518. return nil
  1519. }
  1520. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1521. // the Any type
  1522. func (target *Any) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1523. // panics are recovered and propagated as errors
  1524. defer func() {
  1525. if r := recover(); r != nil {
  1526. if e, ok := r.(error); ok {
  1527. err = e
  1528. } else if s, ok := r.(string); ok {
  1529. err = fmt.Errorf("Unexpected panic: %s", s)
  1530. } else {
  1531. err = fmt.Errorf("Unexpected panic: %+v", r)
  1532. }
  1533. }
  1534. }()
  1535. buff := ctx.Buffer
  1536. // Codec Version Check
  1537. version := buff.ReadUInt8()
  1538. if version != AssetsCodecVersion {
  1539. return fmt.Errorf("Invalid Version Unmarshaling Any. Expected %d, got %d", AssetsCodecVersion, version)
  1540. }
  1541. // --- [begin][read][alias](AssetLabels) ---
  1542. var a map[string]string
  1543. if buff.ReadUInt8() == uint8(0) {
  1544. a = nil
  1545. } else {
  1546. // --- [begin][read][map](map[string]string) ---
  1547. c := buff.ReadInt() // map len
  1548. b := make(map[string]string, c)
  1549. for i := 0; i < c; i++ {
  1550. var v string
  1551. var e string
  1552. if ctx.IsStringTable() {
  1553. f := buff.ReadInt() // read string index
  1554. e = ctx.Table[f]
  1555. } else {
  1556. e = buff.ReadString() // read string
  1557. }
  1558. d := e
  1559. v = d
  1560. var z string
  1561. var h string
  1562. if ctx.IsStringTable() {
  1563. k := buff.ReadInt() // read string index
  1564. h = ctx.Table[k]
  1565. } else {
  1566. h = buff.ReadString() // read string
  1567. }
  1568. g := h
  1569. z = g
  1570. b[v] = z
  1571. }
  1572. a = b
  1573. // --- [end][read][map](map[string]string) ---
  1574. }
  1575. target.labels = AssetLabels(a)
  1576. // --- [end][read][alias](AssetLabels) ---
  1577. if buff.ReadUInt8() == uint8(0) {
  1578. target.properties = nil
  1579. } else {
  1580. // --- [begin][read][struct](AssetProperties) ---
  1581. l := &AssetProperties{}
  1582. buff.ReadInt() // [compatibility, unused]
  1583. errA := l.UnmarshalBinaryWithContext(ctx)
  1584. if errA != nil {
  1585. return errA
  1586. }
  1587. target.properties = l
  1588. // --- [end][read][struct](AssetProperties) ---
  1589. }
  1590. // --- [begin][read][reference](time.Time) ---
  1591. m := &time.Time{}
  1592. n := buff.ReadInt() // byte array length
  1593. o := buff.ReadBytes(n) // byte array
  1594. errB := m.UnmarshalBinary(o)
  1595. if errB != nil {
  1596. return errB
  1597. }
  1598. target.start = *m
  1599. // --- [end][read][reference](time.Time) ---
  1600. // --- [begin][read][reference](time.Time) ---
  1601. p := &time.Time{}
  1602. q := buff.ReadInt() // byte array length
  1603. r := buff.ReadBytes(q) // byte array
  1604. errC := p.UnmarshalBinary(r)
  1605. if errC != nil {
  1606. return errC
  1607. }
  1608. target.end = *p
  1609. // --- [end][read][reference](time.Time) ---
  1610. // --- [begin][read][struct](Window) ---
  1611. s := &Window{}
  1612. buff.ReadInt() // [compatibility, unused]
  1613. errD := s.UnmarshalBinaryWithContext(ctx)
  1614. if errD != nil {
  1615. return errD
  1616. }
  1617. target.window = *s
  1618. // --- [end][read][struct](Window) ---
  1619. t := buff.ReadFloat64() // read float64
  1620. target.adjustment = t
  1621. u := buff.ReadFloat64() // read float64
  1622. target.Cost = u
  1623. return nil
  1624. }
  1625. //--------------------------------------------------------------------------
  1626. // AssetProperties
  1627. //--------------------------------------------------------------------------
  1628. // MarshalBinary serializes the internal properties of this AssetProperties instance
  1629. // into a byte array
  1630. func (target *AssetProperties) MarshalBinary() (data []byte, err error) {
  1631. ctx := &EncodingContext{
  1632. Buffer: util.NewBuffer(),
  1633. Table: nil,
  1634. }
  1635. e := target.MarshalBinaryWithContext(ctx)
  1636. if e != nil {
  1637. return nil, e
  1638. }
  1639. encBytes := ctx.Buffer.Bytes()
  1640. return encBytes, nil
  1641. }
  1642. // MarshalBinaryWithContext serializes the internal properties of this AssetProperties instance
  1643. // into a byte array leveraging a predefined context.
  1644. func (target *AssetProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1645. // panics are recovered and propagated as errors
  1646. defer func() {
  1647. if r := recover(); r != nil {
  1648. if e, ok := r.(error); ok {
  1649. err = e
  1650. } else if s, ok := r.(string); ok {
  1651. err = fmt.Errorf("Unexpected panic: %s", s)
  1652. } else {
  1653. err = fmt.Errorf("Unexpected panic: %+v", r)
  1654. }
  1655. }
  1656. }()
  1657. buff := ctx.Buffer
  1658. buff.WriteUInt8(AssetsCodecVersion) // version
  1659. if ctx.IsStringTable() {
  1660. a := ctx.Table.AddOrGet(target.Category)
  1661. buff.WriteInt(a) // write table index
  1662. } else {
  1663. buff.WriteString(target.Category) // write string
  1664. }
  1665. if ctx.IsStringTable() {
  1666. b := ctx.Table.AddOrGet(target.Provider)
  1667. buff.WriteInt(b) // write table index
  1668. } else {
  1669. buff.WriteString(target.Provider) // write string
  1670. }
  1671. if ctx.IsStringTable() {
  1672. c := ctx.Table.AddOrGet(target.Account)
  1673. buff.WriteInt(c) // write table index
  1674. } else {
  1675. buff.WriteString(target.Account) // write string
  1676. }
  1677. if ctx.IsStringTable() {
  1678. d := ctx.Table.AddOrGet(target.Project)
  1679. buff.WriteInt(d) // write table index
  1680. } else {
  1681. buff.WriteString(target.Project) // write string
  1682. }
  1683. if ctx.IsStringTable() {
  1684. e := ctx.Table.AddOrGet(target.Service)
  1685. buff.WriteInt(e) // write table index
  1686. } else {
  1687. buff.WriteString(target.Service) // write string
  1688. }
  1689. if ctx.IsStringTable() {
  1690. f := ctx.Table.AddOrGet(target.Cluster)
  1691. buff.WriteInt(f) // write table index
  1692. } else {
  1693. buff.WriteString(target.Cluster) // write string
  1694. }
  1695. if ctx.IsStringTable() {
  1696. g := ctx.Table.AddOrGet(target.Name)
  1697. buff.WriteInt(g) // write table index
  1698. } else {
  1699. buff.WriteString(target.Name) // write string
  1700. }
  1701. if ctx.IsStringTable() {
  1702. h := ctx.Table.AddOrGet(target.ProviderID)
  1703. buff.WriteInt(h) // write table index
  1704. } else {
  1705. buff.WriteString(target.ProviderID) // write string
  1706. }
  1707. return nil
  1708. }
  1709. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1710. // the AssetProperties type
  1711. func (target *AssetProperties) UnmarshalBinary(data []byte) error {
  1712. var table []string
  1713. buff := util.NewBufferFromBytes(data)
  1714. // string table header validation
  1715. if isBinaryTag(data, BinaryTagStringTable) {
  1716. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1717. tl := buff.ReadInt() // table length
  1718. if tl > 0 {
  1719. table = make([]string, tl, tl)
  1720. for i := 0; i < tl; i++ {
  1721. table[i] = buff.ReadString()
  1722. }
  1723. }
  1724. }
  1725. ctx := &DecodingContext{
  1726. Buffer: buff,
  1727. Table: table,
  1728. }
  1729. err := target.UnmarshalBinaryWithContext(ctx)
  1730. if err != nil {
  1731. return err
  1732. }
  1733. return nil
  1734. }
  1735. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1736. // the AssetProperties type
  1737. func (target *AssetProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1738. // panics are recovered and propagated as errors
  1739. defer func() {
  1740. if r := recover(); r != nil {
  1741. if e, ok := r.(error); ok {
  1742. err = e
  1743. } else if s, ok := r.(string); ok {
  1744. err = fmt.Errorf("Unexpected panic: %s", s)
  1745. } else {
  1746. err = fmt.Errorf("Unexpected panic: %+v", r)
  1747. }
  1748. }
  1749. }()
  1750. buff := ctx.Buffer
  1751. // Codec Version Check
  1752. version := buff.ReadUInt8()
  1753. if version != AssetsCodecVersion {
  1754. return fmt.Errorf("Invalid Version Unmarshaling AssetProperties. Expected %d, got %d", AssetsCodecVersion, version)
  1755. }
  1756. var b string
  1757. if ctx.IsStringTable() {
  1758. c := buff.ReadInt() // read string index
  1759. b = ctx.Table[c]
  1760. } else {
  1761. b = buff.ReadString() // read string
  1762. }
  1763. a := b
  1764. target.Category = a
  1765. var e string
  1766. if ctx.IsStringTable() {
  1767. f := buff.ReadInt() // read string index
  1768. e = ctx.Table[f]
  1769. } else {
  1770. e = buff.ReadString() // read string
  1771. }
  1772. d := e
  1773. target.Provider = d
  1774. var h string
  1775. if ctx.IsStringTable() {
  1776. k := buff.ReadInt() // read string index
  1777. h = ctx.Table[k]
  1778. } else {
  1779. h = buff.ReadString() // read string
  1780. }
  1781. g := h
  1782. target.Account = g
  1783. var m string
  1784. if ctx.IsStringTable() {
  1785. n := buff.ReadInt() // read string index
  1786. m = ctx.Table[n]
  1787. } else {
  1788. m = buff.ReadString() // read string
  1789. }
  1790. l := m
  1791. target.Project = l
  1792. var p string
  1793. if ctx.IsStringTable() {
  1794. q := buff.ReadInt() // read string index
  1795. p = ctx.Table[q]
  1796. } else {
  1797. p = buff.ReadString() // read string
  1798. }
  1799. o := p
  1800. target.Service = o
  1801. var s string
  1802. if ctx.IsStringTable() {
  1803. t := buff.ReadInt() // read string index
  1804. s = ctx.Table[t]
  1805. } else {
  1806. s = buff.ReadString() // read string
  1807. }
  1808. r := s
  1809. target.Cluster = r
  1810. var w string
  1811. if ctx.IsStringTable() {
  1812. x := buff.ReadInt() // read string index
  1813. w = ctx.Table[x]
  1814. } else {
  1815. w = buff.ReadString() // read string
  1816. }
  1817. u := w
  1818. target.Name = u
  1819. var aa string
  1820. if ctx.IsStringTable() {
  1821. bb := buff.ReadInt() // read string index
  1822. aa = ctx.Table[bb]
  1823. } else {
  1824. aa = buff.ReadString() // read string
  1825. }
  1826. y := aa
  1827. target.ProviderID = y
  1828. return nil
  1829. }
  1830. //--------------------------------------------------------------------------
  1831. // AssetSet
  1832. //--------------------------------------------------------------------------
  1833. // MarshalBinary serializes the internal properties of this AssetSet instance
  1834. // into a byte array
  1835. func (target *AssetSet) MarshalBinary() (data []byte, err error) {
  1836. ctx := &EncodingContext{
  1837. Buffer: util.NewBuffer(),
  1838. Table: NewStringTable(),
  1839. }
  1840. e := target.MarshalBinaryWithContext(ctx)
  1841. if e != nil {
  1842. return nil, e
  1843. }
  1844. encBytes := ctx.Buffer.Bytes()
  1845. sTableBytes := ctx.Table.ToBytes()
  1846. merged := appendBytes(sTableBytes, encBytes)
  1847. return merged, nil
  1848. }
  1849. // MarshalBinaryWithContext serializes the internal properties of this AssetSet instance
  1850. // into a byte array leveraging a predefined context.
  1851. func (target *AssetSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1852. // panics are recovered and propagated as errors
  1853. defer func() {
  1854. if r := recover(); r != nil {
  1855. if e, ok := r.(error); ok {
  1856. err = e
  1857. } else if s, ok := r.(string); ok {
  1858. err = fmt.Errorf("Unexpected panic: %s", s)
  1859. } else {
  1860. err = fmt.Errorf("Unexpected panic: %+v", r)
  1861. }
  1862. }
  1863. }()
  1864. buff := ctx.Buffer
  1865. buff.WriteUInt8(AssetsCodecVersion) // version
  1866. if target.aggregateBy == nil {
  1867. buff.WriteUInt8(uint8(0)) // write nil byte
  1868. } else {
  1869. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1870. // --- [begin][write][slice]([]string) ---
  1871. buff.WriteInt(len(target.aggregateBy)) // array length
  1872. for i := 0; i < len(target.aggregateBy); i++ {
  1873. if ctx.IsStringTable() {
  1874. a := ctx.Table.AddOrGet(target.aggregateBy[i])
  1875. buff.WriteInt(a) // write table index
  1876. } else {
  1877. buff.WriteString(target.aggregateBy[i]) // write string
  1878. }
  1879. }
  1880. // --- [end][write][slice]([]string) ---
  1881. }
  1882. if target.assets == nil {
  1883. buff.WriteUInt8(uint8(0)) // write nil byte
  1884. } else {
  1885. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1886. // --- [begin][write][map](map[string]Asset) ---
  1887. buff.WriteInt(len(target.assets)) // map length
  1888. for v, z := range target.assets {
  1889. if ctx.IsStringTable() {
  1890. b := ctx.Table.AddOrGet(v)
  1891. buff.WriteInt(b) // write table index
  1892. } else {
  1893. buff.WriteString(v) // write string
  1894. }
  1895. if z == nil {
  1896. buff.WriteUInt8(uint8(0)) // write nil byte
  1897. } else {
  1898. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1899. // --- [begin][write][interface](Asset) ---
  1900. c := reflect.ValueOf(z).Interface()
  1901. d, okA := c.(BinEncoder)
  1902. if !okA {
  1903. return fmt.Errorf("Type: %s does not implement %s.BinEncoder", typeToString(z), GeneratorPackageName)
  1904. }
  1905. buff.WriteString(typeToString(z))
  1906. buff.WriteInt(0) // [compatibility, unused]
  1907. errA := d.MarshalBinaryWithContext(ctx)
  1908. if errA != nil {
  1909. return errA
  1910. }
  1911. // --- [end][write][interface](Asset) ---
  1912. }
  1913. }
  1914. // --- [end][write][map](map[string]Asset) ---
  1915. }
  1916. if ctx.IsStringTable() {
  1917. e := ctx.Table.AddOrGet(target.FromSource)
  1918. buff.WriteInt(e) // write table index
  1919. } else {
  1920. buff.WriteString(target.FromSource) // write string
  1921. }
  1922. // --- [begin][write][struct](Window) ---
  1923. buff.WriteInt(0) // [compatibility, unused]
  1924. errB := target.Window.MarshalBinaryWithContext(ctx)
  1925. if errB != nil {
  1926. return errB
  1927. }
  1928. // --- [end][write][struct](Window) ---
  1929. if target.Warnings == nil {
  1930. buff.WriteUInt8(uint8(0)) // write nil byte
  1931. } else {
  1932. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1933. // --- [begin][write][slice]([]string) ---
  1934. buff.WriteInt(len(target.Warnings)) // array length
  1935. for j := 0; j < len(target.Warnings); j++ {
  1936. if ctx.IsStringTable() {
  1937. f := ctx.Table.AddOrGet(target.Warnings[j])
  1938. buff.WriteInt(f) // write table index
  1939. } else {
  1940. buff.WriteString(target.Warnings[j]) // write string
  1941. }
  1942. }
  1943. // --- [end][write][slice]([]string) ---
  1944. }
  1945. if target.Errors == nil {
  1946. buff.WriteUInt8(uint8(0)) // write nil byte
  1947. } else {
  1948. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1949. // --- [begin][write][slice]([]string) ---
  1950. buff.WriteInt(len(target.Errors)) // array length
  1951. for ii := 0; ii < len(target.Errors); ii++ {
  1952. if ctx.IsStringTable() {
  1953. g := ctx.Table.AddOrGet(target.Errors[ii])
  1954. buff.WriteInt(g) // write table index
  1955. } else {
  1956. buff.WriteString(target.Errors[ii]) // write string
  1957. }
  1958. }
  1959. // --- [end][write][slice]([]string) ---
  1960. }
  1961. return nil
  1962. }
  1963. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1964. // the AssetSet type
  1965. func (target *AssetSet) UnmarshalBinary(data []byte) error {
  1966. var table []string
  1967. buff := util.NewBufferFromBytes(data)
  1968. // string table header validation
  1969. if isBinaryTag(data, BinaryTagStringTable) {
  1970. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1971. tl := buff.ReadInt() // table length
  1972. if tl > 0 {
  1973. table = make([]string, tl, tl)
  1974. for i := 0; i < tl; i++ {
  1975. table[i] = buff.ReadString()
  1976. }
  1977. }
  1978. }
  1979. ctx := &DecodingContext{
  1980. Buffer: buff,
  1981. Table: table,
  1982. }
  1983. err := target.UnmarshalBinaryWithContext(ctx)
  1984. if err != nil {
  1985. return err
  1986. }
  1987. return nil
  1988. }
  1989. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1990. // the AssetSet type
  1991. func (target *AssetSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1992. // panics are recovered and propagated as errors
  1993. defer func() {
  1994. if r := recover(); r != nil {
  1995. if e, ok := r.(error); ok {
  1996. err = e
  1997. } else if s, ok := r.(string); ok {
  1998. err = fmt.Errorf("Unexpected panic: %s", s)
  1999. } else {
  2000. err = fmt.Errorf("Unexpected panic: %+v", r)
  2001. }
  2002. }
  2003. }()
  2004. buff := ctx.Buffer
  2005. // Codec Version Check
  2006. version := buff.ReadUInt8()
  2007. if version != AssetsCodecVersion {
  2008. return fmt.Errorf("Invalid Version Unmarshaling AssetSet. Expected %d, got %d", AssetsCodecVersion, version)
  2009. }
  2010. if buff.ReadUInt8() == uint8(0) {
  2011. target.aggregateBy = nil
  2012. } else {
  2013. // --- [begin][read][slice]([]string) ---
  2014. b := buff.ReadInt() // array len
  2015. a := make([]string, b)
  2016. for i := 0; i < b; i++ {
  2017. var c string
  2018. var e string
  2019. if ctx.IsStringTable() {
  2020. f := buff.ReadInt() // read string index
  2021. e = ctx.Table[f]
  2022. } else {
  2023. e = buff.ReadString() // read string
  2024. }
  2025. d := e
  2026. c = d
  2027. a[i] = c
  2028. }
  2029. target.aggregateBy = a
  2030. // --- [end][read][slice]([]string) ---
  2031. }
  2032. if buff.ReadUInt8() == uint8(0) {
  2033. target.assets = nil
  2034. } else {
  2035. // --- [begin][read][map](map[string]Asset) ---
  2036. h := buff.ReadInt() // map len
  2037. g := make(map[string]Asset, h)
  2038. for j := 0; j < h; j++ {
  2039. var v string
  2040. var l string
  2041. if ctx.IsStringTable() {
  2042. m := buff.ReadInt() // read string index
  2043. l = ctx.Table[m]
  2044. } else {
  2045. l = buff.ReadString() // read string
  2046. }
  2047. k := l
  2048. v = k
  2049. var z Asset
  2050. if buff.ReadUInt8() == uint8(0) {
  2051. z = nil
  2052. } else {
  2053. // --- [begin][read][interface](Asset) ---
  2054. n := buff.ReadString()
  2055. _, o, _ := resolveType(n)
  2056. if _, ok := typeMap[o]; !ok {
  2057. return fmt.Errorf("Unknown Type: %s", o)
  2058. }
  2059. p, okA := reflect.New(typeMap[o]).Interface().(BinDecoder)
  2060. if !okA {
  2061. return fmt.Errorf("Type: %s does not implement %s.BinDecoder.", o, GeneratorPackageName)
  2062. }
  2063. buff.ReadInt() // [compatibility, unused]
  2064. errA := p.UnmarshalBinaryWithContext(ctx)
  2065. if errA != nil {
  2066. return errA
  2067. }
  2068. z = p.(Asset)
  2069. // --- [end][read][interface](Asset) ---
  2070. }
  2071. g[v] = z
  2072. }
  2073. target.assets = g
  2074. // --- [end][read][map](map[string]Asset) ---
  2075. }
  2076. var r string
  2077. if ctx.IsStringTable() {
  2078. s := buff.ReadInt() // read string index
  2079. r = ctx.Table[s]
  2080. } else {
  2081. r = buff.ReadString() // read string
  2082. }
  2083. q := r
  2084. target.FromSource = q
  2085. // --- [begin][read][struct](Window) ---
  2086. t := &Window{}
  2087. buff.ReadInt() // [compatibility, unused]
  2088. errB := t.UnmarshalBinaryWithContext(ctx)
  2089. if errB != nil {
  2090. return errB
  2091. }
  2092. target.Window = *t
  2093. // --- [end][read][struct](Window) ---
  2094. if buff.ReadUInt8() == uint8(0) {
  2095. target.Warnings = nil
  2096. } else {
  2097. // --- [begin][read][slice]([]string) ---
  2098. w := buff.ReadInt() // array len
  2099. u := make([]string, w)
  2100. for ii := 0; ii < w; ii++ {
  2101. var x string
  2102. var aa string
  2103. if ctx.IsStringTable() {
  2104. bb := buff.ReadInt() // read string index
  2105. aa = ctx.Table[bb]
  2106. } else {
  2107. aa = buff.ReadString() // read string
  2108. }
  2109. y := aa
  2110. x = y
  2111. u[ii] = x
  2112. }
  2113. target.Warnings = u
  2114. // --- [end][read][slice]([]string) ---
  2115. }
  2116. if buff.ReadUInt8() == uint8(0) {
  2117. target.Errors = nil
  2118. } else {
  2119. // --- [begin][read][slice]([]string) ---
  2120. dd := buff.ReadInt() // array len
  2121. cc := make([]string, dd)
  2122. for jj := 0; jj < dd; jj++ {
  2123. var ee string
  2124. var gg string
  2125. if ctx.IsStringTable() {
  2126. hh := buff.ReadInt() // read string index
  2127. gg = ctx.Table[hh]
  2128. } else {
  2129. gg = buff.ReadString() // read string
  2130. }
  2131. ff := gg
  2132. ee = ff
  2133. cc[jj] = ee
  2134. }
  2135. target.Errors = cc
  2136. // --- [end][read][slice]([]string) ---
  2137. }
  2138. return nil
  2139. }
  2140. //--------------------------------------------------------------------------
  2141. // AssetSetRange
  2142. //--------------------------------------------------------------------------
  2143. // MarshalBinary serializes the internal properties of this AssetSetRange instance
  2144. // into a byte array
  2145. func (target *AssetSetRange) MarshalBinary() (data []byte, err error) {
  2146. ctx := &EncodingContext{
  2147. Buffer: util.NewBuffer(),
  2148. Table: nil,
  2149. }
  2150. e := target.MarshalBinaryWithContext(ctx)
  2151. if e != nil {
  2152. return nil, e
  2153. }
  2154. encBytes := ctx.Buffer.Bytes()
  2155. return encBytes, nil
  2156. }
  2157. // MarshalBinaryWithContext serializes the internal properties of this AssetSetRange instance
  2158. // into a byte array leveraging a predefined context.
  2159. func (target *AssetSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2160. // panics are recovered and propagated as errors
  2161. defer func() {
  2162. if r := recover(); r != nil {
  2163. if e, ok := r.(error); ok {
  2164. err = e
  2165. } else if s, ok := r.(string); ok {
  2166. err = fmt.Errorf("Unexpected panic: %s", s)
  2167. } else {
  2168. err = fmt.Errorf("Unexpected panic: %+v", r)
  2169. }
  2170. }
  2171. }()
  2172. buff := ctx.Buffer
  2173. buff.WriteUInt8(AssetsCodecVersion) // version
  2174. if target.assets == nil {
  2175. buff.WriteUInt8(uint8(0)) // write nil byte
  2176. } else {
  2177. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2178. // --- [begin][write][slice]([]*AssetSet) ---
  2179. buff.WriteInt(len(target.assets)) // array length
  2180. for i := 0; i < len(target.assets); i++ {
  2181. if target.assets[i] == nil {
  2182. buff.WriteUInt8(uint8(0)) // write nil byte
  2183. } else {
  2184. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2185. // --- [begin][write][struct](AssetSet) ---
  2186. buff.WriteInt(0) // [compatibility, unused]
  2187. errA := target.assets[i].MarshalBinaryWithContext(ctx)
  2188. if errA != nil {
  2189. return errA
  2190. }
  2191. // --- [end][write][struct](AssetSet) ---
  2192. }
  2193. }
  2194. // --- [end][write][slice]([]*AssetSet) ---
  2195. }
  2196. if ctx.IsStringTable() {
  2197. a := ctx.Table.AddOrGet(target.FromStore)
  2198. buff.WriteInt(a) // write table index
  2199. } else {
  2200. buff.WriteString(target.FromStore) // write string
  2201. }
  2202. return nil
  2203. }
  2204. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2205. // the AssetSetRange type
  2206. func (target *AssetSetRange) UnmarshalBinary(data []byte) error {
  2207. var table []string
  2208. buff := util.NewBufferFromBytes(data)
  2209. // string table header validation
  2210. if isBinaryTag(data, BinaryTagStringTable) {
  2211. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2212. tl := buff.ReadInt() // table length
  2213. if tl > 0 {
  2214. table = make([]string, tl, tl)
  2215. for i := 0; i < tl; i++ {
  2216. table[i] = buff.ReadString()
  2217. }
  2218. }
  2219. }
  2220. ctx := &DecodingContext{
  2221. Buffer: buff,
  2222. Table: table,
  2223. }
  2224. err := target.UnmarshalBinaryWithContext(ctx)
  2225. if err != nil {
  2226. return err
  2227. }
  2228. return nil
  2229. }
  2230. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2231. // the AssetSetRange type
  2232. func (target *AssetSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2233. // panics are recovered and propagated as errors
  2234. defer func() {
  2235. if r := recover(); r != nil {
  2236. if e, ok := r.(error); ok {
  2237. err = e
  2238. } else if s, ok := r.(string); ok {
  2239. err = fmt.Errorf("Unexpected panic: %s", s)
  2240. } else {
  2241. err = fmt.Errorf("Unexpected panic: %+v", r)
  2242. }
  2243. }
  2244. }()
  2245. buff := ctx.Buffer
  2246. // Codec Version Check
  2247. version := buff.ReadUInt8()
  2248. if version != AssetsCodecVersion {
  2249. return fmt.Errorf("Invalid Version Unmarshaling AssetSetRange. Expected %d, got %d", AssetsCodecVersion, version)
  2250. }
  2251. if buff.ReadUInt8() == uint8(0) {
  2252. target.assets = nil
  2253. } else {
  2254. // --- [begin][read][slice]([]*AssetSet) ---
  2255. b := buff.ReadInt() // array len
  2256. a := make([]*AssetSet, b)
  2257. for i := 0; i < b; i++ {
  2258. var c *AssetSet
  2259. if buff.ReadUInt8() == uint8(0) {
  2260. c = nil
  2261. } else {
  2262. // --- [begin][read][struct](AssetSet) ---
  2263. d := &AssetSet{}
  2264. buff.ReadInt() // [compatibility, unused]
  2265. errA := d.UnmarshalBinaryWithContext(ctx)
  2266. if errA != nil {
  2267. return errA
  2268. }
  2269. c = d
  2270. // --- [end][read][struct](AssetSet) ---
  2271. }
  2272. a[i] = c
  2273. }
  2274. target.assets = a
  2275. // --- [end][read][slice]([]*AssetSet) ---
  2276. }
  2277. var f string
  2278. if ctx.IsStringTable() {
  2279. g := buff.ReadInt() // read string index
  2280. f = ctx.Table[g]
  2281. } else {
  2282. f = buff.ReadString() // read string
  2283. }
  2284. e := f
  2285. target.FromStore = e
  2286. return nil
  2287. }
  2288. //--------------------------------------------------------------------------
  2289. // Breakdown
  2290. //--------------------------------------------------------------------------
  2291. // MarshalBinary serializes the internal properties of this Breakdown instance
  2292. // into a byte array
  2293. func (target *Breakdown) MarshalBinary() (data []byte, err error) {
  2294. ctx := &EncodingContext{
  2295. Buffer: util.NewBuffer(),
  2296. Table: nil,
  2297. }
  2298. e := target.MarshalBinaryWithContext(ctx)
  2299. if e != nil {
  2300. return nil, e
  2301. }
  2302. encBytes := ctx.Buffer.Bytes()
  2303. return encBytes, nil
  2304. }
  2305. // MarshalBinaryWithContext serializes the internal properties of this Breakdown instance
  2306. // into a byte array leveraging a predefined context.
  2307. func (target *Breakdown) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2308. // panics are recovered and propagated as errors
  2309. defer func() {
  2310. if r := recover(); r != nil {
  2311. if e, ok := r.(error); ok {
  2312. err = e
  2313. } else if s, ok := r.(string); ok {
  2314. err = fmt.Errorf("Unexpected panic: %s", s)
  2315. } else {
  2316. err = fmt.Errorf("Unexpected panic: %+v", r)
  2317. }
  2318. }
  2319. }()
  2320. buff := ctx.Buffer
  2321. buff.WriteUInt8(AssetsCodecVersion) // version
  2322. buff.WriteFloat64(target.Idle) // write float64
  2323. buff.WriteFloat64(target.Other) // write float64
  2324. buff.WriteFloat64(target.System) // write float64
  2325. buff.WriteFloat64(target.User) // write float64
  2326. return nil
  2327. }
  2328. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2329. // the Breakdown type
  2330. func (target *Breakdown) UnmarshalBinary(data []byte) error {
  2331. var table []string
  2332. buff := util.NewBufferFromBytes(data)
  2333. // string table header validation
  2334. if isBinaryTag(data, BinaryTagStringTable) {
  2335. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2336. tl := buff.ReadInt() // table length
  2337. if tl > 0 {
  2338. table = make([]string, tl, tl)
  2339. for i := 0; i < tl; i++ {
  2340. table[i] = buff.ReadString()
  2341. }
  2342. }
  2343. }
  2344. ctx := &DecodingContext{
  2345. Buffer: buff,
  2346. Table: table,
  2347. }
  2348. err := target.UnmarshalBinaryWithContext(ctx)
  2349. if err != nil {
  2350. return err
  2351. }
  2352. return nil
  2353. }
  2354. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2355. // the Breakdown type
  2356. func (target *Breakdown) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2357. // panics are recovered and propagated as errors
  2358. defer func() {
  2359. if r := recover(); r != nil {
  2360. if e, ok := r.(error); ok {
  2361. err = e
  2362. } else if s, ok := r.(string); ok {
  2363. err = fmt.Errorf("Unexpected panic: %s", s)
  2364. } else {
  2365. err = fmt.Errorf("Unexpected panic: %+v", r)
  2366. }
  2367. }
  2368. }()
  2369. buff := ctx.Buffer
  2370. // Codec Version Check
  2371. version := buff.ReadUInt8()
  2372. if version != AssetsCodecVersion {
  2373. return fmt.Errorf("Invalid Version Unmarshaling Breakdown. Expected %d, got %d", AssetsCodecVersion, version)
  2374. }
  2375. a := buff.ReadFloat64() // read float64
  2376. target.Idle = a
  2377. b := buff.ReadFloat64() // read float64
  2378. target.Other = b
  2379. c := buff.ReadFloat64() // read float64
  2380. target.System = c
  2381. d := buff.ReadFloat64() // read float64
  2382. target.User = d
  2383. return nil
  2384. }
  2385. //--------------------------------------------------------------------------
  2386. // Cloud
  2387. //--------------------------------------------------------------------------
  2388. // MarshalBinary serializes the internal properties of this Cloud instance
  2389. // into a byte array
  2390. func (target *Cloud) MarshalBinary() (data []byte, err error) {
  2391. ctx := &EncodingContext{
  2392. Buffer: util.NewBuffer(),
  2393. Table: nil,
  2394. }
  2395. e := target.MarshalBinaryWithContext(ctx)
  2396. if e != nil {
  2397. return nil, e
  2398. }
  2399. encBytes := ctx.Buffer.Bytes()
  2400. return encBytes, nil
  2401. }
  2402. // MarshalBinaryWithContext serializes the internal properties of this Cloud instance
  2403. // into a byte array leveraging a predefined context.
  2404. func (target *Cloud) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2405. // panics are recovered and propagated as errors
  2406. defer func() {
  2407. if r := recover(); r != nil {
  2408. if e, ok := r.(error); ok {
  2409. err = e
  2410. } else if s, ok := r.(string); ok {
  2411. err = fmt.Errorf("Unexpected panic: %s", s)
  2412. } else {
  2413. err = fmt.Errorf("Unexpected panic: %+v", r)
  2414. }
  2415. }
  2416. }()
  2417. buff := ctx.Buffer
  2418. buff.WriteUInt8(AssetsCodecVersion) // version
  2419. // --- [begin][write][alias](AssetLabels) ---
  2420. if map[string]string(target.labels) == nil {
  2421. buff.WriteUInt8(uint8(0)) // write nil byte
  2422. } else {
  2423. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2424. // --- [begin][write][map](map[string]string) ---
  2425. buff.WriteInt(len(map[string]string(target.labels))) // map length
  2426. for v, z := range map[string]string(target.labels) {
  2427. if ctx.IsStringTable() {
  2428. a := ctx.Table.AddOrGet(v)
  2429. buff.WriteInt(a) // write table index
  2430. } else {
  2431. buff.WriteString(v) // write string
  2432. }
  2433. if ctx.IsStringTable() {
  2434. b := ctx.Table.AddOrGet(z)
  2435. buff.WriteInt(b) // write table index
  2436. } else {
  2437. buff.WriteString(z) // write string
  2438. }
  2439. }
  2440. // --- [end][write][map](map[string]string) ---
  2441. }
  2442. // --- [end][write][alias](AssetLabels) ---
  2443. if target.properties == nil {
  2444. buff.WriteUInt8(uint8(0)) // write nil byte
  2445. } else {
  2446. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2447. // --- [begin][write][struct](AssetProperties) ---
  2448. buff.WriteInt(0) // [compatibility, unused]
  2449. errA := target.properties.MarshalBinaryWithContext(ctx)
  2450. if errA != nil {
  2451. return errA
  2452. }
  2453. // --- [end][write][struct](AssetProperties) ---
  2454. }
  2455. // --- [begin][write][reference](time.Time) ---
  2456. c, errB := target.start.MarshalBinary()
  2457. if errB != nil {
  2458. return errB
  2459. }
  2460. buff.WriteInt(len(c))
  2461. buff.WriteBytes(c)
  2462. // --- [end][write][reference](time.Time) ---
  2463. // --- [begin][write][reference](time.Time) ---
  2464. d, errC := target.end.MarshalBinary()
  2465. if errC != nil {
  2466. return errC
  2467. }
  2468. buff.WriteInt(len(d))
  2469. buff.WriteBytes(d)
  2470. // --- [end][write][reference](time.Time) ---
  2471. // --- [begin][write][struct](Window) ---
  2472. buff.WriteInt(0) // [compatibility, unused]
  2473. errD := target.window.MarshalBinaryWithContext(ctx)
  2474. if errD != nil {
  2475. return errD
  2476. }
  2477. // --- [end][write][struct](Window) ---
  2478. buff.WriteFloat64(target.adjustment) // write float64
  2479. buff.WriteFloat64(target.Cost) // write float64
  2480. buff.WriteFloat64(target.Credit) // write float64
  2481. return nil
  2482. }
  2483. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2484. // the Cloud type
  2485. func (target *Cloud) UnmarshalBinary(data []byte) error {
  2486. var table []string
  2487. buff := util.NewBufferFromBytes(data)
  2488. // string table header validation
  2489. if isBinaryTag(data, BinaryTagStringTable) {
  2490. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2491. tl := buff.ReadInt() // table length
  2492. if tl > 0 {
  2493. table = make([]string, tl, tl)
  2494. for i := 0; i < tl; i++ {
  2495. table[i] = buff.ReadString()
  2496. }
  2497. }
  2498. }
  2499. ctx := &DecodingContext{
  2500. Buffer: buff,
  2501. Table: table,
  2502. }
  2503. err := target.UnmarshalBinaryWithContext(ctx)
  2504. if err != nil {
  2505. return err
  2506. }
  2507. return nil
  2508. }
  2509. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2510. // the Cloud type
  2511. func (target *Cloud) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2512. // panics are recovered and propagated as errors
  2513. defer func() {
  2514. if r := recover(); r != nil {
  2515. if e, ok := r.(error); ok {
  2516. err = e
  2517. } else if s, ok := r.(string); ok {
  2518. err = fmt.Errorf("Unexpected panic: %s", s)
  2519. } else {
  2520. err = fmt.Errorf("Unexpected panic: %+v", r)
  2521. }
  2522. }
  2523. }()
  2524. buff := ctx.Buffer
  2525. // Codec Version Check
  2526. version := buff.ReadUInt8()
  2527. if version != AssetsCodecVersion {
  2528. return fmt.Errorf("Invalid Version Unmarshaling Cloud. Expected %d, got %d", AssetsCodecVersion, version)
  2529. }
  2530. // --- [begin][read][alias](AssetLabels) ---
  2531. var a map[string]string
  2532. if buff.ReadUInt8() == uint8(0) {
  2533. a = nil
  2534. } else {
  2535. // --- [begin][read][map](map[string]string) ---
  2536. c := buff.ReadInt() // map len
  2537. b := make(map[string]string, c)
  2538. for i := 0; i < c; i++ {
  2539. var v string
  2540. var e string
  2541. if ctx.IsStringTable() {
  2542. f := buff.ReadInt() // read string index
  2543. e = ctx.Table[f]
  2544. } else {
  2545. e = buff.ReadString() // read string
  2546. }
  2547. d := e
  2548. v = d
  2549. var z string
  2550. var h string
  2551. if ctx.IsStringTable() {
  2552. k := buff.ReadInt() // read string index
  2553. h = ctx.Table[k]
  2554. } else {
  2555. h = buff.ReadString() // read string
  2556. }
  2557. g := h
  2558. z = g
  2559. b[v] = z
  2560. }
  2561. a = b
  2562. // --- [end][read][map](map[string]string) ---
  2563. }
  2564. target.labels = AssetLabels(a)
  2565. // --- [end][read][alias](AssetLabels) ---
  2566. if buff.ReadUInt8() == uint8(0) {
  2567. target.properties = nil
  2568. } else {
  2569. // --- [begin][read][struct](AssetProperties) ---
  2570. l := &AssetProperties{}
  2571. buff.ReadInt() // [compatibility, unused]
  2572. errA := l.UnmarshalBinaryWithContext(ctx)
  2573. if errA != nil {
  2574. return errA
  2575. }
  2576. target.properties = l
  2577. // --- [end][read][struct](AssetProperties) ---
  2578. }
  2579. // --- [begin][read][reference](time.Time) ---
  2580. m := &time.Time{}
  2581. n := buff.ReadInt() // byte array length
  2582. o := buff.ReadBytes(n) // byte array
  2583. errB := m.UnmarshalBinary(o)
  2584. if errB != nil {
  2585. return errB
  2586. }
  2587. target.start = *m
  2588. // --- [end][read][reference](time.Time) ---
  2589. // --- [begin][read][reference](time.Time) ---
  2590. p := &time.Time{}
  2591. q := buff.ReadInt() // byte array length
  2592. r := buff.ReadBytes(q) // byte array
  2593. errC := p.UnmarshalBinary(r)
  2594. if errC != nil {
  2595. return errC
  2596. }
  2597. target.end = *p
  2598. // --- [end][read][reference](time.Time) ---
  2599. // --- [begin][read][struct](Window) ---
  2600. s := &Window{}
  2601. buff.ReadInt() // [compatibility, unused]
  2602. errD := s.UnmarshalBinaryWithContext(ctx)
  2603. if errD != nil {
  2604. return errD
  2605. }
  2606. target.window = *s
  2607. // --- [end][read][struct](Window) ---
  2608. t := buff.ReadFloat64() // read float64
  2609. target.adjustment = t
  2610. u := buff.ReadFloat64() // read float64
  2611. target.Cost = u
  2612. w := buff.ReadFloat64() // read float64
  2613. target.Credit = w
  2614. return nil
  2615. }
  2616. //--------------------------------------------------------------------------
  2617. // ClusterManagement
  2618. //--------------------------------------------------------------------------
  2619. // MarshalBinary serializes the internal properties of this ClusterManagement instance
  2620. // into a byte array
  2621. func (target *ClusterManagement) MarshalBinary() (data []byte, err error) {
  2622. ctx := &EncodingContext{
  2623. Buffer: util.NewBuffer(),
  2624. Table: nil,
  2625. }
  2626. e := target.MarshalBinaryWithContext(ctx)
  2627. if e != nil {
  2628. return nil, e
  2629. }
  2630. encBytes := ctx.Buffer.Bytes()
  2631. return encBytes, nil
  2632. }
  2633. // MarshalBinaryWithContext serializes the internal properties of this ClusterManagement instance
  2634. // into a byte array leveraging a predefined context.
  2635. func (target *ClusterManagement) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2636. // panics are recovered and propagated as errors
  2637. defer func() {
  2638. if r := recover(); r != nil {
  2639. if e, ok := r.(error); ok {
  2640. err = e
  2641. } else if s, ok := r.(string); ok {
  2642. err = fmt.Errorf("Unexpected panic: %s", s)
  2643. } else {
  2644. err = fmt.Errorf("Unexpected panic: %+v", r)
  2645. }
  2646. }
  2647. }()
  2648. buff := ctx.Buffer
  2649. buff.WriteUInt8(AssetsCodecVersion) // version
  2650. // --- [begin][write][alias](AssetLabels) ---
  2651. if map[string]string(target.labels) == nil {
  2652. buff.WriteUInt8(uint8(0)) // write nil byte
  2653. } else {
  2654. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2655. // --- [begin][write][map](map[string]string) ---
  2656. buff.WriteInt(len(map[string]string(target.labels))) // map length
  2657. for v, z := range map[string]string(target.labels) {
  2658. if ctx.IsStringTable() {
  2659. a := ctx.Table.AddOrGet(v)
  2660. buff.WriteInt(a) // write table index
  2661. } else {
  2662. buff.WriteString(v) // write string
  2663. }
  2664. if ctx.IsStringTable() {
  2665. b := ctx.Table.AddOrGet(z)
  2666. buff.WriteInt(b) // write table index
  2667. } else {
  2668. buff.WriteString(z) // write string
  2669. }
  2670. }
  2671. // --- [end][write][map](map[string]string) ---
  2672. }
  2673. // --- [end][write][alias](AssetLabels) ---
  2674. if target.properties == nil {
  2675. buff.WriteUInt8(uint8(0)) // write nil byte
  2676. } else {
  2677. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2678. // --- [begin][write][struct](AssetProperties) ---
  2679. buff.WriteInt(0) // [compatibility, unused]
  2680. errA := target.properties.MarshalBinaryWithContext(ctx)
  2681. if errA != nil {
  2682. return errA
  2683. }
  2684. // --- [end][write][struct](AssetProperties) ---
  2685. }
  2686. // --- [begin][write][struct](Window) ---
  2687. buff.WriteInt(0) // [compatibility, unused]
  2688. errB := target.window.MarshalBinaryWithContext(ctx)
  2689. if errB != nil {
  2690. return errB
  2691. }
  2692. // --- [end][write][struct](Window) ---
  2693. buff.WriteFloat64(target.Cost) // write float64
  2694. return nil
  2695. }
  2696. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2697. // the ClusterManagement type
  2698. func (target *ClusterManagement) UnmarshalBinary(data []byte) error {
  2699. var table []string
  2700. buff := util.NewBufferFromBytes(data)
  2701. // string table header validation
  2702. if isBinaryTag(data, BinaryTagStringTable) {
  2703. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2704. tl := buff.ReadInt() // table length
  2705. if tl > 0 {
  2706. table = make([]string, tl, tl)
  2707. for i := 0; i < tl; i++ {
  2708. table[i] = buff.ReadString()
  2709. }
  2710. }
  2711. }
  2712. ctx := &DecodingContext{
  2713. Buffer: buff,
  2714. Table: table,
  2715. }
  2716. err := target.UnmarshalBinaryWithContext(ctx)
  2717. if err != nil {
  2718. return err
  2719. }
  2720. return nil
  2721. }
  2722. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2723. // the ClusterManagement type
  2724. func (target *ClusterManagement) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2725. // panics are recovered and propagated as errors
  2726. defer func() {
  2727. if r := recover(); r != nil {
  2728. if e, ok := r.(error); ok {
  2729. err = e
  2730. } else if s, ok := r.(string); ok {
  2731. err = fmt.Errorf("Unexpected panic: %s", s)
  2732. } else {
  2733. err = fmt.Errorf("Unexpected panic: %+v", r)
  2734. }
  2735. }
  2736. }()
  2737. buff := ctx.Buffer
  2738. // Codec Version Check
  2739. version := buff.ReadUInt8()
  2740. if version != AssetsCodecVersion {
  2741. return fmt.Errorf("Invalid Version Unmarshaling ClusterManagement. Expected %d, got %d", AssetsCodecVersion, version)
  2742. }
  2743. // --- [begin][read][alias](AssetLabels) ---
  2744. var a map[string]string
  2745. if buff.ReadUInt8() == uint8(0) {
  2746. a = nil
  2747. } else {
  2748. // --- [begin][read][map](map[string]string) ---
  2749. c := buff.ReadInt() // map len
  2750. b := make(map[string]string, c)
  2751. for i := 0; i < c; i++ {
  2752. var v string
  2753. var e string
  2754. if ctx.IsStringTable() {
  2755. f := buff.ReadInt() // read string index
  2756. e = ctx.Table[f]
  2757. } else {
  2758. e = buff.ReadString() // read string
  2759. }
  2760. d := e
  2761. v = d
  2762. var z string
  2763. var h string
  2764. if ctx.IsStringTable() {
  2765. k := buff.ReadInt() // read string index
  2766. h = ctx.Table[k]
  2767. } else {
  2768. h = buff.ReadString() // read string
  2769. }
  2770. g := h
  2771. z = g
  2772. b[v] = z
  2773. }
  2774. a = b
  2775. // --- [end][read][map](map[string]string) ---
  2776. }
  2777. target.labels = AssetLabels(a)
  2778. // --- [end][read][alias](AssetLabels) ---
  2779. if buff.ReadUInt8() == uint8(0) {
  2780. target.properties = nil
  2781. } else {
  2782. // --- [begin][read][struct](AssetProperties) ---
  2783. l := &AssetProperties{}
  2784. buff.ReadInt() // [compatibility, unused]
  2785. errA := l.UnmarshalBinaryWithContext(ctx)
  2786. if errA != nil {
  2787. return errA
  2788. }
  2789. target.properties = l
  2790. // --- [end][read][struct](AssetProperties) ---
  2791. }
  2792. // --- [begin][read][struct](Window) ---
  2793. m := &Window{}
  2794. buff.ReadInt() // [compatibility, unused]
  2795. errB := m.UnmarshalBinaryWithContext(ctx)
  2796. if errB != nil {
  2797. return errB
  2798. }
  2799. target.window = *m
  2800. // --- [end][read][struct](Window) ---
  2801. n := buff.ReadFloat64() // read float64
  2802. target.Cost = n
  2803. return nil
  2804. }
  2805. //--------------------------------------------------------------------------
  2806. // Disk
  2807. //--------------------------------------------------------------------------
  2808. // MarshalBinary serializes the internal properties of this Disk instance
  2809. // into a byte array
  2810. func (target *Disk) MarshalBinary() (data []byte, err error) {
  2811. ctx := &EncodingContext{
  2812. Buffer: util.NewBuffer(),
  2813. Table: nil,
  2814. }
  2815. e := target.MarshalBinaryWithContext(ctx)
  2816. if e != nil {
  2817. return nil, e
  2818. }
  2819. encBytes := ctx.Buffer.Bytes()
  2820. return encBytes, nil
  2821. }
  2822. // MarshalBinaryWithContext serializes the internal properties of this Disk instance
  2823. // into a byte array leveraging a predefined context.
  2824. func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2825. // panics are recovered and propagated as errors
  2826. defer func() {
  2827. if r := recover(); r != nil {
  2828. if e, ok := r.(error); ok {
  2829. err = e
  2830. } else if s, ok := r.(string); ok {
  2831. err = fmt.Errorf("Unexpected panic: %s", s)
  2832. } else {
  2833. err = fmt.Errorf("Unexpected panic: %+v", r)
  2834. }
  2835. }
  2836. }()
  2837. buff := ctx.Buffer
  2838. buff.WriteUInt8(AssetsCodecVersion) // version
  2839. // --- [begin][write][alias](AssetLabels) ---
  2840. if map[string]string(target.labels) == nil {
  2841. buff.WriteUInt8(uint8(0)) // write nil byte
  2842. } else {
  2843. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2844. // --- [begin][write][map](map[string]string) ---
  2845. buff.WriteInt(len(map[string]string(target.labels))) // map length
  2846. for v, z := range map[string]string(target.labels) {
  2847. if ctx.IsStringTable() {
  2848. a := ctx.Table.AddOrGet(v)
  2849. buff.WriteInt(a) // write table index
  2850. } else {
  2851. buff.WriteString(v) // write string
  2852. }
  2853. if ctx.IsStringTable() {
  2854. b := ctx.Table.AddOrGet(z)
  2855. buff.WriteInt(b) // write table index
  2856. } else {
  2857. buff.WriteString(z) // write string
  2858. }
  2859. }
  2860. // --- [end][write][map](map[string]string) ---
  2861. }
  2862. // --- [end][write][alias](AssetLabels) ---
  2863. if target.properties == nil {
  2864. buff.WriteUInt8(uint8(0)) // write nil byte
  2865. } else {
  2866. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2867. // --- [begin][write][struct](AssetProperties) ---
  2868. buff.WriteInt(0) // [compatibility, unused]
  2869. errA := target.properties.MarshalBinaryWithContext(ctx)
  2870. if errA != nil {
  2871. return errA
  2872. }
  2873. // --- [end][write][struct](AssetProperties) ---
  2874. }
  2875. // --- [begin][write][reference](time.Time) ---
  2876. c, errB := target.start.MarshalBinary()
  2877. if errB != nil {
  2878. return errB
  2879. }
  2880. buff.WriteInt(len(c))
  2881. buff.WriteBytes(c)
  2882. // --- [end][write][reference](time.Time) ---
  2883. // --- [begin][write][reference](time.Time) ---
  2884. d, errC := target.end.MarshalBinary()
  2885. if errC != nil {
  2886. return errC
  2887. }
  2888. buff.WriteInt(len(d))
  2889. buff.WriteBytes(d)
  2890. // --- [end][write][reference](time.Time) ---
  2891. // --- [begin][write][struct](Window) ---
  2892. buff.WriteInt(0) // [compatibility, unused]
  2893. errD := target.window.MarshalBinaryWithContext(ctx)
  2894. if errD != nil {
  2895. return errD
  2896. }
  2897. // --- [end][write][struct](Window) ---
  2898. buff.WriteFloat64(target.adjustment) // write float64
  2899. buff.WriteFloat64(target.Cost) // write float64
  2900. buff.WriteFloat64(target.ByteHours) // write float64
  2901. buff.WriteFloat64(target.Local) // write float64
  2902. if target.Breakdown == nil {
  2903. buff.WriteUInt8(uint8(0)) // write nil byte
  2904. } else {
  2905. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2906. // --- [begin][write][struct](Breakdown) ---
  2907. buff.WriteInt(0) // [compatibility, unused]
  2908. errE := target.Breakdown.MarshalBinaryWithContext(ctx)
  2909. if errE != nil {
  2910. return errE
  2911. }
  2912. // --- [end][write][struct](Breakdown) ---
  2913. }
  2914. return nil
  2915. }
  2916. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2917. // the Disk type
  2918. func (target *Disk) UnmarshalBinary(data []byte) error {
  2919. var table []string
  2920. buff := util.NewBufferFromBytes(data)
  2921. // string table header validation
  2922. if isBinaryTag(data, BinaryTagStringTable) {
  2923. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2924. tl := buff.ReadInt() // table length
  2925. if tl > 0 {
  2926. table = make([]string, tl, tl)
  2927. for i := 0; i < tl; i++ {
  2928. table[i] = buff.ReadString()
  2929. }
  2930. }
  2931. }
  2932. ctx := &DecodingContext{
  2933. Buffer: buff,
  2934. Table: table,
  2935. }
  2936. err := target.UnmarshalBinaryWithContext(ctx)
  2937. if err != nil {
  2938. return err
  2939. }
  2940. return nil
  2941. }
  2942. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2943. // the Disk type
  2944. func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2945. // panics are recovered and propagated as errors
  2946. defer func() {
  2947. if r := recover(); r != nil {
  2948. if e, ok := r.(error); ok {
  2949. err = e
  2950. } else if s, ok := r.(string); ok {
  2951. err = fmt.Errorf("Unexpected panic: %s", s)
  2952. } else {
  2953. err = fmt.Errorf("Unexpected panic: %+v", r)
  2954. }
  2955. }
  2956. }()
  2957. buff := ctx.Buffer
  2958. // Codec Version Check
  2959. version := buff.ReadUInt8()
  2960. if version != AssetsCodecVersion {
  2961. return fmt.Errorf("Invalid Version Unmarshaling Disk. Expected %d, got %d", AssetsCodecVersion, version)
  2962. }
  2963. // --- [begin][read][alias](AssetLabels) ---
  2964. var a map[string]string
  2965. if buff.ReadUInt8() == uint8(0) {
  2966. a = nil
  2967. } else {
  2968. // --- [begin][read][map](map[string]string) ---
  2969. c := buff.ReadInt() // map len
  2970. b := make(map[string]string, c)
  2971. for i := 0; i < c; i++ {
  2972. var v string
  2973. var e string
  2974. if ctx.IsStringTable() {
  2975. f := buff.ReadInt() // read string index
  2976. e = ctx.Table[f]
  2977. } else {
  2978. e = buff.ReadString() // read string
  2979. }
  2980. d := e
  2981. v = d
  2982. var z string
  2983. var h string
  2984. if ctx.IsStringTable() {
  2985. k := buff.ReadInt() // read string index
  2986. h = ctx.Table[k]
  2987. } else {
  2988. h = buff.ReadString() // read string
  2989. }
  2990. g := h
  2991. z = g
  2992. b[v] = z
  2993. }
  2994. a = b
  2995. // --- [end][read][map](map[string]string) ---
  2996. }
  2997. target.labels = AssetLabels(a)
  2998. // --- [end][read][alias](AssetLabels) ---
  2999. if buff.ReadUInt8() == uint8(0) {
  3000. target.properties = nil
  3001. } else {
  3002. // --- [begin][read][struct](AssetProperties) ---
  3003. l := &AssetProperties{}
  3004. buff.ReadInt() // [compatibility, unused]
  3005. errA := l.UnmarshalBinaryWithContext(ctx)
  3006. if errA != nil {
  3007. return errA
  3008. }
  3009. target.properties = l
  3010. // --- [end][read][struct](AssetProperties) ---
  3011. }
  3012. // --- [begin][read][reference](time.Time) ---
  3013. m := &time.Time{}
  3014. n := buff.ReadInt() // byte array length
  3015. o := buff.ReadBytes(n) // byte array
  3016. errB := m.UnmarshalBinary(o)
  3017. if errB != nil {
  3018. return errB
  3019. }
  3020. target.start = *m
  3021. // --- [end][read][reference](time.Time) ---
  3022. // --- [begin][read][reference](time.Time) ---
  3023. p := &time.Time{}
  3024. q := buff.ReadInt() // byte array length
  3025. r := buff.ReadBytes(q) // byte array
  3026. errC := p.UnmarshalBinary(r)
  3027. if errC != nil {
  3028. return errC
  3029. }
  3030. target.end = *p
  3031. // --- [end][read][reference](time.Time) ---
  3032. // --- [begin][read][struct](Window) ---
  3033. s := &Window{}
  3034. buff.ReadInt() // [compatibility, unused]
  3035. errD := s.UnmarshalBinaryWithContext(ctx)
  3036. if errD != nil {
  3037. return errD
  3038. }
  3039. target.window = *s
  3040. // --- [end][read][struct](Window) ---
  3041. t := buff.ReadFloat64() // read float64
  3042. target.adjustment = t
  3043. u := buff.ReadFloat64() // read float64
  3044. target.Cost = u
  3045. w := buff.ReadFloat64() // read float64
  3046. target.ByteHours = w
  3047. x := buff.ReadFloat64() // read float64
  3048. target.Local = x
  3049. if buff.ReadUInt8() == uint8(0) {
  3050. target.Breakdown = nil
  3051. } else {
  3052. // --- [begin][read][struct](Breakdown) ---
  3053. y := &Breakdown{}
  3054. buff.ReadInt() // [compatibility, unused]
  3055. errE := y.UnmarshalBinaryWithContext(ctx)
  3056. if errE != nil {
  3057. return errE
  3058. }
  3059. target.Breakdown = y
  3060. // --- [end][read][struct](Breakdown) ---
  3061. }
  3062. return nil
  3063. }
  3064. //--------------------------------------------------------------------------
  3065. // LoadBalancer
  3066. //--------------------------------------------------------------------------
  3067. // MarshalBinary serializes the internal properties of this LoadBalancer instance
  3068. // into a byte array
  3069. func (target *LoadBalancer) MarshalBinary() (data []byte, err error) {
  3070. ctx := &EncodingContext{
  3071. Buffer: util.NewBuffer(),
  3072. Table: nil,
  3073. }
  3074. e := target.MarshalBinaryWithContext(ctx)
  3075. if e != nil {
  3076. return nil, e
  3077. }
  3078. encBytes := ctx.Buffer.Bytes()
  3079. return encBytes, nil
  3080. }
  3081. // MarshalBinaryWithContext serializes the internal properties of this LoadBalancer instance
  3082. // into a byte array leveraging a predefined context.
  3083. func (target *LoadBalancer) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3084. // panics are recovered and propagated as errors
  3085. defer func() {
  3086. if r := recover(); r != nil {
  3087. if e, ok := r.(error); ok {
  3088. err = e
  3089. } else if s, ok := r.(string); ok {
  3090. err = fmt.Errorf("Unexpected panic: %s", s)
  3091. } else {
  3092. err = fmt.Errorf("Unexpected panic: %+v", r)
  3093. }
  3094. }
  3095. }()
  3096. buff := ctx.Buffer
  3097. buff.WriteUInt8(AssetsCodecVersion) // version
  3098. if target.properties == nil {
  3099. buff.WriteUInt8(uint8(0)) // write nil byte
  3100. } else {
  3101. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3102. // --- [begin][write][struct](AssetProperties) ---
  3103. buff.WriteInt(0) // [compatibility, unused]
  3104. errA := target.properties.MarshalBinaryWithContext(ctx)
  3105. if errA != nil {
  3106. return errA
  3107. }
  3108. // --- [end][write][struct](AssetProperties) ---
  3109. }
  3110. // --- [begin][write][alias](AssetLabels) ---
  3111. if map[string]string(target.labels) == nil {
  3112. buff.WriteUInt8(uint8(0)) // write nil byte
  3113. } else {
  3114. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3115. // --- [begin][write][map](map[string]string) ---
  3116. buff.WriteInt(len(map[string]string(target.labels))) // map length
  3117. for v, z := range map[string]string(target.labels) {
  3118. if ctx.IsStringTable() {
  3119. a := ctx.Table.AddOrGet(v)
  3120. buff.WriteInt(a) // write table index
  3121. } else {
  3122. buff.WriteString(v) // write string
  3123. }
  3124. if ctx.IsStringTable() {
  3125. b := ctx.Table.AddOrGet(z)
  3126. buff.WriteInt(b) // write table index
  3127. } else {
  3128. buff.WriteString(z) // write string
  3129. }
  3130. }
  3131. // --- [end][write][map](map[string]string) ---
  3132. }
  3133. // --- [end][write][alias](AssetLabels) ---
  3134. // --- [begin][write][reference](time.Time) ---
  3135. c, errB := target.start.MarshalBinary()
  3136. if errB != nil {
  3137. return errB
  3138. }
  3139. buff.WriteInt(len(c))
  3140. buff.WriteBytes(c)
  3141. // --- [end][write][reference](time.Time) ---
  3142. // --- [begin][write][reference](time.Time) ---
  3143. d, errC := target.end.MarshalBinary()
  3144. if errC != nil {
  3145. return errC
  3146. }
  3147. buff.WriteInt(len(d))
  3148. buff.WriteBytes(d)
  3149. // --- [end][write][reference](time.Time) ---
  3150. // --- [begin][write][struct](Window) ---
  3151. buff.WriteInt(0) // [compatibility, unused]
  3152. errD := target.window.MarshalBinaryWithContext(ctx)
  3153. if errD != nil {
  3154. return errD
  3155. }
  3156. // --- [end][write][struct](Window) ---
  3157. buff.WriteFloat64(target.adjustment) // write float64
  3158. buff.WriteFloat64(target.Cost) // write float64
  3159. return nil
  3160. }
  3161. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3162. // the LoadBalancer type
  3163. func (target *LoadBalancer) UnmarshalBinary(data []byte) error {
  3164. var table []string
  3165. buff := util.NewBufferFromBytes(data)
  3166. // string table header validation
  3167. if isBinaryTag(data, BinaryTagStringTable) {
  3168. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3169. tl := buff.ReadInt() // table length
  3170. if tl > 0 {
  3171. table = make([]string, tl, tl)
  3172. for i := 0; i < tl; i++ {
  3173. table[i] = buff.ReadString()
  3174. }
  3175. }
  3176. }
  3177. ctx := &DecodingContext{
  3178. Buffer: buff,
  3179. Table: table,
  3180. }
  3181. err := target.UnmarshalBinaryWithContext(ctx)
  3182. if err != nil {
  3183. return err
  3184. }
  3185. return nil
  3186. }
  3187. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3188. // the LoadBalancer type
  3189. func (target *LoadBalancer) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3190. // panics are recovered and propagated as errors
  3191. defer func() {
  3192. if r := recover(); r != nil {
  3193. if e, ok := r.(error); ok {
  3194. err = e
  3195. } else if s, ok := r.(string); ok {
  3196. err = fmt.Errorf("Unexpected panic: %s", s)
  3197. } else {
  3198. err = fmt.Errorf("Unexpected panic: %+v", r)
  3199. }
  3200. }
  3201. }()
  3202. buff := ctx.Buffer
  3203. // Codec Version Check
  3204. version := buff.ReadUInt8()
  3205. if version != AssetsCodecVersion {
  3206. return fmt.Errorf("Invalid Version Unmarshaling LoadBalancer. Expected %d, got %d", AssetsCodecVersion, version)
  3207. }
  3208. if buff.ReadUInt8() == uint8(0) {
  3209. target.properties = nil
  3210. } else {
  3211. // --- [begin][read][struct](AssetProperties) ---
  3212. a := &AssetProperties{}
  3213. buff.ReadInt() // [compatibility, unused]
  3214. errA := a.UnmarshalBinaryWithContext(ctx)
  3215. if errA != nil {
  3216. return errA
  3217. }
  3218. target.properties = a
  3219. // --- [end][read][struct](AssetProperties) ---
  3220. }
  3221. // --- [begin][read][alias](AssetLabels) ---
  3222. var b map[string]string
  3223. if buff.ReadUInt8() == uint8(0) {
  3224. b = nil
  3225. } else {
  3226. // --- [begin][read][map](map[string]string) ---
  3227. d := buff.ReadInt() // map len
  3228. c := make(map[string]string, d)
  3229. for i := 0; i < d; i++ {
  3230. var v string
  3231. var f string
  3232. if ctx.IsStringTable() {
  3233. g := buff.ReadInt() // read string index
  3234. f = ctx.Table[g]
  3235. } else {
  3236. f = buff.ReadString() // read string
  3237. }
  3238. e := f
  3239. v = e
  3240. var z string
  3241. var k string
  3242. if ctx.IsStringTable() {
  3243. l := buff.ReadInt() // read string index
  3244. k = ctx.Table[l]
  3245. } else {
  3246. k = buff.ReadString() // read string
  3247. }
  3248. h := k
  3249. z = h
  3250. c[v] = z
  3251. }
  3252. b = c
  3253. // --- [end][read][map](map[string]string) ---
  3254. }
  3255. target.labels = AssetLabels(b)
  3256. // --- [end][read][alias](AssetLabels) ---
  3257. // --- [begin][read][reference](time.Time) ---
  3258. m := &time.Time{}
  3259. n := buff.ReadInt() // byte array length
  3260. o := buff.ReadBytes(n) // byte array
  3261. errB := m.UnmarshalBinary(o)
  3262. if errB != nil {
  3263. return errB
  3264. }
  3265. target.start = *m
  3266. // --- [end][read][reference](time.Time) ---
  3267. // --- [begin][read][reference](time.Time) ---
  3268. p := &time.Time{}
  3269. q := buff.ReadInt() // byte array length
  3270. r := buff.ReadBytes(q) // byte array
  3271. errC := p.UnmarshalBinary(r)
  3272. if errC != nil {
  3273. return errC
  3274. }
  3275. target.end = *p
  3276. // --- [end][read][reference](time.Time) ---
  3277. // --- [begin][read][struct](Window) ---
  3278. s := &Window{}
  3279. buff.ReadInt() // [compatibility, unused]
  3280. errD := s.UnmarshalBinaryWithContext(ctx)
  3281. if errD != nil {
  3282. return errD
  3283. }
  3284. target.window = *s
  3285. // --- [end][read][struct](Window) ---
  3286. t := buff.ReadFloat64() // read float64
  3287. target.adjustment = t
  3288. u := buff.ReadFloat64() // read float64
  3289. target.Cost = u
  3290. return nil
  3291. }
  3292. //--------------------------------------------------------------------------
  3293. // Network
  3294. //--------------------------------------------------------------------------
  3295. // MarshalBinary serializes the internal properties of this Network instance
  3296. // into a byte array
  3297. func (target *Network) MarshalBinary() (data []byte, err error) {
  3298. ctx := &EncodingContext{
  3299. Buffer: util.NewBuffer(),
  3300. Table: nil,
  3301. }
  3302. e := target.MarshalBinaryWithContext(ctx)
  3303. if e != nil {
  3304. return nil, e
  3305. }
  3306. encBytes := ctx.Buffer.Bytes()
  3307. return encBytes, nil
  3308. }
  3309. // MarshalBinaryWithContext serializes the internal properties of this Network instance
  3310. // into a byte array leveraging a predefined context.
  3311. func (target *Network) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3312. // panics are recovered and propagated as errors
  3313. defer func() {
  3314. if r := recover(); r != nil {
  3315. if e, ok := r.(error); ok {
  3316. err = e
  3317. } else if s, ok := r.(string); ok {
  3318. err = fmt.Errorf("Unexpected panic: %s", s)
  3319. } else {
  3320. err = fmt.Errorf("Unexpected panic: %+v", r)
  3321. }
  3322. }
  3323. }()
  3324. buff := ctx.Buffer
  3325. buff.WriteUInt8(AssetsCodecVersion) // version
  3326. if target.properties == nil {
  3327. buff.WriteUInt8(uint8(0)) // write nil byte
  3328. } else {
  3329. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3330. // --- [begin][write][struct](AssetProperties) ---
  3331. buff.WriteInt(0) // [compatibility, unused]
  3332. errA := target.properties.MarshalBinaryWithContext(ctx)
  3333. if errA != nil {
  3334. return errA
  3335. }
  3336. // --- [end][write][struct](AssetProperties) ---
  3337. }
  3338. // --- [begin][write][alias](AssetLabels) ---
  3339. if map[string]string(target.labels) == nil {
  3340. buff.WriteUInt8(uint8(0)) // write nil byte
  3341. } else {
  3342. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3343. // --- [begin][write][map](map[string]string) ---
  3344. buff.WriteInt(len(map[string]string(target.labels))) // map length
  3345. for v, z := range map[string]string(target.labels) {
  3346. if ctx.IsStringTable() {
  3347. a := ctx.Table.AddOrGet(v)
  3348. buff.WriteInt(a) // write table index
  3349. } else {
  3350. buff.WriteString(v) // write string
  3351. }
  3352. if ctx.IsStringTable() {
  3353. b := ctx.Table.AddOrGet(z)
  3354. buff.WriteInt(b) // write table index
  3355. } else {
  3356. buff.WriteString(z) // write string
  3357. }
  3358. }
  3359. // --- [end][write][map](map[string]string) ---
  3360. }
  3361. // --- [end][write][alias](AssetLabels) ---
  3362. // --- [begin][write][reference](time.Time) ---
  3363. c, errB := target.start.MarshalBinary()
  3364. if errB != nil {
  3365. return errB
  3366. }
  3367. buff.WriteInt(len(c))
  3368. buff.WriteBytes(c)
  3369. // --- [end][write][reference](time.Time) ---
  3370. // --- [begin][write][reference](time.Time) ---
  3371. d, errC := target.end.MarshalBinary()
  3372. if errC != nil {
  3373. return errC
  3374. }
  3375. buff.WriteInt(len(d))
  3376. buff.WriteBytes(d)
  3377. // --- [end][write][reference](time.Time) ---
  3378. // --- [begin][write][struct](Window) ---
  3379. buff.WriteInt(0) // [compatibility, unused]
  3380. errD := target.window.MarshalBinaryWithContext(ctx)
  3381. if errD != nil {
  3382. return errD
  3383. }
  3384. // --- [end][write][struct](Window) ---
  3385. buff.WriteFloat64(target.adjustment) // write float64
  3386. buff.WriteFloat64(target.Cost) // write float64
  3387. return nil
  3388. }
  3389. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3390. // the Network type
  3391. func (target *Network) UnmarshalBinary(data []byte) error {
  3392. var table []string
  3393. buff := util.NewBufferFromBytes(data)
  3394. // string table header validation
  3395. if isBinaryTag(data, BinaryTagStringTable) {
  3396. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3397. tl := buff.ReadInt() // table length
  3398. if tl > 0 {
  3399. table = make([]string, tl, tl)
  3400. for i := 0; i < tl; i++ {
  3401. table[i] = buff.ReadString()
  3402. }
  3403. }
  3404. }
  3405. ctx := &DecodingContext{
  3406. Buffer: buff,
  3407. Table: table,
  3408. }
  3409. err := target.UnmarshalBinaryWithContext(ctx)
  3410. if err != nil {
  3411. return err
  3412. }
  3413. return nil
  3414. }
  3415. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3416. // the Network type
  3417. func (target *Network) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3418. // panics are recovered and propagated as errors
  3419. defer func() {
  3420. if r := recover(); r != nil {
  3421. if e, ok := r.(error); ok {
  3422. err = e
  3423. } else if s, ok := r.(string); ok {
  3424. err = fmt.Errorf("Unexpected panic: %s", s)
  3425. } else {
  3426. err = fmt.Errorf("Unexpected panic: %+v", r)
  3427. }
  3428. }
  3429. }()
  3430. buff := ctx.Buffer
  3431. // Codec Version Check
  3432. version := buff.ReadUInt8()
  3433. if version != AssetsCodecVersion {
  3434. return fmt.Errorf("Invalid Version Unmarshaling Network. Expected %d, got %d", AssetsCodecVersion, version)
  3435. }
  3436. if buff.ReadUInt8() == uint8(0) {
  3437. target.properties = nil
  3438. } else {
  3439. // --- [begin][read][struct](AssetProperties) ---
  3440. a := &AssetProperties{}
  3441. buff.ReadInt() // [compatibility, unused]
  3442. errA := a.UnmarshalBinaryWithContext(ctx)
  3443. if errA != nil {
  3444. return errA
  3445. }
  3446. target.properties = a
  3447. // --- [end][read][struct](AssetProperties) ---
  3448. }
  3449. // --- [begin][read][alias](AssetLabels) ---
  3450. var b map[string]string
  3451. if buff.ReadUInt8() == uint8(0) {
  3452. b = nil
  3453. } else {
  3454. // --- [begin][read][map](map[string]string) ---
  3455. d := buff.ReadInt() // map len
  3456. c := make(map[string]string, d)
  3457. for i := 0; i < d; i++ {
  3458. var v string
  3459. var f string
  3460. if ctx.IsStringTable() {
  3461. g := buff.ReadInt() // read string index
  3462. f = ctx.Table[g]
  3463. } else {
  3464. f = buff.ReadString() // read string
  3465. }
  3466. e := f
  3467. v = e
  3468. var z string
  3469. var k string
  3470. if ctx.IsStringTable() {
  3471. l := buff.ReadInt() // read string index
  3472. k = ctx.Table[l]
  3473. } else {
  3474. k = buff.ReadString() // read string
  3475. }
  3476. h := k
  3477. z = h
  3478. c[v] = z
  3479. }
  3480. b = c
  3481. // --- [end][read][map](map[string]string) ---
  3482. }
  3483. target.labels = AssetLabels(b)
  3484. // --- [end][read][alias](AssetLabels) ---
  3485. // --- [begin][read][reference](time.Time) ---
  3486. m := &time.Time{}
  3487. n := buff.ReadInt() // byte array length
  3488. o := buff.ReadBytes(n) // byte array
  3489. errB := m.UnmarshalBinary(o)
  3490. if errB != nil {
  3491. return errB
  3492. }
  3493. target.start = *m
  3494. // --- [end][read][reference](time.Time) ---
  3495. // --- [begin][read][reference](time.Time) ---
  3496. p := &time.Time{}
  3497. q := buff.ReadInt() // byte array length
  3498. r := buff.ReadBytes(q) // byte array
  3499. errC := p.UnmarshalBinary(r)
  3500. if errC != nil {
  3501. return errC
  3502. }
  3503. target.end = *p
  3504. // --- [end][read][reference](time.Time) ---
  3505. // --- [begin][read][struct](Window) ---
  3506. s := &Window{}
  3507. buff.ReadInt() // [compatibility, unused]
  3508. errD := s.UnmarshalBinaryWithContext(ctx)
  3509. if errD != nil {
  3510. return errD
  3511. }
  3512. target.window = *s
  3513. // --- [end][read][struct](Window) ---
  3514. t := buff.ReadFloat64() // read float64
  3515. target.adjustment = t
  3516. u := buff.ReadFloat64() // read float64
  3517. target.Cost = u
  3518. return nil
  3519. }
  3520. //--------------------------------------------------------------------------
  3521. // Node
  3522. //--------------------------------------------------------------------------
  3523. // MarshalBinary serializes the internal properties of this Node instance
  3524. // into a byte array
  3525. func (target *Node) MarshalBinary() (data []byte, err error) {
  3526. ctx := &EncodingContext{
  3527. Buffer: util.NewBuffer(),
  3528. Table: nil,
  3529. }
  3530. e := target.MarshalBinaryWithContext(ctx)
  3531. if e != nil {
  3532. return nil, e
  3533. }
  3534. encBytes := ctx.Buffer.Bytes()
  3535. return encBytes, nil
  3536. }
  3537. // MarshalBinaryWithContext serializes the internal properties of this Node instance
  3538. // into a byte array leveraging a predefined context.
  3539. func (target *Node) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3540. // panics are recovered and propagated as errors
  3541. defer func() {
  3542. if r := recover(); r != nil {
  3543. if e, ok := r.(error); ok {
  3544. err = e
  3545. } else if s, ok := r.(string); ok {
  3546. err = fmt.Errorf("Unexpected panic: %s", s)
  3547. } else {
  3548. err = fmt.Errorf("Unexpected panic: %+v", r)
  3549. }
  3550. }
  3551. }()
  3552. buff := ctx.Buffer
  3553. buff.WriteUInt8(AssetsCodecVersion) // version
  3554. if target.properties == nil {
  3555. buff.WriteUInt8(uint8(0)) // write nil byte
  3556. } else {
  3557. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3558. // --- [begin][write][struct](AssetProperties) ---
  3559. buff.WriteInt(0) // [compatibility, unused]
  3560. errA := target.properties.MarshalBinaryWithContext(ctx)
  3561. if errA != nil {
  3562. return errA
  3563. }
  3564. // --- [end][write][struct](AssetProperties) ---
  3565. }
  3566. // --- [begin][write][alias](AssetLabels) ---
  3567. if map[string]string(target.labels) == nil {
  3568. buff.WriteUInt8(uint8(0)) // write nil byte
  3569. } else {
  3570. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3571. // --- [begin][write][map](map[string]string) ---
  3572. buff.WriteInt(len(map[string]string(target.labels))) // map length
  3573. for v, z := range map[string]string(target.labels) {
  3574. if ctx.IsStringTable() {
  3575. a := ctx.Table.AddOrGet(v)
  3576. buff.WriteInt(a) // write table index
  3577. } else {
  3578. buff.WriteString(v) // write string
  3579. }
  3580. if ctx.IsStringTable() {
  3581. b := ctx.Table.AddOrGet(z)
  3582. buff.WriteInt(b) // write table index
  3583. } else {
  3584. buff.WriteString(z) // write string
  3585. }
  3586. }
  3587. // --- [end][write][map](map[string]string) ---
  3588. }
  3589. // --- [end][write][alias](AssetLabels) ---
  3590. // --- [begin][write][reference](time.Time) ---
  3591. c, errB := target.start.MarshalBinary()
  3592. if errB != nil {
  3593. return errB
  3594. }
  3595. buff.WriteInt(len(c))
  3596. buff.WriteBytes(c)
  3597. // --- [end][write][reference](time.Time) ---
  3598. // --- [begin][write][reference](time.Time) ---
  3599. d, errC := target.end.MarshalBinary()
  3600. if errC != nil {
  3601. return errC
  3602. }
  3603. buff.WriteInt(len(d))
  3604. buff.WriteBytes(d)
  3605. // --- [end][write][reference](time.Time) ---
  3606. // --- [begin][write][struct](Window) ---
  3607. buff.WriteInt(0) // [compatibility, unused]
  3608. errD := target.window.MarshalBinaryWithContext(ctx)
  3609. if errD != nil {
  3610. return errD
  3611. }
  3612. // --- [end][write][struct](Window) ---
  3613. buff.WriteFloat64(target.adjustment) // write float64
  3614. if ctx.IsStringTable() {
  3615. e := ctx.Table.AddOrGet(target.NodeType)
  3616. buff.WriteInt(e) // write table index
  3617. } else {
  3618. buff.WriteString(target.NodeType) // write string
  3619. }
  3620. buff.WriteFloat64(target.CPUCoreHours) // write float64
  3621. buff.WriteFloat64(target.RAMByteHours) // write float64
  3622. buff.WriteFloat64(target.GPUHours) // write float64
  3623. if target.CPUBreakdown == nil {
  3624. buff.WriteUInt8(uint8(0)) // write nil byte
  3625. } else {
  3626. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3627. // --- [begin][write][struct](Breakdown) ---
  3628. buff.WriteInt(0) // [compatibility, unused]
  3629. errE := target.CPUBreakdown.MarshalBinaryWithContext(ctx)
  3630. if errE != nil {
  3631. return errE
  3632. }
  3633. // --- [end][write][struct](Breakdown) ---
  3634. }
  3635. if target.RAMBreakdown == nil {
  3636. buff.WriteUInt8(uint8(0)) // write nil byte
  3637. } else {
  3638. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3639. // --- [begin][write][struct](Breakdown) ---
  3640. buff.WriteInt(0) // [compatibility, unused]
  3641. errF := target.RAMBreakdown.MarshalBinaryWithContext(ctx)
  3642. if errF != nil {
  3643. return errF
  3644. }
  3645. // --- [end][write][struct](Breakdown) ---
  3646. }
  3647. buff.WriteFloat64(target.CPUCost) // write float64
  3648. buff.WriteFloat64(target.GPUCost) // write float64
  3649. buff.WriteFloat64(target.GPUCount) // write float64
  3650. buff.WriteFloat64(target.RAMCost) // write float64
  3651. buff.WriteFloat64(target.Discount) // write float64
  3652. buff.WriteFloat64(target.Preemptible) // write float64
  3653. return nil
  3654. }
  3655. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3656. // the Node type
  3657. func (target *Node) UnmarshalBinary(data []byte) error {
  3658. var table []string
  3659. buff := util.NewBufferFromBytes(data)
  3660. // string table header validation
  3661. if isBinaryTag(data, BinaryTagStringTable) {
  3662. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3663. tl := buff.ReadInt() // table length
  3664. if tl > 0 {
  3665. table = make([]string, tl, tl)
  3666. for i := 0; i < tl; i++ {
  3667. table[i] = buff.ReadString()
  3668. }
  3669. }
  3670. }
  3671. ctx := &DecodingContext{
  3672. Buffer: buff,
  3673. Table: table,
  3674. }
  3675. err := target.UnmarshalBinaryWithContext(ctx)
  3676. if err != nil {
  3677. return err
  3678. }
  3679. return nil
  3680. }
  3681. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3682. // the Node type
  3683. func (target *Node) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3684. // panics are recovered and propagated as errors
  3685. defer func() {
  3686. if r := recover(); r != nil {
  3687. if e, ok := r.(error); ok {
  3688. err = e
  3689. } else if s, ok := r.(string); ok {
  3690. err = fmt.Errorf("Unexpected panic: %s", s)
  3691. } else {
  3692. err = fmt.Errorf("Unexpected panic: %+v", r)
  3693. }
  3694. }
  3695. }()
  3696. buff := ctx.Buffer
  3697. // Codec Version Check
  3698. version := buff.ReadUInt8()
  3699. if version != AssetsCodecVersion {
  3700. return fmt.Errorf("Invalid Version Unmarshaling Node. Expected %d, got %d", AssetsCodecVersion, version)
  3701. }
  3702. if buff.ReadUInt8() == uint8(0) {
  3703. target.properties = nil
  3704. } else {
  3705. // --- [begin][read][struct](AssetProperties) ---
  3706. a := &AssetProperties{}
  3707. buff.ReadInt() // [compatibility, unused]
  3708. errA := a.UnmarshalBinaryWithContext(ctx)
  3709. if errA != nil {
  3710. return errA
  3711. }
  3712. target.properties = a
  3713. // --- [end][read][struct](AssetProperties) ---
  3714. }
  3715. // --- [begin][read][alias](AssetLabels) ---
  3716. var b map[string]string
  3717. if buff.ReadUInt8() == uint8(0) {
  3718. b = nil
  3719. } else {
  3720. // --- [begin][read][map](map[string]string) ---
  3721. d := buff.ReadInt() // map len
  3722. c := make(map[string]string, d)
  3723. for i := 0; i < d; i++ {
  3724. var v string
  3725. var f string
  3726. if ctx.IsStringTable() {
  3727. g := buff.ReadInt() // read string index
  3728. f = ctx.Table[g]
  3729. } else {
  3730. f = buff.ReadString() // read string
  3731. }
  3732. e := f
  3733. v = e
  3734. var z string
  3735. var k string
  3736. if ctx.IsStringTable() {
  3737. l := buff.ReadInt() // read string index
  3738. k = ctx.Table[l]
  3739. } else {
  3740. k = buff.ReadString() // read string
  3741. }
  3742. h := k
  3743. z = h
  3744. c[v] = z
  3745. }
  3746. b = c
  3747. // --- [end][read][map](map[string]string) ---
  3748. }
  3749. target.labels = AssetLabels(b)
  3750. // --- [end][read][alias](AssetLabels) ---
  3751. // --- [begin][read][reference](time.Time) ---
  3752. m := &time.Time{}
  3753. n := buff.ReadInt() // byte array length
  3754. o := buff.ReadBytes(n) // byte array
  3755. errB := m.UnmarshalBinary(o)
  3756. if errB != nil {
  3757. return errB
  3758. }
  3759. target.start = *m
  3760. // --- [end][read][reference](time.Time) ---
  3761. // --- [begin][read][reference](time.Time) ---
  3762. p := &time.Time{}
  3763. q := buff.ReadInt() // byte array length
  3764. r := buff.ReadBytes(q) // byte array
  3765. errC := p.UnmarshalBinary(r)
  3766. if errC != nil {
  3767. return errC
  3768. }
  3769. target.end = *p
  3770. // --- [end][read][reference](time.Time) ---
  3771. // --- [begin][read][struct](Window) ---
  3772. s := &Window{}
  3773. buff.ReadInt() // [compatibility, unused]
  3774. errD := s.UnmarshalBinaryWithContext(ctx)
  3775. if errD != nil {
  3776. return errD
  3777. }
  3778. target.window = *s
  3779. // --- [end][read][struct](Window) ---
  3780. t := buff.ReadFloat64() // read float64
  3781. target.adjustment = t
  3782. var w string
  3783. if ctx.IsStringTable() {
  3784. x := buff.ReadInt() // read string index
  3785. w = ctx.Table[x]
  3786. } else {
  3787. w = buff.ReadString() // read string
  3788. }
  3789. u := w
  3790. target.NodeType = u
  3791. y := buff.ReadFloat64() // read float64
  3792. target.CPUCoreHours = y
  3793. aa := buff.ReadFloat64() // read float64
  3794. target.RAMByteHours = aa
  3795. bb := buff.ReadFloat64() // read float64
  3796. target.GPUHours = bb
  3797. if buff.ReadUInt8() == uint8(0) {
  3798. target.CPUBreakdown = nil
  3799. } else {
  3800. // --- [begin][read][struct](Breakdown) ---
  3801. cc := &Breakdown{}
  3802. buff.ReadInt() // [compatibility, unused]
  3803. errE := cc.UnmarshalBinaryWithContext(ctx)
  3804. if errE != nil {
  3805. return errE
  3806. }
  3807. target.CPUBreakdown = cc
  3808. // --- [end][read][struct](Breakdown) ---
  3809. }
  3810. if buff.ReadUInt8() == uint8(0) {
  3811. target.RAMBreakdown = nil
  3812. } else {
  3813. // --- [begin][read][struct](Breakdown) ---
  3814. dd := &Breakdown{}
  3815. buff.ReadInt() // [compatibility, unused]
  3816. errF := dd.UnmarshalBinaryWithContext(ctx)
  3817. if errF != nil {
  3818. return errF
  3819. }
  3820. target.RAMBreakdown = dd
  3821. // --- [end][read][struct](Breakdown) ---
  3822. }
  3823. ee := buff.ReadFloat64() // read float64
  3824. target.CPUCost = ee
  3825. ff := buff.ReadFloat64() // read float64
  3826. target.GPUCost = ff
  3827. gg := buff.ReadFloat64() // read float64
  3828. target.GPUCount = gg
  3829. hh := buff.ReadFloat64() // read float64
  3830. target.RAMCost = hh
  3831. kk := buff.ReadFloat64() // read float64
  3832. target.Discount = kk
  3833. ll := buff.ReadFloat64() // read float64
  3834. target.Preemptible = ll
  3835. return nil
  3836. }
  3837. //--------------------------------------------------------------------------
  3838. // PVAllocation
  3839. //--------------------------------------------------------------------------
  3840. // MarshalBinary serializes the internal properties of this PVAllocation instance
  3841. // into a byte array
  3842. func (target *PVAllocation) MarshalBinary() (data []byte, err error) {
  3843. ctx := &EncodingContext{
  3844. Buffer: util.NewBuffer(),
  3845. Table: nil,
  3846. }
  3847. e := target.MarshalBinaryWithContext(ctx)
  3848. if e != nil {
  3849. return nil, e
  3850. }
  3851. encBytes := ctx.Buffer.Bytes()
  3852. return encBytes, nil
  3853. }
  3854. // MarshalBinaryWithContext serializes the internal properties of this PVAllocation instance
  3855. // into a byte array leveraging a predefined context.
  3856. func (target *PVAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3857. // panics are recovered and propagated as errors
  3858. defer func() {
  3859. if r := recover(); r != nil {
  3860. if e, ok := r.(error); ok {
  3861. err = e
  3862. } else if s, ok := r.(string); ok {
  3863. err = fmt.Errorf("Unexpected panic: %s", s)
  3864. } else {
  3865. err = fmt.Errorf("Unexpected panic: %+v", r)
  3866. }
  3867. }
  3868. }()
  3869. buff := ctx.Buffer
  3870. buff.WriteUInt8(AllocationCodecVersion) // version
  3871. buff.WriteFloat64(target.ByteHours) // write float64
  3872. buff.WriteFloat64(target.Cost) // write float64
  3873. return nil
  3874. }
  3875. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3876. // the PVAllocation type
  3877. func (target *PVAllocation) UnmarshalBinary(data []byte) error {
  3878. var table []string
  3879. buff := util.NewBufferFromBytes(data)
  3880. // string table header validation
  3881. if isBinaryTag(data, BinaryTagStringTable) {
  3882. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3883. tl := buff.ReadInt() // table length
  3884. if tl > 0 {
  3885. table = make([]string, tl, tl)
  3886. for i := 0; i < tl; i++ {
  3887. table[i] = buff.ReadString()
  3888. }
  3889. }
  3890. }
  3891. ctx := &DecodingContext{
  3892. Buffer: buff,
  3893. Table: table,
  3894. }
  3895. err := target.UnmarshalBinaryWithContext(ctx)
  3896. if err != nil {
  3897. return err
  3898. }
  3899. return nil
  3900. }
  3901. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3902. // the PVAllocation type
  3903. func (target *PVAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3904. // panics are recovered and propagated as errors
  3905. defer func() {
  3906. if r := recover(); r != nil {
  3907. if e, ok := r.(error); ok {
  3908. err = e
  3909. } else if s, ok := r.(string); ok {
  3910. err = fmt.Errorf("Unexpected panic: %s", s)
  3911. } else {
  3912. err = fmt.Errorf("Unexpected panic: %+v", r)
  3913. }
  3914. }
  3915. }()
  3916. buff := ctx.Buffer
  3917. // Codec Version Check
  3918. version := buff.ReadUInt8()
  3919. if version != AllocationCodecVersion {
  3920. return fmt.Errorf("Invalid Version Unmarshaling PVAllocation. Expected %d, got %d", AllocationCodecVersion, version)
  3921. }
  3922. a := buff.ReadFloat64() // read float64
  3923. target.ByteHours = a
  3924. b := buff.ReadFloat64() // read float64
  3925. target.Cost = b
  3926. return nil
  3927. }
  3928. //--------------------------------------------------------------------------
  3929. // PVKey
  3930. //--------------------------------------------------------------------------
  3931. // MarshalBinary serializes the internal properties of this PVKey instance
  3932. // into a byte array
  3933. func (target *PVKey) MarshalBinary() (data []byte, err error) {
  3934. ctx := &EncodingContext{
  3935. Buffer: util.NewBuffer(),
  3936. Table: nil,
  3937. }
  3938. e := target.MarshalBinaryWithContext(ctx)
  3939. if e != nil {
  3940. return nil, e
  3941. }
  3942. encBytes := ctx.Buffer.Bytes()
  3943. return encBytes, nil
  3944. }
  3945. // MarshalBinaryWithContext serializes the internal properties of this PVKey instance
  3946. // into a byte array leveraging a predefined context.
  3947. func (target *PVKey) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3948. // panics are recovered and propagated as errors
  3949. defer func() {
  3950. if r := recover(); r != nil {
  3951. if e, ok := r.(error); ok {
  3952. err = e
  3953. } else if s, ok := r.(string); ok {
  3954. err = fmt.Errorf("Unexpected panic: %s", s)
  3955. } else {
  3956. err = fmt.Errorf("Unexpected panic: %+v", r)
  3957. }
  3958. }
  3959. }()
  3960. buff := ctx.Buffer
  3961. buff.WriteUInt8(AllocationCodecVersion) // version
  3962. if ctx.IsStringTable() {
  3963. a := ctx.Table.AddOrGet(target.Cluster)
  3964. buff.WriteInt(a) // write table index
  3965. } else {
  3966. buff.WriteString(target.Cluster) // write string
  3967. }
  3968. if ctx.IsStringTable() {
  3969. b := ctx.Table.AddOrGet(target.Name)
  3970. buff.WriteInt(b) // write table index
  3971. } else {
  3972. buff.WriteString(target.Name) // write string
  3973. }
  3974. return nil
  3975. }
  3976. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3977. // the PVKey type
  3978. func (target *PVKey) UnmarshalBinary(data []byte) error {
  3979. var table []string
  3980. buff := util.NewBufferFromBytes(data)
  3981. // string table header validation
  3982. if isBinaryTag(data, BinaryTagStringTable) {
  3983. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3984. tl := buff.ReadInt() // table length
  3985. if tl > 0 {
  3986. table = make([]string, tl, tl)
  3987. for i := 0; i < tl; i++ {
  3988. table[i] = buff.ReadString()
  3989. }
  3990. }
  3991. }
  3992. ctx := &DecodingContext{
  3993. Buffer: buff,
  3994. Table: table,
  3995. }
  3996. err := target.UnmarshalBinaryWithContext(ctx)
  3997. if err != nil {
  3998. return err
  3999. }
  4000. return nil
  4001. }
  4002. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4003. // the PVKey type
  4004. func (target *PVKey) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4005. // panics are recovered and propagated as errors
  4006. defer func() {
  4007. if r := recover(); r != nil {
  4008. if e, ok := r.(error); ok {
  4009. err = e
  4010. } else if s, ok := r.(string); ok {
  4011. err = fmt.Errorf("Unexpected panic: %s", s)
  4012. } else {
  4013. err = fmt.Errorf("Unexpected panic: %+v", r)
  4014. }
  4015. }
  4016. }()
  4017. buff := ctx.Buffer
  4018. // Codec Version Check
  4019. version := buff.ReadUInt8()
  4020. if version != AllocationCodecVersion {
  4021. return fmt.Errorf("Invalid Version Unmarshaling PVKey. Expected %d, got %d", AllocationCodecVersion, version)
  4022. }
  4023. var b string
  4024. if ctx.IsStringTable() {
  4025. c := buff.ReadInt() // read string index
  4026. b = ctx.Table[c]
  4027. } else {
  4028. b = buff.ReadString() // read string
  4029. }
  4030. a := b
  4031. target.Cluster = a
  4032. var e string
  4033. if ctx.IsStringTable() {
  4034. f := buff.ReadInt() // read string index
  4035. e = ctx.Table[f]
  4036. } else {
  4037. e = buff.ReadString() // read string
  4038. }
  4039. d := e
  4040. target.Name = d
  4041. return nil
  4042. }
  4043. //--------------------------------------------------------------------------
  4044. // RawAllocationOnlyData
  4045. //--------------------------------------------------------------------------
  4046. // MarshalBinary serializes the internal properties of this RawAllocationOnlyData instance
  4047. // into a byte array
  4048. func (target *RawAllocationOnlyData) MarshalBinary() (data []byte, err error) {
  4049. ctx := &EncodingContext{
  4050. Buffer: util.NewBuffer(),
  4051. Table: nil,
  4052. }
  4053. e := target.MarshalBinaryWithContext(ctx)
  4054. if e != nil {
  4055. return nil, e
  4056. }
  4057. encBytes := ctx.Buffer.Bytes()
  4058. return encBytes, nil
  4059. }
  4060. // MarshalBinaryWithContext serializes the internal properties of this RawAllocationOnlyData instance
  4061. // into a byte array leveraging a predefined context.
  4062. func (target *RawAllocationOnlyData) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4063. // panics are recovered and propagated as errors
  4064. defer func() {
  4065. if r := recover(); r != nil {
  4066. if e, ok := r.(error); ok {
  4067. err = e
  4068. } else if s, ok := r.(string); ok {
  4069. err = fmt.Errorf("Unexpected panic: %s", s)
  4070. } else {
  4071. err = fmt.Errorf("Unexpected panic: %+v", r)
  4072. }
  4073. }
  4074. }()
  4075. buff := ctx.Buffer
  4076. buff.WriteUInt8(AllocationCodecVersion) // version
  4077. buff.WriteFloat64(target.CPUCoreUsageMax) // write float64
  4078. buff.WriteFloat64(target.RAMBytesUsageMax) // write float64
  4079. return nil
  4080. }
  4081. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4082. // the RawAllocationOnlyData type
  4083. func (target *RawAllocationOnlyData) UnmarshalBinary(data []byte) error {
  4084. var table []string
  4085. buff := util.NewBufferFromBytes(data)
  4086. // string table header validation
  4087. if isBinaryTag(data, BinaryTagStringTable) {
  4088. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4089. tl := buff.ReadInt() // table length
  4090. if tl > 0 {
  4091. table = make([]string, tl, tl)
  4092. for i := 0; i < tl; i++ {
  4093. table[i] = buff.ReadString()
  4094. }
  4095. }
  4096. }
  4097. ctx := &DecodingContext{
  4098. Buffer: buff,
  4099. Table: table,
  4100. }
  4101. err := target.UnmarshalBinaryWithContext(ctx)
  4102. if err != nil {
  4103. return err
  4104. }
  4105. return nil
  4106. }
  4107. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4108. // the RawAllocationOnlyData type
  4109. func (target *RawAllocationOnlyData) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4110. // panics are recovered and propagated as errors
  4111. defer func() {
  4112. if r := recover(); r != nil {
  4113. if e, ok := r.(error); ok {
  4114. err = e
  4115. } else if s, ok := r.(string); ok {
  4116. err = fmt.Errorf("Unexpected panic: %s", s)
  4117. } else {
  4118. err = fmt.Errorf("Unexpected panic: %+v", r)
  4119. }
  4120. }
  4121. }()
  4122. buff := ctx.Buffer
  4123. // Codec Version Check
  4124. version := buff.ReadUInt8()
  4125. if version != AllocationCodecVersion {
  4126. return fmt.Errorf("Invalid Version Unmarshaling RawAllocationOnlyData. Expected %d, got %d", AllocationCodecVersion, version)
  4127. }
  4128. a := buff.ReadFloat64() // read float64
  4129. target.CPUCoreUsageMax = a
  4130. b := buff.ReadFloat64() // read float64
  4131. target.RAMBytesUsageMax = b
  4132. return nil
  4133. }
  4134. //--------------------------------------------------------------------------
  4135. // SharedAsset
  4136. //--------------------------------------------------------------------------
  4137. // MarshalBinary serializes the internal properties of this SharedAsset instance
  4138. // into a byte array
  4139. func (target *SharedAsset) MarshalBinary() (data []byte, err error) {
  4140. ctx := &EncodingContext{
  4141. Buffer: util.NewBuffer(),
  4142. Table: nil,
  4143. }
  4144. e := target.MarshalBinaryWithContext(ctx)
  4145. if e != nil {
  4146. return nil, e
  4147. }
  4148. encBytes := ctx.Buffer.Bytes()
  4149. return encBytes, nil
  4150. }
  4151. // MarshalBinaryWithContext serializes the internal properties of this SharedAsset instance
  4152. // into a byte array leveraging a predefined context.
  4153. func (target *SharedAsset) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4154. // panics are recovered and propagated as errors
  4155. defer func() {
  4156. if r := recover(); r != nil {
  4157. if e, ok := r.(error); ok {
  4158. err = e
  4159. } else if s, ok := r.(string); ok {
  4160. err = fmt.Errorf("Unexpected panic: %s", s)
  4161. } else {
  4162. err = fmt.Errorf("Unexpected panic: %+v", r)
  4163. }
  4164. }
  4165. }()
  4166. buff := ctx.Buffer
  4167. buff.WriteUInt8(AssetsCodecVersion) // version
  4168. if target.properties == nil {
  4169. buff.WriteUInt8(uint8(0)) // write nil byte
  4170. } else {
  4171. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4172. // --- [begin][write][struct](AssetProperties) ---
  4173. buff.WriteInt(0) // [compatibility, unused]
  4174. errA := target.properties.MarshalBinaryWithContext(ctx)
  4175. if errA != nil {
  4176. return errA
  4177. }
  4178. // --- [end][write][struct](AssetProperties) ---
  4179. }
  4180. // --- [begin][write][alias](AssetLabels) ---
  4181. if map[string]string(target.labels) == nil {
  4182. buff.WriteUInt8(uint8(0)) // write nil byte
  4183. } else {
  4184. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4185. // --- [begin][write][map](map[string]string) ---
  4186. buff.WriteInt(len(map[string]string(target.labels))) // map length
  4187. for v, z := range map[string]string(target.labels) {
  4188. if ctx.IsStringTable() {
  4189. a := ctx.Table.AddOrGet(v)
  4190. buff.WriteInt(a) // write table index
  4191. } else {
  4192. buff.WriteString(v) // write string
  4193. }
  4194. if ctx.IsStringTable() {
  4195. b := ctx.Table.AddOrGet(z)
  4196. buff.WriteInt(b) // write table index
  4197. } else {
  4198. buff.WriteString(z) // write string
  4199. }
  4200. }
  4201. // --- [end][write][map](map[string]string) ---
  4202. }
  4203. // --- [end][write][alias](AssetLabels) ---
  4204. // --- [begin][write][struct](Window) ---
  4205. buff.WriteInt(0) // [compatibility, unused]
  4206. errB := target.window.MarshalBinaryWithContext(ctx)
  4207. if errB != nil {
  4208. return errB
  4209. }
  4210. // --- [end][write][struct](Window) ---
  4211. buff.WriteFloat64(target.Cost) // write float64
  4212. return nil
  4213. }
  4214. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4215. // the SharedAsset type
  4216. func (target *SharedAsset) UnmarshalBinary(data []byte) error {
  4217. var table []string
  4218. buff := util.NewBufferFromBytes(data)
  4219. // string table header validation
  4220. if isBinaryTag(data, BinaryTagStringTable) {
  4221. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4222. tl := buff.ReadInt() // table length
  4223. if tl > 0 {
  4224. table = make([]string, tl, tl)
  4225. for i := 0; i < tl; i++ {
  4226. table[i] = buff.ReadString()
  4227. }
  4228. }
  4229. }
  4230. ctx := &DecodingContext{
  4231. Buffer: buff,
  4232. Table: table,
  4233. }
  4234. err := target.UnmarshalBinaryWithContext(ctx)
  4235. if err != nil {
  4236. return err
  4237. }
  4238. return nil
  4239. }
  4240. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4241. // the SharedAsset type
  4242. func (target *SharedAsset) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4243. // panics are recovered and propagated as errors
  4244. defer func() {
  4245. if r := recover(); r != nil {
  4246. if e, ok := r.(error); ok {
  4247. err = e
  4248. } else if s, ok := r.(string); ok {
  4249. err = fmt.Errorf("Unexpected panic: %s", s)
  4250. } else {
  4251. err = fmt.Errorf("Unexpected panic: %+v", r)
  4252. }
  4253. }
  4254. }()
  4255. buff := ctx.Buffer
  4256. // Codec Version Check
  4257. version := buff.ReadUInt8()
  4258. if version != AssetsCodecVersion {
  4259. return fmt.Errorf("Invalid Version Unmarshaling SharedAsset. Expected %d, got %d", AssetsCodecVersion, version)
  4260. }
  4261. if buff.ReadUInt8() == uint8(0) {
  4262. target.properties = nil
  4263. } else {
  4264. // --- [begin][read][struct](AssetProperties) ---
  4265. a := &AssetProperties{}
  4266. buff.ReadInt() // [compatibility, unused]
  4267. errA := a.UnmarshalBinaryWithContext(ctx)
  4268. if errA != nil {
  4269. return errA
  4270. }
  4271. target.properties = a
  4272. // --- [end][read][struct](AssetProperties) ---
  4273. }
  4274. // --- [begin][read][alias](AssetLabels) ---
  4275. var b map[string]string
  4276. if buff.ReadUInt8() == uint8(0) {
  4277. b = nil
  4278. } else {
  4279. // --- [begin][read][map](map[string]string) ---
  4280. d := buff.ReadInt() // map len
  4281. c := make(map[string]string, d)
  4282. for i := 0; i < d; i++ {
  4283. var v string
  4284. var f string
  4285. if ctx.IsStringTable() {
  4286. g := buff.ReadInt() // read string index
  4287. f = ctx.Table[g]
  4288. } else {
  4289. f = buff.ReadString() // read string
  4290. }
  4291. e := f
  4292. v = e
  4293. var z string
  4294. var k string
  4295. if ctx.IsStringTable() {
  4296. l := buff.ReadInt() // read string index
  4297. k = ctx.Table[l]
  4298. } else {
  4299. k = buff.ReadString() // read string
  4300. }
  4301. h := k
  4302. z = h
  4303. c[v] = z
  4304. }
  4305. b = c
  4306. // --- [end][read][map](map[string]string) ---
  4307. }
  4308. target.labels = AssetLabels(b)
  4309. // --- [end][read][alias](AssetLabels) ---
  4310. // --- [begin][read][struct](Window) ---
  4311. m := &Window{}
  4312. buff.ReadInt() // [compatibility, unused]
  4313. errB := m.UnmarshalBinaryWithContext(ctx)
  4314. if errB != nil {
  4315. return errB
  4316. }
  4317. target.window = *m
  4318. // --- [end][read][struct](Window) ---
  4319. n := buff.ReadFloat64() // read float64
  4320. target.Cost = n
  4321. return nil
  4322. }
  4323. //--------------------------------------------------------------------------
  4324. // Window
  4325. //--------------------------------------------------------------------------
  4326. // MarshalBinary serializes the internal properties of this Window instance
  4327. // into a byte array
  4328. func (target *Window) MarshalBinary() (data []byte, err error) {
  4329. ctx := &EncodingContext{
  4330. Buffer: util.NewBuffer(),
  4331. Table: nil,
  4332. }
  4333. e := target.MarshalBinaryWithContext(ctx)
  4334. if e != nil {
  4335. return nil, e
  4336. }
  4337. encBytes := ctx.Buffer.Bytes()
  4338. return encBytes, nil
  4339. }
  4340. // MarshalBinaryWithContext serializes the internal properties of this Window instance
  4341. // into a byte array leveraging a predefined context.
  4342. func (target *Window) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4343. // panics are recovered and propagated as errors
  4344. defer func() {
  4345. if r := recover(); r != nil {
  4346. if e, ok := r.(error); ok {
  4347. err = e
  4348. } else if s, ok := r.(string); ok {
  4349. err = fmt.Errorf("Unexpected panic: %s", s)
  4350. } else {
  4351. err = fmt.Errorf("Unexpected panic: %+v", r)
  4352. }
  4353. }
  4354. }()
  4355. buff := ctx.Buffer
  4356. buff.WriteUInt8(DefaultCodecVersion) // version
  4357. if target.start == nil {
  4358. buff.WriteUInt8(uint8(0)) // write nil byte
  4359. } else {
  4360. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4361. // --- [begin][write][reference](time.Time) ---
  4362. a, errA := target.start.MarshalBinary()
  4363. if errA != nil {
  4364. return errA
  4365. }
  4366. buff.WriteInt(len(a))
  4367. buff.WriteBytes(a)
  4368. // --- [end][write][reference](time.Time) ---
  4369. }
  4370. if target.end == nil {
  4371. buff.WriteUInt8(uint8(0)) // write nil byte
  4372. } else {
  4373. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4374. // --- [begin][write][reference](time.Time) ---
  4375. b, errB := target.end.MarshalBinary()
  4376. if errB != nil {
  4377. return errB
  4378. }
  4379. buff.WriteInt(len(b))
  4380. buff.WriteBytes(b)
  4381. // --- [end][write][reference](time.Time) ---
  4382. }
  4383. return nil
  4384. }
  4385. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4386. // the Window type
  4387. func (target *Window) UnmarshalBinary(data []byte) error {
  4388. var table []string
  4389. buff := util.NewBufferFromBytes(data)
  4390. // string table header validation
  4391. if isBinaryTag(data, BinaryTagStringTable) {
  4392. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4393. tl := buff.ReadInt() // table length
  4394. if tl > 0 {
  4395. table = make([]string, tl, tl)
  4396. for i := 0; i < tl; i++ {
  4397. table[i] = buff.ReadString()
  4398. }
  4399. }
  4400. }
  4401. ctx := &DecodingContext{
  4402. Buffer: buff,
  4403. Table: table,
  4404. }
  4405. err := target.UnmarshalBinaryWithContext(ctx)
  4406. if err != nil {
  4407. return err
  4408. }
  4409. return nil
  4410. }
  4411. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4412. // the Window type
  4413. func (target *Window) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4414. // panics are recovered and propagated as errors
  4415. defer func() {
  4416. if r := recover(); r != nil {
  4417. if e, ok := r.(error); ok {
  4418. err = e
  4419. } else if s, ok := r.(string); ok {
  4420. err = fmt.Errorf("Unexpected panic: %s", s)
  4421. } else {
  4422. err = fmt.Errorf("Unexpected panic: %+v", r)
  4423. }
  4424. }
  4425. }()
  4426. buff := ctx.Buffer
  4427. // Codec Version Check
  4428. version := buff.ReadUInt8()
  4429. if version != DefaultCodecVersion {
  4430. return fmt.Errorf("Invalid Version Unmarshaling Window. Expected %d, got %d", DefaultCodecVersion, version)
  4431. }
  4432. if buff.ReadUInt8() == uint8(0) {
  4433. target.start = nil
  4434. } else {
  4435. // --- [begin][read][reference](time.Time) ---
  4436. a := &time.Time{}
  4437. b := buff.ReadInt() // byte array length
  4438. c := buff.ReadBytes(b) // byte array
  4439. errA := a.UnmarshalBinary(c)
  4440. if errA != nil {
  4441. return errA
  4442. }
  4443. target.start = a
  4444. // --- [end][read][reference](time.Time) ---
  4445. }
  4446. if buff.ReadUInt8() == uint8(0) {
  4447. target.end = nil
  4448. } else {
  4449. // --- [begin][read][reference](time.Time) ---
  4450. d := &time.Time{}
  4451. e := buff.ReadInt() // byte array length
  4452. f := buff.ReadBytes(e) // byte array
  4453. errB := d.UnmarshalBinary(f)
  4454. if errB != nil {
  4455. return errB
  4456. }
  4457. target.end = d
  4458. // --- [end][read][reference](time.Time) ---
  4459. }
  4460. return nil
  4461. }