kubemodel_codecs.go 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // DO NOT MODIFY
  4. //
  5. // ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻
  6. //
  7. //
  8. // This source file was automatically generated by bingen.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. package kubemodel
  12. import (
  13. "fmt"
  14. util "github.com/opencost/opencost/core/pkg/util"
  15. "reflect"
  16. "strings"
  17. "sync"
  18. "time"
  19. )
  20. const (
  21. // GeneratorPackageName is the package the generator is targetting
  22. GeneratorPackageName string = "kubemodel"
  23. )
  24. // BinaryTags represent the formatting tag used for specific optimization features
  25. const (
  26. // BinaryTagStringTable is written and/or read prior to the existence of a string
  27. // table (where each index is encoded as a string entry in the resource
  28. BinaryTagStringTable string = "BGST"
  29. )
  30. const (
  31. // DefaultCodecVersion is used for any resources listed in the Default version set
  32. DefaultCodecVersion uint8 = 1
  33. )
  34. //--------------------------------------------------------------------------
  35. // Type Map
  36. //--------------------------------------------------------------------------
  37. // Generated type map for resolving interface implementations to
  38. // to concrete types
  39. var typeMap map[string]reflect.Type = map[string]reflect.Type{
  40. "Cluster": reflect.TypeOf((*Cluster)(nil)).Elem(),
  41. "Diagnostic": reflect.TypeOf((*Diagnostic)(nil)).Elem(),
  42. "KubeModelSet": reflect.TypeOf((*KubeModelSet)(nil)).Elem(),
  43. "Metadata": reflect.TypeOf((*Metadata)(nil)).Elem(),
  44. "Namespace": reflect.TypeOf((*Namespace)(nil)).Elem(),
  45. "ResourceQuantity": reflect.TypeOf((*ResourceQuantity)(nil)).Elem(),
  46. "ResourceQuota": reflect.TypeOf((*ResourceQuota)(nil)).Elem(),
  47. "ResourceQuotaSpec": reflect.TypeOf((*ResourceQuotaSpec)(nil)).Elem(),
  48. "ResourceQuotaSpecHard": reflect.TypeOf((*ResourceQuotaSpecHard)(nil)).Elem(),
  49. "ResourceQuotaStatus": reflect.TypeOf((*ResourceQuotaStatus)(nil)).Elem(),
  50. "ResourceQuotaStatusUsed": reflect.TypeOf((*ResourceQuotaStatusUsed)(nil)).Elem(),
  51. "Window": reflect.TypeOf((*Window)(nil)).Elem(),
  52. }
  53. //--------------------------------------------------------------------------
  54. // Type Helpers
  55. //--------------------------------------------------------------------------
  56. // isBinaryTag returns true when the first bytes in the provided binary matches the tag
  57. func isBinaryTag(data []byte, tag string) bool {
  58. return string(data[:len(tag)]) == tag
  59. }
  60. // appendBytes combines a and b into a new byte array
  61. func appendBytes(a []byte, b []byte) []byte {
  62. al := len(a)
  63. bl := len(b)
  64. tl := al + bl
  65. // allocate a new byte array for the combined
  66. // use native copy for speedy byte copying
  67. result := make([]byte, tl, tl)
  68. copy(result, a)
  69. copy(result[al:], b)
  70. return result
  71. }
  72. // typeToString determines the basic properties of the type, the qualifier, package path, and
  73. // type name, and returns the qualified type
  74. func typeToString(f interface{}) string {
  75. qual := ""
  76. t := reflect.TypeOf(f)
  77. if t.Kind() == reflect.Ptr {
  78. t = t.Elem()
  79. qual = "*"
  80. }
  81. return fmt.Sprintf("%s%s.%s", qual, t.PkgPath(), t.Name())
  82. }
  83. // resolveType uses the name of a type and returns the package, base type name, and whether
  84. // or not it's a pointer.
  85. func resolveType(t string) (pkg string, name string, isPtr bool) {
  86. isPtr = t[:1] == "*"
  87. if isPtr {
  88. t = t[1:]
  89. }
  90. slashIndex := strings.LastIndex(t, "/")
  91. if slashIndex >= 0 {
  92. t = t[slashIndex+1:]
  93. }
  94. parts := strings.Split(t, ".")
  95. if parts[0] == GeneratorPackageName {
  96. parts[0] = ""
  97. }
  98. pkg = parts[0]
  99. name = parts[1]
  100. return
  101. }
  102. //--------------------------------------------------------------------------
  103. // StringTable
  104. //--------------------------------------------------------------------------
  105. // StringTable maps strings to specific indices for encoding
  106. type StringTable struct {
  107. l *sync.Mutex
  108. indices map[string]int
  109. next int
  110. }
  111. // NewStringTable Creates a new StringTable instance with provided contents
  112. func NewStringTable(contents ...string) *StringTable {
  113. st := &StringTable{
  114. l: new(sync.Mutex),
  115. indices: make(map[string]int),
  116. next: len(contents),
  117. }
  118. for i, entry := range contents {
  119. st.indices[entry] = i
  120. }
  121. return st
  122. }
  123. // AddOrGet atomically retrieves a string entry's index if it exist. Otherwise, it will
  124. // add the entry and return the index.
  125. func (st *StringTable) AddOrGet(s string) int {
  126. st.l.Lock()
  127. defer st.l.Unlock()
  128. if ind, ok := st.indices[s]; ok {
  129. return ind
  130. }
  131. current := st.next
  132. st.next++
  133. st.indices[s] = current
  134. return current
  135. }
  136. // ToSlice Converts the contents to a string array for encoding.
  137. func (st *StringTable) ToSlice() []string {
  138. st.l.Lock()
  139. defer st.l.Unlock()
  140. if st.next == 0 {
  141. return []string{}
  142. }
  143. sl := make([]string, st.next, st.next)
  144. for s, i := range st.indices {
  145. sl[i] = s
  146. }
  147. return sl
  148. }
  149. // ToBytes Converts the contents to a binary encoded representation
  150. func (st *StringTable) ToBytes() []byte {
  151. buff := util.NewBuffer()
  152. buff.WriteBytes([]byte(BinaryTagStringTable)) // bingen table header
  153. strs := st.ToSlice()
  154. buff.WriteInt(len(strs)) // table length
  155. for _, s := range strs {
  156. buff.WriteString(s)
  157. }
  158. return buff.Bytes()
  159. }
  160. //--------------------------------------------------------------------------
  161. // Codec Context
  162. //--------------------------------------------------------------------------
  163. // EncodingContext is a context object passed to the encoders to ensure reuse of buffer
  164. // and table data
  165. type EncodingContext struct {
  166. Buffer *util.Buffer
  167. Table *StringTable
  168. }
  169. // IsStringTable returns true if the table is available
  170. func (ec *EncodingContext) IsStringTable() bool {
  171. return ec.Table != nil
  172. }
  173. // DecodingContext is a context object passed to the decoders to ensure parent objects
  174. // reuse as much data as possible
  175. type DecodingContext struct {
  176. Buffer *util.Buffer
  177. Table []string
  178. }
  179. // IsStringTable returns true if the table is available
  180. func (dc *DecodingContext) IsStringTable() bool {
  181. return len(dc.Table) > 0
  182. }
  183. //--------------------------------------------------------------------------
  184. // Binary Codec
  185. //--------------------------------------------------------------------------
  186. // BinEncoder is an encoding interface which defines a context based marshal contract.
  187. type BinEncoder interface {
  188. MarshalBinaryWithContext(*EncodingContext) error
  189. }
  190. // BinDecoder is a decoding interface which defines a context based unmarshal contract.
  191. type BinDecoder interface {
  192. UnmarshalBinaryWithContext(*DecodingContext) error
  193. }
  194. //--------------------------------------------------------------------------
  195. // Cluster
  196. //--------------------------------------------------------------------------
  197. // MarshalBinary serializes the internal properties of this Cluster instance
  198. // into a byte array
  199. func (target *Cluster) MarshalBinary() (data []byte, err error) {
  200. ctx := &EncodingContext{
  201. Buffer: util.NewBuffer(),
  202. Table: nil,
  203. }
  204. e := target.MarshalBinaryWithContext(ctx)
  205. if e != nil {
  206. return nil, e
  207. }
  208. encBytes := ctx.Buffer.Bytes()
  209. return encBytes, nil
  210. }
  211. // MarshalBinaryWithContext serializes the internal properties of this Cluster instance
  212. // into a byte array leveraging a predefined context.
  213. func (target *Cluster) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  214. // panics are recovered and propagated as errors
  215. defer func() {
  216. if r := recover(); r != nil {
  217. if e, ok := r.(error); ok {
  218. err = e
  219. } else if s, ok := r.(string); ok {
  220. err = fmt.Errorf("Unexpected panic: %s", s)
  221. } else {
  222. err = fmt.Errorf("Unexpected panic: %+v", r)
  223. }
  224. }
  225. }()
  226. buff := ctx.Buffer
  227. buff.WriteUInt8(DefaultCodecVersion) // version
  228. if ctx.IsStringTable() {
  229. a := ctx.Table.AddOrGet(target.UID)
  230. buff.WriteInt(a) // write table index
  231. } else {
  232. buff.WriteString(target.UID) // write string
  233. }
  234. // --- [begin][write][alias](Provider) ---
  235. if ctx.IsStringTable() {
  236. b := ctx.Table.AddOrGet(string(target.Provider))
  237. buff.WriteInt(b) // write table index
  238. } else {
  239. buff.WriteString(string(target.Provider)) // write string
  240. }
  241. // --- [end][write][alias](Provider) ---
  242. if ctx.IsStringTable() {
  243. c := ctx.Table.AddOrGet(target.Account)
  244. buff.WriteInt(c) // write table index
  245. } else {
  246. buff.WriteString(target.Account) // write string
  247. }
  248. if ctx.IsStringTable() {
  249. d := ctx.Table.AddOrGet(target.Name)
  250. buff.WriteInt(d) // write table index
  251. } else {
  252. buff.WriteString(target.Name) // write string
  253. }
  254. // --- [begin][write][reference](time.Time) ---
  255. e, errA := target.Start.MarshalBinary()
  256. if errA != nil {
  257. return errA
  258. }
  259. buff.WriteInt(len(e))
  260. buff.WriteBytes(e)
  261. // --- [end][write][reference](time.Time) ---
  262. // --- [begin][write][reference](time.Time) ---
  263. f, errB := target.End.MarshalBinary()
  264. if errB != nil {
  265. return errB
  266. }
  267. buff.WriteInt(len(f))
  268. buff.WriteBytes(f)
  269. // --- [end][write][reference](time.Time) ---
  270. return nil
  271. }
  272. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  273. // the Cluster type
  274. func (target *Cluster) UnmarshalBinary(data []byte) error {
  275. var table []string
  276. buff := util.NewBufferFromBytes(data)
  277. // string table header validation
  278. if isBinaryTag(data, BinaryTagStringTable) {
  279. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  280. tl := buff.ReadInt() // table length
  281. if tl > 0 {
  282. table = make([]string, tl, tl)
  283. for i := 0; i < tl; i++ {
  284. table[i] = buff.ReadString()
  285. }
  286. }
  287. }
  288. ctx := &DecodingContext{
  289. Buffer: buff,
  290. Table: table,
  291. }
  292. err := target.UnmarshalBinaryWithContext(ctx)
  293. if err != nil {
  294. return err
  295. }
  296. return nil
  297. }
  298. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  299. // the Cluster type
  300. func (target *Cluster) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  301. // panics are recovered and propagated as errors
  302. defer func() {
  303. if r := recover(); r != nil {
  304. if e, ok := r.(error); ok {
  305. err = e
  306. } else if s, ok := r.(string); ok {
  307. err = fmt.Errorf("Unexpected panic: %s", s)
  308. } else {
  309. err = fmt.Errorf("Unexpected panic: %+v", r)
  310. }
  311. }
  312. }()
  313. buff := ctx.Buffer
  314. version := buff.ReadUInt8()
  315. if version > DefaultCodecVersion {
  316. return fmt.Errorf("Invalid Version Unmarshaling Cluster. Expected %d or less, got %d", DefaultCodecVersion, version)
  317. }
  318. // field version check
  319. if uint8(1) <= version {
  320. var b string
  321. if ctx.IsStringTable() {
  322. c := buff.ReadInt() // read string index
  323. b = ctx.Table[c]
  324. } else {
  325. b = buff.ReadString() // read string
  326. }
  327. a := b
  328. target.UID = a
  329. } else {
  330. target.UID = "" // default
  331. }
  332. // field version check
  333. if uint8(1) <= version {
  334. // --- [begin][read][alias](Provider) ---
  335. var d string
  336. var f string
  337. if ctx.IsStringTable() {
  338. g := buff.ReadInt() // read string index
  339. f = ctx.Table[g]
  340. } else {
  341. f = buff.ReadString() // read string
  342. }
  343. e := f
  344. d = e
  345. target.Provider = Provider(d)
  346. // --- [end][read][alias](Provider) ---
  347. } else {
  348. }
  349. // field version check
  350. if uint8(1) <= version {
  351. var k string
  352. if ctx.IsStringTable() {
  353. l := buff.ReadInt() // read string index
  354. k = ctx.Table[l]
  355. } else {
  356. k = buff.ReadString() // read string
  357. }
  358. h := k
  359. target.Account = h
  360. } else {
  361. target.Account = "" // default
  362. }
  363. // field version check
  364. if uint8(1) <= version {
  365. var n string
  366. if ctx.IsStringTable() {
  367. o := buff.ReadInt() // read string index
  368. n = ctx.Table[o]
  369. } else {
  370. n = buff.ReadString() // read string
  371. }
  372. m := n
  373. target.Name = m
  374. } else {
  375. target.Name = "" // default
  376. }
  377. // field version check
  378. if uint8(1) <= version {
  379. // --- [begin][read][reference](time.Time) ---
  380. p := &time.Time{}
  381. q := buff.ReadInt() // byte array length
  382. r := buff.ReadBytes(q) // byte array
  383. errA := p.UnmarshalBinary(r)
  384. if errA != nil {
  385. return errA
  386. }
  387. target.Start = *p
  388. // --- [end][read][reference](time.Time) ---
  389. } else {
  390. }
  391. // field version check
  392. if uint8(1) <= version {
  393. // --- [begin][read][reference](time.Time) ---
  394. s := &time.Time{}
  395. t := buff.ReadInt() // byte array length
  396. u := buff.ReadBytes(t) // byte array
  397. errB := s.UnmarshalBinary(u)
  398. if errB != nil {
  399. return errB
  400. }
  401. target.End = *s
  402. // --- [end][read][reference](time.Time) ---
  403. } else {
  404. }
  405. return nil
  406. }
  407. //--------------------------------------------------------------------------
  408. // Diagnostic
  409. //--------------------------------------------------------------------------
  410. // MarshalBinary serializes the internal properties of this Diagnostic instance
  411. // into a byte array
  412. func (target *Diagnostic) MarshalBinary() (data []byte, err error) {
  413. ctx := &EncodingContext{
  414. Buffer: util.NewBuffer(),
  415. Table: nil,
  416. }
  417. e := target.MarshalBinaryWithContext(ctx)
  418. if e != nil {
  419. return nil, e
  420. }
  421. encBytes := ctx.Buffer.Bytes()
  422. return encBytes, nil
  423. }
  424. // MarshalBinaryWithContext serializes the internal properties of this Diagnostic instance
  425. // into a byte array leveraging a predefined context.
  426. func (target *Diagnostic) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  427. // panics are recovered and propagated as errors
  428. defer func() {
  429. if r := recover(); r != nil {
  430. if e, ok := r.(error); ok {
  431. err = e
  432. } else if s, ok := r.(string); ok {
  433. err = fmt.Errorf("Unexpected panic: %s", s)
  434. } else {
  435. err = fmt.Errorf("Unexpected panic: %+v", r)
  436. }
  437. }
  438. }()
  439. buff := ctx.Buffer
  440. buff.WriteUInt8(DefaultCodecVersion) // version
  441. // --- [begin][write][reference](time.Time) ---
  442. a, errA := target.Timestamp.MarshalBinary()
  443. if errA != nil {
  444. return errA
  445. }
  446. buff.WriteInt(len(a))
  447. buff.WriteBytes(a)
  448. // --- [end][write][reference](time.Time) ---
  449. // --- [begin][write][alias](DiagnosticLevel) ---
  450. buff.WriteInt(int(target.Level)) // write int
  451. // --- [end][write][alias](DiagnosticLevel) ---
  452. if ctx.IsStringTable() {
  453. b := ctx.Table.AddOrGet(target.Message)
  454. buff.WriteInt(b) // write table index
  455. } else {
  456. buff.WriteString(target.Message) // write string
  457. }
  458. if target.Details == nil {
  459. buff.WriteUInt8(uint8(0)) // write nil byte
  460. } else {
  461. buff.WriteUInt8(uint8(1)) // write non-nil byte
  462. // --- [begin][write][map](map[string]string) ---
  463. buff.WriteInt(len(target.Details)) // map length
  464. for v, z := range target.Details {
  465. if ctx.IsStringTable() {
  466. c := ctx.Table.AddOrGet(v)
  467. buff.WriteInt(c) // write table index
  468. } else {
  469. buff.WriteString(v) // write string
  470. }
  471. if ctx.IsStringTable() {
  472. d := ctx.Table.AddOrGet(z)
  473. buff.WriteInt(d) // write table index
  474. } else {
  475. buff.WriteString(z) // write string
  476. }
  477. }
  478. // --- [end][write][map](map[string]string) ---
  479. }
  480. return nil
  481. }
  482. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  483. // the Diagnostic type
  484. func (target *Diagnostic) UnmarshalBinary(data []byte) error {
  485. var table []string
  486. buff := util.NewBufferFromBytes(data)
  487. // string table header validation
  488. if isBinaryTag(data, BinaryTagStringTable) {
  489. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  490. tl := buff.ReadInt() // table length
  491. if tl > 0 {
  492. table = make([]string, tl, tl)
  493. for i := 0; i < tl; i++ {
  494. table[i] = buff.ReadString()
  495. }
  496. }
  497. }
  498. ctx := &DecodingContext{
  499. Buffer: buff,
  500. Table: table,
  501. }
  502. err := target.UnmarshalBinaryWithContext(ctx)
  503. if err != nil {
  504. return err
  505. }
  506. return nil
  507. }
  508. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  509. // the Diagnostic type
  510. func (target *Diagnostic) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  511. // panics are recovered and propagated as errors
  512. defer func() {
  513. if r := recover(); r != nil {
  514. if e, ok := r.(error); ok {
  515. err = e
  516. } else if s, ok := r.(string); ok {
  517. err = fmt.Errorf("Unexpected panic: %s", s)
  518. } else {
  519. err = fmt.Errorf("Unexpected panic: %+v", r)
  520. }
  521. }
  522. }()
  523. buff := ctx.Buffer
  524. version := buff.ReadUInt8()
  525. if version > DefaultCodecVersion {
  526. return fmt.Errorf("Invalid Version Unmarshaling Diagnostic. Expected %d or less, got %d", DefaultCodecVersion, version)
  527. }
  528. // field version check
  529. if uint8(1) <= version {
  530. // --- [begin][read][reference](time.Time) ---
  531. a := &time.Time{}
  532. b := buff.ReadInt() // byte array length
  533. c := buff.ReadBytes(b) // byte array
  534. errA := a.UnmarshalBinary(c)
  535. if errA != nil {
  536. return errA
  537. }
  538. target.Timestamp = *a
  539. // --- [end][read][reference](time.Time) ---
  540. } else {
  541. }
  542. // field version check
  543. if uint8(1) <= version {
  544. // --- [begin][read][alias](DiagnosticLevel) ---
  545. var d int
  546. e := buff.ReadInt() // read int
  547. d = e
  548. target.Level = DiagnosticLevel(d)
  549. // --- [end][read][alias](DiagnosticLevel) ---
  550. } else {
  551. }
  552. // field version check
  553. if uint8(1) <= version {
  554. var g string
  555. if ctx.IsStringTable() {
  556. h := buff.ReadInt() // read string index
  557. g = ctx.Table[h]
  558. } else {
  559. g = buff.ReadString() // read string
  560. }
  561. f := g
  562. target.Message = f
  563. } else {
  564. target.Message = "" // default
  565. }
  566. // field version check
  567. if uint8(1) <= version {
  568. if buff.ReadUInt8() == uint8(0) {
  569. target.Details = nil
  570. } else {
  571. // --- [begin][read][map](map[string]string) ---
  572. l := buff.ReadInt() // map len
  573. k := make(map[string]string, l)
  574. for i := 0; i < l; i++ {
  575. var v string
  576. var n string
  577. if ctx.IsStringTable() {
  578. o := buff.ReadInt() // read string index
  579. n = ctx.Table[o]
  580. } else {
  581. n = buff.ReadString() // read string
  582. }
  583. m := n
  584. v = m
  585. var z string
  586. var q string
  587. if ctx.IsStringTable() {
  588. r := buff.ReadInt() // read string index
  589. q = ctx.Table[r]
  590. } else {
  591. q = buff.ReadString() // read string
  592. }
  593. p := q
  594. z = p
  595. k[v] = z
  596. }
  597. target.Details = k
  598. // --- [end][read][map](map[string]string) ---
  599. }
  600. } else {
  601. target.Details = nil
  602. }
  603. return nil
  604. }
  605. //--------------------------------------------------------------------------
  606. // KubeModelSet
  607. //--------------------------------------------------------------------------
  608. // MarshalBinary serializes the internal properties of this KubeModelSet instance
  609. // into a byte array
  610. func (target *KubeModelSet) MarshalBinary() (data []byte, err error) {
  611. ctx := &EncodingContext{
  612. Buffer: util.NewBuffer(),
  613. Table: NewStringTable(),
  614. }
  615. e := target.MarshalBinaryWithContext(ctx)
  616. if e != nil {
  617. return nil, e
  618. }
  619. encBytes := ctx.Buffer.Bytes()
  620. sTableBytes := ctx.Table.ToBytes()
  621. merged := appendBytes(sTableBytes, encBytes)
  622. return merged, nil
  623. }
  624. // MarshalBinaryWithContext serializes the internal properties of this KubeModelSet instance
  625. // into a byte array leveraging a predefined context.
  626. func (target *KubeModelSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  627. // panics are recovered and propagated as errors
  628. defer func() {
  629. if r := recover(); r != nil {
  630. if e, ok := r.(error); ok {
  631. err = e
  632. } else if s, ok := r.(string); ok {
  633. err = fmt.Errorf("Unexpected panic: %s", s)
  634. } else {
  635. err = fmt.Errorf("Unexpected panic: %+v", r)
  636. }
  637. }
  638. }()
  639. buff := ctx.Buffer
  640. buff.WriteUInt8(DefaultCodecVersion) // version
  641. if target.Metadata == nil {
  642. buff.WriteUInt8(uint8(0)) // write nil byte
  643. } else {
  644. buff.WriteUInt8(uint8(1)) // write non-nil byte
  645. // --- [begin][write][struct](Metadata) ---
  646. buff.WriteInt(0) // [compatibility, unused]
  647. errA := target.Metadata.MarshalBinaryWithContext(ctx)
  648. if errA != nil {
  649. return errA
  650. }
  651. // --- [end][write][struct](Metadata) ---
  652. }
  653. // --- [begin][write][struct](Window) ---
  654. buff.WriteInt(0) // [compatibility, unused]
  655. errB := target.Window.MarshalBinaryWithContext(ctx)
  656. if errB != nil {
  657. return errB
  658. }
  659. // --- [end][write][struct](Window) ---
  660. if target.Cluster == nil {
  661. buff.WriteUInt8(uint8(0)) // write nil byte
  662. } else {
  663. buff.WriteUInt8(uint8(1)) // write non-nil byte
  664. // --- [begin][write][struct](Cluster) ---
  665. buff.WriteInt(0) // [compatibility, unused]
  666. errC := target.Cluster.MarshalBinaryWithContext(ctx)
  667. if errC != nil {
  668. return errC
  669. }
  670. // --- [end][write][struct](Cluster) ---
  671. }
  672. if target.Namespaces == nil {
  673. buff.WriteUInt8(uint8(0)) // write nil byte
  674. } else {
  675. buff.WriteUInt8(uint8(1)) // write non-nil byte
  676. // --- [begin][write][map](map[string]*Namespace) ---
  677. buff.WriteInt(len(target.Namespaces)) // map length
  678. for v, z := range target.Namespaces {
  679. if ctx.IsStringTable() {
  680. a := ctx.Table.AddOrGet(v)
  681. buff.WriteInt(a) // write table index
  682. } else {
  683. buff.WriteString(v) // write string
  684. }
  685. if z == nil {
  686. buff.WriteUInt8(uint8(0)) // write nil byte
  687. } else {
  688. buff.WriteUInt8(uint8(1)) // write non-nil byte
  689. // --- [begin][write][struct](Namespace) ---
  690. buff.WriteInt(0) // [compatibility, unused]
  691. errD := z.MarshalBinaryWithContext(ctx)
  692. if errD != nil {
  693. return errD
  694. }
  695. // --- [end][write][struct](Namespace) ---
  696. }
  697. }
  698. // --- [end][write][map](map[string]*Namespace) ---
  699. }
  700. if target.ResourceQuotas == nil {
  701. buff.WriteUInt8(uint8(0)) // write nil byte
  702. } else {
  703. buff.WriteUInt8(uint8(1)) // write non-nil byte
  704. // --- [begin][write][map](map[string]*ResourceQuota) ---
  705. buff.WriteInt(len(target.ResourceQuotas)) // map length
  706. for vv, zz := range target.ResourceQuotas {
  707. if ctx.IsStringTable() {
  708. b := ctx.Table.AddOrGet(vv)
  709. buff.WriteInt(b) // write table index
  710. } else {
  711. buff.WriteString(vv) // write string
  712. }
  713. if zz == nil {
  714. buff.WriteUInt8(uint8(0)) // write nil byte
  715. } else {
  716. buff.WriteUInt8(uint8(1)) // write non-nil byte
  717. // --- [begin][write][struct](ResourceQuota) ---
  718. buff.WriteInt(0) // [compatibility, unused]
  719. errE := zz.MarshalBinaryWithContext(ctx)
  720. if errE != nil {
  721. return errE
  722. }
  723. // --- [end][write][struct](ResourceQuota) ---
  724. }
  725. }
  726. // --- [end][write][map](map[string]*ResourceQuota) ---
  727. }
  728. return nil
  729. }
  730. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  731. // the KubeModelSet type
  732. func (target *KubeModelSet) UnmarshalBinary(data []byte) error {
  733. var table []string
  734. buff := util.NewBufferFromBytes(data)
  735. // string table header validation
  736. if isBinaryTag(data, BinaryTagStringTable) {
  737. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  738. tl := buff.ReadInt() // table length
  739. if tl > 0 {
  740. table = make([]string, tl, tl)
  741. for i := 0; i < tl; i++ {
  742. table[i] = buff.ReadString()
  743. }
  744. }
  745. }
  746. ctx := &DecodingContext{
  747. Buffer: buff,
  748. Table: table,
  749. }
  750. err := target.UnmarshalBinaryWithContext(ctx)
  751. if err != nil {
  752. return err
  753. }
  754. return nil
  755. }
  756. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  757. // the KubeModelSet type
  758. func (target *KubeModelSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  759. // panics are recovered and propagated as errors
  760. defer func() {
  761. if r := recover(); r != nil {
  762. if e, ok := r.(error); ok {
  763. err = e
  764. } else if s, ok := r.(string); ok {
  765. err = fmt.Errorf("Unexpected panic: %s", s)
  766. } else {
  767. err = fmt.Errorf("Unexpected panic: %+v", r)
  768. }
  769. }
  770. }()
  771. buff := ctx.Buffer
  772. version := buff.ReadUInt8()
  773. if version > DefaultCodecVersion {
  774. return fmt.Errorf("Invalid Version Unmarshaling KubeModelSet. Expected %d or less, got %d", DefaultCodecVersion, version)
  775. }
  776. // field version check
  777. if uint8(1) <= version {
  778. if buff.ReadUInt8() == uint8(0) {
  779. target.Metadata = nil
  780. } else {
  781. // --- [begin][read][struct](Metadata) ---
  782. a := &Metadata{}
  783. buff.ReadInt() // [compatibility, unused]
  784. errA := a.UnmarshalBinaryWithContext(ctx)
  785. if errA != nil {
  786. return errA
  787. }
  788. target.Metadata = a
  789. // --- [end][read][struct](Metadata) ---
  790. }
  791. } else {
  792. target.Metadata = nil
  793. }
  794. // field version check
  795. if uint8(1) <= version {
  796. // --- [begin][read][struct](Window) ---
  797. b := &Window{}
  798. buff.ReadInt() // [compatibility, unused]
  799. errB := b.UnmarshalBinaryWithContext(ctx)
  800. if errB != nil {
  801. return errB
  802. }
  803. target.Window = *b
  804. // --- [end][read][struct](Window) ---
  805. } else {
  806. }
  807. // field version check
  808. if uint8(1) <= version {
  809. if buff.ReadUInt8() == uint8(0) {
  810. target.Cluster = nil
  811. } else {
  812. // --- [begin][read][struct](Cluster) ---
  813. c := &Cluster{}
  814. buff.ReadInt() // [compatibility, unused]
  815. errC := c.UnmarshalBinaryWithContext(ctx)
  816. if errC != nil {
  817. return errC
  818. }
  819. target.Cluster = c
  820. // --- [end][read][struct](Cluster) ---
  821. }
  822. } else {
  823. target.Cluster = nil
  824. }
  825. // field version check
  826. if uint8(1) <= version {
  827. if buff.ReadUInt8() == uint8(0) {
  828. target.Namespaces = nil
  829. } else {
  830. // --- [begin][read][map](map[string]*Namespace) ---
  831. e := buff.ReadInt() // map len
  832. d := make(map[string]*Namespace, e)
  833. for i := 0; i < e; i++ {
  834. var v string
  835. var g string
  836. if ctx.IsStringTable() {
  837. h := buff.ReadInt() // read string index
  838. g = ctx.Table[h]
  839. } else {
  840. g = buff.ReadString() // read string
  841. }
  842. f := g
  843. v = f
  844. var z *Namespace
  845. if buff.ReadUInt8() == uint8(0) {
  846. z = nil
  847. } else {
  848. // --- [begin][read][struct](Namespace) ---
  849. k := &Namespace{}
  850. buff.ReadInt() // [compatibility, unused]
  851. errD := k.UnmarshalBinaryWithContext(ctx)
  852. if errD != nil {
  853. return errD
  854. }
  855. z = k
  856. // --- [end][read][struct](Namespace) ---
  857. }
  858. d[v] = z
  859. }
  860. target.Namespaces = d
  861. // --- [end][read][map](map[string]*Namespace) ---
  862. }
  863. } else {
  864. target.Namespaces = nil
  865. }
  866. // field version check
  867. if uint8(1) <= version {
  868. if buff.ReadUInt8() == uint8(0) {
  869. target.ResourceQuotas = nil
  870. } else {
  871. // --- [begin][read][map](map[string]*ResourceQuota) ---
  872. m := buff.ReadInt() // map len
  873. l := make(map[string]*ResourceQuota, m)
  874. for j := 0; j < m; j++ {
  875. var vv string
  876. var o string
  877. if ctx.IsStringTable() {
  878. p := buff.ReadInt() // read string index
  879. o = ctx.Table[p]
  880. } else {
  881. o = buff.ReadString() // read string
  882. }
  883. n := o
  884. vv = n
  885. var zz *ResourceQuota
  886. if buff.ReadUInt8() == uint8(0) {
  887. zz = nil
  888. } else {
  889. // --- [begin][read][struct](ResourceQuota) ---
  890. q := &ResourceQuota{}
  891. buff.ReadInt() // [compatibility, unused]
  892. errE := q.UnmarshalBinaryWithContext(ctx)
  893. if errE != nil {
  894. return errE
  895. }
  896. zz = q
  897. // --- [end][read][struct](ResourceQuota) ---
  898. }
  899. l[vv] = zz
  900. }
  901. target.ResourceQuotas = l
  902. // --- [end][read][map](map[string]*ResourceQuota) ---
  903. }
  904. } else {
  905. target.ResourceQuotas = nil
  906. }
  907. return nil
  908. }
  909. //--------------------------------------------------------------------------
  910. // Metadata
  911. //--------------------------------------------------------------------------
  912. // MarshalBinary serializes the internal properties of this Metadata instance
  913. // into a byte array
  914. func (target *Metadata) MarshalBinary() (data []byte, err error) {
  915. ctx := &EncodingContext{
  916. Buffer: util.NewBuffer(),
  917. Table: nil,
  918. }
  919. e := target.MarshalBinaryWithContext(ctx)
  920. if e != nil {
  921. return nil, e
  922. }
  923. encBytes := ctx.Buffer.Bytes()
  924. return encBytes, nil
  925. }
  926. // MarshalBinaryWithContext serializes the internal properties of this Metadata instance
  927. // into a byte array leveraging a predefined context.
  928. func (target *Metadata) 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(DefaultCodecVersion) // version
  943. // --- [begin][write][reference](time.Time) ---
  944. a, errA := target.CreatedAt.MarshalBinary()
  945. if errA != nil {
  946. return errA
  947. }
  948. buff.WriteInt(len(a))
  949. buff.WriteBytes(a)
  950. // --- [end][write][reference](time.Time) ---
  951. // --- [begin][write][reference](time.Time) ---
  952. b, errB := target.CompletedAt.MarshalBinary()
  953. if errB != nil {
  954. return errB
  955. }
  956. buff.WriteInt(len(b))
  957. buff.WriteBytes(b)
  958. // --- [end][write][reference](time.Time) ---
  959. buff.WriteInt(target.ObjectCount) // write int
  960. if target.Diagnostics == nil {
  961. buff.WriteUInt8(uint8(0)) // write nil byte
  962. } else {
  963. buff.WriteUInt8(uint8(1)) // write non-nil byte
  964. // --- [begin][write][slice]([]Diagnostic) ---
  965. buff.WriteInt(len(target.Diagnostics)) // array length
  966. for i := 0; i < len(target.Diagnostics); i++ {
  967. // --- [begin][write][struct](Diagnostic) ---
  968. buff.WriteInt(0) // [compatibility, unused]
  969. errC := target.Diagnostics[i].MarshalBinaryWithContext(ctx)
  970. if errC != nil {
  971. return errC
  972. }
  973. // --- [end][write][struct](Diagnostic) ---
  974. }
  975. // --- [end][write][slice]([]Diagnostic) ---
  976. }
  977. // --- [begin][write][alias](DiagnosticLevel) ---
  978. buff.WriteInt(int(target.DiagnosticLevel)) // write int
  979. // --- [end][write][alias](DiagnosticLevel) ---
  980. return nil
  981. }
  982. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  983. // the Metadata type
  984. func (target *Metadata) UnmarshalBinary(data []byte) error {
  985. var table []string
  986. buff := util.NewBufferFromBytes(data)
  987. // string table header validation
  988. if isBinaryTag(data, BinaryTagStringTable) {
  989. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  990. tl := buff.ReadInt() // table length
  991. if tl > 0 {
  992. table = make([]string, tl, tl)
  993. for i := 0; i < tl; i++ {
  994. table[i] = buff.ReadString()
  995. }
  996. }
  997. }
  998. ctx := &DecodingContext{
  999. Buffer: buff,
  1000. Table: table,
  1001. }
  1002. err := target.UnmarshalBinaryWithContext(ctx)
  1003. if err != nil {
  1004. return err
  1005. }
  1006. return nil
  1007. }
  1008. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1009. // the Metadata type
  1010. func (target *Metadata) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1011. // panics are recovered and propagated as errors
  1012. defer func() {
  1013. if r := recover(); r != nil {
  1014. if e, ok := r.(error); ok {
  1015. err = e
  1016. } else if s, ok := r.(string); ok {
  1017. err = fmt.Errorf("Unexpected panic: %s", s)
  1018. } else {
  1019. err = fmt.Errorf("Unexpected panic: %+v", r)
  1020. }
  1021. }
  1022. }()
  1023. buff := ctx.Buffer
  1024. version := buff.ReadUInt8()
  1025. if version > DefaultCodecVersion {
  1026. return fmt.Errorf("Invalid Version Unmarshaling Metadata. Expected %d or less, got %d", DefaultCodecVersion, version)
  1027. }
  1028. // field version check
  1029. if uint8(1) <= version {
  1030. // --- [begin][read][reference](time.Time) ---
  1031. a := &time.Time{}
  1032. b := buff.ReadInt() // byte array length
  1033. c := buff.ReadBytes(b) // byte array
  1034. errA := a.UnmarshalBinary(c)
  1035. if errA != nil {
  1036. return errA
  1037. }
  1038. target.CreatedAt = *a
  1039. // --- [end][read][reference](time.Time) ---
  1040. } else {
  1041. }
  1042. // field version check
  1043. if uint8(1) <= version {
  1044. // --- [begin][read][reference](time.Time) ---
  1045. d := &time.Time{}
  1046. e := buff.ReadInt() // byte array length
  1047. f := buff.ReadBytes(e) // byte array
  1048. errB := d.UnmarshalBinary(f)
  1049. if errB != nil {
  1050. return errB
  1051. }
  1052. target.CompletedAt = *d
  1053. // --- [end][read][reference](time.Time) ---
  1054. } else {
  1055. }
  1056. // field version check
  1057. if uint8(1) <= version {
  1058. g := buff.ReadInt() // read int
  1059. target.ObjectCount = g
  1060. } else {
  1061. target.ObjectCount = int(0) // default
  1062. }
  1063. // field version check
  1064. if uint8(1) <= version {
  1065. if buff.ReadUInt8() == uint8(0) {
  1066. target.Diagnostics = nil
  1067. } else {
  1068. // --- [begin][read][slice]([]Diagnostic) ---
  1069. k := buff.ReadInt() // array len
  1070. h := make([]Diagnostic, k)
  1071. for i := 0; i < k; i++ {
  1072. // --- [begin][read][struct](Diagnostic) ---
  1073. m := &Diagnostic{}
  1074. buff.ReadInt() // [compatibility, unused]
  1075. errC := m.UnmarshalBinaryWithContext(ctx)
  1076. if errC != nil {
  1077. return errC
  1078. }
  1079. l := *m
  1080. // --- [end][read][struct](Diagnostic) ---
  1081. h[i] = l
  1082. }
  1083. target.Diagnostics = h
  1084. // --- [end][read][slice]([]Diagnostic) ---
  1085. }
  1086. } else {
  1087. target.Diagnostics = nil
  1088. }
  1089. // field version check
  1090. if uint8(1) <= version {
  1091. // --- [begin][read][alias](DiagnosticLevel) ---
  1092. var n int
  1093. o := buff.ReadInt() // read int
  1094. n = o
  1095. target.DiagnosticLevel = DiagnosticLevel(n)
  1096. // --- [end][read][alias](DiagnosticLevel) ---
  1097. } else {
  1098. }
  1099. return nil
  1100. }
  1101. //--------------------------------------------------------------------------
  1102. // Namespace
  1103. //--------------------------------------------------------------------------
  1104. // MarshalBinary serializes the internal properties of this Namespace instance
  1105. // into a byte array
  1106. func (target *Namespace) MarshalBinary() (data []byte, err error) {
  1107. ctx := &EncodingContext{
  1108. Buffer: util.NewBuffer(),
  1109. Table: nil,
  1110. }
  1111. e := target.MarshalBinaryWithContext(ctx)
  1112. if e != nil {
  1113. return nil, e
  1114. }
  1115. encBytes := ctx.Buffer.Bytes()
  1116. return encBytes, nil
  1117. }
  1118. // MarshalBinaryWithContext serializes the internal properties of this Namespace instance
  1119. // into a byte array leveraging a predefined context.
  1120. func (target *Namespace) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1121. // panics are recovered and propagated as errors
  1122. defer func() {
  1123. if r := recover(); r != nil {
  1124. if e, ok := r.(error); ok {
  1125. err = e
  1126. } else if s, ok := r.(string); ok {
  1127. err = fmt.Errorf("Unexpected panic: %s", s)
  1128. } else {
  1129. err = fmt.Errorf("Unexpected panic: %+v", r)
  1130. }
  1131. }
  1132. }()
  1133. buff := ctx.Buffer
  1134. buff.WriteUInt8(DefaultCodecVersion) // version
  1135. if ctx.IsStringTable() {
  1136. a := ctx.Table.AddOrGet(target.UID)
  1137. buff.WriteInt(a) // write table index
  1138. } else {
  1139. buff.WriteString(target.UID) // write string
  1140. }
  1141. if ctx.IsStringTable() {
  1142. b := ctx.Table.AddOrGet(target.ClusterUID)
  1143. buff.WriteInt(b) // write table index
  1144. } else {
  1145. buff.WriteString(target.ClusterUID) // write string
  1146. }
  1147. if ctx.IsStringTable() {
  1148. c := ctx.Table.AddOrGet(target.Name)
  1149. buff.WriteInt(c) // write table index
  1150. } else {
  1151. buff.WriteString(target.Name) // write string
  1152. }
  1153. if target.Labels == nil {
  1154. buff.WriteUInt8(uint8(0)) // write nil byte
  1155. } else {
  1156. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1157. // --- [begin][write][map](map[string]string) ---
  1158. buff.WriteInt(len(target.Labels)) // map length
  1159. for v, z := range target.Labels {
  1160. if ctx.IsStringTable() {
  1161. d := ctx.Table.AddOrGet(v)
  1162. buff.WriteInt(d) // write table index
  1163. } else {
  1164. buff.WriteString(v) // write string
  1165. }
  1166. if ctx.IsStringTable() {
  1167. e := ctx.Table.AddOrGet(z)
  1168. buff.WriteInt(e) // write table index
  1169. } else {
  1170. buff.WriteString(z) // write string
  1171. }
  1172. }
  1173. // --- [end][write][map](map[string]string) ---
  1174. }
  1175. if target.Annotations == nil {
  1176. buff.WriteUInt8(uint8(0)) // write nil byte
  1177. } else {
  1178. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1179. // --- [begin][write][map](map[string]string) ---
  1180. buff.WriteInt(len(target.Annotations)) // map length
  1181. for vv, zz := range target.Annotations {
  1182. if ctx.IsStringTable() {
  1183. f := ctx.Table.AddOrGet(vv)
  1184. buff.WriteInt(f) // write table index
  1185. } else {
  1186. buff.WriteString(vv) // write string
  1187. }
  1188. if ctx.IsStringTable() {
  1189. g := ctx.Table.AddOrGet(zz)
  1190. buff.WriteInt(g) // write table index
  1191. } else {
  1192. buff.WriteString(zz) // write string
  1193. }
  1194. }
  1195. // --- [end][write][map](map[string]string) ---
  1196. }
  1197. // --- [begin][write][reference](time.Time) ---
  1198. h, errA := target.Start.MarshalBinary()
  1199. if errA != nil {
  1200. return errA
  1201. }
  1202. buff.WriteInt(len(h))
  1203. buff.WriteBytes(h)
  1204. // --- [end][write][reference](time.Time) ---
  1205. // --- [begin][write][reference](time.Time) ---
  1206. k, errB := target.End.MarshalBinary()
  1207. if errB != nil {
  1208. return errB
  1209. }
  1210. buff.WriteInt(len(k))
  1211. buff.WriteBytes(k)
  1212. // --- [end][write][reference](time.Time) ---
  1213. return nil
  1214. }
  1215. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1216. // the Namespace type
  1217. func (target *Namespace) UnmarshalBinary(data []byte) error {
  1218. var table []string
  1219. buff := util.NewBufferFromBytes(data)
  1220. // string table header validation
  1221. if isBinaryTag(data, BinaryTagStringTable) {
  1222. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1223. tl := buff.ReadInt() // table length
  1224. if tl > 0 {
  1225. table = make([]string, tl, tl)
  1226. for i := 0; i < tl; i++ {
  1227. table[i] = buff.ReadString()
  1228. }
  1229. }
  1230. }
  1231. ctx := &DecodingContext{
  1232. Buffer: buff,
  1233. Table: table,
  1234. }
  1235. err := target.UnmarshalBinaryWithContext(ctx)
  1236. if err != nil {
  1237. return err
  1238. }
  1239. return nil
  1240. }
  1241. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1242. // the Namespace type
  1243. func (target *Namespace) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1244. // panics are recovered and propagated as errors
  1245. defer func() {
  1246. if r := recover(); r != nil {
  1247. if e, ok := r.(error); ok {
  1248. err = e
  1249. } else if s, ok := r.(string); ok {
  1250. err = fmt.Errorf("Unexpected panic: %s", s)
  1251. } else {
  1252. err = fmt.Errorf("Unexpected panic: %+v", r)
  1253. }
  1254. }
  1255. }()
  1256. buff := ctx.Buffer
  1257. version := buff.ReadUInt8()
  1258. if version > DefaultCodecVersion {
  1259. return fmt.Errorf("Invalid Version Unmarshaling Namespace. Expected %d or less, got %d", DefaultCodecVersion, version)
  1260. }
  1261. // field version check
  1262. if uint8(1) <= version {
  1263. var b string
  1264. if ctx.IsStringTable() {
  1265. c := buff.ReadInt() // read string index
  1266. b = ctx.Table[c]
  1267. } else {
  1268. b = buff.ReadString() // read string
  1269. }
  1270. a := b
  1271. target.UID = a
  1272. } else {
  1273. target.UID = "" // default
  1274. }
  1275. // field version check
  1276. if uint8(1) <= version {
  1277. var e string
  1278. if ctx.IsStringTable() {
  1279. f := buff.ReadInt() // read string index
  1280. e = ctx.Table[f]
  1281. } else {
  1282. e = buff.ReadString() // read string
  1283. }
  1284. d := e
  1285. target.ClusterUID = d
  1286. } else {
  1287. target.ClusterUID = "" // default
  1288. }
  1289. // field version check
  1290. if uint8(1) <= version {
  1291. var h string
  1292. if ctx.IsStringTable() {
  1293. k := buff.ReadInt() // read string index
  1294. h = ctx.Table[k]
  1295. } else {
  1296. h = buff.ReadString() // read string
  1297. }
  1298. g := h
  1299. target.Name = g
  1300. } else {
  1301. target.Name = "" // default
  1302. }
  1303. // field version check
  1304. if uint8(1) <= version {
  1305. if buff.ReadUInt8() == uint8(0) {
  1306. target.Labels = nil
  1307. } else {
  1308. // --- [begin][read][map](map[string]string) ---
  1309. m := buff.ReadInt() // map len
  1310. l := make(map[string]string, m)
  1311. for i := 0; i < m; i++ {
  1312. var v string
  1313. var o string
  1314. if ctx.IsStringTable() {
  1315. p := buff.ReadInt() // read string index
  1316. o = ctx.Table[p]
  1317. } else {
  1318. o = buff.ReadString() // read string
  1319. }
  1320. n := o
  1321. v = n
  1322. var z string
  1323. var r string
  1324. if ctx.IsStringTable() {
  1325. s := buff.ReadInt() // read string index
  1326. r = ctx.Table[s]
  1327. } else {
  1328. r = buff.ReadString() // read string
  1329. }
  1330. q := r
  1331. z = q
  1332. l[v] = z
  1333. }
  1334. target.Labels = l
  1335. // --- [end][read][map](map[string]string) ---
  1336. }
  1337. } else {
  1338. target.Labels = nil
  1339. }
  1340. // field version check
  1341. if uint8(1) <= version {
  1342. if buff.ReadUInt8() == uint8(0) {
  1343. target.Annotations = nil
  1344. } else {
  1345. // --- [begin][read][map](map[string]string) ---
  1346. u := buff.ReadInt() // map len
  1347. t := make(map[string]string, u)
  1348. for j := 0; j < u; j++ {
  1349. var vv string
  1350. var x string
  1351. if ctx.IsStringTable() {
  1352. y := buff.ReadInt() // read string index
  1353. x = ctx.Table[y]
  1354. } else {
  1355. x = buff.ReadString() // read string
  1356. }
  1357. w := x
  1358. vv = w
  1359. var zz string
  1360. var bb string
  1361. if ctx.IsStringTable() {
  1362. cc := buff.ReadInt() // read string index
  1363. bb = ctx.Table[cc]
  1364. } else {
  1365. bb = buff.ReadString() // read string
  1366. }
  1367. aa := bb
  1368. zz = aa
  1369. t[vv] = zz
  1370. }
  1371. target.Annotations = t
  1372. // --- [end][read][map](map[string]string) ---
  1373. }
  1374. } else {
  1375. target.Annotations = nil
  1376. }
  1377. // field version check
  1378. if uint8(1) <= version {
  1379. // --- [begin][read][reference](time.Time) ---
  1380. dd := &time.Time{}
  1381. ee := buff.ReadInt() // byte array length
  1382. ff := buff.ReadBytes(ee) // byte array
  1383. errA := dd.UnmarshalBinary(ff)
  1384. if errA != nil {
  1385. return errA
  1386. }
  1387. target.Start = *dd
  1388. // --- [end][read][reference](time.Time) ---
  1389. } else {
  1390. }
  1391. // field version check
  1392. if uint8(1) <= version {
  1393. // --- [begin][read][reference](time.Time) ---
  1394. gg := &time.Time{}
  1395. hh := buff.ReadInt() // byte array length
  1396. kk := buff.ReadBytes(hh) // byte array
  1397. errB := gg.UnmarshalBinary(kk)
  1398. if errB != nil {
  1399. return errB
  1400. }
  1401. target.End = *gg
  1402. // --- [end][read][reference](time.Time) ---
  1403. } else {
  1404. }
  1405. return nil
  1406. }
  1407. //--------------------------------------------------------------------------
  1408. // ResourceQuantity
  1409. //--------------------------------------------------------------------------
  1410. // MarshalBinary serializes the internal properties of this ResourceQuantity instance
  1411. // into a byte array
  1412. func (target *ResourceQuantity) MarshalBinary() (data []byte, err error) {
  1413. ctx := &EncodingContext{
  1414. Buffer: util.NewBuffer(),
  1415. Table: nil,
  1416. }
  1417. e := target.MarshalBinaryWithContext(ctx)
  1418. if e != nil {
  1419. return nil, e
  1420. }
  1421. encBytes := ctx.Buffer.Bytes()
  1422. return encBytes, nil
  1423. }
  1424. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuantity instance
  1425. // into a byte array leveraging a predefined context.
  1426. func (target *ResourceQuantity) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1427. // panics are recovered and propagated as errors
  1428. defer func() {
  1429. if r := recover(); r != nil {
  1430. if e, ok := r.(error); ok {
  1431. err = e
  1432. } else if s, ok := r.(string); ok {
  1433. err = fmt.Errorf("Unexpected panic: %s", s)
  1434. } else {
  1435. err = fmt.Errorf("Unexpected panic: %+v", r)
  1436. }
  1437. }
  1438. }()
  1439. buff := ctx.Buffer
  1440. buff.WriteUInt8(DefaultCodecVersion) // version
  1441. // --- [begin][write][alias](Resource) ---
  1442. if ctx.IsStringTable() {
  1443. a := ctx.Table.AddOrGet(string(target.Resource))
  1444. buff.WriteInt(a) // write table index
  1445. } else {
  1446. buff.WriteString(string(target.Resource)) // write string
  1447. }
  1448. // --- [end][write][alias](Resource) ---
  1449. // --- [begin][write][alias](Unit) ---
  1450. if ctx.IsStringTable() {
  1451. b := ctx.Table.AddOrGet(string(target.Unit))
  1452. buff.WriteInt(b) // write table index
  1453. } else {
  1454. buff.WriteString(string(target.Unit)) // write string
  1455. }
  1456. // --- [end][write][alias](Unit) ---
  1457. // --- [begin][write][alias](Stats) ---
  1458. if map[StatType]float64(target.Values) == nil {
  1459. buff.WriteUInt8(uint8(0)) // write nil byte
  1460. } else {
  1461. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1462. // --- [begin][write][map](map[StatType]float64) ---
  1463. buff.WriteInt(len(map[StatType]float64(target.Values))) // map length
  1464. for v, z := range map[StatType]float64(target.Values) {
  1465. // --- [begin][write][alias](StatType) ---
  1466. if ctx.IsStringTable() {
  1467. c := ctx.Table.AddOrGet(string(v))
  1468. buff.WriteInt(c) // write table index
  1469. } else {
  1470. buff.WriteString(string(v)) // write string
  1471. }
  1472. // --- [end][write][alias](StatType) ---
  1473. buff.WriteFloat64(z) // write float64
  1474. }
  1475. // --- [end][write][map](map[StatType]float64) ---
  1476. }
  1477. // --- [end][write][alias](Stats) ---
  1478. return nil
  1479. }
  1480. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1481. // the ResourceQuantity type
  1482. func (target *ResourceQuantity) UnmarshalBinary(data []byte) error {
  1483. var table []string
  1484. buff := util.NewBufferFromBytes(data)
  1485. // string table header validation
  1486. if isBinaryTag(data, BinaryTagStringTable) {
  1487. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1488. tl := buff.ReadInt() // table length
  1489. if tl > 0 {
  1490. table = make([]string, tl, tl)
  1491. for i := 0; i < tl; i++ {
  1492. table[i] = buff.ReadString()
  1493. }
  1494. }
  1495. }
  1496. ctx := &DecodingContext{
  1497. Buffer: buff,
  1498. Table: table,
  1499. }
  1500. err := target.UnmarshalBinaryWithContext(ctx)
  1501. if err != nil {
  1502. return err
  1503. }
  1504. return nil
  1505. }
  1506. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1507. // the ResourceQuantity type
  1508. func (target *ResourceQuantity) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1509. // panics are recovered and propagated as errors
  1510. defer func() {
  1511. if r := recover(); r != nil {
  1512. if e, ok := r.(error); ok {
  1513. err = e
  1514. } else if s, ok := r.(string); ok {
  1515. err = fmt.Errorf("Unexpected panic: %s", s)
  1516. } else {
  1517. err = fmt.Errorf("Unexpected panic: %+v", r)
  1518. }
  1519. }
  1520. }()
  1521. buff := ctx.Buffer
  1522. version := buff.ReadUInt8()
  1523. if version > DefaultCodecVersion {
  1524. return fmt.Errorf("Invalid Version Unmarshaling ResourceQuantity. Expected %d or less, got %d", DefaultCodecVersion, version)
  1525. }
  1526. // field version check
  1527. if uint8(1) <= version {
  1528. // --- [begin][read][alias](Resource) ---
  1529. var a string
  1530. var c string
  1531. if ctx.IsStringTable() {
  1532. d := buff.ReadInt() // read string index
  1533. c = ctx.Table[d]
  1534. } else {
  1535. c = buff.ReadString() // read string
  1536. }
  1537. b := c
  1538. a = b
  1539. target.Resource = Resource(a)
  1540. // --- [end][read][alias](Resource) ---
  1541. } else {
  1542. }
  1543. // field version check
  1544. if uint8(1) <= version {
  1545. // --- [begin][read][alias](Unit) ---
  1546. var e string
  1547. var g string
  1548. if ctx.IsStringTable() {
  1549. h := buff.ReadInt() // read string index
  1550. g = ctx.Table[h]
  1551. } else {
  1552. g = buff.ReadString() // read string
  1553. }
  1554. f := g
  1555. e = f
  1556. target.Unit = Unit(e)
  1557. // --- [end][read][alias](Unit) ---
  1558. } else {
  1559. }
  1560. // field version check
  1561. if uint8(1) <= version {
  1562. // --- [begin][read][alias](Stats) ---
  1563. var k map[StatType]float64
  1564. if buff.ReadUInt8() == uint8(0) {
  1565. k = nil
  1566. } else {
  1567. // --- [begin][read][map](map[StatType]float64) ---
  1568. m := buff.ReadInt() // map len
  1569. l := make(map[StatType]float64, m)
  1570. for i := 0; i < m; i++ {
  1571. // --- [begin][read][alias](StatType) ---
  1572. var n string
  1573. var p string
  1574. if ctx.IsStringTable() {
  1575. q := buff.ReadInt() // read string index
  1576. p = ctx.Table[q]
  1577. } else {
  1578. p = buff.ReadString() // read string
  1579. }
  1580. o := p
  1581. n = o
  1582. v := StatType(n)
  1583. // --- [end][read][alias](StatType) ---
  1584. var z float64
  1585. r := buff.ReadFloat64() // read float64
  1586. z = r
  1587. l[v] = z
  1588. }
  1589. k = l
  1590. // --- [end][read][map](map[StatType]float64) ---
  1591. }
  1592. target.Values = Stats(k)
  1593. // --- [end][read][alias](Stats) ---
  1594. } else {
  1595. }
  1596. return nil
  1597. }
  1598. //--------------------------------------------------------------------------
  1599. // ResourceQuota
  1600. //--------------------------------------------------------------------------
  1601. // MarshalBinary serializes the internal properties of this ResourceQuota instance
  1602. // into a byte array
  1603. func (target *ResourceQuota) MarshalBinary() (data []byte, err error) {
  1604. ctx := &EncodingContext{
  1605. Buffer: util.NewBuffer(),
  1606. Table: nil,
  1607. }
  1608. e := target.MarshalBinaryWithContext(ctx)
  1609. if e != nil {
  1610. return nil, e
  1611. }
  1612. encBytes := ctx.Buffer.Bytes()
  1613. return encBytes, nil
  1614. }
  1615. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuota instance
  1616. // into a byte array leveraging a predefined context.
  1617. func (target *ResourceQuota) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1618. // panics are recovered and propagated as errors
  1619. defer func() {
  1620. if r := recover(); r != nil {
  1621. if e, ok := r.(error); ok {
  1622. err = e
  1623. } else if s, ok := r.(string); ok {
  1624. err = fmt.Errorf("Unexpected panic: %s", s)
  1625. } else {
  1626. err = fmt.Errorf("Unexpected panic: %+v", r)
  1627. }
  1628. }
  1629. }()
  1630. buff := ctx.Buffer
  1631. buff.WriteUInt8(DefaultCodecVersion) // version
  1632. if ctx.IsStringTable() {
  1633. a := ctx.Table.AddOrGet(target.UID)
  1634. buff.WriteInt(a) // write table index
  1635. } else {
  1636. buff.WriteString(target.UID) // write string
  1637. }
  1638. if ctx.IsStringTable() {
  1639. b := ctx.Table.AddOrGet(target.NamespaceUID)
  1640. buff.WriteInt(b) // write table index
  1641. } else {
  1642. buff.WriteString(target.NamespaceUID) // write string
  1643. }
  1644. if ctx.IsStringTable() {
  1645. c := ctx.Table.AddOrGet(target.Name)
  1646. buff.WriteInt(c) // write table index
  1647. } else {
  1648. buff.WriteString(target.Name) // write string
  1649. }
  1650. if target.Spec == nil {
  1651. buff.WriteUInt8(uint8(0)) // write nil byte
  1652. } else {
  1653. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1654. // --- [begin][write][struct](ResourceQuotaSpec) ---
  1655. buff.WriteInt(0) // [compatibility, unused]
  1656. errA := target.Spec.MarshalBinaryWithContext(ctx)
  1657. if errA != nil {
  1658. return errA
  1659. }
  1660. // --- [end][write][struct](ResourceQuotaSpec) ---
  1661. }
  1662. if target.Status == nil {
  1663. buff.WriteUInt8(uint8(0)) // write nil byte
  1664. } else {
  1665. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1666. // --- [begin][write][struct](ResourceQuotaStatus) ---
  1667. buff.WriteInt(0) // [compatibility, unused]
  1668. errB := target.Status.MarshalBinaryWithContext(ctx)
  1669. if errB != nil {
  1670. return errB
  1671. }
  1672. // --- [end][write][struct](ResourceQuotaStatus) ---
  1673. }
  1674. // --- [begin][write][reference](time.Time) ---
  1675. d, errC := target.Start.MarshalBinary()
  1676. if errC != nil {
  1677. return errC
  1678. }
  1679. buff.WriteInt(len(d))
  1680. buff.WriteBytes(d)
  1681. // --- [end][write][reference](time.Time) ---
  1682. // --- [begin][write][reference](time.Time) ---
  1683. e, errD := target.End.MarshalBinary()
  1684. if errD != nil {
  1685. return errD
  1686. }
  1687. buff.WriteInt(len(e))
  1688. buff.WriteBytes(e)
  1689. // --- [end][write][reference](time.Time) ---
  1690. return nil
  1691. }
  1692. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1693. // the ResourceQuota type
  1694. func (target *ResourceQuota) UnmarshalBinary(data []byte) error {
  1695. var table []string
  1696. buff := util.NewBufferFromBytes(data)
  1697. // string table header validation
  1698. if isBinaryTag(data, BinaryTagStringTable) {
  1699. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1700. tl := buff.ReadInt() // table length
  1701. if tl > 0 {
  1702. table = make([]string, tl, tl)
  1703. for i := 0; i < tl; i++ {
  1704. table[i] = buff.ReadString()
  1705. }
  1706. }
  1707. }
  1708. ctx := &DecodingContext{
  1709. Buffer: buff,
  1710. Table: table,
  1711. }
  1712. err := target.UnmarshalBinaryWithContext(ctx)
  1713. if err != nil {
  1714. return err
  1715. }
  1716. return nil
  1717. }
  1718. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1719. // the ResourceQuota type
  1720. func (target *ResourceQuota) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1721. // panics are recovered and propagated as errors
  1722. defer func() {
  1723. if r := recover(); r != nil {
  1724. if e, ok := r.(error); ok {
  1725. err = e
  1726. } else if s, ok := r.(string); ok {
  1727. err = fmt.Errorf("Unexpected panic: %s", s)
  1728. } else {
  1729. err = fmt.Errorf("Unexpected panic: %+v", r)
  1730. }
  1731. }
  1732. }()
  1733. buff := ctx.Buffer
  1734. version := buff.ReadUInt8()
  1735. if version > DefaultCodecVersion {
  1736. return fmt.Errorf("Invalid Version Unmarshaling ResourceQuota. Expected %d or less, got %d", DefaultCodecVersion, version)
  1737. }
  1738. // field version check
  1739. if uint8(1) <= version {
  1740. var b string
  1741. if ctx.IsStringTable() {
  1742. c := buff.ReadInt() // read string index
  1743. b = ctx.Table[c]
  1744. } else {
  1745. b = buff.ReadString() // read string
  1746. }
  1747. a := b
  1748. target.UID = a
  1749. } else {
  1750. target.UID = "" // default
  1751. }
  1752. // field version check
  1753. if uint8(1) <= version {
  1754. var e string
  1755. if ctx.IsStringTable() {
  1756. f := buff.ReadInt() // read string index
  1757. e = ctx.Table[f]
  1758. } else {
  1759. e = buff.ReadString() // read string
  1760. }
  1761. d := e
  1762. target.NamespaceUID = d
  1763. } else {
  1764. target.NamespaceUID = "" // default
  1765. }
  1766. // field version check
  1767. if uint8(1) <= version {
  1768. var h string
  1769. if ctx.IsStringTable() {
  1770. k := buff.ReadInt() // read string index
  1771. h = ctx.Table[k]
  1772. } else {
  1773. h = buff.ReadString() // read string
  1774. }
  1775. g := h
  1776. target.Name = g
  1777. } else {
  1778. target.Name = "" // default
  1779. }
  1780. // field version check
  1781. if uint8(1) <= version {
  1782. if buff.ReadUInt8() == uint8(0) {
  1783. target.Spec = nil
  1784. } else {
  1785. // --- [begin][read][struct](ResourceQuotaSpec) ---
  1786. l := &ResourceQuotaSpec{}
  1787. buff.ReadInt() // [compatibility, unused]
  1788. errA := l.UnmarshalBinaryWithContext(ctx)
  1789. if errA != nil {
  1790. return errA
  1791. }
  1792. target.Spec = l
  1793. // --- [end][read][struct](ResourceQuotaSpec) ---
  1794. }
  1795. } else {
  1796. target.Spec = nil
  1797. }
  1798. // field version check
  1799. if uint8(1) <= version {
  1800. if buff.ReadUInt8() == uint8(0) {
  1801. target.Status = nil
  1802. } else {
  1803. // --- [begin][read][struct](ResourceQuotaStatus) ---
  1804. m := &ResourceQuotaStatus{}
  1805. buff.ReadInt() // [compatibility, unused]
  1806. errB := m.UnmarshalBinaryWithContext(ctx)
  1807. if errB != nil {
  1808. return errB
  1809. }
  1810. target.Status = m
  1811. // --- [end][read][struct](ResourceQuotaStatus) ---
  1812. }
  1813. } else {
  1814. target.Status = nil
  1815. }
  1816. // field version check
  1817. if uint8(1) <= version {
  1818. // --- [begin][read][reference](time.Time) ---
  1819. n := &time.Time{}
  1820. o := buff.ReadInt() // byte array length
  1821. p := buff.ReadBytes(o) // byte array
  1822. errC := n.UnmarshalBinary(p)
  1823. if errC != nil {
  1824. return errC
  1825. }
  1826. target.Start = *n
  1827. // --- [end][read][reference](time.Time) ---
  1828. } else {
  1829. }
  1830. // field version check
  1831. if uint8(1) <= version {
  1832. // --- [begin][read][reference](time.Time) ---
  1833. q := &time.Time{}
  1834. r := buff.ReadInt() // byte array length
  1835. s := buff.ReadBytes(r) // byte array
  1836. errD := q.UnmarshalBinary(s)
  1837. if errD != nil {
  1838. return errD
  1839. }
  1840. target.End = *q
  1841. // --- [end][read][reference](time.Time) ---
  1842. } else {
  1843. }
  1844. return nil
  1845. }
  1846. //--------------------------------------------------------------------------
  1847. // ResourceQuotaSpec
  1848. //--------------------------------------------------------------------------
  1849. // MarshalBinary serializes the internal properties of this ResourceQuotaSpec instance
  1850. // into a byte array
  1851. func (target *ResourceQuotaSpec) MarshalBinary() (data []byte, err error) {
  1852. ctx := &EncodingContext{
  1853. Buffer: util.NewBuffer(),
  1854. Table: nil,
  1855. }
  1856. e := target.MarshalBinaryWithContext(ctx)
  1857. if e != nil {
  1858. return nil, e
  1859. }
  1860. encBytes := ctx.Buffer.Bytes()
  1861. return encBytes, nil
  1862. }
  1863. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaSpec instance
  1864. // into a byte array leveraging a predefined context.
  1865. func (target *ResourceQuotaSpec) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1866. // panics are recovered and propagated as errors
  1867. defer func() {
  1868. if r := recover(); r != nil {
  1869. if e, ok := r.(error); ok {
  1870. err = e
  1871. } else if s, ok := r.(string); ok {
  1872. err = fmt.Errorf("Unexpected panic: %s", s)
  1873. } else {
  1874. err = fmt.Errorf("Unexpected panic: %+v", r)
  1875. }
  1876. }
  1877. }()
  1878. buff := ctx.Buffer
  1879. buff.WriteUInt8(DefaultCodecVersion) // version
  1880. if target.Hard == nil {
  1881. buff.WriteUInt8(uint8(0)) // write nil byte
  1882. } else {
  1883. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1884. // --- [begin][write][struct](ResourceQuotaSpecHard) ---
  1885. buff.WriteInt(0) // [compatibility, unused]
  1886. errA := target.Hard.MarshalBinaryWithContext(ctx)
  1887. if errA != nil {
  1888. return errA
  1889. }
  1890. // --- [end][write][struct](ResourceQuotaSpecHard) ---
  1891. }
  1892. return nil
  1893. }
  1894. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1895. // the ResourceQuotaSpec type
  1896. func (target *ResourceQuotaSpec) UnmarshalBinary(data []byte) error {
  1897. var table []string
  1898. buff := util.NewBufferFromBytes(data)
  1899. // string table header validation
  1900. if isBinaryTag(data, BinaryTagStringTable) {
  1901. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1902. tl := buff.ReadInt() // table length
  1903. if tl > 0 {
  1904. table = make([]string, tl, tl)
  1905. for i := 0; i < tl; i++ {
  1906. table[i] = buff.ReadString()
  1907. }
  1908. }
  1909. }
  1910. ctx := &DecodingContext{
  1911. Buffer: buff,
  1912. Table: table,
  1913. }
  1914. err := target.UnmarshalBinaryWithContext(ctx)
  1915. if err != nil {
  1916. return err
  1917. }
  1918. return nil
  1919. }
  1920. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1921. // the ResourceQuotaSpec type
  1922. func (target *ResourceQuotaSpec) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1923. // panics are recovered and propagated as errors
  1924. defer func() {
  1925. if r := recover(); r != nil {
  1926. if e, ok := r.(error); ok {
  1927. err = e
  1928. } else if s, ok := r.(string); ok {
  1929. err = fmt.Errorf("Unexpected panic: %s", s)
  1930. } else {
  1931. err = fmt.Errorf("Unexpected panic: %+v", r)
  1932. }
  1933. }
  1934. }()
  1935. buff := ctx.Buffer
  1936. version := buff.ReadUInt8()
  1937. if version > DefaultCodecVersion {
  1938. return fmt.Errorf("Invalid Version Unmarshaling ResourceQuotaSpec. Expected %d or less, got %d", DefaultCodecVersion, version)
  1939. }
  1940. // field version check
  1941. if uint8(1) <= version {
  1942. if buff.ReadUInt8() == uint8(0) {
  1943. target.Hard = nil
  1944. } else {
  1945. // --- [begin][read][struct](ResourceQuotaSpecHard) ---
  1946. a := &ResourceQuotaSpecHard{}
  1947. buff.ReadInt() // [compatibility, unused]
  1948. errA := a.UnmarshalBinaryWithContext(ctx)
  1949. if errA != nil {
  1950. return errA
  1951. }
  1952. target.Hard = a
  1953. // --- [end][read][struct](ResourceQuotaSpecHard) ---
  1954. }
  1955. } else {
  1956. target.Hard = nil
  1957. }
  1958. return nil
  1959. }
  1960. //--------------------------------------------------------------------------
  1961. // ResourceQuotaSpecHard
  1962. //--------------------------------------------------------------------------
  1963. // MarshalBinary serializes the internal properties of this ResourceQuotaSpecHard instance
  1964. // into a byte array
  1965. func (target *ResourceQuotaSpecHard) MarshalBinary() (data []byte, err error) {
  1966. ctx := &EncodingContext{
  1967. Buffer: util.NewBuffer(),
  1968. Table: nil,
  1969. }
  1970. e := target.MarshalBinaryWithContext(ctx)
  1971. if e != nil {
  1972. return nil, e
  1973. }
  1974. encBytes := ctx.Buffer.Bytes()
  1975. return encBytes, nil
  1976. }
  1977. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaSpecHard instance
  1978. // into a byte array leveraging a predefined context.
  1979. func (target *ResourceQuotaSpecHard) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1980. // panics are recovered and propagated as errors
  1981. defer func() {
  1982. if r := recover(); r != nil {
  1983. if e, ok := r.(error); ok {
  1984. err = e
  1985. } else if s, ok := r.(string); ok {
  1986. err = fmt.Errorf("Unexpected panic: %s", s)
  1987. } else {
  1988. err = fmt.Errorf("Unexpected panic: %+v", r)
  1989. }
  1990. }
  1991. }()
  1992. buff := ctx.Buffer
  1993. buff.WriteUInt8(DefaultCodecVersion) // version
  1994. // --- [begin][write][alias](ResourceQuantities) ---
  1995. if map[Resource]ResourceQuantity(target.Requests) == nil {
  1996. buff.WriteUInt8(uint8(0)) // write nil byte
  1997. } else {
  1998. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1999. // --- [begin][write][map](map[Resource]ResourceQuantity) ---
  2000. buff.WriteInt(len(map[Resource]ResourceQuantity(target.Requests))) // map length
  2001. for v, z := range map[Resource]ResourceQuantity(target.Requests) {
  2002. // --- [begin][write][alias](Resource) ---
  2003. if ctx.IsStringTable() {
  2004. a := ctx.Table.AddOrGet(string(v))
  2005. buff.WriteInt(a) // write table index
  2006. } else {
  2007. buff.WriteString(string(v)) // write string
  2008. }
  2009. // --- [end][write][alias](Resource) ---
  2010. // --- [begin][write][struct](ResourceQuantity) ---
  2011. buff.WriteInt(0) // [compatibility, unused]
  2012. errA := z.MarshalBinaryWithContext(ctx)
  2013. if errA != nil {
  2014. return errA
  2015. }
  2016. // --- [end][write][struct](ResourceQuantity) ---
  2017. }
  2018. // --- [end][write][map](map[Resource]ResourceQuantity) ---
  2019. }
  2020. // --- [end][write][alias](ResourceQuantities) ---
  2021. // --- [begin][write][alias](ResourceQuantities) ---
  2022. if map[Resource]ResourceQuantity(target.Limits) == nil {
  2023. buff.WriteUInt8(uint8(0)) // write nil byte
  2024. } else {
  2025. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2026. // --- [begin][write][map](map[Resource]ResourceQuantity) ---
  2027. buff.WriteInt(len(map[Resource]ResourceQuantity(target.Limits))) // map length
  2028. for vv, zz := range map[Resource]ResourceQuantity(target.Limits) {
  2029. // --- [begin][write][alias](Resource) ---
  2030. if ctx.IsStringTable() {
  2031. b := ctx.Table.AddOrGet(string(vv))
  2032. buff.WriteInt(b) // write table index
  2033. } else {
  2034. buff.WriteString(string(vv)) // write string
  2035. }
  2036. // --- [end][write][alias](Resource) ---
  2037. // --- [begin][write][struct](ResourceQuantity) ---
  2038. buff.WriteInt(0) // [compatibility, unused]
  2039. errB := zz.MarshalBinaryWithContext(ctx)
  2040. if errB != nil {
  2041. return errB
  2042. }
  2043. // --- [end][write][struct](ResourceQuantity) ---
  2044. }
  2045. // --- [end][write][map](map[Resource]ResourceQuantity) ---
  2046. }
  2047. // --- [end][write][alias](ResourceQuantities) ---
  2048. return nil
  2049. }
  2050. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2051. // the ResourceQuotaSpecHard type
  2052. func (target *ResourceQuotaSpecHard) UnmarshalBinary(data []byte) error {
  2053. var table []string
  2054. buff := util.NewBufferFromBytes(data)
  2055. // string table header validation
  2056. if isBinaryTag(data, BinaryTagStringTable) {
  2057. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2058. tl := buff.ReadInt() // table length
  2059. if tl > 0 {
  2060. table = make([]string, tl, tl)
  2061. for i := 0; i < tl; i++ {
  2062. table[i] = buff.ReadString()
  2063. }
  2064. }
  2065. }
  2066. ctx := &DecodingContext{
  2067. Buffer: buff,
  2068. Table: table,
  2069. }
  2070. err := target.UnmarshalBinaryWithContext(ctx)
  2071. if err != nil {
  2072. return err
  2073. }
  2074. return nil
  2075. }
  2076. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2077. // the ResourceQuotaSpecHard type
  2078. func (target *ResourceQuotaSpecHard) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2079. // panics are recovered and propagated as errors
  2080. defer func() {
  2081. if r := recover(); r != nil {
  2082. if e, ok := r.(error); ok {
  2083. err = e
  2084. } else if s, ok := r.(string); ok {
  2085. err = fmt.Errorf("Unexpected panic: %s", s)
  2086. } else {
  2087. err = fmt.Errorf("Unexpected panic: %+v", r)
  2088. }
  2089. }
  2090. }()
  2091. buff := ctx.Buffer
  2092. version := buff.ReadUInt8()
  2093. if version > DefaultCodecVersion {
  2094. return fmt.Errorf("Invalid Version Unmarshaling ResourceQuotaSpecHard. Expected %d or less, got %d", DefaultCodecVersion, version)
  2095. }
  2096. // field version check
  2097. if uint8(1) <= version {
  2098. // --- [begin][read][alias](ResourceQuantities) ---
  2099. var a map[Resource]ResourceQuantity
  2100. if buff.ReadUInt8() == uint8(0) {
  2101. a = nil
  2102. } else {
  2103. // --- [begin][read][map](map[Resource]ResourceQuantity) ---
  2104. c := buff.ReadInt() // map len
  2105. b := make(map[Resource]ResourceQuantity, c)
  2106. for i := 0; i < c; i++ {
  2107. // --- [begin][read][alias](Resource) ---
  2108. var d string
  2109. var f string
  2110. if ctx.IsStringTable() {
  2111. g := buff.ReadInt() // read string index
  2112. f = ctx.Table[g]
  2113. } else {
  2114. f = buff.ReadString() // read string
  2115. }
  2116. e := f
  2117. d = e
  2118. v := Resource(d)
  2119. // --- [end][read][alias](Resource) ---
  2120. // --- [begin][read][struct](ResourceQuantity) ---
  2121. h := &ResourceQuantity{}
  2122. buff.ReadInt() // [compatibility, unused]
  2123. errA := h.UnmarshalBinaryWithContext(ctx)
  2124. if errA != nil {
  2125. return errA
  2126. }
  2127. z := *h
  2128. // --- [end][read][struct](ResourceQuantity) ---
  2129. b[v] = z
  2130. }
  2131. a = b
  2132. // --- [end][read][map](map[Resource]ResourceQuantity) ---
  2133. }
  2134. target.Requests = ResourceQuantities(a)
  2135. // --- [end][read][alias](ResourceQuantities) ---
  2136. } else {
  2137. }
  2138. // field version check
  2139. if uint8(1) <= version {
  2140. // --- [begin][read][alias](ResourceQuantities) ---
  2141. var k map[Resource]ResourceQuantity
  2142. if buff.ReadUInt8() == uint8(0) {
  2143. k = nil
  2144. } else {
  2145. // --- [begin][read][map](map[Resource]ResourceQuantity) ---
  2146. m := buff.ReadInt() // map len
  2147. l := make(map[Resource]ResourceQuantity, m)
  2148. for j := 0; j < m; j++ {
  2149. // --- [begin][read][alias](Resource) ---
  2150. var n string
  2151. var p string
  2152. if ctx.IsStringTable() {
  2153. q := buff.ReadInt() // read string index
  2154. p = ctx.Table[q]
  2155. } else {
  2156. p = buff.ReadString() // read string
  2157. }
  2158. o := p
  2159. n = o
  2160. vv := Resource(n)
  2161. // --- [end][read][alias](Resource) ---
  2162. // --- [begin][read][struct](ResourceQuantity) ---
  2163. r := &ResourceQuantity{}
  2164. buff.ReadInt() // [compatibility, unused]
  2165. errB := r.UnmarshalBinaryWithContext(ctx)
  2166. if errB != nil {
  2167. return errB
  2168. }
  2169. zz := *r
  2170. // --- [end][read][struct](ResourceQuantity) ---
  2171. l[vv] = zz
  2172. }
  2173. k = l
  2174. // --- [end][read][map](map[Resource]ResourceQuantity) ---
  2175. }
  2176. target.Limits = ResourceQuantities(k)
  2177. // --- [end][read][alias](ResourceQuantities) ---
  2178. } else {
  2179. }
  2180. return nil
  2181. }
  2182. //--------------------------------------------------------------------------
  2183. // ResourceQuotaStatus
  2184. //--------------------------------------------------------------------------
  2185. // MarshalBinary serializes the internal properties of this ResourceQuotaStatus instance
  2186. // into a byte array
  2187. func (target *ResourceQuotaStatus) MarshalBinary() (data []byte, err error) {
  2188. ctx := &EncodingContext{
  2189. Buffer: util.NewBuffer(),
  2190. Table: nil,
  2191. }
  2192. e := target.MarshalBinaryWithContext(ctx)
  2193. if e != nil {
  2194. return nil, e
  2195. }
  2196. encBytes := ctx.Buffer.Bytes()
  2197. return encBytes, nil
  2198. }
  2199. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaStatus instance
  2200. // into a byte array leveraging a predefined context.
  2201. func (target *ResourceQuotaStatus) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2202. // panics are recovered and propagated as errors
  2203. defer func() {
  2204. if r := recover(); r != nil {
  2205. if e, ok := r.(error); ok {
  2206. err = e
  2207. } else if s, ok := r.(string); ok {
  2208. err = fmt.Errorf("Unexpected panic: %s", s)
  2209. } else {
  2210. err = fmt.Errorf("Unexpected panic: %+v", r)
  2211. }
  2212. }
  2213. }()
  2214. buff := ctx.Buffer
  2215. buff.WriteUInt8(DefaultCodecVersion) // version
  2216. if target.Used == nil {
  2217. buff.WriteUInt8(uint8(0)) // write nil byte
  2218. } else {
  2219. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2220. // --- [begin][write][struct](ResourceQuotaStatusUsed) ---
  2221. buff.WriteInt(0) // [compatibility, unused]
  2222. errA := target.Used.MarshalBinaryWithContext(ctx)
  2223. if errA != nil {
  2224. return errA
  2225. }
  2226. // --- [end][write][struct](ResourceQuotaStatusUsed) ---
  2227. }
  2228. return nil
  2229. }
  2230. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2231. // the ResourceQuotaStatus type
  2232. func (target *ResourceQuotaStatus) UnmarshalBinary(data []byte) error {
  2233. var table []string
  2234. buff := util.NewBufferFromBytes(data)
  2235. // string table header validation
  2236. if isBinaryTag(data, BinaryTagStringTable) {
  2237. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2238. tl := buff.ReadInt() // table length
  2239. if tl > 0 {
  2240. table = make([]string, tl, tl)
  2241. for i := 0; i < tl; i++ {
  2242. table[i] = buff.ReadString()
  2243. }
  2244. }
  2245. }
  2246. ctx := &DecodingContext{
  2247. Buffer: buff,
  2248. Table: table,
  2249. }
  2250. err := target.UnmarshalBinaryWithContext(ctx)
  2251. if err != nil {
  2252. return err
  2253. }
  2254. return nil
  2255. }
  2256. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2257. // the ResourceQuotaStatus type
  2258. func (target *ResourceQuotaStatus) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2259. // panics are recovered and propagated as errors
  2260. defer func() {
  2261. if r := recover(); r != nil {
  2262. if e, ok := r.(error); ok {
  2263. err = e
  2264. } else if s, ok := r.(string); ok {
  2265. err = fmt.Errorf("Unexpected panic: %s", s)
  2266. } else {
  2267. err = fmt.Errorf("Unexpected panic: %+v", r)
  2268. }
  2269. }
  2270. }()
  2271. buff := ctx.Buffer
  2272. version := buff.ReadUInt8()
  2273. if version > DefaultCodecVersion {
  2274. return fmt.Errorf("Invalid Version Unmarshaling ResourceQuotaStatus. Expected %d or less, got %d", DefaultCodecVersion, version)
  2275. }
  2276. // field version check
  2277. if uint8(1) <= version {
  2278. if buff.ReadUInt8() == uint8(0) {
  2279. target.Used = nil
  2280. } else {
  2281. // --- [begin][read][struct](ResourceQuotaStatusUsed) ---
  2282. a := &ResourceQuotaStatusUsed{}
  2283. buff.ReadInt() // [compatibility, unused]
  2284. errA := a.UnmarshalBinaryWithContext(ctx)
  2285. if errA != nil {
  2286. return errA
  2287. }
  2288. target.Used = a
  2289. // --- [end][read][struct](ResourceQuotaStatusUsed) ---
  2290. }
  2291. } else {
  2292. target.Used = nil
  2293. }
  2294. return nil
  2295. }
  2296. //--------------------------------------------------------------------------
  2297. // ResourceQuotaStatusUsed
  2298. //--------------------------------------------------------------------------
  2299. // MarshalBinary serializes the internal properties of this ResourceQuotaStatusUsed instance
  2300. // into a byte array
  2301. func (target *ResourceQuotaStatusUsed) MarshalBinary() (data []byte, err error) {
  2302. ctx := &EncodingContext{
  2303. Buffer: util.NewBuffer(),
  2304. Table: nil,
  2305. }
  2306. e := target.MarshalBinaryWithContext(ctx)
  2307. if e != nil {
  2308. return nil, e
  2309. }
  2310. encBytes := ctx.Buffer.Bytes()
  2311. return encBytes, nil
  2312. }
  2313. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaStatusUsed instance
  2314. // into a byte array leveraging a predefined context.
  2315. func (target *ResourceQuotaStatusUsed) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2316. // panics are recovered and propagated as errors
  2317. defer func() {
  2318. if r := recover(); r != nil {
  2319. if e, ok := r.(error); ok {
  2320. err = e
  2321. } else if s, ok := r.(string); ok {
  2322. err = fmt.Errorf("Unexpected panic: %s", s)
  2323. } else {
  2324. err = fmt.Errorf("Unexpected panic: %+v", r)
  2325. }
  2326. }
  2327. }()
  2328. buff := ctx.Buffer
  2329. buff.WriteUInt8(DefaultCodecVersion) // version
  2330. // --- [begin][write][alias](ResourceQuantities) ---
  2331. if map[Resource]ResourceQuantity(target.Requests) == nil {
  2332. buff.WriteUInt8(uint8(0)) // write nil byte
  2333. } else {
  2334. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2335. // --- [begin][write][map](map[Resource]ResourceQuantity) ---
  2336. buff.WriteInt(len(map[Resource]ResourceQuantity(target.Requests))) // map length
  2337. for v, z := range map[Resource]ResourceQuantity(target.Requests) {
  2338. // --- [begin][write][alias](Resource) ---
  2339. if ctx.IsStringTable() {
  2340. a := ctx.Table.AddOrGet(string(v))
  2341. buff.WriteInt(a) // write table index
  2342. } else {
  2343. buff.WriteString(string(v)) // write string
  2344. }
  2345. // --- [end][write][alias](Resource) ---
  2346. // --- [begin][write][struct](ResourceQuantity) ---
  2347. buff.WriteInt(0) // [compatibility, unused]
  2348. errA := z.MarshalBinaryWithContext(ctx)
  2349. if errA != nil {
  2350. return errA
  2351. }
  2352. // --- [end][write][struct](ResourceQuantity) ---
  2353. }
  2354. // --- [end][write][map](map[Resource]ResourceQuantity) ---
  2355. }
  2356. // --- [end][write][alias](ResourceQuantities) ---
  2357. // --- [begin][write][alias](ResourceQuantities) ---
  2358. if map[Resource]ResourceQuantity(target.Limits) == nil {
  2359. buff.WriteUInt8(uint8(0)) // write nil byte
  2360. } else {
  2361. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2362. // --- [begin][write][map](map[Resource]ResourceQuantity) ---
  2363. buff.WriteInt(len(map[Resource]ResourceQuantity(target.Limits))) // map length
  2364. for vv, zz := range map[Resource]ResourceQuantity(target.Limits) {
  2365. // --- [begin][write][alias](Resource) ---
  2366. if ctx.IsStringTable() {
  2367. b := ctx.Table.AddOrGet(string(vv))
  2368. buff.WriteInt(b) // write table index
  2369. } else {
  2370. buff.WriteString(string(vv)) // write string
  2371. }
  2372. // --- [end][write][alias](Resource) ---
  2373. // --- [begin][write][struct](ResourceQuantity) ---
  2374. buff.WriteInt(0) // [compatibility, unused]
  2375. errB := zz.MarshalBinaryWithContext(ctx)
  2376. if errB != nil {
  2377. return errB
  2378. }
  2379. // --- [end][write][struct](ResourceQuantity) ---
  2380. }
  2381. // --- [end][write][map](map[Resource]ResourceQuantity) ---
  2382. }
  2383. // --- [end][write][alias](ResourceQuantities) ---
  2384. return nil
  2385. }
  2386. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2387. // the ResourceQuotaStatusUsed type
  2388. func (target *ResourceQuotaStatusUsed) UnmarshalBinary(data []byte) error {
  2389. var table []string
  2390. buff := util.NewBufferFromBytes(data)
  2391. // string table header validation
  2392. if isBinaryTag(data, BinaryTagStringTable) {
  2393. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2394. tl := buff.ReadInt() // table length
  2395. if tl > 0 {
  2396. table = make([]string, tl, tl)
  2397. for i := 0; i < tl; i++ {
  2398. table[i] = buff.ReadString()
  2399. }
  2400. }
  2401. }
  2402. ctx := &DecodingContext{
  2403. Buffer: buff,
  2404. Table: table,
  2405. }
  2406. err := target.UnmarshalBinaryWithContext(ctx)
  2407. if err != nil {
  2408. return err
  2409. }
  2410. return nil
  2411. }
  2412. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2413. // the ResourceQuotaStatusUsed type
  2414. func (target *ResourceQuotaStatusUsed) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2415. // panics are recovered and propagated as errors
  2416. defer func() {
  2417. if r := recover(); r != nil {
  2418. if e, ok := r.(error); ok {
  2419. err = e
  2420. } else if s, ok := r.(string); ok {
  2421. err = fmt.Errorf("Unexpected panic: %s", s)
  2422. } else {
  2423. err = fmt.Errorf("Unexpected panic: %+v", r)
  2424. }
  2425. }
  2426. }()
  2427. buff := ctx.Buffer
  2428. version := buff.ReadUInt8()
  2429. if version > DefaultCodecVersion {
  2430. return fmt.Errorf("Invalid Version Unmarshaling ResourceQuotaStatusUsed. Expected %d or less, got %d", DefaultCodecVersion, version)
  2431. }
  2432. // field version check
  2433. if uint8(1) <= version {
  2434. // --- [begin][read][alias](ResourceQuantities) ---
  2435. var a map[Resource]ResourceQuantity
  2436. if buff.ReadUInt8() == uint8(0) {
  2437. a = nil
  2438. } else {
  2439. // --- [begin][read][map](map[Resource]ResourceQuantity) ---
  2440. c := buff.ReadInt() // map len
  2441. b := make(map[Resource]ResourceQuantity, c)
  2442. for i := 0; i < c; i++ {
  2443. // --- [begin][read][alias](Resource) ---
  2444. var d string
  2445. var f string
  2446. if ctx.IsStringTable() {
  2447. g := buff.ReadInt() // read string index
  2448. f = ctx.Table[g]
  2449. } else {
  2450. f = buff.ReadString() // read string
  2451. }
  2452. e := f
  2453. d = e
  2454. v := Resource(d)
  2455. // --- [end][read][alias](Resource) ---
  2456. // --- [begin][read][struct](ResourceQuantity) ---
  2457. h := &ResourceQuantity{}
  2458. buff.ReadInt() // [compatibility, unused]
  2459. errA := h.UnmarshalBinaryWithContext(ctx)
  2460. if errA != nil {
  2461. return errA
  2462. }
  2463. z := *h
  2464. // --- [end][read][struct](ResourceQuantity) ---
  2465. b[v] = z
  2466. }
  2467. a = b
  2468. // --- [end][read][map](map[Resource]ResourceQuantity) ---
  2469. }
  2470. target.Requests = ResourceQuantities(a)
  2471. // --- [end][read][alias](ResourceQuantities) ---
  2472. } else {
  2473. }
  2474. // field version check
  2475. if uint8(1) <= version {
  2476. // --- [begin][read][alias](ResourceQuantities) ---
  2477. var k map[Resource]ResourceQuantity
  2478. if buff.ReadUInt8() == uint8(0) {
  2479. k = nil
  2480. } else {
  2481. // --- [begin][read][map](map[Resource]ResourceQuantity) ---
  2482. m := buff.ReadInt() // map len
  2483. l := make(map[Resource]ResourceQuantity, m)
  2484. for j := 0; j < m; j++ {
  2485. // --- [begin][read][alias](Resource) ---
  2486. var n string
  2487. var p string
  2488. if ctx.IsStringTable() {
  2489. q := buff.ReadInt() // read string index
  2490. p = ctx.Table[q]
  2491. } else {
  2492. p = buff.ReadString() // read string
  2493. }
  2494. o := p
  2495. n = o
  2496. vv := Resource(n)
  2497. // --- [end][read][alias](Resource) ---
  2498. // --- [begin][read][struct](ResourceQuantity) ---
  2499. r := &ResourceQuantity{}
  2500. buff.ReadInt() // [compatibility, unused]
  2501. errB := r.UnmarshalBinaryWithContext(ctx)
  2502. if errB != nil {
  2503. return errB
  2504. }
  2505. zz := *r
  2506. // --- [end][read][struct](ResourceQuantity) ---
  2507. l[vv] = zz
  2508. }
  2509. k = l
  2510. // --- [end][read][map](map[Resource]ResourceQuantity) ---
  2511. }
  2512. target.Limits = ResourceQuantities(k)
  2513. // --- [end][read][alias](ResourceQuantities) ---
  2514. } else {
  2515. }
  2516. return nil
  2517. }
  2518. //--------------------------------------------------------------------------
  2519. // Window
  2520. //--------------------------------------------------------------------------
  2521. // MarshalBinary serializes the internal properties of this Window instance
  2522. // into a byte array
  2523. func (target *Window) MarshalBinary() (data []byte, err error) {
  2524. ctx := &EncodingContext{
  2525. Buffer: util.NewBuffer(),
  2526. Table: nil,
  2527. }
  2528. e := target.MarshalBinaryWithContext(ctx)
  2529. if e != nil {
  2530. return nil, e
  2531. }
  2532. encBytes := ctx.Buffer.Bytes()
  2533. return encBytes, nil
  2534. }
  2535. // MarshalBinaryWithContext serializes the internal properties of this Window instance
  2536. // into a byte array leveraging a predefined context.
  2537. func (target *Window) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2538. // panics are recovered and propagated as errors
  2539. defer func() {
  2540. if r := recover(); r != nil {
  2541. if e, ok := r.(error); ok {
  2542. err = e
  2543. } else if s, ok := r.(string); ok {
  2544. err = fmt.Errorf("Unexpected panic: %s", s)
  2545. } else {
  2546. err = fmt.Errorf("Unexpected panic: %+v", r)
  2547. }
  2548. }
  2549. }()
  2550. buff := ctx.Buffer
  2551. buff.WriteUInt8(DefaultCodecVersion) // version
  2552. // --- [begin][write][reference](time.Time) ---
  2553. a, errA := target.Start.MarshalBinary()
  2554. if errA != nil {
  2555. return errA
  2556. }
  2557. buff.WriteInt(len(a))
  2558. buff.WriteBytes(a)
  2559. // --- [end][write][reference](time.Time) ---
  2560. // --- [begin][write][reference](time.Time) ---
  2561. b, errB := target.End.MarshalBinary()
  2562. if errB != nil {
  2563. return errB
  2564. }
  2565. buff.WriteInt(len(b))
  2566. buff.WriteBytes(b)
  2567. // --- [end][write][reference](time.Time) ---
  2568. return nil
  2569. }
  2570. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2571. // the Window type
  2572. func (target *Window) UnmarshalBinary(data []byte) error {
  2573. var table []string
  2574. buff := util.NewBufferFromBytes(data)
  2575. // string table header validation
  2576. if isBinaryTag(data, BinaryTagStringTable) {
  2577. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2578. tl := buff.ReadInt() // table length
  2579. if tl > 0 {
  2580. table = make([]string, tl, tl)
  2581. for i := 0; i < tl; i++ {
  2582. table[i] = buff.ReadString()
  2583. }
  2584. }
  2585. }
  2586. ctx := &DecodingContext{
  2587. Buffer: buff,
  2588. Table: table,
  2589. }
  2590. err := target.UnmarshalBinaryWithContext(ctx)
  2591. if err != nil {
  2592. return err
  2593. }
  2594. return nil
  2595. }
  2596. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2597. // the Window type
  2598. func (target *Window) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2599. // panics are recovered and propagated as errors
  2600. defer func() {
  2601. if r := recover(); r != nil {
  2602. if e, ok := r.(error); ok {
  2603. err = e
  2604. } else if s, ok := r.(string); ok {
  2605. err = fmt.Errorf("Unexpected panic: %s", s)
  2606. } else {
  2607. err = fmt.Errorf("Unexpected panic: %+v", r)
  2608. }
  2609. }
  2610. }()
  2611. buff := ctx.Buffer
  2612. version := buff.ReadUInt8()
  2613. if version > DefaultCodecVersion {
  2614. return fmt.Errorf("Invalid Version Unmarshaling Window. Expected %d or less, got %d", DefaultCodecVersion, version)
  2615. }
  2616. // field version check
  2617. if uint8(1) <= version {
  2618. // --- [begin][read][reference](time.Time) ---
  2619. a := &time.Time{}
  2620. b := buff.ReadInt() // byte array length
  2621. c := buff.ReadBytes(b) // byte array
  2622. errA := a.UnmarshalBinary(c)
  2623. if errA != nil {
  2624. return errA
  2625. }
  2626. target.Start = *a
  2627. // --- [end][read][reference](time.Time) ---
  2628. } else {
  2629. }
  2630. // field version check
  2631. if uint8(1) <= version {
  2632. // --- [begin][read][reference](time.Time) ---
  2633. d := &time.Time{}
  2634. e := buff.ReadInt() // byte array length
  2635. f := buff.ReadBytes(e) // byte array
  2636. errB := d.UnmarshalBinary(f)
  2637. if errB != nil {
  2638. return errB
  2639. }
  2640. target.End = *d
  2641. // --- [end][read][reference](time.Time) ---
  2642. } else {
  2643. }
  2644. return nil
  2645. }