kubemodel_codecs.go 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014
  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. "cmp"
  14. "fmt"
  15. "io"
  16. "iter"
  17. "os"
  18. "reflect"
  19. "slices"
  20. "strings"
  21. "sync"
  22. "time"
  23. "unsafe"
  24. util "github.com/opencost/opencost/core/pkg/util"
  25. )
  26. const (
  27. // GeneratorPackageName is the package the generator is targetting
  28. GeneratorPackageName string = "kubemodel"
  29. StringHeaderSize = int64(unsafe.Sizeof(""))
  30. // BinaryTagStringTable is written and/or read prior to the existence of a string
  31. // table (where each index is encoded as a string entry in the resource
  32. BinaryTagStringTable string = "BGST"
  33. // DefaultCodecVersion is used for any resources listed in the Default version set
  34. DefaultCodecVersion uint8 = 1
  35. )
  36. //--------------------------------------------------------------------------
  37. // Configuration
  38. //--------------------------------------------------------------------------
  39. var (
  40. bingenConfigLock sync.RWMutex
  41. bingenConfig *BingenConfiguration = DefaultBingenConfiguration()
  42. )
  43. // BingenConfiguration is used to set any custom configuration in the way files are encoded
  44. // or decoded.
  45. type BingenConfiguration struct {
  46. // FileBackedStringTableEnabled enables the use of file-backed string tables for streaming
  47. // bingen decoding.
  48. FileBackedStringTableEnabled bool
  49. // FileBackedStringTableDir is the directory to write the string table files for reading.
  50. FileBackedStringTableDir string
  51. // FileBackedStringTableMemoMaxBytes limits in-memory memoization for file-backed table lookups.
  52. // 0 disables memoization.
  53. FileBackedStringTableMemoMaxBytes int64
  54. }
  55. // DefaultBingenConfiguration creates the default implementation of the bingen configuration
  56. // and returns it.
  57. func DefaultBingenConfiguration() *BingenConfiguration {
  58. return &BingenConfiguration{
  59. FileBackedStringTableEnabled: false,
  60. FileBackedStringTableDir: os.TempDir(),
  61. FileBackedStringTableMemoMaxBytes: 0,
  62. }
  63. }
  64. // ConfigureBingen accepts a new *BingenConfiguration instance which updates the internal decoder
  65. // and encoder behavior.
  66. func ConfigureBingen(config *BingenConfiguration) {
  67. bingenConfigLock.Lock()
  68. defer bingenConfigLock.Unlock()
  69. if config == nil {
  70. config = DefaultBingenConfiguration()
  71. }
  72. bingenConfig = config
  73. }
  74. // IsBingenFileBackedStringTableEnabled accessor for file backed string table configuration
  75. func IsBingenFileBackedStringTableEnabled() bool {
  76. bingenConfigLock.RLock()
  77. defer bingenConfigLock.RUnlock()
  78. return bingenConfig.FileBackedStringTableEnabled
  79. }
  80. // BingenFileBackedStringTableDir returns the directory configured for file backed string tables.
  81. func BingenFileBackedStringTableDir() string {
  82. bingenConfigLock.RLock()
  83. defer bingenConfigLock.RUnlock()
  84. return bingenConfig.FileBackedStringTableDir
  85. }
  86. // BingenFileBackedStringTableMemoMaxBytes returns the maximum bytes used for file-backed memo cache.
  87. func BingenFileBackedStringTableMemoMaxBytes() int64 {
  88. bingenConfigLock.RLock()
  89. defer bingenConfigLock.RUnlock()
  90. return bingenConfig.FileBackedStringTableMemoMaxBytes
  91. }
  92. //--------------------------------------------------------------------------
  93. // Type Map
  94. //--------------------------------------------------------------------------
  95. // Generated type map for resolving interface implementations to to concrete types
  96. var typeMap map[string]reflect.Type = map[string]reflect.Type{
  97. "Cluster": reflect.TypeFor[Cluster](),
  98. "Diagnostic": reflect.TypeFor[Diagnostic](),
  99. "KubeModelSet": reflect.TypeFor[KubeModelSet](),
  100. "Metadata": reflect.TypeFor[Metadata](),
  101. "Namespace": reflect.TypeFor[Namespace](),
  102. "ResourceQuantity": reflect.TypeFor[ResourceQuantity](),
  103. "ResourceQuota": reflect.TypeFor[ResourceQuota](),
  104. "ResourceQuotaSpec": reflect.TypeFor[ResourceQuotaSpec](),
  105. "ResourceQuotaSpecHard": reflect.TypeFor[ResourceQuotaSpecHard](),
  106. "ResourceQuotaStatus": reflect.TypeFor[ResourceQuotaStatus](),
  107. "ResourceQuotaStatusUsed": reflect.TypeFor[ResourceQuotaStatusUsed](),
  108. "Window": reflect.TypeFor[Window](),
  109. }
  110. //--------------------------------------------------------------------------
  111. // Type Helpers
  112. //--------------------------------------------------------------------------
  113. // isBinaryTag returns true when the first bytes in the provided binary matches the tag
  114. func isBinaryTag(data []byte, tag string) bool {
  115. if len(data) < len(tag) {
  116. return false
  117. }
  118. return string(data[:len(tag)]) == tag
  119. }
  120. // isReaderBinaryTag is used to peek the header for an io.Reader Buffer
  121. func isReaderBinaryTag(buff *util.Buffer, tag string) bool {
  122. data, err := buff.Peek(len(tag))
  123. if err != nil && err != io.EOF {
  124. panic(fmt.Sprintf("called Peek() on a non buffered reader: %s", err))
  125. }
  126. if len(data) < len(tag) {
  127. return false
  128. }
  129. return string(data[:len(tag)]) == tag
  130. }
  131. // typeToString determines the basic properties of the type, the qualifier, package path, and
  132. // type name, and returns the qualified type
  133. func typeToString(f interface{}) string {
  134. qual := ""
  135. t := reflect.TypeOf(f)
  136. if t.Kind() == reflect.Ptr {
  137. t = t.Elem()
  138. qual = "*"
  139. }
  140. return fmt.Sprintf("%s%s.%s", qual, t.PkgPath(), t.Name())
  141. }
  142. // resolveType uses the name of a type and returns the package, base type name, and whether
  143. // or not it's a pointer.
  144. func resolveType(t string) (pkg string, name string, isPtr bool) {
  145. isPtr = t[:1] == "*"
  146. if isPtr {
  147. t = t[1:]
  148. }
  149. slashIndex := strings.LastIndex(t, "/")
  150. if slashIndex >= 0 {
  151. t = t[slashIndex+1:]
  152. }
  153. parts := strings.Split(t, ".")
  154. if parts[0] == GeneratorPackageName {
  155. parts[0] = ""
  156. }
  157. pkg = parts[0]
  158. name = parts[1]
  159. return
  160. }
  161. //--------------------------------------------------------------------------
  162. // Stream Helpers
  163. //--------------------------------------------------------------------------
  164. // StreamFactoryFunc is an alias for a func that creates a BingenStream implementation.
  165. type StreamFactoryFunc func(io.Reader) BingenStream
  166. // Generated streamable factory map for finding the specific new stream methods
  167. // by T type
  168. var streamFactoryMap map[reflect.Type]StreamFactoryFunc = map[reflect.Type]StreamFactoryFunc{
  169. reflect.TypeFor[KubeModelSet](): NewKubeModelSetStream,
  170. }
  171. // NewStreamFor accepts an io.Reader, and returns a new BingenStream for the generic T
  172. // type provided _if_ it is a registered bingen type that is annotated as 'streamable'. See
  173. // the streamFactoryMap for generated type listings.
  174. func NewStreamFor[T any](reader io.Reader) (BingenStream, error) {
  175. typeKey := reflect.TypeFor[T]()
  176. factory, ok := streamFactoryMap[typeKey]
  177. if !ok {
  178. return nil, fmt.Errorf("the type: %s is not a registered bingen streamable type", typeKey.Name())
  179. }
  180. return factory(reader), nil
  181. }
  182. // BingenStream is the stream interface for all streamable types
  183. type BingenStream interface {
  184. // Stream returns the iterator which will stream each field of the target type and
  185. // return the field info as well as the value.
  186. Stream() iter.Seq2[BingenFieldInfo, *BingenValue]
  187. // Close will close any dynamic io.Reader used to stream in the fields
  188. Close()
  189. // Error returns an error if one occurred during the process of streaming the type's fields.
  190. // This can be checked after iterating through the Stream().
  191. Error() error
  192. }
  193. // BingenValue contains the value of a field as well as any index/key associated with that value.
  194. type BingenValue struct {
  195. Value any
  196. Index any
  197. }
  198. // IsNil is just a method accessor way to check to see if the value returned was nil
  199. func (bv *BingenValue) IsNil() bool {
  200. return bv == nil
  201. }
  202. // creates a single BingenValue instance without a key or index
  203. func singleV(value any) *BingenValue {
  204. return &BingenValue{
  205. Value: value,
  206. }
  207. }
  208. // creates a pair of key/index and value.
  209. func pairV(index any, value any) *BingenValue {
  210. return &BingenValue{
  211. Value: value,
  212. Index: index,
  213. }
  214. }
  215. // BingenFieldInfo contains the type of the field being streamed as well as the name of the field.
  216. type BingenFieldInfo struct {
  217. Type reflect.Type
  218. Name string
  219. }
  220. //--------------------------------------------------------------------------
  221. // String Table Writer
  222. //--------------------------------------------------------------------------
  223. // StringTableWriter is the interface used to write the string table for encoding.
  224. type StringTableWriter interface {
  225. // AddOrGet adds a string to the string table and returns the new index or
  226. // an existing index.
  227. AddOrGet(s string) int
  228. // WriteTo will write the StringTable data (with the header) to the provided
  229. // Buffer starting a the current write position
  230. WriteTo(b *util.Buffer)
  231. }
  232. // IndexedStringTableWriter maps strings to specific indices for encoding
  233. type IndexedStringTableWriter struct {
  234. indices map[string]int
  235. next int
  236. }
  237. // NewIndexedStringTableWriter Creates a new IndexedStringTableWriter instance.
  238. func NewIndexedStringTableWriter() *IndexedStringTableWriter {
  239. return &IndexedStringTableWriter{
  240. indices: make(map[string]int),
  241. next: 0,
  242. }
  243. }
  244. // AddOrGet retrieves a string entry's index if it exists. Otherwise, it adds the entry and returns the new index.
  245. func (st *IndexedStringTableWriter) AddOrGet(s string) int {
  246. if ind, ok := st.indices[s]; ok {
  247. return ind
  248. }
  249. current := st.next
  250. st.next++
  251. st.indices[s] = current
  252. return current
  253. }
  254. // ToSlice Converts the contents to a string array for encoding.
  255. func (st *IndexedStringTableWriter) ToSlice() []string {
  256. if st.next == 0 {
  257. return []string{}
  258. }
  259. sl := make([]string, st.next)
  260. for s, i := range st.indices {
  261. sl[i] = s
  262. }
  263. return sl
  264. }
  265. // ToBytes Converts the contents to a binary encoded representation
  266. func (st *IndexedStringTableWriter) ToBytes() []byte {
  267. buff := util.NewBuffer()
  268. st.WriteTo(buff)
  269. return buff.Bytes()
  270. }
  271. // WriteTo will write the StringTable data (with the header) to the provided
  272. // Buffer starting a the current write position
  273. func (st *IndexedStringTableWriter) WriteTo(buff *util.Buffer) {
  274. // bingen string table header
  275. buff.WriteBytes([]byte(BinaryTagStringTable))
  276. // get an ordered string slice to encode
  277. strs := st.ToSlice()
  278. buff.WriteInt(len(strs)) // table length
  279. for _, s := range strs {
  280. buff.WriteString(s)
  281. }
  282. }
  283. type indexed struct {
  284. s string
  285. count uint64
  286. index int
  287. }
  288. func newIndexed(s string, index int) *indexed {
  289. return &indexed{
  290. s: s,
  291. count: 1,
  292. index: index,
  293. }
  294. }
  295. // PrepassStringTableWriter maps strings to specific indices for encoding, sorted by the total
  296. // number of times they're accessed
  297. type PrepassStringTableWriter struct {
  298. prepass map[string]*indexed
  299. next int
  300. }
  301. // NewPrepassStringTableWriter creates a new PrepassStringTableWriter instance.
  302. func NewPrepassStringTableWriter() *PrepassStringTableWriter {
  303. return &PrepassStringTableWriter{
  304. prepass: make(map[string]*indexed),
  305. }
  306. }
  307. // AddOrGet retrieves a string entry's index if it exists. Otherwise, it adds the entry and returns the new index.
  308. func (st *PrepassStringTableWriter) AddOrGet(s string) int {
  309. if ind, ok := st.prepass[s]; ok {
  310. ind.count += 1
  311. return ind.index
  312. }
  313. current := st.next
  314. st.next++
  315. st.prepass[s] = newIndexed(s, current)
  316. return current
  317. }
  318. // WriteSortedTo sorts the string table by the number of accesses, writes the table in that
  319. // order, then returns a new StringTableWriter implementation that can be used for the new
  320. // sorted order index lookups.
  321. func (st *PrepassStringTableWriter) WriteSortedTo(buff *util.Buffer) StringTableWriter {
  322. sl := make([]*indexed, st.next)
  323. for _, ind := range st.prepass {
  324. sl[ind.index] = ind
  325. }
  326. slices.SortFunc(sl, func(a *indexed, b *indexed) int {
  327. return -cmp.Compare(a.count, b.count)
  328. })
  329. sti := NewIndexedStringTableWriter()
  330. for _, ind := range sl {
  331. sti.AddOrGet(ind.s)
  332. }
  333. sti.WriteTo(buff)
  334. return sti
  335. }
  336. // WriteTo will write the StringTable data (with the header) to the provided
  337. // Buffer starting a the current write position
  338. func (st *PrepassStringTableWriter) WriteTo(buff *util.Buffer) {
  339. panic("Prepass StringTableWriter cannot write directly")
  340. }
  341. //--------------------------------------------------------------------------
  342. // String Table Reader
  343. //--------------------------------------------------------------------------
  344. // StringTableReader is the interface used to read the string table from the decoding.
  345. type StringTableReader interface {
  346. // At returns the string entry at a specific index, or panics on out of bounds.
  347. At(index int) string
  348. // Len returns the total number of strings loaded in the string table.
  349. Len() int
  350. // Close will clear the loaded table, and drop any external resources used.
  351. Close() error
  352. }
  353. // SliceStringTableReader is a basic pre-loaded []string that provides index-based access.
  354. // The cost of this implementation is holding all strings in memory, which provides faster
  355. // lookup performance at the expense of memory usage.
  356. type SliceStringTableReader struct {
  357. table []string
  358. }
  359. // NewSliceStringTableReaderFrom creates a new SliceStringTableReader instance loading
  360. // data directly from the buffer. The buffer's position should start at the table length.
  361. func NewSliceStringTableReaderFrom(buffer *util.Buffer) StringTableReader {
  362. // table length
  363. tl := buffer.ReadInt()
  364. var table []string
  365. if tl > 0 {
  366. table = make([]string, tl)
  367. for i := range tl {
  368. table[i] = buffer.ReadString()
  369. }
  370. }
  371. return &SliceStringTableReader{
  372. table: table,
  373. }
  374. }
  375. // At returns the string entry at a specific index, or panics on out of bounds.
  376. func (sstr *SliceStringTableReader) At(index int) string {
  377. if index < 0 || index >= len(sstr.table) {
  378. panic(fmt.Errorf("%s: string table index out of bounds: %d", GeneratorPackageName, index))
  379. }
  380. return sstr.table[index]
  381. }
  382. // Len returns the total number of strings loaded in the string table.
  383. func (sstr *SliceStringTableReader) Len() int {
  384. if sstr == nil {
  385. return 0
  386. }
  387. return len(sstr.table)
  388. }
  389. // Close for the slice tables just nils out the slice and returns
  390. func (sstr *SliceStringTableReader) Close() error {
  391. sstr.table = nil
  392. return nil
  393. }
  394. // fileStringRef maps a bingen string-table index to a payload stored in a temp file.
  395. type fileStringRef struct {
  396. off int64
  397. length int
  398. }
  399. // FileStringTableReader leverages a local file to write string table data for lookup. On
  400. // memory focused systems, this allows a slower parse with a significant decrease in memory
  401. // usage. This implementation is often pair with streaming readers for high throughput with
  402. // reduced memory usage.
  403. type FileStringTableReader struct {
  404. f *os.File
  405. refs []fileStringRef
  406. memo []string
  407. }
  408. // NewFileStringTableFromBuffer reads exactly tl length-prefixed (uint16) string payloads from buffer
  409. // and appends each payload to a new temp file. It does not retain full strings in memory.
  410. func NewFileStringTableReaderFrom(buffer *util.Buffer, dir string, memoMaxBytes int64) StringTableReader {
  411. // helper func to cast a string in-place to a byte slice.
  412. // NOTE: Return value is READ-ONLY. DO NOT MODIFY!
  413. byteSliceFor := func(s string) []byte {
  414. return unsafe.Slice(unsafe.StringData(s), len(s))
  415. }
  416. err := os.MkdirAll(dir, 0755)
  417. if err != nil {
  418. panic(fmt.Errorf("%s: failed to create string table directory: %w", GeneratorPackageName, err))
  419. }
  420. f, err := os.CreateTemp(dir, fmt.Sprintf("%s-bgst-*", GeneratorPackageName))
  421. if err != nil {
  422. panic(fmt.Errorf("%s: failed to create string table file: %w", GeneratorPackageName, err))
  423. }
  424. var writeErr error
  425. defer func() {
  426. if writeErr != nil {
  427. _ = f.Close()
  428. }
  429. }()
  430. // table length
  431. tl := buffer.ReadInt()
  432. var refs []fileStringRef
  433. if tl > 0 {
  434. refs = make([]fileStringRef, tl)
  435. for i := range tl {
  436. payload := byteSliceFor(buffer.ReadString())
  437. var off int64
  438. if len(payload) > 0 {
  439. off, err = f.Seek(0, io.SeekEnd)
  440. if err != nil {
  441. writeErr = fmt.Errorf("%s: failed to seek string table file: %w", GeneratorPackageName, err)
  442. panic(writeErr)
  443. }
  444. if _, err := f.Write(payload); err != nil {
  445. writeErr = fmt.Errorf("%s: failed to write string table entry %d: %w", GeneratorPackageName, i, err)
  446. panic(writeErr)
  447. }
  448. }
  449. refs[i] = fileStringRef{
  450. off: off,
  451. length: len(payload),
  452. }
  453. }
  454. }
  455. var memo []string
  456. // Pre-load cache with strings up to memoMaxBytes, respecting string boundaries
  457. if memoMaxBytes > 0 && len(refs) > 0 {
  458. memo = make([]string, len(refs))
  459. var cumulativeSize int64
  460. for i, ref := range refs {
  461. // Check if adding this string would exceed the limit
  462. if cumulativeSize+int64(ref.length)+StringHeaderSize > memoMaxBytes {
  463. // Would exceed limit, stop here
  464. break
  465. }
  466. // Read string from file and cache it
  467. if ref.length > 0 {
  468. b := make([]byte, ref.length)
  469. _, err := f.ReadAt(b, ref.off)
  470. if err != nil {
  471. // If we can't read, skip this entry but continue
  472. continue
  473. }
  474. // Cast the allocated bytes to a string in-place
  475. str := unsafe.String(unsafe.SliceData(b), len(b))
  476. memo[i] = str
  477. cumulativeSize += int64(ref.length) + StringHeaderSize
  478. }
  479. }
  480. }
  481. return &FileStringTableReader{
  482. f: f,
  483. refs: refs,
  484. memo: memo,
  485. }
  486. }
  487. // At returns the string from the internal file using the reference's offset and length.
  488. func (fstr *FileStringTableReader) At(index int) string {
  489. if fstr == nil || fstr.f == nil {
  490. panic(fmt.Errorf("%s: failed to read file string table data", GeneratorPackageName))
  491. }
  492. if index < 0 || index >= len(fstr.refs) {
  493. panic(fmt.Errorf("%s: string table index out of bounds: %d", GeneratorPackageName, index))
  494. }
  495. ref := fstr.refs[index]
  496. if ref.length == 0 {
  497. return ""
  498. }
  499. // Check cache first
  500. if fstr.memo != nil && len(fstr.memo) > index && fstr.memo[index] != "" {
  501. return fstr.memo[index]
  502. }
  503. // Cache miss - read from file
  504. b := make([]byte, ref.length)
  505. _, err := fstr.f.ReadAt(b, ref.off)
  506. if err != nil {
  507. return ""
  508. }
  509. // Cast the allocated bytes to a string in-place, as we were the ones that allocated the bytes
  510. return unsafe.String(unsafe.SliceData(b), len(b))
  511. }
  512. // Len returns the total number of strings loaded in the string table.
  513. func (fstr *FileStringTableReader) Len() int {
  514. if fstr == nil {
  515. return 0
  516. }
  517. return len(fstr.refs)
  518. }
  519. // Close for the file string table reader closes the file and deletes it.
  520. func (fstr *FileStringTableReader) Close() error {
  521. if fstr == nil || fstr.f == nil {
  522. return nil
  523. }
  524. path := fstr.f.Name()
  525. err := fstr.f.Close()
  526. fstr.f = nil
  527. fstr.refs = nil
  528. fstr.memo = nil
  529. if path != "" {
  530. _ = os.Remove(path)
  531. }
  532. return err
  533. }
  534. //--------------------------------------------------------------------------
  535. // Codec Context
  536. //--------------------------------------------------------------------------
  537. // EncodingContext is a context object passed to the encoders to ensure reuse of buffer
  538. // and table data
  539. type EncodingContext struct {
  540. Buffer *util.Buffer
  541. Table StringTableWriter
  542. }
  543. // NewEncodingContext creates a new EncodingContext instance that will create a new []byte buffer
  544. // for writing, and return the context
  545. func NewEncodingContext(tableWriter StringTableWriter) *EncodingContext {
  546. return &EncodingContext{
  547. Buffer: util.NewBuffer(),
  548. Table: tableWriter,
  549. }
  550. }
  551. // NewEncodingContextFromWriter creates a new EncodingContext instance that will create a new Buffer
  552. // from the provided io.Writer and StringTableWriter.
  553. func NewEncodingContextFromWriter(writer io.Writer, tableWriter StringTableWriter) *EncodingContext {
  554. return &EncodingContext{
  555. Buffer: util.NewBufferFromWriter(writer),
  556. Table: tableWriter,
  557. }
  558. }
  559. // NewEncodingContextFromBuffer creates a new EncodingContext instance that will leverage an existing
  560. // Buffer and StringTableWriter.
  561. func NewEncodingContextFromBuffer(buffer *util.Buffer, tableWriter StringTableWriter) *EncodingContext {
  562. return &EncodingContext{
  563. Buffer: buffer,
  564. Table: tableWriter,
  565. }
  566. }
  567. // ToBytes returns the encoded string table bytes (if applicable) combined with the encoded buffer bytes. If
  568. // a string table is being used, the string table bytes will be written first to ensure correct ordering for
  569. // decoding.
  570. func (ec *EncodingContext) ToBytes() []byte {
  571. encBytes := ec.Buffer.Bytes()
  572. if ec.Table != nil {
  573. buff := util.NewBuffer()
  574. ec.Table.WriteTo(buff)
  575. buff.WriteBytes(encBytes)
  576. return buff.Bytes()
  577. }
  578. return encBytes
  579. }
  580. // IsStringTable returns true if the table is available
  581. func (ec *EncodingContext) IsStringTable() bool {
  582. return ec.Table != nil
  583. }
  584. // DecodingContext is a context object passed to the decoders to ensure parent objects
  585. // reuse as much data as possible
  586. type DecodingContext struct {
  587. Buffer *util.Buffer
  588. Table StringTableReader
  589. }
  590. // NewDecodingContextFromBytes creates a new DecodingContext instance using an byte slice
  591. func NewDecodingContextFromBytes(data []byte) *DecodingContext {
  592. var table StringTableReader
  593. buff := util.NewBufferFromBytes(data)
  594. // string table header validation
  595. if isBinaryTag(data, BinaryTagStringTable) {
  596. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  597. // always use a slice string table with a byte array since the
  598. // data is already in memory
  599. table = NewSliceStringTableReaderFrom(buff)
  600. }
  601. return &DecodingContext{
  602. Buffer: buff,
  603. Table: table,
  604. }
  605. }
  606. // NewDecodingContextFromReader creates a new DecodingContext instance using an io.Reader
  607. // implementation
  608. func NewDecodingContextFromReader(reader io.Reader) *DecodingContext {
  609. var table StringTableReader
  610. buff := util.NewBufferFromReader(reader)
  611. if isReaderBinaryTag(buff, BinaryTagStringTable) {
  612. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  613. // create correct string table implementation
  614. if IsBingenFileBackedStringTableEnabled() {
  615. table = NewFileStringTableReaderFrom(buff, BingenFileBackedStringTableDir(), BingenFileBackedStringTableMemoMaxBytes())
  616. } else {
  617. table = NewSliceStringTableReaderFrom(buff)
  618. }
  619. }
  620. return &DecodingContext{
  621. Buffer: buff,
  622. Table: table,
  623. }
  624. }
  625. // IsStringTable returns true if the table is available
  626. func (dc *DecodingContext) IsStringTable() bool {
  627. return dc.Table != nil && dc.Table.Len() > 0
  628. }
  629. // Close will ensure that any string table resources and buffer resources are
  630. // cleaned up.
  631. func (dc *DecodingContext) Close() {
  632. if dc.Table != nil {
  633. _ = dc.Table.Close()
  634. dc.Table = nil
  635. }
  636. }
  637. //--------------------------------------------------------------------------
  638. // Binary Codec
  639. //--------------------------------------------------------------------------
  640. // BinEncoder is an encoding interface which defines a context based marshal contract.
  641. type BinEncoder interface {
  642. MarshalBinaryWithContext(*EncodingContext) error
  643. }
  644. // BinDecoder is a decoding interface which defines a context based unmarshal contract.
  645. type BinDecoder interface {
  646. UnmarshalBinaryWithContext(*DecodingContext) error
  647. }
  648. //--------------------------------------------------------------------------
  649. // Cluster
  650. //--------------------------------------------------------------------------
  651. // MarshalBinary serializes the internal properties of this Cluster instance
  652. // into a byte array
  653. func (target *Cluster) MarshalBinary() (data []byte, err error) {
  654. ctx := NewEncodingContext(nil)
  655. e := target.MarshalBinaryWithContext(ctx)
  656. if e != nil {
  657. return nil, e
  658. }
  659. return ctx.ToBytes(), nil
  660. }
  661. // MarshalBinary serializes the internal properties of this Cluster instance
  662. // into an io.Writer.
  663. func (target *Cluster) MarshalBinaryTo(writer io.Writer) error {
  664. buff := util.NewBufferFromWriter(writer)
  665. defer buff.Flush()
  666. ctx := NewEncodingContextFromBuffer(buff, nil)
  667. return target.MarshalBinaryWithContext(ctx)
  668. }
  669. // MarshalBinaryWithContext serializes the internal properties of this Cluster instance
  670. // into a byte array leveraging a predefined context.
  671. func (target *Cluster) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  672. // panics are recovered and propagated as errors
  673. defer func() {
  674. if r := recover(); r != nil {
  675. if e, ok := r.(error); ok {
  676. err = e
  677. } else if s, ok := r.(string); ok {
  678. err = fmt.Errorf("unexpected panic: %s", s)
  679. } else {
  680. err = fmt.Errorf("unexpected panic: %+v", r)
  681. }
  682. }
  683. }()
  684. buff := ctx.Buffer
  685. buff.WriteUInt8(DefaultCodecVersion) // version
  686. if ctx.IsStringTable() {
  687. a := ctx.Table.AddOrGet(target.UID)
  688. buff.WriteInt(a) // write table index
  689. } else {
  690. buff.WriteString(target.UID) // write string
  691. }
  692. // --- [begin][write][alias](Provider) ---
  693. if ctx.IsStringTable() {
  694. b := ctx.Table.AddOrGet(string(target.Provider))
  695. buff.WriteInt(b) // write table index
  696. } else {
  697. buff.WriteString(string(target.Provider)) // write string
  698. }
  699. // --- [end][write][alias](Provider) ---
  700. if ctx.IsStringTable() {
  701. c := ctx.Table.AddOrGet(target.Account)
  702. buff.WriteInt(c) // write table index
  703. } else {
  704. buff.WriteString(target.Account) // write string
  705. }
  706. if ctx.IsStringTable() {
  707. d := ctx.Table.AddOrGet(target.Name)
  708. buff.WriteInt(d) // write table index
  709. } else {
  710. buff.WriteString(target.Name) // write string
  711. }
  712. // --- [begin][write][reference](time.Time) ---
  713. e, errA := target.Start.MarshalBinary()
  714. if errA != nil {
  715. return errA
  716. }
  717. buff.WriteInt(len(e))
  718. buff.WriteBytes(e)
  719. // --- [end][write][reference](time.Time) ---
  720. // --- [begin][write][reference](time.Time) ---
  721. f, errB := target.End.MarshalBinary()
  722. if errB != nil {
  723. return errB
  724. }
  725. buff.WriteInt(len(f))
  726. buff.WriteBytes(f)
  727. // --- [end][write][reference](time.Time) ---
  728. return nil
  729. }
  730. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  731. // the Cluster type
  732. func (target *Cluster) UnmarshalBinary(data []byte) error {
  733. ctx := NewDecodingContextFromBytes(data)
  734. defer ctx.Close()
  735. err := target.UnmarshalBinaryWithContext(ctx)
  736. if err != nil {
  737. return err
  738. }
  739. return nil
  740. }
  741. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  742. // the Cluster type
  743. func (target *Cluster) UnmarshalBinaryFromReader(reader io.Reader) error {
  744. ctx := NewDecodingContextFromReader(reader)
  745. defer ctx.Close()
  746. err := target.UnmarshalBinaryWithContext(ctx)
  747. if err != nil {
  748. return err
  749. }
  750. return nil
  751. }
  752. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  753. // the Cluster type
  754. func (target *Cluster) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  755. // panics are recovered and propagated as errors
  756. defer func() {
  757. if r := recover(); r != nil {
  758. if e, ok := r.(error); ok {
  759. err = e
  760. } else if s, ok := r.(string); ok {
  761. err = fmt.Errorf("unexpected panic: %s", s)
  762. } else {
  763. err = fmt.Errorf("unexpected panic: %+v", r)
  764. }
  765. }
  766. }()
  767. buff := ctx.Buffer
  768. version := buff.ReadUInt8()
  769. if version > DefaultCodecVersion {
  770. return fmt.Errorf("Invalid Version Unmarshalling Cluster. Expected %d or less, got %d", DefaultCodecVersion, version)
  771. }
  772. // field version check
  773. if uint8(1) <= version {
  774. var b string
  775. if ctx.IsStringTable() {
  776. c := buff.ReadInt() // read string index
  777. b = ctx.Table.At(c)
  778. } else {
  779. b = buff.ReadString() // read string
  780. }
  781. a := b
  782. target.UID = a
  783. } else {
  784. target.UID = "" // default
  785. }
  786. // field version check
  787. if uint8(1) <= version {
  788. // --- [begin][read][alias](Provider) ---
  789. var d string
  790. var f string
  791. if ctx.IsStringTable() {
  792. g := buff.ReadInt() // read string index
  793. f = ctx.Table.At(g)
  794. } else {
  795. f = buff.ReadString() // read string
  796. }
  797. e := f
  798. d = e
  799. target.Provider = Provider(d)
  800. // --- [end][read][alias](Provider) ---
  801. } else {
  802. }
  803. // field version check
  804. if uint8(1) <= version {
  805. var l string
  806. if ctx.IsStringTable() {
  807. m := buff.ReadInt() // read string index
  808. l = ctx.Table.At(m)
  809. } else {
  810. l = buff.ReadString() // read string
  811. }
  812. h := l
  813. target.Account = h
  814. } else {
  815. target.Account = "" // default
  816. }
  817. // field version check
  818. if uint8(1) <= version {
  819. var o string
  820. if ctx.IsStringTable() {
  821. p := buff.ReadInt() // read string index
  822. o = ctx.Table.At(p)
  823. } else {
  824. o = buff.ReadString() // read string
  825. }
  826. n := o
  827. target.Name = n
  828. } else {
  829. target.Name = "" // default
  830. }
  831. // field version check
  832. if uint8(1) <= version {
  833. // --- [begin][read][reference](time.Time) ---
  834. q := new(time.Time)
  835. r := buff.ReadInt() // byte array length
  836. s := buff.ReadBytes(r)
  837. errA := q.UnmarshalBinary(s)
  838. if errA != nil {
  839. return errA
  840. }
  841. target.Start = *q
  842. // --- [end][read][reference](time.Time) ---
  843. } else {
  844. }
  845. // field version check
  846. if uint8(1) <= version {
  847. // --- [begin][read][reference](time.Time) ---
  848. t := new(time.Time)
  849. u := buff.ReadInt() // byte array length
  850. w := buff.ReadBytes(u)
  851. errB := t.UnmarshalBinary(w)
  852. if errB != nil {
  853. return errB
  854. }
  855. target.End = *t
  856. // --- [end][read][reference](time.Time) ---
  857. } else {
  858. }
  859. return nil
  860. }
  861. //--------------------------------------------------------------------------
  862. // Diagnostic
  863. //--------------------------------------------------------------------------
  864. // MarshalBinary serializes the internal properties of this Diagnostic instance
  865. // into a byte array
  866. func (target *Diagnostic) MarshalBinary() (data []byte, err error) {
  867. ctx := NewEncodingContext(nil)
  868. e := target.MarshalBinaryWithContext(ctx)
  869. if e != nil {
  870. return nil, e
  871. }
  872. return ctx.ToBytes(), nil
  873. }
  874. // MarshalBinary serializes the internal properties of this Diagnostic instance
  875. // into an io.Writer.
  876. func (target *Diagnostic) MarshalBinaryTo(writer io.Writer) error {
  877. buff := util.NewBufferFromWriter(writer)
  878. defer buff.Flush()
  879. ctx := NewEncodingContextFromBuffer(buff, nil)
  880. return target.MarshalBinaryWithContext(ctx)
  881. }
  882. // MarshalBinaryWithContext serializes the internal properties of this Diagnostic instance
  883. // into a byte array leveraging a predefined context.
  884. func (target *Diagnostic) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  885. // panics are recovered and propagated as errors
  886. defer func() {
  887. if r := recover(); r != nil {
  888. if e, ok := r.(error); ok {
  889. err = e
  890. } else if s, ok := r.(string); ok {
  891. err = fmt.Errorf("unexpected panic: %s", s)
  892. } else {
  893. err = fmt.Errorf("unexpected panic: %+v", r)
  894. }
  895. }
  896. }()
  897. buff := ctx.Buffer
  898. buff.WriteUInt8(DefaultCodecVersion) // version
  899. // --- [begin][write][reference](time.Time) ---
  900. a, errA := target.Timestamp.MarshalBinary()
  901. if errA != nil {
  902. return errA
  903. }
  904. buff.WriteInt(len(a))
  905. buff.WriteBytes(a)
  906. // --- [end][write][reference](time.Time) ---
  907. // --- [begin][write][alias](DiagnosticLevel) ---
  908. buff.WriteInt(int(target.Level)) // write int
  909. // --- [end][write][alias](DiagnosticLevel) ---
  910. if ctx.IsStringTable() {
  911. b := ctx.Table.AddOrGet(target.Message)
  912. buff.WriteInt(b) // write table index
  913. } else {
  914. buff.WriteString(target.Message) // write string
  915. }
  916. if target.Details == nil {
  917. buff.WriteUInt8(uint8(0)) // write nil byte
  918. } else {
  919. buff.WriteUInt8(uint8(1)) // write non-nil byte
  920. // --- [begin][write][map](map[string]string) ---
  921. buff.WriteInt(len(target.Details)) // map length
  922. for v, z := range target.Details {
  923. if ctx.IsStringTable() {
  924. c := ctx.Table.AddOrGet(v)
  925. buff.WriteInt(c) // write table index
  926. } else {
  927. buff.WriteString(v) // write string
  928. }
  929. if ctx.IsStringTable() {
  930. d := ctx.Table.AddOrGet(z)
  931. buff.WriteInt(d) // write table index
  932. } else {
  933. buff.WriteString(z) // write string
  934. }
  935. }
  936. // --- [end][write][map](map[string]string) ---
  937. }
  938. return nil
  939. }
  940. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  941. // the Diagnostic type
  942. func (target *Diagnostic) UnmarshalBinary(data []byte) error {
  943. ctx := NewDecodingContextFromBytes(data)
  944. defer ctx.Close()
  945. err := target.UnmarshalBinaryWithContext(ctx)
  946. if err != nil {
  947. return err
  948. }
  949. return nil
  950. }
  951. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  952. // the Diagnostic type
  953. func (target *Diagnostic) UnmarshalBinaryFromReader(reader io.Reader) error {
  954. ctx := NewDecodingContextFromReader(reader)
  955. defer ctx.Close()
  956. err := target.UnmarshalBinaryWithContext(ctx)
  957. if err != nil {
  958. return err
  959. }
  960. return nil
  961. }
  962. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  963. // the Diagnostic type
  964. func (target *Diagnostic) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  965. // panics are recovered and propagated as errors
  966. defer func() {
  967. if r := recover(); r != nil {
  968. if e, ok := r.(error); ok {
  969. err = e
  970. } else if s, ok := r.(string); ok {
  971. err = fmt.Errorf("unexpected panic: %s", s)
  972. } else {
  973. err = fmt.Errorf("unexpected panic: %+v", r)
  974. }
  975. }
  976. }()
  977. buff := ctx.Buffer
  978. version := buff.ReadUInt8()
  979. if version > DefaultCodecVersion {
  980. return fmt.Errorf("Invalid Version Unmarshalling Diagnostic. Expected %d or less, got %d", DefaultCodecVersion, version)
  981. }
  982. // field version check
  983. if uint8(1) <= version {
  984. // --- [begin][read][reference](time.Time) ---
  985. a := new(time.Time)
  986. b := buff.ReadInt() // byte array length
  987. c := buff.ReadBytes(b)
  988. errA := a.UnmarshalBinary(c)
  989. if errA != nil {
  990. return errA
  991. }
  992. target.Timestamp = *a
  993. // --- [end][read][reference](time.Time) ---
  994. } else {
  995. }
  996. // field version check
  997. if uint8(1) <= version {
  998. // --- [begin][read][alias](DiagnosticLevel) ---
  999. var d int
  1000. e := buff.ReadInt() // read int
  1001. d = e
  1002. target.Level = DiagnosticLevel(d)
  1003. // --- [end][read][alias](DiagnosticLevel) ---
  1004. } else {
  1005. }
  1006. // field version check
  1007. if uint8(1) <= version {
  1008. var g string
  1009. if ctx.IsStringTable() {
  1010. h := buff.ReadInt() // read string index
  1011. g = ctx.Table.At(h)
  1012. } else {
  1013. g = buff.ReadString() // read string
  1014. }
  1015. f := g
  1016. target.Message = f
  1017. } else {
  1018. target.Message = "" // default
  1019. }
  1020. // field version check
  1021. if uint8(1) <= version {
  1022. if buff.ReadUInt8() == uint8(0) {
  1023. target.Details = nil
  1024. } else {
  1025. // --- [begin][read][map](map[string]string) ---
  1026. m := buff.ReadInt() // map len
  1027. l := make(map[string]string, m)
  1028. for range m {
  1029. var v string
  1030. var o string
  1031. if ctx.IsStringTable() {
  1032. p := buff.ReadInt() // read string index
  1033. o = ctx.Table.At(p)
  1034. } else {
  1035. o = buff.ReadString() // read string
  1036. }
  1037. n := o
  1038. v = n
  1039. var z string
  1040. var r string
  1041. if ctx.IsStringTable() {
  1042. s := buff.ReadInt() // read string index
  1043. r = ctx.Table.At(s)
  1044. } else {
  1045. r = buff.ReadString() // read string
  1046. }
  1047. q := r
  1048. z = q
  1049. l[v] = z
  1050. }
  1051. target.Details = l
  1052. // --- [end][read][map](map[string]string) ---
  1053. }
  1054. } else {
  1055. target.Details = nil
  1056. }
  1057. return nil
  1058. }
  1059. //--------------------------------------------------------------------------
  1060. // KubeModelSet
  1061. //--------------------------------------------------------------------------
  1062. // MarshalBinary serializes the internal properties of this KubeModelSet instance
  1063. // into a byte array
  1064. func (target *KubeModelSet) MarshalBinary() (data []byte, err error) {
  1065. ctx := NewEncodingContext(NewIndexedStringTableWriter())
  1066. e := target.MarshalBinaryWithContext(ctx)
  1067. if e != nil {
  1068. return nil, e
  1069. }
  1070. return ctx.ToBytes(), nil
  1071. }
  1072. // MarshalBinary serializes the internal properties of this KubeModelSet instance
  1073. // into an io.Writer.
  1074. func (target *KubeModelSet) MarshalBinaryTo(writer io.Writer) error {
  1075. buff := util.NewBufferFromWriter(writer)
  1076. defer buff.Flush()
  1077. // run a pre-pass to collect all strings into the string table and discard all writes to the main
  1078. // buffer. Then, we write the string table, sorted by number of repeated uses (descending), to the
  1079. // main buffer, and use the resulting table as part of the context for the main pass.
  1080. prepass := NewPrepassStringTableWriter()
  1081. prepassCtx := NewEncodingContextFromWriter(io.Discard, prepass)
  1082. e := target.MarshalBinaryWithContext(prepassCtx)
  1083. if e != nil {
  1084. return e
  1085. }
  1086. tableWriter := prepass.WriteSortedTo(buff)
  1087. ctx := NewEncodingContextFromBuffer(buff, tableWriter)
  1088. return target.MarshalBinaryWithContext(ctx)
  1089. }
  1090. // MarshalBinaryWithContext serializes the internal properties of this KubeModelSet instance
  1091. // into a byte array leveraging a predefined context.
  1092. func (target *KubeModelSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1093. // panics are recovered and propagated as errors
  1094. defer func() {
  1095. if r := recover(); r != nil {
  1096. if e, ok := r.(error); ok {
  1097. err = e
  1098. } else if s, ok := r.(string); ok {
  1099. err = fmt.Errorf("unexpected panic: %s", s)
  1100. } else {
  1101. err = fmt.Errorf("unexpected panic: %+v", r)
  1102. }
  1103. }
  1104. }()
  1105. buff := ctx.Buffer
  1106. buff.WriteUInt8(DefaultCodecVersion) // version
  1107. if target.Metadata == nil {
  1108. buff.WriteUInt8(uint8(0)) // write nil byte
  1109. } else {
  1110. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1111. // --- [begin][write][struct](Metadata) ---
  1112. buff.WriteInt(0) // [compatibility, unused]
  1113. errA := target.Metadata.MarshalBinaryWithContext(ctx)
  1114. if errA != nil {
  1115. return errA
  1116. }
  1117. // --- [end][write][struct](Metadata) ---
  1118. }
  1119. // --- [begin][write][struct](Window) ---
  1120. buff.WriteInt(0) // [compatibility, unused]
  1121. errB := target.Window.MarshalBinaryWithContext(ctx)
  1122. if errB != nil {
  1123. return errB
  1124. }
  1125. // --- [end][write][struct](Window) ---
  1126. if target.Cluster == nil {
  1127. buff.WriteUInt8(uint8(0)) // write nil byte
  1128. } else {
  1129. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1130. // --- [begin][write][struct](Cluster) ---
  1131. buff.WriteInt(0) // [compatibility, unused]
  1132. errC := target.Cluster.MarshalBinaryWithContext(ctx)
  1133. if errC != nil {
  1134. return errC
  1135. }
  1136. // --- [end][write][struct](Cluster) ---
  1137. }
  1138. if target.Namespaces == nil {
  1139. buff.WriteUInt8(uint8(0)) // write nil byte
  1140. } else {
  1141. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1142. // --- [begin][write][map](map[string]*Namespace) ---
  1143. buff.WriteInt(len(target.Namespaces)) // map length
  1144. for v, z := range target.Namespaces {
  1145. if ctx.IsStringTable() {
  1146. a := ctx.Table.AddOrGet(v)
  1147. buff.WriteInt(a) // write table index
  1148. } else {
  1149. buff.WriteString(v) // write string
  1150. }
  1151. if z == nil {
  1152. buff.WriteUInt8(uint8(0)) // write nil byte
  1153. } else {
  1154. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1155. // --- [begin][write][struct](Namespace) ---
  1156. buff.WriteInt(0) // [compatibility, unused]
  1157. errD := z.MarshalBinaryWithContext(ctx)
  1158. if errD != nil {
  1159. return errD
  1160. }
  1161. // --- [end][write][struct](Namespace) ---
  1162. }
  1163. }
  1164. // --- [end][write][map](map[string]*Namespace) ---
  1165. }
  1166. if target.ResourceQuotas == nil {
  1167. buff.WriteUInt8(uint8(0)) // write nil byte
  1168. } else {
  1169. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1170. // --- [begin][write][map](map[string]*ResourceQuota) ---
  1171. buff.WriteInt(len(target.ResourceQuotas)) // map length
  1172. for vv, zz := range target.ResourceQuotas {
  1173. if ctx.IsStringTable() {
  1174. b := ctx.Table.AddOrGet(vv)
  1175. buff.WriteInt(b) // write table index
  1176. } else {
  1177. buff.WriteString(vv) // write string
  1178. }
  1179. if zz == nil {
  1180. buff.WriteUInt8(uint8(0)) // write nil byte
  1181. } else {
  1182. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1183. // --- [begin][write][struct](ResourceQuota) ---
  1184. buff.WriteInt(0) // [compatibility, unused]
  1185. errE := zz.MarshalBinaryWithContext(ctx)
  1186. if errE != nil {
  1187. return errE
  1188. }
  1189. // --- [end][write][struct](ResourceQuota) ---
  1190. }
  1191. }
  1192. // --- [end][write][map](map[string]*ResourceQuota) ---
  1193. }
  1194. return nil
  1195. }
  1196. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1197. // the KubeModelSet type
  1198. func (target *KubeModelSet) UnmarshalBinary(data []byte) error {
  1199. ctx := NewDecodingContextFromBytes(data)
  1200. defer ctx.Close()
  1201. err := target.UnmarshalBinaryWithContext(ctx)
  1202. if err != nil {
  1203. return err
  1204. }
  1205. return nil
  1206. }
  1207. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  1208. // the KubeModelSet type
  1209. func (target *KubeModelSet) UnmarshalBinaryFromReader(reader io.Reader) error {
  1210. ctx := NewDecodingContextFromReader(reader)
  1211. defer ctx.Close()
  1212. err := target.UnmarshalBinaryWithContext(ctx)
  1213. if err != nil {
  1214. return err
  1215. }
  1216. return nil
  1217. }
  1218. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1219. // the KubeModelSet type
  1220. func (target *KubeModelSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1221. // panics are recovered and propagated as errors
  1222. defer func() {
  1223. if r := recover(); r != nil {
  1224. if e, ok := r.(error); ok {
  1225. err = e
  1226. } else if s, ok := r.(string); ok {
  1227. err = fmt.Errorf("unexpected panic: %s", s)
  1228. } else {
  1229. err = fmt.Errorf("unexpected panic: %+v", r)
  1230. }
  1231. }
  1232. }()
  1233. buff := ctx.Buffer
  1234. version := buff.ReadUInt8()
  1235. if version > DefaultCodecVersion {
  1236. return fmt.Errorf("Invalid Version Unmarshalling KubeModelSet. Expected %d or less, got %d", DefaultCodecVersion, version)
  1237. }
  1238. // field version check
  1239. if uint8(1) <= version {
  1240. if buff.ReadUInt8() == uint8(0) {
  1241. target.Metadata = nil
  1242. } else {
  1243. // --- [begin][read][struct](Metadata) ---
  1244. a := new(Metadata)
  1245. buff.ReadInt() // [compatibility, unused]
  1246. errA := a.UnmarshalBinaryWithContext(ctx)
  1247. if errA != nil {
  1248. return errA
  1249. }
  1250. target.Metadata = a
  1251. // --- [end][read][struct](Metadata) ---
  1252. }
  1253. } else {
  1254. target.Metadata = nil
  1255. }
  1256. // field version check
  1257. if uint8(1) <= version {
  1258. // --- [begin][read][struct](Window) ---
  1259. b := new(Window)
  1260. buff.ReadInt() // [compatibility, unused]
  1261. errB := b.UnmarshalBinaryWithContext(ctx)
  1262. if errB != nil {
  1263. return errB
  1264. }
  1265. target.Window = *b
  1266. // --- [end][read][struct](Window) ---
  1267. } else {
  1268. }
  1269. // field version check
  1270. if uint8(1) <= version {
  1271. if buff.ReadUInt8() == uint8(0) {
  1272. target.Cluster = nil
  1273. } else {
  1274. // --- [begin][read][struct](Cluster) ---
  1275. c := new(Cluster)
  1276. buff.ReadInt() // [compatibility, unused]
  1277. errC := c.UnmarshalBinaryWithContext(ctx)
  1278. if errC != nil {
  1279. return errC
  1280. }
  1281. target.Cluster = c
  1282. // --- [end][read][struct](Cluster) ---
  1283. }
  1284. } else {
  1285. target.Cluster = nil
  1286. }
  1287. // field version check
  1288. if uint8(1) <= version {
  1289. if buff.ReadUInt8() == uint8(0) {
  1290. target.Namespaces = nil
  1291. } else {
  1292. // --- [begin][read][map](map[string]*Namespace) ---
  1293. e := buff.ReadInt() // map len
  1294. d := make(map[string]*Namespace, e)
  1295. for range e {
  1296. var v string
  1297. var g string
  1298. if ctx.IsStringTable() {
  1299. h := buff.ReadInt() // read string index
  1300. g = ctx.Table.At(h)
  1301. } else {
  1302. g = buff.ReadString() // read string
  1303. }
  1304. f := g
  1305. v = f
  1306. var z *Namespace
  1307. if buff.ReadUInt8() == uint8(0) {
  1308. z = nil
  1309. } else {
  1310. // --- [begin][read][struct](Namespace) ---
  1311. l := new(Namespace)
  1312. buff.ReadInt() // [compatibility, unused]
  1313. errD := l.UnmarshalBinaryWithContext(ctx)
  1314. if errD != nil {
  1315. return errD
  1316. }
  1317. z = l
  1318. // --- [end][read][struct](Namespace) ---
  1319. }
  1320. d[v] = z
  1321. }
  1322. target.Namespaces = d
  1323. // --- [end][read][map](map[string]*Namespace) ---
  1324. }
  1325. } else {
  1326. target.Namespaces = nil
  1327. }
  1328. // field version check
  1329. if uint8(1) <= version {
  1330. if buff.ReadUInt8() == uint8(0) {
  1331. target.ResourceQuotas = nil
  1332. } else {
  1333. // --- [begin][read][map](map[string]*ResourceQuota) ---
  1334. n := buff.ReadInt() // map len
  1335. m := make(map[string]*ResourceQuota, n)
  1336. for range n {
  1337. var vv string
  1338. var p string
  1339. if ctx.IsStringTable() {
  1340. q := buff.ReadInt() // read string index
  1341. p = ctx.Table.At(q)
  1342. } else {
  1343. p = buff.ReadString() // read string
  1344. }
  1345. o := p
  1346. vv = o
  1347. var zz *ResourceQuota
  1348. if buff.ReadUInt8() == uint8(0) {
  1349. zz = nil
  1350. } else {
  1351. // --- [begin][read][struct](ResourceQuota) ---
  1352. r := new(ResourceQuota)
  1353. buff.ReadInt() // [compatibility, unused]
  1354. errE := r.UnmarshalBinaryWithContext(ctx)
  1355. if errE != nil {
  1356. return errE
  1357. }
  1358. zz = r
  1359. // --- [end][read][struct](ResourceQuota) ---
  1360. }
  1361. m[vv] = zz
  1362. }
  1363. target.ResourceQuotas = m
  1364. // --- [end][read][map](map[string]*ResourceQuota) ---
  1365. }
  1366. } else {
  1367. target.ResourceQuotas = nil
  1368. }
  1369. return nil
  1370. }
  1371. //--------------------------------------------------------------------------
  1372. // KubeModelSetStream
  1373. //--------------------------------------------------------------------------
  1374. // KubeModelSetStream is a single use field stream for the contents of an KubeModelSet instance. Instead of creating an instance and populating
  1375. // the fields on that instance, we provide a streaming iterator which yields (BingenFieldInfo, *BingenValue) tuples for each
  1376. // streamable element. All slices and maps will be flattened one depth and each element streamed individually.
  1377. type KubeModelSetStream struct {
  1378. reader io.Reader
  1379. ctx *DecodingContext
  1380. err error
  1381. }
  1382. // Closes closes the internal io.Reader used to read and parse the KubeModelSet fields.
  1383. // This should be called once the stream is no longer needed.
  1384. func (stream *KubeModelSetStream) Close() {
  1385. if closer, ok := stream.reader.(io.Closer); ok {
  1386. closer.Close()
  1387. }
  1388. stream.ctx.Close()
  1389. }
  1390. // Error returns an error if one occurred during the process of streaming the KubeModelSet
  1391. // This can be checked after iterating through the Stream().
  1392. func (stream *KubeModelSetStream) Error() error {
  1393. return stream.err
  1394. }
  1395. // NewKubeModelSetStream creates a new KubeModelSetStream, which uses the io.Reader data to stream all internal fields of an KubeModelSet instance
  1396. func NewKubeModelSetStream(reader io.Reader) BingenStream {
  1397. ctx := NewDecodingContextFromReader(reader)
  1398. return &KubeModelSetStream{
  1399. ctx: ctx,
  1400. reader: reader,
  1401. }
  1402. }
  1403. // Stream returns the iterator which will stream each field of the target type.
  1404. func (stream *KubeModelSetStream) Stream() iter.Seq2[BingenFieldInfo, *BingenValue] {
  1405. return func(yield func(BingenFieldInfo, *BingenValue) bool) {
  1406. var fi BingenFieldInfo
  1407. ctx := stream.ctx
  1408. buff := ctx.Buffer
  1409. version := buff.ReadUInt8()
  1410. if version > DefaultCodecVersion {
  1411. stream.err = fmt.Errorf("Invalid Version Unmarshalling KubeModelSet. Expected %d or less, got %d", DefaultCodecVersion, version)
  1412. return
  1413. }
  1414. fi = BingenFieldInfo{
  1415. Type: reflect.TypeFor[*Metadata](),
  1416. Name: "Metadata",
  1417. }
  1418. // field version check
  1419. if uint8(1) <= version {
  1420. if buff.ReadUInt8() == uint8(0) {
  1421. if !yield(fi, nil) {
  1422. return
  1423. }
  1424. } else {
  1425. // --- [begin][read][struct](Metadata) ---
  1426. b := new(Metadata)
  1427. buff.ReadInt() // [compatibility, unused]
  1428. errA := b.UnmarshalBinaryWithContext(ctx)
  1429. if errA != nil {
  1430. stream.err = errA
  1431. return
  1432. }
  1433. a := b
  1434. // --- [end][read][struct](Metadata) ---
  1435. if !yield(fi, singleV(a)) {
  1436. return
  1437. }
  1438. }
  1439. } else {
  1440. if !yield(fi, nil) {
  1441. return
  1442. }
  1443. }
  1444. fi = BingenFieldInfo{
  1445. Type: reflect.TypeFor[Window](),
  1446. Name: "Window",
  1447. }
  1448. // field version check
  1449. if uint8(1) <= version {
  1450. // --- [begin][read][struct](Window) ---
  1451. d := new(Window)
  1452. buff.ReadInt() // [compatibility, unused]
  1453. errB := d.UnmarshalBinaryWithContext(ctx)
  1454. if errB != nil {
  1455. stream.err = errB
  1456. return
  1457. }
  1458. c := *d
  1459. // --- [end][read][struct](Window) ---
  1460. if !yield(fi, singleV(c)) {
  1461. return
  1462. }
  1463. } else {
  1464. }
  1465. fi = BingenFieldInfo{
  1466. Type: reflect.TypeFor[*Cluster](),
  1467. Name: "Cluster",
  1468. }
  1469. // field version check
  1470. if uint8(1) <= version {
  1471. if buff.ReadUInt8() == uint8(0) {
  1472. if !yield(fi, nil) {
  1473. return
  1474. }
  1475. } else {
  1476. // --- [begin][read][struct](Cluster) ---
  1477. f := new(Cluster)
  1478. buff.ReadInt() // [compatibility, unused]
  1479. errC := f.UnmarshalBinaryWithContext(ctx)
  1480. if errC != nil {
  1481. stream.err = errC
  1482. return
  1483. }
  1484. e := f
  1485. // --- [end][read][struct](Cluster) ---
  1486. if !yield(fi, singleV(e)) {
  1487. return
  1488. }
  1489. }
  1490. } else {
  1491. if !yield(fi, nil) {
  1492. return
  1493. }
  1494. }
  1495. fi = BingenFieldInfo{
  1496. Type: reflect.TypeFor[map[string]*Namespace](),
  1497. Name: "Namespaces",
  1498. }
  1499. // field version check
  1500. if uint8(1) <= version {
  1501. if buff.ReadUInt8() == uint8(0) {
  1502. if !yield(fi, nil) {
  1503. return
  1504. }
  1505. } else {
  1506. // --- [begin][read][streaming-map](map[string]*Namespace) ---
  1507. g := buff.ReadInt() // map len
  1508. for range g {
  1509. var v string
  1510. var l string
  1511. if ctx.IsStringTable() {
  1512. m := buff.ReadInt() // read string index
  1513. l = ctx.Table.At(m)
  1514. } else {
  1515. l = buff.ReadString() // read string
  1516. }
  1517. h := l
  1518. v = h
  1519. var z *Namespace
  1520. if buff.ReadUInt8() == uint8(0) {
  1521. z = nil
  1522. } else {
  1523. // --- [begin][read][struct](Namespace) ---
  1524. n := new(Namespace)
  1525. buff.ReadInt() // [compatibility, unused]
  1526. errD := n.UnmarshalBinaryWithContext(ctx)
  1527. if errD != nil {
  1528. stream.err = errD
  1529. return
  1530. }
  1531. z = n
  1532. // --- [end][read][struct](Namespace) ---
  1533. }
  1534. if !yield(fi, pairV(v, z)) {
  1535. return
  1536. }
  1537. }
  1538. // --- [end][read][streaming-map](map[string]*Namespace) ---
  1539. }
  1540. } else {
  1541. if !yield(fi, nil) {
  1542. return
  1543. }
  1544. }
  1545. fi = BingenFieldInfo{
  1546. Type: reflect.TypeFor[map[string]*ResourceQuota](),
  1547. Name: "ResourceQuotas",
  1548. }
  1549. // field version check
  1550. if uint8(1) <= version {
  1551. if buff.ReadUInt8() == uint8(0) {
  1552. if !yield(fi, nil) {
  1553. return
  1554. }
  1555. } else {
  1556. // --- [begin][read][streaming-map](map[string]*ResourceQuota) ---
  1557. o := buff.ReadInt() // map len
  1558. for range o {
  1559. var vv string
  1560. var q string
  1561. if ctx.IsStringTable() {
  1562. r := buff.ReadInt() // read string index
  1563. q = ctx.Table.At(r)
  1564. } else {
  1565. q = buff.ReadString() // read string
  1566. }
  1567. p := q
  1568. vv = p
  1569. var zz *ResourceQuota
  1570. if buff.ReadUInt8() == uint8(0) {
  1571. zz = nil
  1572. } else {
  1573. // --- [begin][read][struct](ResourceQuota) ---
  1574. s := new(ResourceQuota)
  1575. buff.ReadInt() // [compatibility, unused]
  1576. errE := s.UnmarshalBinaryWithContext(ctx)
  1577. if errE != nil {
  1578. stream.err = errE
  1579. return
  1580. }
  1581. zz = s
  1582. // --- [end][read][struct](ResourceQuota) ---
  1583. }
  1584. if !yield(fi, pairV(vv, zz)) {
  1585. return
  1586. }
  1587. }
  1588. // --- [end][read][streaming-map](map[string]*ResourceQuota) ---
  1589. }
  1590. } else {
  1591. if !yield(fi, nil) {
  1592. return
  1593. }
  1594. }
  1595. }
  1596. }
  1597. //--------------------------------------------------------------------------
  1598. // Metadata
  1599. //--------------------------------------------------------------------------
  1600. // MarshalBinary serializes the internal properties of this Metadata instance
  1601. // into a byte array
  1602. func (target *Metadata) MarshalBinary() (data []byte, err error) {
  1603. ctx := NewEncodingContext(nil)
  1604. e := target.MarshalBinaryWithContext(ctx)
  1605. if e != nil {
  1606. return nil, e
  1607. }
  1608. return ctx.ToBytes(), nil
  1609. }
  1610. // MarshalBinary serializes the internal properties of this Metadata instance
  1611. // into an io.Writer.
  1612. func (target *Metadata) MarshalBinaryTo(writer io.Writer) error {
  1613. buff := util.NewBufferFromWriter(writer)
  1614. defer buff.Flush()
  1615. ctx := NewEncodingContextFromBuffer(buff, nil)
  1616. return target.MarshalBinaryWithContext(ctx)
  1617. }
  1618. // MarshalBinaryWithContext serializes the internal properties of this Metadata instance
  1619. // into a byte array leveraging a predefined context.
  1620. func (target *Metadata) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1621. // panics are recovered and propagated as errors
  1622. defer func() {
  1623. if r := recover(); r != nil {
  1624. if e, ok := r.(error); ok {
  1625. err = e
  1626. } else if s, ok := r.(string); ok {
  1627. err = fmt.Errorf("unexpected panic: %s", s)
  1628. } else {
  1629. err = fmt.Errorf("unexpected panic: %+v", r)
  1630. }
  1631. }
  1632. }()
  1633. buff := ctx.Buffer
  1634. buff.WriteUInt8(DefaultCodecVersion) // version
  1635. // --- [begin][write][reference](time.Time) ---
  1636. a, errA := target.CreatedAt.MarshalBinary()
  1637. if errA != nil {
  1638. return errA
  1639. }
  1640. buff.WriteInt(len(a))
  1641. buff.WriteBytes(a)
  1642. // --- [end][write][reference](time.Time) ---
  1643. // --- [begin][write][reference](time.Time) ---
  1644. b, errB := target.CompletedAt.MarshalBinary()
  1645. if errB != nil {
  1646. return errB
  1647. }
  1648. buff.WriteInt(len(b))
  1649. buff.WriteBytes(b)
  1650. // --- [end][write][reference](time.Time) ---
  1651. buff.WriteInt(target.ObjectCount) // write int
  1652. if target.Diagnostics == nil {
  1653. buff.WriteUInt8(uint8(0)) // write nil byte
  1654. } else {
  1655. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1656. // --- [begin][write][slice]([]Diagnostic) ---
  1657. buff.WriteInt(len(target.Diagnostics)) // slice length
  1658. for i := range target.Diagnostics {
  1659. // --- [begin][write][struct](Diagnostic) ---
  1660. buff.WriteInt(0) // [compatibility, unused]
  1661. errC := target.Diagnostics[i].MarshalBinaryWithContext(ctx)
  1662. if errC != nil {
  1663. return errC
  1664. }
  1665. // --- [end][write][struct](Diagnostic) ---
  1666. }
  1667. // --- [end][write][slice]([]Diagnostic) ---
  1668. }
  1669. // --- [begin][write][alias](DiagnosticLevel) ---
  1670. buff.WriteInt(int(target.DiagnosticLevel)) // write int
  1671. // --- [end][write][alias](DiagnosticLevel) ---
  1672. return nil
  1673. }
  1674. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1675. // the Metadata type
  1676. func (target *Metadata) UnmarshalBinary(data []byte) error {
  1677. ctx := NewDecodingContextFromBytes(data)
  1678. defer ctx.Close()
  1679. err := target.UnmarshalBinaryWithContext(ctx)
  1680. if err != nil {
  1681. return err
  1682. }
  1683. return nil
  1684. }
  1685. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  1686. // the Metadata type
  1687. func (target *Metadata) UnmarshalBinaryFromReader(reader io.Reader) error {
  1688. ctx := NewDecodingContextFromReader(reader)
  1689. defer ctx.Close()
  1690. err := target.UnmarshalBinaryWithContext(ctx)
  1691. if err != nil {
  1692. return err
  1693. }
  1694. return nil
  1695. }
  1696. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1697. // the Metadata type
  1698. func (target *Metadata) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1699. // panics are recovered and propagated as errors
  1700. defer func() {
  1701. if r := recover(); r != nil {
  1702. if e, ok := r.(error); ok {
  1703. err = e
  1704. } else if s, ok := r.(string); ok {
  1705. err = fmt.Errorf("unexpected panic: %s", s)
  1706. } else {
  1707. err = fmt.Errorf("unexpected panic: %+v", r)
  1708. }
  1709. }
  1710. }()
  1711. buff := ctx.Buffer
  1712. version := buff.ReadUInt8()
  1713. if version > DefaultCodecVersion {
  1714. return fmt.Errorf("Invalid Version Unmarshalling Metadata. Expected %d or less, got %d", DefaultCodecVersion, version)
  1715. }
  1716. // field version check
  1717. if uint8(1) <= version {
  1718. // --- [begin][read][reference](time.Time) ---
  1719. a := new(time.Time)
  1720. b := buff.ReadInt() // byte array length
  1721. c := buff.ReadBytes(b)
  1722. errA := a.UnmarshalBinary(c)
  1723. if errA != nil {
  1724. return errA
  1725. }
  1726. target.CreatedAt = *a
  1727. // --- [end][read][reference](time.Time) ---
  1728. } else {
  1729. }
  1730. // field version check
  1731. if uint8(1) <= version {
  1732. // --- [begin][read][reference](time.Time) ---
  1733. d := new(time.Time)
  1734. e := buff.ReadInt() // byte array length
  1735. f := buff.ReadBytes(e)
  1736. errB := d.UnmarshalBinary(f)
  1737. if errB != nil {
  1738. return errB
  1739. }
  1740. target.CompletedAt = *d
  1741. // --- [end][read][reference](time.Time) ---
  1742. } else {
  1743. }
  1744. // field version check
  1745. if uint8(1) <= version {
  1746. g := buff.ReadInt() // read int
  1747. target.ObjectCount = g
  1748. } else {
  1749. target.ObjectCount = int(0) // default
  1750. }
  1751. // field version check
  1752. if uint8(1) <= version {
  1753. if buff.ReadUInt8() == uint8(0) {
  1754. target.Diagnostics = nil
  1755. } else {
  1756. // --- [begin][read][slice]([]Diagnostic) ---
  1757. l := buff.ReadInt() // slice len
  1758. h := make([]Diagnostic, l)
  1759. for i := range l {
  1760. // --- [begin][read][struct](Diagnostic) ---
  1761. n := new(Diagnostic)
  1762. buff.ReadInt() // [compatibility, unused]
  1763. errC := n.UnmarshalBinaryWithContext(ctx)
  1764. if errC != nil {
  1765. return errC
  1766. }
  1767. m := *n
  1768. // --- [end][read][struct](Diagnostic) ---
  1769. h[i] = m
  1770. }
  1771. target.Diagnostics = h
  1772. // --- [end][read][slice]([]Diagnostic) ---
  1773. }
  1774. } else {
  1775. target.Diagnostics = nil
  1776. }
  1777. // field version check
  1778. if uint8(1) <= version {
  1779. // --- [begin][read][alias](DiagnosticLevel) ---
  1780. var o int
  1781. p := buff.ReadInt() // read int
  1782. o = p
  1783. target.DiagnosticLevel = DiagnosticLevel(o)
  1784. // --- [end][read][alias](DiagnosticLevel) ---
  1785. } else {
  1786. }
  1787. return nil
  1788. }
  1789. //--------------------------------------------------------------------------
  1790. // Namespace
  1791. //--------------------------------------------------------------------------
  1792. // MarshalBinary serializes the internal properties of this Namespace instance
  1793. // into a byte array
  1794. func (target *Namespace) MarshalBinary() (data []byte, err error) {
  1795. ctx := NewEncodingContext(nil)
  1796. e := target.MarshalBinaryWithContext(ctx)
  1797. if e != nil {
  1798. return nil, e
  1799. }
  1800. return ctx.ToBytes(), nil
  1801. }
  1802. // MarshalBinary serializes the internal properties of this Namespace instance
  1803. // into an io.Writer.
  1804. func (target *Namespace) MarshalBinaryTo(writer io.Writer) error {
  1805. buff := util.NewBufferFromWriter(writer)
  1806. defer buff.Flush()
  1807. ctx := NewEncodingContextFromBuffer(buff, nil)
  1808. return target.MarshalBinaryWithContext(ctx)
  1809. }
  1810. // MarshalBinaryWithContext serializes the internal properties of this Namespace instance
  1811. // into a byte array leveraging a predefined context.
  1812. func (target *Namespace) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1813. // panics are recovered and propagated as errors
  1814. defer func() {
  1815. if r := recover(); r != nil {
  1816. if e, ok := r.(error); ok {
  1817. err = e
  1818. } else if s, ok := r.(string); ok {
  1819. err = fmt.Errorf("unexpected panic: %s", s)
  1820. } else {
  1821. err = fmt.Errorf("unexpected panic: %+v", r)
  1822. }
  1823. }
  1824. }()
  1825. buff := ctx.Buffer
  1826. buff.WriteUInt8(DefaultCodecVersion) // version
  1827. if ctx.IsStringTable() {
  1828. a := ctx.Table.AddOrGet(target.UID)
  1829. buff.WriteInt(a) // write table index
  1830. } else {
  1831. buff.WriteString(target.UID) // write string
  1832. }
  1833. if ctx.IsStringTable() {
  1834. b := ctx.Table.AddOrGet(target.ClusterUID)
  1835. buff.WriteInt(b) // write table index
  1836. } else {
  1837. buff.WriteString(target.ClusterUID) // write string
  1838. }
  1839. if ctx.IsStringTable() {
  1840. c := ctx.Table.AddOrGet(target.Name)
  1841. buff.WriteInt(c) // write table index
  1842. } else {
  1843. buff.WriteString(target.Name) // write string
  1844. }
  1845. if target.Labels == nil {
  1846. buff.WriteUInt8(uint8(0)) // write nil byte
  1847. } else {
  1848. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1849. // --- [begin][write][map](map[string]string) ---
  1850. buff.WriteInt(len(target.Labels)) // map length
  1851. for v, z := range target.Labels {
  1852. if ctx.IsStringTable() {
  1853. d := ctx.Table.AddOrGet(v)
  1854. buff.WriteInt(d) // write table index
  1855. } else {
  1856. buff.WriteString(v) // write string
  1857. }
  1858. if ctx.IsStringTable() {
  1859. e := ctx.Table.AddOrGet(z)
  1860. buff.WriteInt(e) // write table index
  1861. } else {
  1862. buff.WriteString(z) // write string
  1863. }
  1864. }
  1865. // --- [end][write][map](map[string]string) ---
  1866. }
  1867. if target.Annotations == nil {
  1868. buff.WriteUInt8(uint8(0)) // write nil byte
  1869. } else {
  1870. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1871. // --- [begin][write][map](map[string]string) ---
  1872. buff.WriteInt(len(target.Annotations)) // map length
  1873. for vv, zz := range target.Annotations {
  1874. if ctx.IsStringTable() {
  1875. f := ctx.Table.AddOrGet(vv)
  1876. buff.WriteInt(f) // write table index
  1877. } else {
  1878. buff.WriteString(vv) // write string
  1879. }
  1880. if ctx.IsStringTable() {
  1881. g := ctx.Table.AddOrGet(zz)
  1882. buff.WriteInt(g) // write table index
  1883. } else {
  1884. buff.WriteString(zz) // write string
  1885. }
  1886. }
  1887. // --- [end][write][map](map[string]string) ---
  1888. }
  1889. // --- [begin][write][reference](time.Time) ---
  1890. h, errA := target.Start.MarshalBinary()
  1891. if errA != nil {
  1892. return errA
  1893. }
  1894. buff.WriteInt(len(h))
  1895. buff.WriteBytes(h)
  1896. // --- [end][write][reference](time.Time) ---
  1897. // --- [begin][write][reference](time.Time) ---
  1898. l, errB := target.End.MarshalBinary()
  1899. if errB != nil {
  1900. return errB
  1901. }
  1902. buff.WriteInt(len(l))
  1903. buff.WriteBytes(l)
  1904. // --- [end][write][reference](time.Time) ---
  1905. return nil
  1906. }
  1907. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1908. // the Namespace type
  1909. func (target *Namespace) UnmarshalBinary(data []byte) error {
  1910. ctx := NewDecodingContextFromBytes(data)
  1911. defer ctx.Close()
  1912. err := target.UnmarshalBinaryWithContext(ctx)
  1913. if err != nil {
  1914. return err
  1915. }
  1916. return nil
  1917. }
  1918. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  1919. // the Namespace type
  1920. func (target *Namespace) UnmarshalBinaryFromReader(reader io.Reader) error {
  1921. ctx := NewDecodingContextFromReader(reader)
  1922. defer ctx.Close()
  1923. err := target.UnmarshalBinaryWithContext(ctx)
  1924. if err != nil {
  1925. return err
  1926. }
  1927. return nil
  1928. }
  1929. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1930. // the Namespace type
  1931. func (target *Namespace) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1932. // panics are recovered and propagated as errors
  1933. defer func() {
  1934. if r := recover(); r != nil {
  1935. if e, ok := r.(error); ok {
  1936. err = e
  1937. } else if s, ok := r.(string); ok {
  1938. err = fmt.Errorf("unexpected panic: %s", s)
  1939. } else {
  1940. err = fmt.Errorf("unexpected panic: %+v", r)
  1941. }
  1942. }
  1943. }()
  1944. buff := ctx.Buffer
  1945. version := buff.ReadUInt8()
  1946. if version > DefaultCodecVersion {
  1947. return fmt.Errorf("Invalid Version Unmarshalling Namespace. Expected %d or less, got %d", DefaultCodecVersion, version)
  1948. }
  1949. // field version check
  1950. if uint8(1) <= version {
  1951. var b string
  1952. if ctx.IsStringTable() {
  1953. c := buff.ReadInt() // read string index
  1954. b = ctx.Table.At(c)
  1955. } else {
  1956. b = buff.ReadString() // read string
  1957. }
  1958. a := b
  1959. target.UID = a
  1960. } else {
  1961. target.UID = "" // default
  1962. }
  1963. // field version check
  1964. if uint8(1) <= version {
  1965. var e string
  1966. if ctx.IsStringTable() {
  1967. f := buff.ReadInt() // read string index
  1968. e = ctx.Table.At(f)
  1969. } else {
  1970. e = buff.ReadString() // read string
  1971. }
  1972. d := e
  1973. target.ClusterUID = d
  1974. } else {
  1975. target.ClusterUID = "" // default
  1976. }
  1977. // field version check
  1978. if uint8(1) <= version {
  1979. var h string
  1980. if ctx.IsStringTable() {
  1981. l := buff.ReadInt() // read string index
  1982. h = ctx.Table.At(l)
  1983. } else {
  1984. h = buff.ReadString() // read string
  1985. }
  1986. g := h
  1987. target.Name = g
  1988. } else {
  1989. target.Name = "" // default
  1990. }
  1991. // field version check
  1992. if uint8(1) <= version {
  1993. if buff.ReadUInt8() == uint8(0) {
  1994. target.Labels = nil
  1995. } else {
  1996. // --- [begin][read][map](map[string]string) ---
  1997. n := buff.ReadInt() // map len
  1998. m := make(map[string]string, n)
  1999. for range n {
  2000. var v string
  2001. var p string
  2002. if ctx.IsStringTable() {
  2003. q := buff.ReadInt() // read string index
  2004. p = ctx.Table.At(q)
  2005. } else {
  2006. p = buff.ReadString() // read string
  2007. }
  2008. o := p
  2009. v = o
  2010. var z string
  2011. var s string
  2012. if ctx.IsStringTable() {
  2013. t := buff.ReadInt() // read string index
  2014. s = ctx.Table.At(t)
  2015. } else {
  2016. s = buff.ReadString() // read string
  2017. }
  2018. r := s
  2019. z = r
  2020. m[v] = z
  2021. }
  2022. target.Labels = m
  2023. // --- [end][read][map](map[string]string) ---
  2024. }
  2025. } else {
  2026. target.Labels = nil
  2027. }
  2028. // field version check
  2029. if uint8(1) <= version {
  2030. if buff.ReadUInt8() == uint8(0) {
  2031. target.Annotations = nil
  2032. } else {
  2033. // --- [begin][read][map](map[string]string) ---
  2034. w := buff.ReadInt() // map len
  2035. u := make(map[string]string, w)
  2036. for range w {
  2037. var vv string
  2038. var y string
  2039. if ctx.IsStringTable() {
  2040. aa := buff.ReadInt() // read string index
  2041. y = ctx.Table.At(aa)
  2042. } else {
  2043. y = buff.ReadString() // read string
  2044. }
  2045. x := y
  2046. vv = x
  2047. var zz string
  2048. var cc string
  2049. if ctx.IsStringTable() {
  2050. dd := buff.ReadInt() // read string index
  2051. cc = ctx.Table.At(dd)
  2052. } else {
  2053. cc = buff.ReadString() // read string
  2054. }
  2055. bb := cc
  2056. zz = bb
  2057. u[vv] = zz
  2058. }
  2059. target.Annotations = u
  2060. // --- [end][read][map](map[string]string) ---
  2061. }
  2062. } else {
  2063. target.Annotations = nil
  2064. }
  2065. // field version check
  2066. if uint8(1) <= version {
  2067. // --- [begin][read][reference](time.Time) ---
  2068. ee := new(time.Time)
  2069. ff := buff.ReadInt() // byte array length
  2070. gg := buff.ReadBytes(ff)
  2071. errA := ee.UnmarshalBinary(gg)
  2072. if errA != nil {
  2073. return errA
  2074. }
  2075. target.Start = *ee
  2076. // --- [end][read][reference](time.Time) ---
  2077. } else {
  2078. }
  2079. // field version check
  2080. if uint8(1) <= version {
  2081. // --- [begin][read][reference](time.Time) ---
  2082. hh := new(time.Time)
  2083. ll := buff.ReadInt() // byte array length
  2084. mm := buff.ReadBytes(ll)
  2085. errB := hh.UnmarshalBinary(mm)
  2086. if errB != nil {
  2087. return errB
  2088. }
  2089. target.End = *hh
  2090. // --- [end][read][reference](time.Time) ---
  2091. } else {
  2092. }
  2093. return nil
  2094. }
  2095. //--------------------------------------------------------------------------
  2096. // ResourceQuantity
  2097. //--------------------------------------------------------------------------
  2098. // MarshalBinary serializes the internal properties of this ResourceQuantity instance
  2099. // into a byte array
  2100. func (target *ResourceQuantity) MarshalBinary() (data []byte, err error) {
  2101. ctx := NewEncodingContext(nil)
  2102. e := target.MarshalBinaryWithContext(ctx)
  2103. if e != nil {
  2104. return nil, e
  2105. }
  2106. return ctx.ToBytes(), nil
  2107. }
  2108. // MarshalBinary serializes the internal properties of this ResourceQuantity instance
  2109. // into an io.Writer.
  2110. func (target *ResourceQuantity) MarshalBinaryTo(writer io.Writer) error {
  2111. buff := util.NewBufferFromWriter(writer)
  2112. defer buff.Flush()
  2113. ctx := NewEncodingContextFromBuffer(buff, nil)
  2114. return target.MarshalBinaryWithContext(ctx)
  2115. }
  2116. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuantity instance
  2117. // into a byte array leveraging a predefined context.
  2118. func (target *ResourceQuantity) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2119. // panics are recovered and propagated as errors
  2120. defer func() {
  2121. if r := recover(); r != nil {
  2122. if e, ok := r.(error); ok {
  2123. err = e
  2124. } else if s, ok := r.(string); ok {
  2125. err = fmt.Errorf("unexpected panic: %s", s)
  2126. } else {
  2127. err = fmt.Errorf("unexpected panic: %+v", r)
  2128. }
  2129. }
  2130. }()
  2131. buff := ctx.Buffer
  2132. buff.WriteUInt8(DefaultCodecVersion) // version
  2133. // --- [begin][write][alias](Resource) ---
  2134. if ctx.IsStringTable() {
  2135. a := ctx.Table.AddOrGet(string(target.Resource))
  2136. buff.WriteInt(a) // write table index
  2137. } else {
  2138. buff.WriteString(string(target.Resource)) // write string
  2139. }
  2140. // --- [end][write][alias](Resource) ---
  2141. // --- [begin][write][alias](Unit) ---
  2142. if ctx.IsStringTable() {
  2143. b := ctx.Table.AddOrGet(string(target.Unit))
  2144. buff.WriteInt(b) // write table index
  2145. } else {
  2146. buff.WriteString(string(target.Unit)) // write string
  2147. }
  2148. // --- [end][write][alias](Unit) ---
  2149. // --- [begin][write][alias](Stats) ---
  2150. if map[StatType]float64(target.Values) == nil {
  2151. buff.WriteUInt8(uint8(0)) // write nil byte
  2152. } else {
  2153. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2154. // --- [begin][write][map](map[StatType]float64) ---
  2155. buff.WriteInt(len(map[StatType]float64(target.Values))) // map length
  2156. for v, z := range map[StatType]float64(target.Values) {
  2157. // --- [begin][write][alias](StatType) ---
  2158. if ctx.IsStringTable() {
  2159. c := ctx.Table.AddOrGet(string(v))
  2160. buff.WriteInt(c) // write table index
  2161. } else {
  2162. buff.WriteString(string(v)) // write string
  2163. }
  2164. // --- [end][write][alias](StatType) ---
  2165. buff.WriteFloat64(z) // write float64
  2166. }
  2167. // --- [end][write][map](map[StatType]float64) ---
  2168. }
  2169. // --- [end][write][alias](Stats) ---
  2170. return nil
  2171. }
  2172. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2173. // the ResourceQuantity type
  2174. func (target *ResourceQuantity) UnmarshalBinary(data []byte) error {
  2175. ctx := NewDecodingContextFromBytes(data)
  2176. defer ctx.Close()
  2177. err := target.UnmarshalBinaryWithContext(ctx)
  2178. if err != nil {
  2179. return err
  2180. }
  2181. return nil
  2182. }
  2183. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  2184. // the ResourceQuantity type
  2185. func (target *ResourceQuantity) UnmarshalBinaryFromReader(reader io.Reader) error {
  2186. ctx := NewDecodingContextFromReader(reader)
  2187. defer ctx.Close()
  2188. err := target.UnmarshalBinaryWithContext(ctx)
  2189. if err != nil {
  2190. return err
  2191. }
  2192. return nil
  2193. }
  2194. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2195. // the ResourceQuantity type
  2196. func (target *ResourceQuantity) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2197. // panics are recovered and propagated as errors
  2198. defer func() {
  2199. if r := recover(); r != nil {
  2200. if e, ok := r.(error); ok {
  2201. err = e
  2202. } else if s, ok := r.(string); ok {
  2203. err = fmt.Errorf("unexpected panic: %s", s)
  2204. } else {
  2205. err = fmt.Errorf("unexpected panic: %+v", r)
  2206. }
  2207. }
  2208. }()
  2209. buff := ctx.Buffer
  2210. version := buff.ReadUInt8()
  2211. if version > DefaultCodecVersion {
  2212. return fmt.Errorf("Invalid Version Unmarshalling ResourceQuantity. Expected %d or less, got %d", DefaultCodecVersion, version)
  2213. }
  2214. // field version check
  2215. if uint8(1) <= version {
  2216. // --- [begin][read][alias](Resource) ---
  2217. var a string
  2218. var c string
  2219. if ctx.IsStringTable() {
  2220. d := buff.ReadInt() // read string index
  2221. c = ctx.Table.At(d)
  2222. } else {
  2223. c = buff.ReadString() // read string
  2224. }
  2225. b := c
  2226. a = b
  2227. target.Resource = Resource(a)
  2228. // --- [end][read][alias](Resource) ---
  2229. } else {
  2230. }
  2231. // field version check
  2232. if uint8(1) <= version {
  2233. // --- [begin][read][alias](Unit) ---
  2234. var e string
  2235. var g string
  2236. if ctx.IsStringTable() {
  2237. h := buff.ReadInt() // read string index
  2238. g = ctx.Table.At(h)
  2239. } else {
  2240. g = buff.ReadString() // read string
  2241. }
  2242. f := g
  2243. e = f
  2244. target.Unit = Unit(e)
  2245. // --- [end][read][alias](Unit) ---
  2246. } else {
  2247. }
  2248. // field version check
  2249. if uint8(1) <= version {
  2250. // --- [begin][read][alias](Stats) ---
  2251. var l map[StatType]float64
  2252. if buff.ReadUInt8() == uint8(0) {
  2253. l = nil
  2254. } else {
  2255. // --- [begin][read][map](map[StatType]float64) ---
  2256. n := buff.ReadInt() // map len
  2257. m := make(map[StatType]float64, n)
  2258. for range n {
  2259. // --- [begin][read][alias](StatType) ---
  2260. var o string
  2261. var q string
  2262. if ctx.IsStringTable() {
  2263. r := buff.ReadInt() // read string index
  2264. q = ctx.Table.At(r)
  2265. } else {
  2266. q = buff.ReadString() // read string
  2267. }
  2268. p := q
  2269. o = p
  2270. v := StatType(o)
  2271. // --- [end][read][alias](StatType) ---
  2272. var z float64
  2273. s := buff.ReadFloat64() // read float64
  2274. z = s
  2275. m[v] = z
  2276. }
  2277. l = m
  2278. // --- [end][read][map](map[StatType]float64) ---
  2279. }
  2280. target.Values = Stats(l)
  2281. // --- [end][read][alias](Stats) ---
  2282. } else {
  2283. }
  2284. return nil
  2285. }
  2286. //--------------------------------------------------------------------------
  2287. // ResourceQuota
  2288. //--------------------------------------------------------------------------
  2289. // MarshalBinary serializes the internal properties of this ResourceQuota instance
  2290. // into a byte array
  2291. func (target *ResourceQuota) MarshalBinary() (data []byte, err error) {
  2292. ctx := NewEncodingContext(nil)
  2293. e := target.MarshalBinaryWithContext(ctx)
  2294. if e != nil {
  2295. return nil, e
  2296. }
  2297. return ctx.ToBytes(), nil
  2298. }
  2299. // MarshalBinary serializes the internal properties of this ResourceQuota instance
  2300. // into an io.Writer.
  2301. func (target *ResourceQuota) MarshalBinaryTo(writer io.Writer) error {
  2302. buff := util.NewBufferFromWriter(writer)
  2303. defer buff.Flush()
  2304. ctx := NewEncodingContextFromBuffer(buff, nil)
  2305. return target.MarshalBinaryWithContext(ctx)
  2306. }
  2307. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuota instance
  2308. // into a byte array leveraging a predefined context.
  2309. func (target *ResourceQuota) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2310. // panics are recovered and propagated as errors
  2311. defer func() {
  2312. if r := recover(); r != nil {
  2313. if e, ok := r.(error); ok {
  2314. err = e
  2315. } else if s, ok := r.(string); ok {
  2316. err = fmt.Errorf("unexpected panic: %s", s)
  2317. } else {
  2318. err = fmt.Errorf("unexpected panic: %+v", r)
  2319. }
  2320. }
  2321. }()
  2322. buff := ctx.Buffer
  2323. buff.WriteUInt8(DefaultCodecVersion) // version
  2324. if ctx.IsStringTable() {
  2325. a := ctx.Table.AddOrGet(target.UID)
  2326. buff.WriteInt(a) // write table index
  2327. } else {
  2328. buff.WriteString(target.UID) // write string
  2329. }
  2330. if ctx.IsStringTable() {
  2331. b := ctx.Table.AddOrGet(target.NamespaceUID)
  2332. buff.WriteInt(b) // write table index
  2333. } else {
  2334. buff.WriteString(target.NamespaceUID) // write string
  2335. }
  2336. if ctx.IsStringTable() {
  2337. c := ctx.Table.AddOrGet(target.Name)
  2338. buff.WriteInt(c) // write table index
  2339. } else {
  2340. buff.WriteString(target.Name) // write string
  2341. }
  2342. if target.Spec == nil {
  2343. buff.WriteUInt8(uint8(0)) // write nil byte
  2344. } else {
  2345. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2346. // --- [begin][write][struct](ResourceQuotaSpec) ---
  2347. buff.WriteInt(0) // [compatibility, unused]
  2348. errA := target.Spec.MarshalBinaryWithContext(ctx)
  2349. if errA != nil {
  2350. return errA
  2351. }
  2352. // --- [end][write][struct](ResourceQuotaSpec) ---
  2353. }
  2354. if target.Status == nil {
  2355. buff.WriteUInt8(uint8(0)) // write nil byte
  2356. } else {
  2357. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2358. // --- [begin][write][struct](ResourceQuotaStatus) ---
  2359. buff.WriteInt(0) // [compatibility, unused]
  2360. errB := target.Status.MarshalBinaryWithContext(ctx)
  2361. if errB != nil {
  2362. return errB
  2363. }
  2364. // --- [end][write][struct](ResourceQuotaStatus) ---
  2365. }
  2366. // --- [begin][write][reference](time.Time) ---
  2367. d, errC := target.Start.MarshalBinary()
  2368. if errC != nil {
  2369. return errC
  2370. }
  2371. buff.WriteInt(len(d))
  2372. buff.WriteBytes(d)
  2373. // --- [end][write][reference](time.Time) ---
  2374. // --- [begin][write][reference](time.Time) ---
  2375. e, errD := target.End.MarshalBinary()
  2376. if errD != nil {
  2377. return errD
  2378. }
  2379. buff.WriteInt(len(e))
  2380. buff.WriteBytes(e)
  2381. // --- [end][write][reference](time.Time) ---
  2382. return nil
  2383. }
  2384. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2385. // the ResourceQuota type
  2386. func (target *ResourceQuota) UnmarshalBinary(data []byte) error {
  2387. ctx := NewDecodingContextFromBytes(data)
  2388. defer ctx.Close()
  2389. err := target.UnmarshalBinaryWithContext(ctx)
  2390. if err != nil {
  2391. return err
  2392. }
  2393. return nil
  2394. }
  2395. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  2396. // the ResourceQuota type
  2397. func (target *ResourceQuota) UnmarshalBinaryFromReader(reader io.Reader) error {
  2398. ctx := NewDecodingContextFromReader(reader)
  2399. defer ctx.Close()
  2400. err := target.UnmarshalBinaryWithContext(ctx)
  2401. if err != nil {
  2402. return err
  2403. }
  2404. return nil
  2405. }
  2406. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2407. // the ResourceQuota type
  2408. func (target *ResourceQuota) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2409. // panics are recovered and propagated as errors
  2410. defer func() {
  2411. if r := recover(); r != nil {
  2412. if e, ok := r.(error); ok {
  2413. err = e
  2414. } else if s, ok := r.(string); ok {
  2415. err = fmt.Errorf("unexpected panic: %s", s)
  2416. } else {
  2417. err = fmt.Errorf("unexpected panic: %+v", r)
  2418. }
  2419. }
  2420. }()
  2421. buff := ctx.Buffer
  2422. version := buff.ReadUInt8()
  2423. if version > DefaultCodecVersion {
  2424. return fmt.Errorf("Invalid Version Unmarshalling ResourceQuota. Expected %d or less, got %d", DefaultCodecVersion, version)
  2425. }
  2426. // field version check
  2427. if uint8(1) <= version {
  2428. var b string
  2429. if ctx.IsStringTable() {
  2430. c := buff.ReadInt() // read string index
  2431. b = ctx.Table.At(c)
  2432. } else {
  2433. b = buff.ReadString() // read string
  2434. }
  2435. a := b
  2436. target.UID = a
  2437. } else {
  2438. target.UID = "" // default
  2439. }
  2440. // field version check
  2441. if uint8(1) <= version {
  2442. var e string
  2443. if ctx.IsStringTable() {
  2444. f := buff.ReadInt() // read string index
  2445. e = ctx.Table.At(f)
  2446. } else {
  2447. e = buff.ReadString() // read string
  2448. }
  2449. d := e
  2450. target.NamespaceUID = d
  2451. } else {
  2452. target.NamespaceUID = "" // default
  2453. }
  2454. // field version check
  2455. if uint8(1) <= version {
  2456. var h string
  2457. if ctx.IsStringTable() {
  2458. l := buff.ReadInt() // read string index
  2459. h = ctx.Table.At(l)
  2460. } else {
  2461. h = buff.ReadString() // read string
  2462. }
  2463. g := h
  2464. target.Name = g
  2465. } else {
  2466. target.Name = "" // default
  2467. }
  2468. // field version check
  2469. if uint8(1) <= version {
  2470. if buff.ReadUInt8() == uint8(0) {
  2471. target.Spec = nil
  2472. } else {
  2473. // --- [begin][read][struct](ResourceQuotaSpec) ---
  2474. m := new(ResourceQuotaSpec)
  2475. buff.ReadInt() // [compatibility, unused]
  2476. errA := m.UnmarshalBinaryWithContext(ctx)
  2477. if errA != nil {
  2478. return errA
  2479. }
  2480. target.Spec = m
  2481. // --- [end][read][struct](ResourceQuotaSpec) ---
  2482. }
  2483. } else {
  2484. target.Spec = nil
  2485. }
  2486. // field version check
  2487. if uint8(1) <= version {
  2488. if buff.ReadUInt8() == uint8(0) {
  2489. target.Status = nil
  2490. } else {
  2491. // --- [begin][read][struct](ResourceQuotaStatus) ---
  2492. n := new(ResourceQuotaStatus)
  2493. buff.ReadInt() // [compatibility, unused]
  2494. errB := n.UnmarshalBinaryWithContext(ctx)
  2495. if errB != nil {
  2496. return errB
  2497. }
  2498. target.Status = n
  2499. // --- [end][read][struct](ResourceQuotaStatus) ---
  2500. }
  2501. } else {
  2502. target.Status = nil
  2503. }
  2504. // field version check
  2505. if uint8(1) <= version {
  2506. // --- [begin][read][reference](time.Time) ---
  2507. o := new(time.Time)
  2508. p := buff.ReadInt() // byte array length
  2509. q := buff.ReadBytes(p)
  2510. errC := o.UnmarshalBinary(q)
  2511. if errC != nil {
  2512. return errC
  2513. }
  2514. target.Start = *o
  2515. // --- [end][read][reference](time.Time) ---
  2516. } else {
  2517. }
  2518. // field version check
  2519. if uint8(1) <= version {
  2520. // --- [begin][read][reference](time.Time) ---
  2521. r := new(time.Time)
  2522. s := buff.ReadInt() // byte array length
  2523. t := buff.ReadBytes(s)
  2524. errD := r.UnmarshalBinary(t)
  2525. if errD != nil {
  2526. return errD
  2527. }
  2528. target.End = *r
  2529. // --- [end][read][reference](time.Time) ---
  2530. } else {
  2531. }
  2532. return nil
  2533. }
  2534. //--------------------------------------------------------------------------
  2535. // ResourceQuotaSpec
  2536. //--------------------------------------------------------------------------
  2537. // MarshalBinary serializes the internal properties of this ResourceQuotaSpec instance
  2538. // into a byte array
  2539. func (target *ResourceQuotaSpec) MarshalBinary() (data []byte, err error) {
  2540. ctx := NewEncodingContext(nil)
  2541. e := target.MarshalBinaryWithContext(ctx)
  2542. if e != nil {
  2543. return nil, e
  2544. }
  2545. return ctx.ToBytes(), nil
  2546. }
  2547. // MarshalBinary serializes the internal properties of this ResourceQuotaSpec instance
  2548. // into an io.Writer.
  2549. func (target *ResourceQuotaSpec) MarshalBinaryTo(writer io.Writer) error {
  2550. buff := util.NewBufferFromWriter(writer)
  2551. defer buff.Flush()
  2552. ctx := NewEncodingContextFromBuffer(buff, nil)
  2553. return target.MarshalBinaryWithContext(ctx)
  2554. }
  2555. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaSpec instance
  2556. // into a byte array leveraging a predefined context.
  2557. func (target *ResourceQuotaSpec) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2558. // panics are recovered and propagated as errors
  2559. defer func() {
  2560. if r := recover(); r != nil {
  2561. if e, ok := r.(error); ok {
  2562. err = e
  2563. } else if s, ok := r.(string); ok {
  2564. err = fmt.Errorf("unexpected panic: %s", s)
  2565. } else {
  2566. err = fmt.Errorf("unexpected panic: %+v", r)
  2567. }
  2568. }
  2569. }()
  2570. buff := ctx.Buffer
  2571. buff.WriteUInt8(DefaultCodecVersion) // version
  2572. if target.Hard == nil {
  2573. buff.WriteUInt8(uint8(0)) // write nil byte
  2574. } else {
  2575. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2576. // --- [begin][write][struct](ResourceQuotaSpecHard) ---
  2577. buff.WriteInt(0) // [compatibility, unused]
  2578. errA := target.Hard.MarshalBinaryWithContext(ctx)
  2579. if errA != nil {
  2580. return errA
  2581. }
  2582. // --- [end][write][struct](ResourceQuotaSpecHard) ---
  2583. }
  2584. return nil
  2585. }
  2586. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2587. // the ResourceQuotaSpec type
  2588. func (target *ResourceQuotaSpec) UnmarshalBinary(data []byte) error {
  2589. ctx := NewDecodingContextFromBytes(data)
  2590. defer ctx.Close()
  2591. err := target.UnmarshalBinaryWithContext(ctx)
  2592. if err != nil {
  2593. return err
  2594. }
  2595. return nil
  2596. }
  2597. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  2598. // the ResourceQuotaSpec type
  2599. func (target *ResourceQuotaSpec) UnmarshalBinaryFromReader(reader io.Reader) error {
  2600. ctx := NewDecodingContextFromReader(reader)
  2601. defer ctx.Close()
  2602. err := target.UnmarshalBinaryWithContext(ctx)
  2603. if err != nil {
  2604. return err
  2605. }
  2606. return nil
  2607. }
  2608. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2609. // the ResourceQuotaSpec type
  2610. func (target *ResourceQuotaSpec) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2611. // panics are recovered and propagated as errors
  2612. defer func() {
  2613. if r := recover(); r != nil {
  2614. if e, ok := r.(error); ok {
  2615. err = e
  2616. } else if s, ok := r.(string); ok {
  2617. err = fmt.Errorf("unexpected panic: %s", s)
  2618. } else {
  2619. err = fmt.Errorf("unexpected panic: %+v", r)
  2620. }
  2621. }
  2622. }()
  2623. buff := ctx.Buffer
  2624. version := buff.ReadUInt8()
  2625. if version > DefaultCodecVersion {
  2626. return fmt.Errorf("Invalid Version Unmarshalling ResourceQuotaSpec. Expected %d or less, got %d", DefaultCodecVersion, version)
  2627. }
  2628. // field version check
  2629. if uint8(1) <= version {
  2630. if buff.ReadUInt8() == uint8(0) {
  2631. target.Hard = nil
  2632. } else {
  2633. // --- [begin][read][struct](ResourceQuotaSpecHard) ---
  2634. a := new(ResourceQuotaSpecHard)
  2635. buff.ReadInt() // [compatibility, unused]
  2636. errA := a.UnmarshalBinaryWithContext(ctx)
  2637. if errA != nil {
  2638. return errA
  2639. }
  2640. target.Hard = a
  2641. // --- [end][read][struct](ResourceQuotaSpecHard) ---
  2642. }
  2643. } else {
  2644. target.Hard = nil
  2645. }
  2646. return nil
  2647. }
  2648. //--------------------------------------------------------------------------
  2649. // ResourceQuotaSpecHard
  2650. //--------------------------------------------------------------------------
  2651. // MarshalBinary serializes the internal properties of this ResourceQuotaSpecHard instance
  2652. // into a byte array
  2653. func (target *ResourceQuotaSpecHard) MarshalBinary() (data []byte, err error) {
  2654. ctx := NewEncodingContext(nil)
  2655. e := target.MarshalBinaryWithContext(ctx)
  2656. if e != nil {
  2657. return nil, e
  2658. }
  2659. return ctx.ToBytes(), nil
  2660. }
  2661. // MarshalBinary serializes the internal properties of this ResourceQuotaSpecHard instance
  2662. // into an io.Writer.
  2663. func (target *ResourceQuotaSpecHard) MarshalBinaryTo(writer io.Writer) error {
  2664. buff := util.NewBufferFromWriter(writer)
  2665. defer buff.Flush()
  2666. ctx := NewEncodingContextFromBuffer(buff, nil)
  2667. return target.MarshalBinaryWithContext(ctx)
  2668. }
  2669. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaSpecHard instance
  2670. // into a byte array leveraging a predefined context.
  2671. func (target *ResourceQuotaSpecHard) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2672. // panics are recovered and propagated as errors
  2673. defer func() {
  2674. if r := recover(); r != nil {
  2675. if e, ok := r.(error); ok {
  2676. err = e
  2677. } else if s, ok := r.(string); ok {
  2678. err = fmt.Errorf("unexpected panic: %s", s)
  2679. } else {
  2680. err = fmt.Errorf("unexpected panic: %+v", r)
  2681. }
  2682. }
  2683. }()
  2684. buff := ctx.Buffer
  2685. buff.WriteUInt8(DefaultCodecVersion) // version
  2686. // --- [begin][write][alias](ResourceQuantities) ---
  2687. if map[Resource]ResourceQuantity(target.Requests) == nil {
  2688. buff.WriteUInt8(uint8(0)) // write nil byte
  2689. } else {
  2690. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2691. // --- [begin][write][map](map[Resource]ResourceQuantity) ---
  2692. buff.WriteInt(len(map[Resource]ResourceQuantity(target.Requests))) // map length
  2693. for v, z := range map[Resource]ResourceQuantity(target.Requests) {
  2694. // --- [begin][write][alias](Resource) ---
  2695. if ctx.IsStringTable() {
  2696. a := ctx.Table.AddOrGet(string(v))
  2697. buff.WriteInt(a) // write table index
  2698. } else {
  2699. buff.WriteString(string(v)) // write string
  2700. }
  2701. // --- [end][write][alias](Resource) ---
  2702. // --- [begin][write][struct](ResourceQuantity) ---
  2703. buff.WriteInt(0) // [compatibility, unused]
  2704. errA := z.MarshalBinaryWithContext(ctx)
  2705. if errA != nil {
  2706. return errA
  2707. }
  2708. // --- [end][write][struct](ResourceQuantity) ---
  2709. }
  2710. // --- [end][write][map](map[Resource]ResourceQuantity) ---
  2711. }
  2712. // --- [end][write][alias](ResourceQuantities) ---
  2713. // --- [begin][write][alias](ResourceQuantities) ---
  2714. if map[Resource]ResourceQuantity(target.Limits) == nil {
  2715. buff.WriteUInt8(uint8(0)) // write nil byte
  2716. } else {
  2717. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2718. // --- [begin][write][map](map[Resource]ResourceQuantity) ---
  2719. buff.WriteInt(len(map[Resource]ResourceQuantity(target.Limits))) // map length
  2720. for vv, zz := range map[Resource]ResourceQuantity(target.Limits) {
  2721. // --- [begin][write][alias](Resource) ---
  2722. if ctx.IsStringTable() {
  2723. b := ctx.Table.AddOrGet(string(vv))
  2724. buff.WriteInt(b) // write table index
  2725. } else {
  2726. buff.WriteString(string(vv)) // write string
  2727. }
  2728. // --- [end][write][alias](Resource) ---
  2729. // --- [begin][write][struct](ResourceQuantity) ---
  2730. buff.WriteInt(0) // [compatibility, unused]
  2731. errB := zz.MarshalBinaryWithContext(ctx)
  2732. if errB != nil {
  2733. return errB
  2734. }
  2735. // --- [end][write][struct](ResourceQuantity) ---
  2736. }
  2737. // --- [end][write][map](map[Resource]ResourceQuantity) ---
  2738. }
  2739. // --- [end][write][alias](ResourceQuantities) ---
  2740. return nil
  2741. }
  2742. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2743. // the ResourceQuotaSpecHard type
  2744. func (target *ResourceQuotaSpecHard) UnmarshalBinary(data []byte) error {
  2745. ctx := NewDecodingContextFromBytes(data)
  2746. defer ctx.Close()
  2747. err := target.UnmarshalBinaryWithContext(ctx)
  2748. if err != nil {
  2749. return err
  2750. }
  2751. return nil
  2752. }
  2753. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  2754. // the ResourceQuotaSpecHard type
  2755. func (target *ResourceQuotaSpecHard) UnmarshalBinaryFromReader(reader io.Reader) error {
  2756. ctx := NewDecodingContextFromReader(reader)
  2757. defer ctx.Close()
  2758. err := target.UnmarshalBinaryWithContext(ctx)
  2759. if err != nil {
  2760. return err
  2761. }
  2762. return nil
  2763. }
  2764. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2765. // the ResourceQuotaSpecHard type
  2766. func (target *ResourceQuotaSpecHard) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2767. // panics are recovered and propagated as errors
  2768. defer func() {
  2769. if r := recover(); r != nil {
  2770. if e, ok := r.(error); ok {
  2771. err = e
  2772. } else if s, ok := r.(string); ok {
  2773. err = fmt.Errorf("unexpected panic: %s", s)
  2774. } else {
  2775. err = fmt.Errorf("unexpected panic: %+v", r)
  2776. }
  2777. }
  2778. }()
  2779. buff := ctx.Buffer
  2780. version := buff.ReadUInt8()
  2781. if version > DefaultCodecVersion {
  2782. return fmt.Errorf("Invalid Version Unmarshalling ResourceQuotaSpecHard. Expected %d or less, got %d", DefaultCodecVersion, version)
  2783. }
  2784. // field version check
  2785. if uint8(1) <= version {
  2786. // --- [begin][read][alias](ResourceQuantities) ---
  2787. var a map[Resource]ResourceQuantity
  2788. if buff.ReadUInt8() == uint8(0) {
  2789. a = nil
  2790. } else {
  2791. // --- [begin][read][map](map[Resource]ResourceQuantity) ---
  2792. c := buff.ReadInt() // map len
  2793. b := make(map[Resource]ResourceQuantity, c)
  2794. for range c {
  2795. // --- [begin][read][alias](Resource) ---
  2796. var d string
  2797. var f string
  2798. if ctx.IsStringTable() {
  2799. g := buff.ReadInt() // read string index
  2800. f = ctx.Table.At(g)
  2801. } else {
  2802. f = buff.ReadString() // read string
  2803. }
  2804. e := f
  2805. d = e
  2806. v := Resource(d)
  2807. // --- [end][read][alias](Resource) ---
  2808. // --- [begin][read][struct](ResourceQuantity) ---
  2809. h := new(ResourceQuantity)
  2810. buff.ReadInt() // [compatibility, unused]
  2811. errA := h.UnmarshalBinaryWithContext(ctx)
  2812. if errA != nil {
  2813. return errA
  2814. }
  2815. z := *h
  2816. // --- [end][read][struct](ResourceQuantity) ---
  2817. b[v] = z
  2818. }
  2819. a = b
  2820. // --- [end][read][map](map[Resource]ResourceQuantity) ---
  2821. }
  2822. target.Requests = ResourceQuantities(a)
  2823. // --- [end][read][alias](ResourceQuantities) ---
  2824. } else {
  2825. }
  2826. // field version check
  2827. if uint8(1) <= version {
  2828. // --- [begin][read][alias](ResourceQuantities) ---
  2829. var l map[Resource]ResourceQuantity
  2830. if buff.ReadUInt8() == uint8(0) {
  2831. l = nil
  2832. } else {
  2833. // --- [begin][read][map](map[Resource]ResourceQuantity) ---
  2834. n := buff.ReadInt() // map len
  2835. m := make(map[Resource]ResourceQuantity, n)
  2836. for range n {
  2837. // --- [begin][read][alias](Resource) ---
  2838. var o string
  2839. var q string
  2840. if ctx.IsStringTable() {
  2841. r := buff.ReadInt() // read string index
  2842. q = ctx.Table.At(r)
  2843. } else {
  2844. q = buff.ReadString() // read string
  2845. }
  2846. p := q
  2847. o = p
  2848. vv := Resource(o)
  2849. // --- [end][read][alias](Resource) ---
  2850. // --- [begin][read][struct](ResourceQuantity) ---
  2851. s := new(ResourceQuantity)
  2852. buff.ReadInt() // [compatibility, unused]
  2853. errB := s.UnmarshalBinaryWithContext(ctx)
  2854. if errB != nil {
  2855. return errB
  2856. }
  2857. zz := *s
  2858. // --- [end][read][struct](ResourceQuantity) ---
  2859. m[vv] = zz
  2860. }
  2861. l = m
  2862. // --- [end][read][map](map[Resource]ResourceQuantity) ---
  2863. }
  2864. target.Limits = ResourceQuantities(l)
  2865. // --- [end][read][alias](ResourceQuantities) ---
  2866. } else {
  2867. }
  2868. return nil
  2869. }
  2870. //--------------------------------------------------------------------------
  2871. // ResourceQuotaStatus
  2872. //--------------------------------------------------------------------------
  2873. // MarshalBinary serializes the internal properties of this ResourceQuotaStatus instance
  2874. // into a byte array
  2875. func (target *ResourceQuotaStatus) MarshalBinary() (data []byte, err error) {
  2876. ctx := NewEncodingContext(nil)
  2877. e := target.MarshalBinaryWithContext(ctx)
  2878. if e != nil {
  2879. return nil, e
  2880. }
  2881. return ctx.ToBytes(), nil
  2882. }
  2883. // MarshalBinary serializes the internal properties of this ResourceQuotaStatus instance
  2884. // into an io.Writer.
  2885. func (target *ResourceQuotaStatus) MarshalBinaryTo(writer io.Writer) error {
  2886. buff := util.NewBufferFromWriter(writer)
  2887. defer buff.Flush()
  2888. ctx := NewEncodingContextFromBuffer(buff, nil)
  2889. return target.MarshalBinaryWithContext(ctx)
  2890. }
  2891. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaStatus instance
  2892. // into a byte array leveraging a predefined context.
  2893. func (target *ResourceQuotaStatus) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2894. // panics are recovered and propagated as errors
  2895. defer func() {
  2896. if r := recover(); r != nil {
  2897. if e, ok := r.(error); ok {
  2898. err = e
  2899. } else if s, ok := r.(string); ok {
  2900. err = fmt.Errorf("unexpected panic: %s", s)
  2901. } else {
  2902. err = fmt.Errorf("unexpected panic: %+v", r)
  2903. }
  2904. }
  2905. }()
  2906. buff := ctx.Buffer
  2907. buff.WriteUInt8(DefaultCodecVersion) // version
  2908. if target.Used == nil {
  2909. buff.WriteUInt8(uint8(0)) // write nil byte
  2910. } else {
  2911. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2912. // --- [begin][write][struct](ResourceQuotaStatusUsed) ---
  2913. buff.WriteInt(0) // [compatibility, unused]
  2914. errA := target.Used.MarshalBinaryWithContext(ctx)
  2915. if errA != nil {
  2916. return errA
  2917. }
  2918. // --- [end][write][struct](ResourceQuotaStatusUsed) ---
  2919. }
  2920. return nil
  2921. }
  2922. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2923. // the ResourceQuotaStatus type
  2924. func (target *ResourceQuotaStatus) UnmarshalBinary(data []byte) error {
  2925. ctx := NewDecodingContextFromBytes(data)
  2926. defer ctx.Close()
  2927. err := target.UnmarshalBinaryWithContext(ctx)
  2928. if err != nil {
  2929. return err
  2930. }
  2931. return nil
  2932. }
  2933. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  2934. // the ResourceQuotaStatus type
  2935. func (target *ResourceQuotaStatus) UnmarshalBinaryFromReader(reader io.Reader) error {
  2936. ctx := NewDecodingContextFromReader(reader)
  2937. defer ctx.Close()
  2938. err := target.UnmarshalBinaryWithContext(ctx)
  2939. if err != nil {
  2940. return err
  2941. }
  2942. return nil
  2943. }
  2944. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2945. // the ResourceQuotaStatus type
  2946. func (target *ResourceQuotaStatus) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2947. // panics are recovered and propagated as errors
  2948. defer func() {
  2949. if r := recover(); r != nil {
  2950. if e, ok := r.(error); ok {
  2951. err = e
  2952. } else if s, ok := r.(string); ok {
  2953. err = fmt.Errorf("unexpected panic: %s", s)
  2954. } else {
  2955. err = fmt.Errorf("unexpected panic: %+v", r)
  2956. }
  2957. }
  2958. }()
  2959. buff := ctx.Buffer
  2960. version := buff.ReadUInt8()
  2961. if version > DefaultCodecVersion {
  2962. return fmt.Errorf("Invalid Version Unmarshalling ResourceQuotaStatus. Expected %d or less, got %d", DefaultCodecVersion, version)
  2963. }
  2964. // field version check
  2965. if uint8(1) <= version {
  2966. if buff.ReadUInt8() == uint8(0) {
  2967. target.Used = nil
  2968. } else {
  2969. // --- [begin][read][struct](ResourceQuotaStatusUsed) ---
  2970. a := new(ResourceQuotaStatusUsed)
  2971. buff.ReadInt() // [compatibility, unused]
  2972. errA := a.UnmarshalBinaryWithContext(ctx)
  2973. if errA != nil {
  2974. return errA
  2975. }
  2976. target.Used = a
  2977. // --- [end][read][struct](ResourceQuotaStatusUsed) ---
  2978. }
  2979. } else {
  2980. target.Used = nil
  2981. }
  2982. return nil
  2983. }
  2984. //--------------------------------------------------------------------------
  2985. // ResourceQuotaStatusUsed
  2986. //--------------------------------------------------------------------------
  2987. // MarshalBinary serializes the internal properties of this ResourceQuotaStatusUsed instance
  2988. // into a byte array
  2989. func (target *ResourceQuotaStatusUsed) MarshalBinary() (data []byte, err error) {
  2990. ctx := NewEncodingContext(nil)
  2991. e := target.MarshalBinaryWithContext(ctx)
  2992. if e != nil {
  2993. return nil, e
  2994. }
  2995. return ctx.ToBytes(), nil
  2996. }
  2997. // MarshalBinary serializes the internal properties of this ResourceQuotaStatusUsed instance
  2998. // into an io.Writer.
  2999. func (target *ResourceQuotaStatusUsed) MarshalBinaryTo(writer io.Writer) error {
  3000. buff := util.NewBufferFromWriter(writer)
  3001. defer buff.Flush()
  3002. ctx := NewEncodingContextFromBuffer(buff, nil)
  3003. return target.MarshalBinaryWithContext(ctx)
  3004. }
  3005. // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaStatusUsed instance
  3006. // into a byte array leveraging a predefined context.
  3007. func (target *ResourceQuotaStatusUsed) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3008. // panics are recovered and propagated as errors
  3009. defer func() {
  3010. if r := recover(); r != nil {
  3011. if e, ok := r.(error); ok {
  3012. err = e
  3013. } else if s, ok := r.(string); ok {
  3014. err = fmt.Errorf("unexpected panic: %s", s)
  3015. } else {
  3016. err = fmt.Errorf("unexpected panic: %+v", r)
  3017. }
  3018. }
  3019. }()
  3020. buff := ctx.Buffer
  3021. buff.WriteUInt8(DefaultCodecVersion) // version
  3022. // --- [begin][write][alias](ResourceQuantities) ---
  3023. if map[Resource]ResourceQuantity(target.Requests) == nil {
  3024. buff.WriteUInt8(uint8(0)) // write nil byte
  3025. } else {
  3026. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3027. // --- [begin][write][map](map[Resource]ResourceQuantity) ---
  3028. buff.WriteInt(len(map[Resource]ResourceQuantity(target.Requests))) // map length
  3029. for v, z := range map[Resource]ResourceQuantity(target.Requests) {
  3030. // --- [begin][write][alias](Resource) ---
  3031. if ctx.IsStringTable() {
  3032. a := ctx.Table.AddOrGet(string(v))
  3033. buff.WriteInt(a) // write table index
  3034. } else {
  3035. buff.WriteString(string(v)) // write string
  3036. }
  3037. // --- [end][write][alias](Resource) ---
  3038. // --- [begin][write][struct](ResourceQuantity) ---
  3039. buff.WriteInt(0) // [compatibility, unused]
  3040. errA := z.MarshalBinaryWithContext(ctx)
  3041. if errA != nil {
  3042. return errA
  3043. }
  3044. // --- [end][write][struct](ResourceQuantity) ---
  3045. }
  3046. // --- [end][write][map](map[Resource]ResourceQuantity) ---
  3047. }
  3048. // --- [end][write][alias](ResourceQuantities) ---
  3049. // --- [begin][write][alias](ResourceQuantities) ---
  3050. if map[Resource]ResourceQuantity(target.Limits) == nil {
  3051. buff.WriteUInt8(uint8(0)) // write nil byte
  3052. } else {
  3053. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3054. // --- [begin][write][map](map[Resource]ResourceQuantity) ---
  3055. buff.WriteInt(len(map[Resource]ResourceQuantity(target.Limits))) // map length
  3056. for vv, zz := range map[Resource]ResourceQuantity(target.Limits) {
  3057. // --- [begin][write][alias](Resource) ---
  3058. if ctx.IsStringTable() {
  3059. b := ctx.Table.AddOrGet(string(vv))
  3060. buff.WriteInt(b) // write table index
  3061. } else {
  3062. buff.WriteString(string(vv)) // write string
  3063. }
  3064. // --- [end][write][alias](Resource) ---
  3065. // --- [begin][write][struct](ResourceQuantity) ---
  3066. buff.WriteInt(0) // [compatibility, unused]
  3067. errB := zz.MarshalBinaryWithContext(ctx)
  3068. if errB != nil {
  3069. return errB
  3070. }
  3071. // --- [end][write][struct](ResourceQuantity) ---
  3072. }
  3073. // --- [end][write][map](map[Resource]ResourceQuantity) ---
  3074. }
  3075. // --- [end][write][alias](ResourceQuantities) ---
  3076. return nil
  3077. }
  3078. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3079. // the ResourceQuotaStatusUsed type
  3080. func (target *ResourceQuotaStatusUsed) UnmarshalBinary(data []byte) error {
  3081. ctx := NewDecodingContextFromBytes(data)
  3082. defer ctx.Close()
  3083. err := target.UnmarshalBinaryWithContext(ctx)
  3084. if err != nil {
  3085. return err
  3086. }
  3087. return nil
  3088. }
  3089. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  3090. // the ResourceQuotaStatusUsed type
  3091. func (target *ResourceQuotaStatusUsed) UnmarshalBinaryFromReader(reader io.Reader) error {
  3092. ctx := NewDecodingContextFromReader(reader)
  3093. defer ctx.Close()
  3094. err := target.UnmarshalBinaryWithContext(ctx)
  3095. if err != nil {
  3096. return err
  3097. }
  3098. return nil
  3099. }
  3100. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3101. // the ResourceQuotaStatusUsed type
  3102. func (target *ResourceQuotaStatusUsed) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3103. // panics are recovered and propagated as errors
  3104. defer func() {
  3105. if r := recover(); r != nil {
  3106. if e, ok := r.(error); ok {
  3107. err = e
  3108. } else if s, ok := r.(string); ok {
  3109. err = fmt.Errorf("unexpected panic: %s", s)
  3110. } else {
  3111. err = fmt.Errorf("unexpected panic: %+v", r)
  3112. }
  3113. }
  3114. }()
  3115. buff := ctx.Buffer
  3116. version := buff.ReadUInt8()
  3117. if version > DefaultCodecVersion {
  3118. return fmt.Errorf("Invalid Version Unmarshalling ResourceQuotaStatusUsed. Expected %d or less, got %d", DefaultCodecVersion, version)
  3119. }
  3120. // field version check
  3121. if uint8(1) <= version {
  3122. // --- [begin][read][alias](ResourceQuantities) ---
  3123. var a map[Resource]ResourceQuantity
  3124. if buff.ReadUInt8() == uint8(0) {
  3125. a = nil
  3126. } else {
  3127. // --- [begin][read][map](map[Resource]ResourceQuantity) ---
  3128. c := buff.ReadInt() // map len
  3129. b := make(map[Resource]ResourceQuantity, c)
  3130. for range c {
  3131. // --- [begin][read][alias](Resource) ---
  3132. var d string
  3133. var f string
  3134. if ctx.IsStringTable() {
  3135. g := buff.ReadInt() // read string index
  3136. f = ctx.Table.At(g)
  3137. } else {
  3138. f = buff.ReadString() // read string
  3139. }
  3140. e := f
  3141. d = e
  3142. v := Resource(d)
  3143. // --- [end][read][alias](Resource) ---
  3144. // --- [begin][read][struct](ResourceQuantity) ---
  3145. h := new(ResourceQuantity)
  3146. buff.ReadInt() // [compatibility, unused]
  3147. errA := h.UnmarshalBinaryWithContext(ctx)
  3148. if errA != nil {
  3149. return errA
  3150. }
  3151. z := *h
  3152. // --- [end][read][struct](ResourceQuantity) ---
  3153. b[v] = z
  3154. }
  3155. a = b
  3156. // --- [end][read][map](map[Resource]ResourceQuantity) ---
  3157. }
  3158. target.Requests = ResourceQuantities(a)
  3159. // --- [end][read][alias](ResourceQuantities) ---
  3160. } else {
  3161. }
  3162. // field version check
  3163. if uint8(1) <= version {
  3164. // --- [begin][read][alias](ResourceQuantities) ---
  3165. var l map[Resource]ResourceQuantity
  3166. if buff.ReadUInt8() == uint8(0) {
  3167. l = nil
  3168. } else {
  3169. // --- [begin][read][map](map[Resource]ResourceQuantity) ---
  3170. n := buff.ReadInt() // map len
  3171. m := make(map[Resource]ResourceQuantity, n)
  3172. for range n {
  3173. // --- [begin][read][alias](Resource) ---
  3174. var o string
  3175. var q string
  3176. if ctx.IsStringTable() {
  3177. r := buff.ReadInt() // read string index
  3178. q = ctx.Table.At(r)
  3179. } else {
  3180. q = buff.ReadString() // read string
  3181. }
  3182. p := q
  3183. o = p
  3184. vv := Resource(o)
  3185. // --- [end][read][alias](Resource) ---
  3186. // --- [begin][read][struct](ResourceQuantity) ---
  3187. s := new(ResourceQuantity)
  3188. buff.ReadInt() // [compatibility, unused]
  3189. errB := s.UnmarshalBinaryWithContext(ctx)
  3190. if errB != nil {
  3191. return errB
  3192. }
  3193. zz := *s
  3194. // --- [end][read][struct](ResourceQuantity) ---
  3195. m[vv] = zz
  3196. }
  3197. l = m
  3198. // --- [end][read][map](map[Resource]ResourceQuantity) ---
  3199. }
  3200. target.Limits = ResourceQuantities(l)
  3201. // --- [end][read][alias](ResourceQuantities) ---
  3202. } else {
  3203. }
  3204. return nil
  3205. }
  3206. //--------------------------------------------------------------------------
  3207. // Window
  3208. //--------------------------------------------------------------------------
  3209. // MarshalBinary serializes the internal properties of this Window instance
  3210. // into a byte array
  3211. func (target *Window) MarshalBinary() (data []byte, err error) {
  3212. ctx := NewEncodingContext(nil)
  3213. e := target.MarshalBinaryWithContext(ctx)
  3214. if e != nil {
  3215. return nil, e
  3216. }
  3217. return ctx.ToBytes(), nil
  3218. }
  3219. // MarshalBinary serializes the internal properties of this Window instance
  3220. // into an io.Writer.
  3221. func (target *Window) MarshalBinaryTo(writer io.Writer) error {
  3222. buff := util.NewBufferFromWriter(writer)
  3223. defer buff.Flush()
  3224. ctx := NewEncodingContextFromBuffer(buff, nil)
  3225. return target.MarshalBinaryWithContext(ctx)
  3226. }
  3227. // MarshalBinaryWithContext serializes the internal properties of this Window instance
  3228. // into a byte array leveraging a predefined context.
  3229. func (target *Window) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3230. // panics are recovered and propagated as errors
  3231. defer func() {
  3232. if r := recover(); r != nil {
  3233. if e, ok := r.(error); ok {
  3234. err = e
  3235. } else if s, ok := r.(string); ok {
  3236. err = fmt.Errorf("unexpected panic: %s", s)
  3237. } else {
  3238. err = fmt.Errorf("unexpected panic: %+v", r)
  3239. }
  3240. }
  3241. }()
  3242. buff := ctx.Buffer
  3243. buff.WriteUInt8(DefaultCodecVersion) // version
  3244. // --- [begin][write][reference](time.Time) ---
  3245. a, errA := target.Start.MarshalBinary()
  3246. if errA != nil {
  3247. return errA
  3248. }
  3249. buff.WriteInt(len(a))
  3250. buff.WriteBytes(a)
  3251. // --- [end][write][reference](time.Time) ---
  3252. // --- [begin][write][reference](time.Time) ---
  3253. b, errB := target.End.MarshalBinary()
  3254. if errB != nil {
  3255. return errB
  3256. }
  3257. buff.WriteInt(len(b))
  3258. buff.WriteBytes(b)
  3259. // --- [end][write][reference](time.Time) ---
  3260. return nil
  3261. }
  3262. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3263. // the Window type
  3264. func (target *Window) UnmarshalBinary(data []byte) error {
  3265. ctx := NewDecodingContextFromBytes(data)
  3266. defer ctx.Close()
  3267. err := target.UnmarshalBinaryWithContext(ctx)
  3268. if err != nil {
  3269. return err
  3270. }
  3271. return nil
  3272. }
  3273. // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
  3274. // the Window type
  3275. func (target *Window) UnmarshalBinaryFromReader(reader io.Reader) error {
  3276. ctx := NewDecodingContextFromReader(reader)
  3277. defer ctx.Close()
  3278. err := target.UnmarshalBinaryWithContext(ctx)
  3279. if err != nil {
  3280. return err
  3281. }
  3282. return nil
  3283. }
  3284. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3285. // the Window type
  3286. func (target *Window) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3287. // panics are recovered and propagated as errors
  3288. defer func() {
  3289. if r := recover(); r != nil {
  3290. if e, ok := r.(error); ok {
  3291. err = e
  3292. } else if s, ok := r.(string); ok {
  3293. err = fmt.Errorf("unexpected panic: %s", s)
  3294. } else {
  3295. err = fmt.Errorf("unexpected panic: %+v", r)
  3296. }
  3297. }
  3298. }()
  3299. buff := ctx.Buffer
  3300. version := buff.ReadUInt8()
  3301. if version > DefaultCodecVersion {
  3302. return fmt.Errorf("Invalid Version Unmarshalling Window. Expected %d or less, got %d", DefaultCodecVersion, version)
  3303. }
  3304. // field version check
  3305. if uint8(1) <= version {
  3306. // --- [begin][read][reference](time.Time) ---
  3307. a := new(time.Time)
  3308. b := buff.ReadInt() // byte array length
  3309. c := buff.ReadBytes(b)
  3310. errA := a.UnmarshalBinary(c)
  3311. if errA != nil {
  3312. return errA
  3313. }
  3314. target.Start = *a
  3315. // --- [end][read][reference](time.Time) ---
  3316. } else {
  3317. }
  3318. // field version check
  3319. if uint8(1) <= version {
  3320. // --- [begin][read][reference](time.Time) ---
  3321. d := new(time.Time)
  3322. e := buff.ReadInt() // byte array length
  3323. f := buff.ReadBytes(e)
  3324. errB := d.UnmarshalBinary(f)
  3325. if errB != nil {
  3326. return errB
  3327. }
  3328. target.End = *d
  3329. // --- [end][read][reference](time.Time) ---
  3330. } else {
  3331. }
  3332. return nil
  3333. }