kubemodel_codecs.go 71 KB

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