| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014 |
- ////////////////////////////////////////////////////////////////////////////////
- //
- // DO NOT MODIFY
- //
- // ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻
- //
- //
- // This source file was automatically generated by bingen.
- //
- ////////////////////////////////////////////////////////////////////////////////
- package kubemodel
- import (
- "cmp"
- "fmt"
- "io"
- "iter"
- "os"
- "reflect"
- "slices"
- "strings"
- "sync"
- "time"
- "unsafe"
- util "github.com/opencost/opencost/core/pkg/util"
- )
- const (
- // GeneratorPackageName is the package the generator is targetting
- GeneratorPackageName string = "kubemodel"
- StringHeaderSize = int64(unsafe.Sizeof(""))
- // BinaryTagStringTable is written and/or read prior to the existence of a string
- // table (where each index is encoded as a string entry in the resource
- BinaryTagStringTable string = "BGST"
- // DefaultCodecVersion is used for any resources listed in the Default version set
- DefaultCodecVersion uint8 = 1
- )
- //--------------------------------------------------------------------------
- // Configuration
- //--------------------------------------------------------------------------
- var (
- bingenConfigLock sync.RWMutex
- bingenConfig *BingenConfiguration = DefaultBingenConfiguration()
- )
- // BingenConfiguration is used to set any custom configuration in the way files are encoded
- // or decoded.
- type BingenConfiguration struct {
- // FileBackedStringTableEnabled enables the use of file-backed string tables for streaming
- // bingen decoding.
- FileBackedStringTableEnabled bool
- // FileBackedStringTableDir is the directory to write the string table files for reading.
- FileBackedStringTableDir string
- // FileBackedStringTableMemoMaxBytes limits in-memory memoization for file-backed table lookups.
- // 0 disables memoization.
- FileBackedStringTableMemoMaxBytes int64
- }
- // DefaultBingenConfiguration creates the default implementation of the bingen configuration
- // and returns it.
- func DefaultBingenConfiguration() *BingenConfiguration {
- return &BingenConfiguration{
- FileBackedStringTableEnabled: false,
- FileBackedStringTableDir: os.TempDir(),
- FileBackedStringTableMemoMaxBytes: 0,
- }
- }
- // ConfigureBingen accepts a new *BingenConfiguration instance which updates the internal decoder
- // and encoder behavior.
- func ConfigureBingen(config *BingenConfiguration) {
- bingenConfigLock.Lock()
- defer bingenConfigLock.Unlock()
- if config == nil {
- config = DefaultBingenConfiguration()
- }
- bingenConfig = config
- }
- // IsBingenFileBackedStringTableEnabled accessor for file backed string table configuration
- func IsBingenFileBackedStringTableEnabled() bool {
- bingenConfigLock.RLock()
- defer bingenConfigLock.RUnlock()
- return bingenConfig.FileBackedStringTableEnabled
- }
- // BingenFileBackedStringTableDir returns the directory configured for file backed string tables.
- func BingenFileBackedStringTableDir() string {
- bingenConfigLock.RLock()
- defer bingenConfigLock.RUnlock()
- return bingenConfig.FileBackedStringTableDir
- }
- // BingenFileBackedStringTableMemoMaxBytes returns the maximum bytes used for file-backed memo cache.
- func BingenFileBackedStringTableMemoMaxBytes() int64 {
- bingenConfigLock.RLock()
- defer bingenConfigLock.RUnlock()
- return bingenConfig.FileBackedStringTableMemoMaxBytes
- }
- //--------------------------------------------------------------------------
- // Type Map
- //--------------------------------------------------------------------------
- // Generated type map for resolving interface implementations to to concrete types
- var typeMap map[string]reflect.Type = map[string]reflect.Type{
- "Cluster": reflect.TypeFor[Cluster](),
- "Diagnostic": reflect.TypeFor[Diagnostic](),
- "KubeModelSet": reflect.TypeFor[KubeModelSet](),
- "Metadata": reflect.TypeFor[Metadata](),
- "Namespace": reflect.TypeFor[Namespace](),
- "ResourceQuantity": reflect.TypeFor[ResourceQuantity](),
- "ResourceQuota": reflect.TypeFor[ResourceQuota](),
- "ResourceQuotaSpec": reflect.TypeFor[ResourceQuotaSpec](),
- "ResourceQuotaSpecHard": reflect.TypeFor[ResourceQuotaSpecHard](),
- "ResourceQuotaStatus": reflect.TypeFor[ResourceQuotaStatus](),
- "ResourceQuotaStatusUsed": reflect.TypeFor[ResourceQuotaStatusUsed](),
- "Window": reflect.TypeFor[Window](),
- }
- //--------------------------------------------------------------------------
- // Type Helpers
- //--------------------------------------------------------------------------
- // isBinaryTag returns true when the first bytes in the provided binary matches the tag
- func isBinaryTag(data []byte, tag string) bool {
- if len(data) < len(tag) {
- return false
- }
- return string(data[:len(tag)]) == tag
- }
- // isReaderBinaryTag is used to peek the header for an io.Reader Buffer
- func isReaderBinaryTag(buff *util.Buffer, tag string) bool {
- data, err := buff.Peek(len(tag))
- if err != nil && err != io.EOF {
- panic(fmt.Sprintf("called Peek() on a non buffered reader: %s", err))
- }
- if len(data) < len(tag) {
- return false
- }
- return string(data[:len(tag)]) == tag
- }
- // typeToString determines the basic properties of the type, the qualifier, package path, and
- // type name, and returns the qualified type
- func typeToString(f interface{}) string {
- qual := ""
- t := reflect.TypeOf(f)
- if t.Kind() == reflect.Ptr {
- t = t.Elem()
- qual = "*"
- }
- return fmt.Sprintf("%s%s.%s", qual, t.PkgPath(), t.Name())
- }
- // resolveType uses the name of a type and returns the package, base type name, and whether
- // or not it's a pointer.
- func resolveType(t string) (pkg string, name string, isPtr bool) {
- isPtr = t[:1] == "*"
- if isPtr {
- t = t[1:]
- }
- slashIndex := strings.LastIndex(t, "/")
- if slashIndex >= 0 {
- t = t[slashIndex+1:]
- }
- parts := strings.Split(t, ".")
- if parts[0] == GeneratorPackageName {
- parts[0] = ""
- }
- pkg = parts[0]
- name = parts[1]
- return
- }
- //--------------------------------------------------------------------------
- // Stream Helpers
- //--------------------------------------------------------------------------
- // StreamFactoryFunc is an alias for a func that creates a BingenStream implementation.
- type StreamFactoryFunc func(io.Reader) BingenStream
- // Generated streamable factory map for finding the specific new stream methods
- // by T type
- var streamFactoryMap map[reflect.Type]StreamFactoryFunc = map[reflect.Type]StreamFactoryFunc{
- reflect.TypeFor[KubeModelSet](): NewKubeModelSetStream,
- }
- // NewStreamFor accepts an io.Reader, and returns a new BingenStream for the generic T
- // type provided _if_ it is a registered bingen type that is annotated as 'streamable'. See
- // the streamFactoryMap for generated type listings.
- func NewStreamFor[T any](reader io.Reader) (BingenStream, error) {
- typeKey := reflect.TypeFor[T]()
- factory, ok := streamFactoryMap[typeKey]
- if !ok {
- return nil, fmt.Errorf("the type: %s is not a registered bingen streamable type", typeKey.Name())
- }
- return factory(reader), nil
- }
- // BingenStream is the stream interface for all streamable types
- type BingenStream interface {
- // Stream returns the iterator which will stream each field of the target type and
- // return the field info as well as the value.
- Stream() iter.Seq2[BingenFieldInfo, *BingenValue]
- // Close will close any dynamic io.Reader used to stream in the fields
- Close()
- // Error returns an error if one occurred during the process of streaming the type's fields.
- // This can be checked after iterating through the Stream().
- Error() error
- }
- // BingenValue contains the value of a field as well as any index/key associated with that value.
- type BingenValue struct {
- Value any
- Index any
- }
- // IsNil is just a method accessor way to check to see if the value returned was nil
- func (bv *BingenValue) IsNil() bool {
- return bv == nil
- }
- // creates a single BingenValue instance without a key or index
- func singleV(value any) *BingenValue {
- return &BingenValue{
- Value: value,
- }
- }
- // creates a pair of key/index and value.
- func pairV(index any, value any) *BingenValue {
- return &BingenValue{
- Value: value,
- Index: index,
- }
- }
- // BingenFieldInfo contains the type of the field being streamed as well as the name of the field.
- type BingenFieldInfo struct {
- Type reflect.Type
- Name string
- }
- //--------------------------------------------------------------------------
- // String Table Writer
- //--------------------------------------------------------------------------
- // StringTableWriter is the interface used to write the string table for encoding.
- type StringTableWriter interface {
- // AddOrGet adds a string to the string table and returns the new index or
- // an existing index.
- AddOrGet(s string) int
- // WriteTo will write the StringTable data (with the header) to the provided
- // Buffer starting a the current write position
- WriteTo(b *util.Buffer)
- }
- // IndexedStringTableWriter maps strings to specific indices for encoding
- type IndexedStringTableWriter struct {
- indices map[string]int
- next int
- }
- // NewIndexedStringTableWriter Creates a new IndexedStringTableWriter instance.
- func NewIndexedStringTableWriter() *IndexedStringTableWriter {
- return &IndexedStringTableWriter{
- indices: make(map[string]int),
- next: 0,
- }
- }
- // AddOrGet retrieves a string entry's index if it exists. Otherwise, it adds the entry and returns the new index.
- func (st *IndexedStringTableWriter) AddOrGet(s string) int {
- if ind, ok := st.indices[s]; ok {
- return ind
- }
- current := st.next
- st.next++
- st.indices[s] = current
- return current
- }
- // ToSlice Converts the contents to a string array for encoding.
- func (st *IndexedStringTableWriter) ToSlice() []string {
- if st.next == 0 {
- return []string{}
- }
- sl := make([]string, st.next)
- for s, i := range st.indices {
- sl[i] = s
- }
- return sl
- }
- // ToBytes Converts the contents to a binary encoded representation
- func (st *IndexedStringTableWriter) ToBytes() []byte {
- buff := util.NewBuffer()
- st.WriteTo(buff)
- return buff.Bytes()
- }
- // WriteTo will write the StringTable data (with the header) to the provided
- // Buffer starting a the current write position
- func (st *IndexedStringTableWriter) WriteTo(buff *util.Buffer) {
- // bingen string table header
- buff.WriteBytes([]byte(BinaryTagStringTable))
- // get an ordered string slice to encode
- strs := st.ToSlice()
- buff.WriteInt(len(strs)) // table length
- for _, s := range strs {
- buff.WriteString(s)
- }
- }
- type indexed struct {
- s string
- count uint64
- index int
- }
- func newIndexed(s string, index int) *indexed {
- return &indexed{
- s: s,
- count: 1,
- index: index,
- }
- }
- // PrepassStringTableWriter maps strings to specific indices for encoding, sorted by the total
- // number of times they're accessed
- type PrepassStringTableWriter struct {
- prepass map[string]*indexed
- next int
- }
- // NewPrepassStringTableWriter creates a new PrepassStringTableWriter instance.
- func NewPrepassStringTableWriter() *PrepassStringTableWriter {
- return &PrepassStringTableWriter{
- prepass: make(map[string]*indexed),
- }
- }
- // AddOrGet retrieves a string entry's index if it exists. Otherwise, it adds the entry and returns the new index.
- func (st *PrepassStringTableWriter) AddOrGet(s string) int {
- if ind, ok := st.prepass[s]; ok {
- ind.count += 1
- return ind.index
- }
- current := st.next
- st.next++
- st.prepass[s] = newIndexed(s, current)
- return current
- }
- // WriteSortedTo sorts the string table by the number of accesses, writes the table in that
- // order, then returns a new StringTableWriter implementation that can be used for the new
- // sorted order index lookups.
- func (st *PrepassStringTableWriter) WriteSortedTo(buff *util.Buffer) StringTableWriter {
- sl := make([]*indexed, st.next)
- for _, ind := range st.prepass {
- sl[ind.index] = ind
- }
- slices.SortFunc(sl, func(a *indexed, b *indexed) int {
- return -cmp.Compare(a.count, b.count)
- })
- sti := NewIndexedStringTableWriter()
- for _, ind := range sl {
- sti.AddOrGet(ind.s)
- }
- sti.WriteTo(buff)
- return sti
- }
- // WriteTo will write the StringTable data (with the header) to the provided
- // Buffer starting a the current write position
- func (st *PrepassStringTableWriter) WriteTo(buff *util.Buffer) {
- panic("Prepass StringTableWriter cannot write directly")
- }
- //--------------------------------------------------------------------------
- // String Table Reader
- //--------------------------------------------------------------------------
- // StringTableReader is the interface used to read the string table from the decoding.
- type StringTableReader interface {
- // At returns the string entry at a specific index, or panics on out of bounds.
- At(index int) string
- // Len returns the total number of strings loaded in the string table.
- Len() int
- // Close will clear the loaded table, and drop any external resources used.
- Close() error
- }
- // SliceStringTableReader is a basic pre-loaded []string that provides index-based access.
- // The cost of this implementation is holding all strings in memory, which provides faster
- // lookup performance at the expense of memory usage.
- type SliceStringTableReader struct {
- table []string
- }
- // NewSliceStringTableReaderFrom creates a new SliceStringTableReader instance loading
- // data directly from the buffer. The buffer's position should start at the table length.
- func NewSliceStringTableReaderFrom(buffer *util.Buffer) StringTableReader {
- // table length
- tl := buffer.ReadInt()
- var table []string
- if tl > 0 {
- table = make([]string, tl)
- for i := range tl {
- table[i] = buffer.ReadString()
- }
- }
- return &SliceStringTableReader{
- table: table,
- }
- }
- // At returns the string entry at a specific index, or panics on out of bounds.
- func (sstr *SliceStringTableReader) At(index int) string {
- if index < 0 || index >= len(sstr.table) {
- panic(fmt.Errorf("%s: string table index out of bounds: %d", GeneratorPackageName, index))
- }
- return sstr.table[index]
- }
- // Len returns the total number of strings loaded in the string table.
- func (sstr *SliceStringTableReader) Len() int {
- if sstr == nil {
- return 0
- }
- return len(sstr.table)
- }
- // Close for the slice tables just nils out the slice and returns
- func (sstr *SliceStringTableReader) Close() error {
- sstr.table = nil
- return nil
- }
- // fileStringRef maps a bingen string-table index to a payload stored in a temp file.
- type fileStringRef struct {
- off int64
- length int
- }
- // FileStringTableReader leverages a local file to write string table data for lookup. On
- // memory focused systems, this allows a slower parse with a significant decrease in memory
- // usage. This implementation is often pair with streaming readers for high throughput with
- // reduced memory usage.
- type FileStringTableReader struct {
- f *os.File
- refs []fileStringRef
- memo []string
- }
- // NewFileStringTableFromBuffer reads exactly tl length-prefixed (uint16) string payloads from buffer
- // and appends each payload to a new temp file. It does not retain full strings in memory.
- func NewFileStringTableReaderFrom(buffer *util.Buffer, dir string, memoMaxBytes int64) StringTableReader {
- // helper func to cast a string in-place to a byte slice.
- // NOTE: Return value is READ-ONLY. DO NOT MODIFY!
- byteSliceFor := func(s string) []byte {
- return unsafe.Slice(unsafe.StringData(s), len(s))
- }
- err := os.MkdirAll(dir, 0755)
- if err != nil {
- panic(fmt.Errorf("%s: failed to create string table directory: %w", GeneratorPackageName, err))
- }
- f, err := os.CreateTemp(dir, fmt.Sprintf("%s-bgst-*", GeneratorPackageName))
- if err != nil {
- panic(fmt.Errorf("%s: failed to create string table file: %w", GeneratorPackageName, err))
- }
- var writeErr error
- defer func() {
- if writeErr != nil {
- _ = f.Close()
- }
- }()
- // table length
- tl := buffer.ReadInt()
- var refs []fileStringRef
- if tl > 0 {
- refs = make([]fileStringRef, tl)
- for i := range tl {
- payload := byteSliceFor(buffer.ReadString())
- var off int64
- if len(payload) > 0 {
- off, err = f.Seek(0, io.SeekEnd)
- if err != nil {
- writeErr = fmt.Errorf("%s: failed to seek string table file: %w", GeneratorPackageName, err)
- panic(writeErr)
- }
- if _, err := f.Write(payload); err != nil {
- writeErr = fmt.Errorf("%s: failed to write string table entry %d: %w", GeneratorPackageName, i, err)
- panic(writeErr)
- }
- }
- refs[i] = fileStringRef{
- off: off,
- length: len(payload),
- }
- }
- }
- var memo []string
- // Pre-load cache with strings up to memoMaxBytes, respecting string boundaries
- if memoMaxBytes > 0 && len(refs) > 0 {
- memo = make([]string, len(refs))
- var cumulativeSize int64
- for i, ref := range refs {
- // Check if adding this string would exceed the limit
- if cumulativeSize+int64(ref.length)+StringHeaderSize > memoMaxBytes {
- // Would exceed limit, stop here
- break
- }
- // Read string from file and cache it
- if ref.length > 0 {
- b := make([]byte, ref.length)
- _, err := f.ReadAt(b, ref.off)
- if err != nil {
- // If we can't read, skip this entry but continue
- continue
- }
- // Cast the allocated bytes to a string in-place
- str := unsafe.String(unsafe.SliceData(b), len(b))
- memo[i] = str
- cumulativeSize += int64(ref.length) + StringHeaderSize
- }
- }
- }
- return &FileStringTableReader{
- f: f,
- refs: refs,
- memo: memo,
- }
- }
- // At returns the string from the internal file using the reference's offset and length.
- func (fstr *FileStringTableReader) At(index int) string {
- if fstr == nil || fstr.f == nil {
- panic(fmt.Errorf("%s: failed to read file string table data", GeneratorPackageName))
- }
- if index < 0 || index >= len(fstr.refs) {
- panic(fmt.Errorf("%s: string table index out of bounds: %d", GeneratorPackageName, index))
- }
- ref := fstr.refs[index]
- if ref.length == 0 {
- return ""
- }
- // Check cache first
- if fstr.memo != nil && len(fstr.memo) > index && fstr.memo[index] != "" {
- return fstr.memo[index]
- }
- // Cache miss - read from file
- b := make([]byte, ref.length)
- _, err := fstr.f.ReadAt(b, ref.off)
- if err != nil {
- return ""
- }
- // Cast the allocated bytes to a string in-place, as we were the ones that allocated the bytes
- return unsafe.String(unsafe.SliceData(b), len(b))
- }
- // Len returns the total number of strings loaded in the string table.
- func (fstr *FileStringTableReader) Len() int {
- if fstr == nil {
- return 0
- }
- return len(fstr.refs)
- }
- // Close for the file string table reader closes the file and deletes it.
- func (fstr *FileStringTableReader) Close() error {
- if fstr == nil || fstr.f == nil {
- return nil
- }
- path := fstr.f.Name()
- err := fstr.f.Close()
- fstr.f = nil
- fstr.refs = nil
- fstr.memo = nil
- if path != "" {
- _ = os.Remove(path)
- }
- return err
- }
- //--------------------------------------------------------------------------
- // Codec Context
- //--------------------------------------------------------------------------
- // EncodingContext is a context object passed to the encoders to ensure reuse of buffer
- // and table data
- type EncodingContext struct {
- Buffer *util.Buffer
- Table StringTableWriter
- }
- // NewEncodingContext creates a new EncodingContext instance that will create a new []byte buffer
- // for writing, and return the context
- func NewEncodingContext(tableWriter StringTableWriter) *EncodingContext {
- return &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: tableWriter,
- }
- }
- // NewEncodingContextFromWriter creates a new EncodingContext instance that will create a new Buffer
- // from the provided io.Writer and StringTableWriter.
- func NewEncodingContextFromWriter(writer io.Writer, tableWriter StringTableWriter) *EncodingContext {
- return &EncodingContext{
- Buffer: util.NewBufferFromWriter(writer),
- Table: tableWriter,
- }
- }
- // NewEncodingContextFromBuffer creates a new EncodingContext instance that will leverage an existing
- // Buffer and StringTableWriter.
- func NewEncodingContextFromBuffer(buffer *util.Buffer, tableWriter StringTableWriter) *EncodingContext {
- return &EncodingContext{
- Buffer: buffer,
- Table: tableWriter,
- }
- }
- // ToBytes returns the encoded string table bytes (if applicable) combined with the encoded buffer bytes. If
- // a string table is being used, the string table bytes will be written first to ensure correct ordering for
- // decoding.
- func (ec *EncodingContext) ToBytes() []byte {
- encBytes := ec.Buffer.Bytes()
- if ec.Table != nil {
- buff := util.NewBuffer()
- ec.Table.WriteTo(buff)
- buff.WriteBytes(encBytes)
- return buff.Bytes()
- }
- return encBytes
- }
- // IsStringTable returns true if the table is available
- func (ec *EncodingContext) IsStringTable() bool {
- return ec.Table != nil
- }
- // DecodingContext is a context object passed to the decoders to ensure parent objects
- // reuse as much data as possible
- type DecodingContext struct {
- Buffer *util.Buffer
- Table StringTableReader
- }
- // NewDecodingContextFromBytes creates a new DecodingContext instance using an byte slice
- func NewDecodingContextFromBytes(data []byte) *DecodingContext {
- var table StringTableReader
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- // always use a slice string table with a byte array since the
- // data is already in memory
- table = NewSliceStringTableReaderFrom(buff)
- }
- return &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- }
- // NewDecodingContextFromReader creates a new DecodingContext instance using an io.Reader
- // implementation
- func NewDecodingContextFromReader(reader io.Reader) *DecodingContext {
- var table StringTableReader
- buff := util.NewBufferFromReader(reader)
- if isReaderBinaryTag(buff, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- // create correct string table implementation
- if IsBingenFileBackedStringTableEnabled() {
- table = NewFileStringTableReaderFrom(buff, BingenFileBackedStringTableDir(), BingenFileBackedStringTableMemoMaxBytes())
- } else {
- table = NewSliceStringTableReaderFrom(buff)
- }
- }
- return &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- }
- // IsStringTable returns true if the table is available
- func (dc *DecodingContext) IsStringTable() bool {
- return dc.Table != nil && dc.Table.Len() > 0
- }
- // Close will ensure that any string table resources and buffer resources are
- // cleaned up.
- func (dc *DecodingContext) Close() {
- if dc.Table != nil {
- _ = dc.Table.Close()
- dc.Table = nil
- }
- }
- //--------------------------------------------------------------------------
- // Binary Codec
- //--------------------------------------------------------------------------
- // BinEncoder is an encoding interface which defines a context based marshal contract.
- type BinEncoder interface {
- MarshalBinaryWithContext(*EncodingContext) error
- }
- // BinDecoder is a decoding interface which defines a context based unmarshal contract.
- type BinDecoder interface {
- UnmarshalBinaryWithContext(*DecodingContext) error
- }
- //--------------------------------------------------------------------------
- // Cluster
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this Cluster instance
- // into a byte array
- func (target *Cluster) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this Cluster instance
- // into an io.Writer.
- func (target *Cluster) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this Cluster instance
- // into a byte array leveraging a predefined context.
- func (target *Cluster) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- if ctx.IsStringTable() {
- a := ctx.Table.AddOrGet(target.UID)
- buff.WriteInt(a) // write table index
- } else {
- buff.WriteString(target.UID) // write string
- }
- // --- [begin][write][alias](Provider) ---
- if ctx.IsStringTable() {
- b := ctx.Table.AddOrGet(string(target.Provider))
- buff.WriteInt(b) // write table index
- } else {
- buff.WriteString(string(target.Provider)) // write string
- }
- // --- [end][write][alias](Provider) ---
- if ctx.IsStringTable() {
- c := ctx.Table.AddOrGet(target.Account)
- buff.WriteInt(c) // write table index
- } else {
- buff.WriteString(target.Account) // write string
- }
- if ctx.IsStringTable() {
- d := ctx.Table.AddOrGet(target.Name)
- buff.WriteInt(d) // write table index
- } else {
- buff.WriteString(target.Name) // write string
- }
- // --- [begin][write][reference](time.Time) ---
- e, errA := target.Start.MarshalBinary()
- if errA != nil {
- return errA
- }
- buff.WriteInt(len(e))
- buff.WriteBytes(e)
- // --- [end][write][reference](time.Time) ---
- // --- [begin][write][reference](time.Time) ---
- f, errB := target.End.MarshalBinary()
- if errB != nil {
- return errB
- }
- buff.WriteInt(len(f))
- buff.WriteBytes(f)
- // --- [end][write][reference](time.Time) ---
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the Cluster type
- func (target *Cluster) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the Cluster type
- func (target *Cluster) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the Cluster type
- func (target *Cluster) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling Cluster. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- var b string
- if ctx.IsStringTable() {
- c := buff.ReadInt() // read string index
- b = ctx.Table.At(c)
- } else {
- b = buff.ReadString() // read string
- }
- a := b
- target.UID = a
- } else {
- target.UID = "" // default
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](Provider) ---
- var d string
- var f string
- if ctx.IsStringTable() {
- g := buff.ReadInt() // read string index
- f = ctx.Table.At(g)
- } else {
- f = buff.ReadString() // read string
- }
- e := f
- d = e
- target.Provider = Provider(d)
- // --- [end][read][alias](Provider) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- var l string
- if ctx.IsStringTable() {
- m := buff.ReadInt() // read string index
- l = ctx.Table.At(m)
- } else {
- l = buff.ReadString() // read string
- }
- h := l
- target.Account = h
- } else {
- target.Account = "" // default
- }
- // field version check
- if uint8(1) <= version {
- var o string
- if ctx.IsStringTable() {
- p := buff.ReadInt() // read string index
- o = ctx.Table.At(p)
- } else {
- o = buff.ReadString() // read string
- }
- n := o
- target.Name = n
- } else {
- target.Name = "" // default
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- q := new(time.Time)
- r := buff.ReadInt() // byte array length
- s := buff.ReadBytes(r)
- errA := q.UnmarshalBinary(s)
- if errA != nil {
- return errA
- }
- target.Start = *q
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- t := new(time.Time)
- u := buff.ReadInt() // byte array length
- w := buff.ReadBytes(u)
- errB := t.UnmarshalBinary(w)
- if errB != nil {
- return errB
- }
- target.End = *t
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // Diagnostic
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this Diagnostic instance
- // into a byte array
- func (target *Diagnostic) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this Diagnostic instance
- // into an io.Writer.
- func (target *Diagnostic) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this Diagnostic instance
- // into a byte array leveraging a predefined context.
- func (target *Diagnostic) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- // --- [begin][write][reference](time.Time) ---
- a, errA := target.Timestamp.MarshalBinary()
- if errA != nil {
- return errA
- }
- buff.WriteInt(len(a))
- buff.WriteBytes(a)
- // --- [end][write][reference](time.Time) ---
- // --- [begin][write][alias](DiagnosticLevel) ---
- buff.WriteInt(int(target.Level)) // write int
- // --- [end][write][alias](DiagnosticLevel) ---
- if ctx.IsStringTable() {
- b := ctx.Table.AddOrGet(target.Message)
- buff.WriteInt(b) // write table index
- } else {
- buff.WriteString(target.Message) // write string
- }
- if target.Details == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][map](map[string]string) ---
- buff.WriteInt(len(target.Details)) // map length
- for v, z := range target.Details {
- if ctx.IsStringTable() {
- c := ctx.Table.AddOrGet(v)
- buff.WriteInt(c) // write table index
- } else {
- buff.WriteString(v) // write string
- }
- if ctx.IsStringTable() {
- d := ctx.Table.AddOrGet(z)
- buff.WriteInt(d) // write table index
- } else {
- buff.WriteString(z) // write string
- }
- }
- // --- [end][write][map](map[string]string) ---
- }
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the Diagnostic type
- func (target *Diagnostic) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the Diagnostic type
- func (target *Diagnostic) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the Diagnostic type
- func (target *Diagnostic) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling Diagnostic. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- a := new(time.Time)
- b := buff.ReadInt() // byte array length
- c := buff.ReadBytes(b)
- errA := a.UnmarshalBinary(c)
- if errA != nil {
- return errA
- }
- target.Timestamp = *a
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](DiagnosticLevel) ---
- var d int
- e := buff.ReadInt() // read int
- d = e
- target.Level = DiagnosticLevel(d)
- // --- [end][read][alias](DiagnosticLevel) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- var g string
- if ctx.IsStringTable() {
- h := buff.ReadInt() // read string index
- g = ctx.Table.At(h)
- } else {
- g = buff.ReadString() // read string
- }
- f := g
- target.Message = f
- } else {
- target.Message = "" // default
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Details = nil
- } else {
- // --- [begin][read][map](map[string]string) ---
- m := buff.ReadInt() // map len
- l := make(map[string]string, m)
- for range m {
- var v string
- var o string
- if ctx.IsStringTable() {
- p := buff.ReadInt() // read string index
- o = ctx.Table.At(p)
- } else {
- o = buff.ReadString() // read string
- }
- n := o
- v = n
- var z string
- var r string
- if ctx.IsStringTable() {
- s := buff.ReadInt() // read string index
- r = ctx.Table.At(s)
- } else {
- r = buff.ReadString() // read string
- }
- q := r
- z = q
- l[v] = z
- }
- target.Details = l
- // --- [end][read][map](map[string]string) ---
- }
- } else {
- target.Details = nil
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // KubeModelSet
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this KubeModelSet instance
- // into a byte array
- func (target *KubeModelSet) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(NewIndexedStringTableWriter())
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this KubeModelSet instance
- // into an io.Writer.
- func (target *KubeModelSet) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- // run a pre-pass to collect all strings into the string table and discard all writes to the main
- // buffer. Then, we write the string table, sorted by number of repeated uses (descending), to the
- // main buffer, and use the resulting table as part of the context for the main pass.
- prepass := NewPrepassStringTableWriter()
- prepassCtx := NewEncodingContextFromWriter(io.Discard, prepass)
- e := target.MarshalBinaryWithContext(prepassCtx)
- if e != nil {
- return e
- }
- tableWriter := prepass.WriteSortedTo(buff)
- ctx := NewEncodingContextFromBuffer(buff, tableWriter)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this KubeModelSet instance
- // into a byte array leveraging a predefined context.
- func (target *KubeModelSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- if target.Metadata == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][struct](Metadata) ---
- buff.WriteInt(0) // [compatibility, unused]
- errA := target.Metadata.MarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- // --- [end][write][struct](Metadata) ---
- }
- // --- [begin][write][struct](Window) ---
- buff.WriteInt(0) // [compatibility, unused]
- errB := target.Window.MarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- // --- [end][write][struct](Window) ---
- if target.Cluster == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][struct](Cluster) ---
- buff.WriteInt(0) // [compatibility, unused]
- errC := target.Cluster.MarshalBinaryWithContext(ctx)
- if errC != nil {
- return errC
- }
- // --- [end][write][struct](Cluster) ---
- }
- if target.Namespaces == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][map](map[string]*Namespace) ---
- buff.WriteInt(len(target.Namespaces)) // map length
- for v, z := range target.Namespaces {
- if ctx.IsStringTable() {
- a := ctx.Table.AddOrGet(v)
- buff.WriteInt(a) // write table index
- } else {
- buff.WriteString(v) // write string
- }
- if z == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][struct](Namespace) ---
- buff.WriteInt(0) // [compatibility, unused]
- errD := z.MarshalBinaryWithContext(ctx)
- if errD != nil {
- return errD
- }
- // --- [end][write][struct](Namespace) ---
- }
- }
- // --- [end][write][map](map[string]*Namespace) ---
- }
- if target.ResourceQuotas == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][map](map[string]*ResourceQuota) ---
- buff.WriteInt(len(target.ResourceQuotas)) // map length
- for vv, zz := range target.ResourceQuotas {
- if ctx.IsStringTable() {
- b := ctx.Table.AddOrGet(vv)
- buff.WriteInt(b) // write table index
- } else {
- buff.WriteString(vv) // write string
- }
- if zz == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][struct](ResourceQuota) ---
- buff.WriteInt(0) // [compatibility, unused]
- errE := zz.MarshalBinaryWithContext(ctx)
- if errE != nil {
- return errE
- }
- // --- [end][write][struct](ResourceQuota) ---
- }
- }
- // --- [end][write][map](map[string]*ResourceQuota) ---
- }
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the KubeModelSet type
- func (target *KubeModelSet) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the KubeModelSet type
- func (target *KubeModelSet) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the KubeModelSet type
- func (target *KubeModelSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling KubeModelSet. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Metadata = nil
- } else {
- // --- [begin][read][struct](Metadata) ---
- a := new(Metadata)
- buff.ReadInt() // [compatibility, unused]
- errA := a.UnmarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- target.Metadata = a
- // --- [end][read][struct](Metadata) ---
- }
- } else {
- target.Metadata = nil
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][struct](Window) ---
- b := new(Window)
- buff.ReadInt() // [compatibility, unused]
- errB := b.UnmarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- target.Window = *b
- // --- [end][read][struct](Window) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Cluster = nil
- } else {
- // --- [begin][read][struct](Cluster) ---
- c := new(Cluster)
- buff.ReadInt() // [compatibility, unused]
- errC := c.UnmarshalBinaryWithContext(ctx)
- if errC != nil {
- return errC
- }
- target.Cluster = c
- // --- [end][read][struct](Cluster) ---
- }
- } else {
- target.Cluster = nil
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Namespaces = nil
- } else {
- // --- [begin][read][map](map[string]*Namespace) ---
- e := buff.ReadInt() // map len
- d := make(map[string]*Namespace, e)
- for range e {
- var v string
- var g string
- if ctx.IsStringTable() {
- h := buff.ReadInt() // read string index
- g = ctx.Table.At(h)
- } else {
- g = buff.ReadString() // read string
- }
- f := g
- v = f
- var z *Namespace
- if buff.ReadUInt8() == uint8(0) {
- z = nil
- } else {
- // --- [begin][read][struct](Namespace) ---
- l := new(Namespace)
- buff.ReadInt() // [compatibility, unused]
- errD := l.UnmarshalBinaryWithContext(ctx)
- if errD != nil {
- return errD
- }
- z = l
- // --- [end][read][struct](Namespace) ---
- }
- d[v] = z
- }
- target.Namespaces = d
- // --- [end][read][map](map[string]*Namespace) ---
- }
- } else {
- target.Namespaces = nil
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.ResourceQuotas = nil
- } else {
- // --- [begin][read][map](map[string]*ResourceQuota) ---
- n := buff.ReadInt() // map len
- m := make(map[string]*ResourceQuota, n)
- for range n {
- var vv string
- var p string
- if ctx.IsStringTable() {
- q := buff.ReadInt() // read string index
- p = ctx.Table.At(q)
- } else {
- p = buff.ReadString() // read string
- }
- o := p
- vv = o
- var zz *ResourceQuota
- if buff.ReadUInt8() == uint8(0) {
- zz = nil
- } else {
- // --- [begin][read][struct](ResourceQuota) ---
- r := new(ResourceQuota)
- buff.ReadInt() // [compatibility, unused]
- errE := r.UnmarshalBinaryWithContext(ctx)
- if errE != nil {
- return errE
- }
- zz = r
- // --- [end][read][struct](ResourceQuota) ---
- }
- m[vv] = zz
- }
- target.ResourceQuotas = m
- // --- [end][read][map](map[string]*ResourceQuota) ---
- }
- } else {
- target.ResourceQuotas = nil
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // KubeModelSetStream
- //--------------------------------------------------------------------------
- // KubeModelSetStream is a single use field stream for the contents of an KubeModelSet instance. Instead of creating an instance and populating
- // the fields on that instance, we provide a streaming iterator which yields (BingenFieldInfo, *BingenValue) tuples for each
- // streamable element. All slices and maps will be flattened one depth and each element streamed individually.
- type KubeModelSetStream struct {
- reader io.Reader
- ctx *DecodingContext
- err error
- }
- // Closes closes the internal io.Reader used to read and parse the KubeModelSet fields.
- // This should be called once the stream is no longer needed.
- func (stream *KubeModelSetStream) Close() {
- if closer, ok := stream.reader.(io.Closer); ok {
- closer.Close()
- }
- stream.ctx.Close()
- }
- // Error returns an error if one occurred during the process of streaming the KubeModelSet
- // This can be checked after iterating through the Stream().
- func (stream *KubeModelSetStream) Error() error {
- return stream.err
- }
- // NewKubeModelSetStream creates a new KubeModelSetStream, which uses the io.Reader data to stream all internal fields of an KubeModelSet instance
- func NewKubeModelSetStream(reader io.Reader) BingenStream {
- ctx := NewDecodingContextFromReader(reader)
- return &KubeModelSetStream{
- ctx: ctx,
- reader: reader,
- }
- }
- // Stream returns the iterator which will stream each field of the target type.
- func (stream *KubeModelSetStream) Stream() iter.Seq2[BingenFieldInfo, *BingenValue] {
- return func(yield func(BingenFieldInfo, *BingenValue) bool) {
- var fi BingenFieldInfo
- ctx := stream.ctx
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- stream.err = fmt.Errorf("Invalid Version Unmarshalling KubeModelSet. Expected %d or less, got %d", DefaultCodecVersion, version)
- return
- }
- fi = BingenFieldInfo{
- Type: reflect.TypeFor[*Metadata](),
- Name: "Metadata",
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- if !yield(fi, nil) {
- return
- }
- } else {
- // --- [begin][read][struct](Metadata) ---
- b := new(Metadata)
- buff.ReadInt() // [compatibility, unused]
- errA := b.UnmarshalBinaryWithContext(ctx)
- if errA != nil {
- stream.err = errA
- return
- }
- a := b
- // --- [end][read][struct](Metadata) ---
- if !yield(fi, singleV(a)) {
- return
- }
- }
- } else {
- if !yield(fi, nil) {
- return
- }
- }
- fi = BingenFieldInfo{
- Type: reflect.TypeFor[Window](),
- Name: "Window",
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][struct](Window) ---
- d := new(Window)
- buff.ReadInt() // [compatibility, unused]
- errB := d.UnmarshalBinaryWithContext(ctx)
- if errB != nil {
- stream.err = errB
- return
- }
- c := *d
- // --- [end][read][struct](Window) ---
- if !yield(fi, singleV(c)) {
- return
- }
- } else {
- }
- fi = BingenFieldInfo{
- Type: reflect.TypeFor[*Cluster](),
- Name: "Cluster",
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- if !yield(fi, nil) {
- return
- }
- } else {
- // --- [begin][read][struct](Cluster) ---
- f := new(Cluster)
- buff.ReadInt() // [compatibility, unused]
- errC := f.UnmarshalBinaryWithContext(ctx)
- if errC != nil {
- stream.err = errC
- return
- }
- e := f
- // --- [end][read][struct](Cluster) ---
- if !yield(fi, singleV(e)) {
- return
- }
- }
- } else {
- if !yield(fi, nil) {
- return
- }
- }
- fi = BingenFieldInfo{
- Type: reflect.TypeFor[map[string]*Namespace](),
- Name: "Namespaces",
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- if !yield(fi, nil) {
- return
- }
- } else {
- // --- [begin][read][streaming-map](map[string]*Namespace) ---
- g := buff.ReadInt() // map len
- for range g {
- var v string
- var l string
- if ctx.IsStringTable() {
- m := buff.ReadInt() // read string index
- l = ctx.Table.At(m)
- } else {
- l = buff.ReadString() // read string
- }
- h := l
- v = h
- var z *Namespace
- if buff.ReadUInt8() == uint8(0) {
- z = nil
- } else {
- // --- [begin][read][struct](Namespace) ---
- n := new(Namespace)
- buff.ReadInt() // [compatibility, unused]
- errD := n.UnmarshalBinaryWithContext(ctx)
- if errD != nil {
- stream.err = errD
- return
- }
- z = n
- // --- [end][read][struct](Namespace) ---
- }
- if !yield(fi, pairV(v, z)) {
- return
- }
- }
- // --- [end][read][streaming-map](map[string]*Namespace) ---
- }
- } else {
- if !yield(fi, nil) {
- return
- }
- }
- fi = BingenFieldInfo{
- Type: reflect.TypeFor[map[string]*ResourceQuota](),
- Name: "ResourceQuotas",
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- if !yield(fi, nil) {
- return
- }
- } else {
- // --- [begin][read][streaming-map](map[string]*ResourceQuota) ---
- o := buff.ReadInt() // map len
- for range o {
- var vv string
- var q string
- if ctx.IsStringTable() {
- r := buff.ReadInt() // read string index
- q = ctx.Table.At(r)
- } else {
- q = buff.ReadString() // read string
- }
- p := q
- vv = p
- var zz *ResourceQuota
- if buff.ReadUInt8() == uint8(0) {
- zz = nil
- } else {
- // --- [begin][read][struct](ResourceQuota) ---
- s := new(ResourceQuota)
- buff.ReadInt() // [compatibility, unused]
- errE := s.UnmarshalBinaryWithContext(ctx)
- if errE != nil {
- stream.err = errE
- return
- }
- zz = s
- // --- [end][read][struct](ResourceQuota) ---
- }
- if !yield(fi, pairV(vv, zz)) {
- return
- }
- }
- // --- [end][read][streaming-map](map[string]*ResourceQuota) ---
- }
- } else {
- if !yield(fi, nil) {
- return
- }
- }
- }
- }
- //--------------------------------------------------------------------------
- // Metadata
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this Metadata instance
- // into a byte array
- func (target *Metadata) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this Metadata instance
- // into an io.Writer.
- func (target *Metadata) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this Metadata instance
- // into a byte array leveraging a predefined context.
- func (target *Metadata) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- // --- [begin][write][reference](time.Time) ---
- a, errA := target.CreatedAt.MarshalBinary()
- if errA != nil {
- return errA
- }
- buff.WriteInt(len(a))
- buff.WriteBytes(a)
- // --- [end][write][reference](time.Time) ---
- // --- [begin][write][reference](time.Time) ---
- b, errB := target.CompletedAt.MarshalBinary()
- if errB != nil {
- return errB
- }
- buff.WriteInt(len(b))
- buff.WriteBytes(b)
- // --- [end][write][reference](time.Time) ---
- buff.WriteInt(target.ObjectCount) // write int
- if target.Diagnostics == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][slice]([]Diagnostic) ---
- buff.WriteInt(len(target.Diagnostics)) // slice length
- for i := range target.Diagnostics {
- // --- [begin][write][struct](Diagnostic) ---
- buff.WriteInt(0) // [compatibility, unused]
- errC := target.Diagnostics[i].MarshalBinaryWithContext(ctx)
- if errC != nil {
- return errC
- }
- // --- [end][write][struct](Diagnostic) ---
- }
- // --- [end][write][slice]([]Diagnostic) ---
- }
- // --- [begin][write][alias](DiagnosticLevel) ---
- buff.WriteInt(int(target.DiagnosticLevel)) // write int
- // --- [end][write][alias](DiagnosticLevel) ---
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the Metadata type
- func (target *Metadata) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the Metadata type
- func (target *Metadata) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the Metadata type
- func (target *Metadata) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling Metadata. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- a := new(time.Time)
- b := buff.ReadInt() // byte array length
- c := buff.ReadBytes(b)
- errA := a.UnmarshalBinary(c)
- if errA != nil {
- return errA
- }
- target.CreatedAt = *a
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- d := new(time.Time)
- e := buff.ReadInt() // byte array length
- f := buff.ReadBytes(e)
- errB := d.UnmarshalBinary(f)
- if errB != nil {
- return errB
- }
- target.CompletedAt = *d
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- g := buff.ReadInt() // read int
- target.ObjectCount = g
- } else {
- target.ObjectCount = int(0) // default
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Diagnostics = nil
- } else {
- // --- [begin][read][slice]([]Diagnostic) ---
- l := buff.ReadInt() // slice len
- h := make([]Diagnostic, l)
- for i := range l {
- // --- [begin][read][struct](Diagnostic) ---
- n := new(Diagnostic)
- buff.ReadInt() // [compatibility, unused]
- errC := n.UnmarshalBinaryWithContext(ctx)
- if errC != nil {
- return errC
- }
- m := *n
- // --- [end][read][struct](Diagnostic) ---
- h[i] = m
- }
- target.Diagnostics = h
- // --- [end][read][slice]([]Diagnostic) ---
- }
- } else {
- target.Diagnostics = nil
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](DiagnosticLevel) ---
- var o int
- p := buff.ReadInt() // read int
- o = p
- target.DiagnosticLevel = DiagnosticLevel(o)
- // --- [end][read][alias](DiagnosticLevel) ---
- } else {
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // Namespace
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this Namespace instance
- // into a byte array
- func (target *Namespace) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this Namespace instance
- // into an io.Writer.
- func (target *Namespace) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this Namespace instance
- // into a byte array leveraging a predefined context.
- func (target *Namespace) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- if ctx.IsStringTable() {
- a := ctx.Table.AddOrGet(target.UID)
- buff.WriteInt(a) // write table index
- } else {
- buff.WriteString(target.UID) // write string
- }
- if ctx.IsStringTable() {
- b := ctx.Table.AddOrGet(target.ClusterUID)
- buff.WriteInt(b) // write table index
- } else {
- buff.WriteString(target.ClusterUID) // write string
- }
- if ctx.IsStringTable() {
- c := ctx.Table.AddOrGet(target.Name)
- buff.WriteInt(c) // write table index
- } else {
- buff.WriteString(target.Name) // write string
- }
- if target.Labels == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][map](map[string]string) ---
- buff.WriteInt(len(target.Labels)) // map length
- for v, z := range target.Labels {
- if ctx.IsStringTable() {
- d := ctx.Table.AddOrGet(v)
- buff.WriteInt(d) // write table index
- } else {
- buff.WriteString(v) // write string
- }
- if ctx.IsStringTable() {
- e := ctx.Table.AddOrGet(z)
- buff.WriteInt(e) // write table index
- } else {
- buff.WriteString(z) // write string
- }
- }
- // --- [end][write][map](map[string]string) ---
- }
- if target.Annotations == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][map](map[string]string) ---
- buff.WriteInt(len(target.Annotations)) // map length
- for vv, zz := range target.Annotations {
- if ctx.IsStringTable() {
- f := ctx.Table.AddOrGet(vv)
- buff.WriteInt(f) // write table index
- } else {
- buff.WriteString(vv) // write string
- }
- if ctx.IsStringTable() {
- g := ctx.Table.AddOrGet(zz)
- buff.WriteInt(g) // write table index
- } else {
- buff.WriteString(zz) // write string
- }
- }
- // --- [end][write][map](map[string]string) ---
- }
- // --- [begin][write][reference](time.Time) ---
- h, errA := target.Start.MarshalBinary()
- if errA != nil {
- return errA
- }
- buff.WriteInt(len(h))
- buff.WriteBytes(h)
- // --- [end][write][reference](time.Time) ---
- // --- [begin][write][reference](time.Time) ---
- l, errB := target.End.MarshalBinary()
- if errB != nil {
- return errB
- }
- buff.WriteInt(len(l))
- buff.WriteBytes(l)
- // --- [end][write][reference](time.Time) ---
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the Namespace type
- func (target *Namespace) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the Namespace type
- func (target *Namespace) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the Namespace type
- func (target *Namespace) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling Namespace. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- var b string
- if ctx.IsStringTable() {
- c := buff.ReadInt() // read string index
- b = ctx.Table.At(c)
- } else {
- b = buff.ReadString() // read string
- }
- a := b
- target.UID = a
- } else {
- target.UID = "" // default
- }
- // field version check
- if uint8(1) <= version {
- var e string
- if ctx.IsStringTable() {
- f := buff.ReadInt() // read string index
- e = ctx.Table.At(f)
- } else {
- e = buff.ReadString() // read string
- }
- d := e
- target.ClusterUID = d
- } else {
- target.ClusterUID = "" // default
- }
- // field version check
- if uint8(1) <= version {
- var h string
- if ctx.IsStringTable() {
- l := buff.ReadInt() // read string index
- h = ctx.Table.At(l)
- } else {
- h = buff.ReadString() // read string
- }
- g := h
- target.Name = g
- } else {
- target.Name = "" // default
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Labels = nil
- } else {
- // --- [begin][read][map](map[string]string) ---
- n := buff.ReadInt() // map len
- m := make(map[string]string, n)
- for range n {
- var v string
- var p string
- if ctx.IsStringTable() {
- q := buff.ReadInt() // read string index
- p = ctx.Table.At(q)
- } else {
- p = buff.ReadString() // read string
- }
- o := p
- v = o
- var z string
- var s string
- if ctx.IsStringTable() {
- t := buff.ReadInt() // read string index
- s = ctx.Table.At(t)
- } else {
- s = buff.ReadString() // read string
- }
- r := s
- z = r
- m[v] = z
- }
- target.Labels = m
- // --- [end][read][map](map[string]string) ---
- }
- } else {
- target.Labels = nil
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Annotations = nil
- } else {
- // --- [begin][read][map](map[string]string) ---
- w := buff.ReadInt() // map len
- u := make(map[string]string, w)
- for range w {
- var vv string
- var y string
- if ctx.IsStringTable() {
- aa := buff.ReadInt() // read string index
- y = ctx.Table.At(aa)
- } else {
- y = buff.ReadString() // read string
- }
- x := y
- vv = x
- var zz string
- var cc string
- if ctx.IsStringTable() {
- dd := buff.ReadInt() // read string index
- cc = ctx.Table.At(dd)
- } else {
- cc = buff.ReadString() // read string
- }
- bb := cc
- zz = bb
- u[vv] = zz
- }
- target.Annotations = u
- // --- [end][read][map](map[string]string) ---
- }
- } else {
- target.Annotations = nil
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- ee := new(time.Time)
- ff := buff.ReadInt() // byte array length
- gg := buff.ReadBytes(ff)
- errA := ee.UnmarshalBinary(gg)
- if errA != nil {
- return errA
- }
- target.Start = *ee
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- hh := new(time.Time)
- ll := buff.ReadInt() // byte array length
- mm := buff.ReadBytes(ll)
- errB := hh.UnmarshalBinary(mm)
- if errB != nil {
- return errB
- }
- target.End = *hh
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // ResourceQuantity
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this ResourceQuantity instance
- // into a byte array
- func (target *ResourceQuantity) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this ResourceQuantity instance
- // into an io.Writer.
- func (target *ResourceQuantity) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this ResourceQuantity instance
- // into a byte array leveraging a predefined context.
- func (target *ResourceQuantity) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- // --- [begin][write][alias](Resource) ---
- if ctx.IsStringTable() {
- a := ctx.Table.AddOrGet(string(target.Resource))
- buff.WriteInt(a) // write table index
- } else {
- buff.WriteString(string(target.Resource)) // write string
- }
- // --- [end][write][alias](Resource) ---
- // --- [begin][write][alias](Unit) ---
- if ctx.IsStringTable() {
- b := ctx.Table.AddOrGet(string(target.Unit))
- buff.WriteInt(b) // write table index
- } else {
- buff.WriteString(string(target.Unit)) // write string
- }
- // --- [end][write][alias](Unit) ---
- // --- [begin][write][alias](Stats) ---
- if map[StatType]float64(target.Values) == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][map](map[StatType]float64) ---
- buff.WriteInt(len(map[StatType]float64(target.Values))) // map length
- for v, z := range map[StatType]float64(target.Values) {
- // --- [begin][write][alias](StatType) ---
- if ctx.IsStringTable() {
- c := ctx.Table.AddOrGet(string(v))
- buff.WriteInt(c) // write table index
- } else {
- buff.WriteString(string(v)) // write string
- }
- // --- [end][write][alias](StatType) ---
- buff.WriteFloat64(z) // write float64
- }
- // --- [end][write][map](map[StatType]float64) ---
- }
- // --- [end][write][alias](Stats) ---
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the ResourceQuantity type
- func (target *ResourceQuantity) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the ResourceQuantity type
- func (target *ResourceQuantity) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the ResourceQuantity type
- func (target *ResourceQuantity) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling ResourceQuantity. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](Resource) ---
- var a string
- var c string
- if ctx.IsStringTable() {
- d := buff.ReadInt() // read string index
- c = ctx.Table.At(d)
- } else {
- c = buff.ReadString() // read string
- }
- b := c
- a = b
- target.Resource = Resource(a)
- // --- [end][read][alias](Resource) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](Unit) ---
- var e string
- var g string
- if ctx.IsStringTable() {
- h := buff.ReadInt() // read string index
- g = ctx.Table.At(h)
- } else {
- g = buff.ReadString() // read string
- }
- f := g
- e = f
- target.Unit = Unit(e)
- // --- [end][read][alias](Unit) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](Stats) ---
- var l map[StatType]float64
- if buff.ReadUInt8() == uint8(0) {
- l = nil
- } else {
- // --- [begin][read][map](map[StatType]float64) ---
- n := buff.ReadInt() // map len
- m := make(map[StatType]float64, n)
- for range n {
- // --- [begin][read][alias](StatType) ---
- var o string
- var q string
- if ctx.IsStringTable() {
- r := buff.ReadInt() // read string index
- q = ctx.Table.At(r)
- } else {
- q = buff.ReadString() // read string
- }
- p := q
- o = p
- v := StatType(o)
- // --- [end][read][alias](StatType) ---
- var z float64
- s := buff.ReadFloat64() // read float64
- z = s
- m[v] = z
- }
- l = m
- // --- [end][read][map](map[StatType]float64) ---
- }
- target.Values = Stats(l)
- // --- [end][read][alias](Stats) ---
- } else {
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // ResourceQuota
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this ResourceQuota instance
- // into a byte array
- func (target *ResourceQuota) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this ResourceQuota instance
- // into an io.Writer.
- func (target *ResourceQuota) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this ResourceQuota instance
- // into a byte array leveraging a predefined context.
- func (target *ResourceQuota) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- if ctx.IsStringTable() {
- a := ctx.Table.AddOrGet(target.UID)
- buff.WriteInt(a) // write table index
- } else {
- buff.WriteString(target.UID) // write string
- }
- if ctx.IsStringTable() {
- b := ctx.Table.AddOrGet(target.NamespaceUID)
- buff.WriteInt(b) // write table index
- } else {
- buff.WriteString(target.NamespaceUID) // write string
- }
- if ctx.IsStringTable() {
- c := ctx.Table.AddOrGet(target.Name)
- buff.WriteInt(c) // write table index
- } else {
- buff.WriteString(target.Name) // write string
- }
- if target.Spec == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][struct](ResourceQuotaSpec) ---
- buff.WriteInt(0) // [compatibility, unused]
- errA := target.Spec.MarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- // --- [end][write][struct](ResourceQuotaSpec) ---
- }
- if target.Status == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][struct](ResourceQuotaStatus) ---
- buff.WriteInt(0) // [compatibility, unused]
- errB := target.Status.MarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- // --- [end][write][struct](ResourceQuotaStatus) ---
- }
- // --- [begin][write][reference](time.Time) ---
- d, errC := target.Start.MarshalBinary()
- if errC != nil {
- return errC
- }
- buff.WriteInt(len(d))
- buff.WriteBytes(d)
- // --- [end][write][reference](time.Time) ---
- // --- [begin][write][reference](time.Time) ---
- e, errD := target.End.MarshalBinary()
- if errD != nil {
- return errD
- }
- buff.WriteInt(len(e))
- buff.WriteBytes(e)
- // --- [end][write][reference](time.Time) ---
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the ResourceQuota type
- func (target *ResourceQuota) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the ResourceQuota type
- func (target *ResourceQuota) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the ResourceQuota type
- func (target *ResourceQuota) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling ResourceQuota. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- var b string
- if ctx.IsStringTable() {
- c := buff.ReadInt() // read string index
- b = ctx.Table.At(c)
- } else {
- b = buff.ReadString() // read string
- }
- a := b
- target.UID = a
- } else {
- target.UID = "" // default
- }
- // field version check
- if uint8(1) <= version {
- var e string
- if ctx.IsStringTable() {
- f := buff.ReadInt() // read string index
- e = ctx.Table.At(f)
- } else {
- e = buff.ReadString() // read string
- }
- d := e
- target.NamespaceUID = d
- } else {
- target.NamespaceUID = "" // default
- }
- // field version check
- if uint8(1) <= version {
- var h string
- if ctx.IsStringTable() {
- l := buff.ReadInt() // read string index
- h = ctx.Table.At(l)
- } else {
- h = buff.ReadString() // read string
- }
- g := h
- target.Name = g
- } else {
- target.Name = "" // default
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Spec = nil
- } else {
- // --- [begin][read][struct](ResourceQuotaSpec) ---
- m := new(ResourceQuotaSpec)
- buff.ReadInt() // [compatibility, unused]
- errA := m.UnmarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- target.Spec = m
- // --- [end][read][struct](ResourceQuotaSpec) ---
- }
- } else {
- target.Spec = nil
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Status = nil
- } else {
- // --- [begin][read][struct](ResourceQuotaStatus) ---
- n := new(ResourceQuotaStatus)
- buff.ReadInt() // [compatibility, unused]
- errB := n.UnmarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- target.Status = n
- // --- [end][read][struct](ResourceQuotaStatus) ---
- }
- } else {
- target.Status = nil
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- o := new(time.Time)
- p := buff.ReadInt() // byte array length
- q := buff.ReadBytes(p)
- errC := o.UnmarshalBinary(q)
- if errC != nil {
- return errC
- }
- target.Start = *o
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- r := new(time.Time)
- s := buff.ReadInt() // byte array length
- t := buff.ReadBytes(s)
- errD := r.UnmarshalBinary(t)
- if errD != nil {
- return errD
- }
- target.End = *r
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // ResourceQuotaSpec
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this ResourceQuotaSpec instance
- // into a byte array
- func (target *ResourceQuotaSpec) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this ResourceQuotaSpec instance
- // into an io.Writer.
- func (target *ResourceQuotaSpec) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaSpec instance
- // into a byte array leveraging a predefined context.
- func (target *ResourceQuotaSpec) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- if target.Hard == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][struct](ResourceQuotaSpecHard) ---
- buff.WriteInt(0) // [compatibility, unused]
- errA := target.Hard.MarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- // --- [end][write][struct](ResourceQuotaSpecHard) ---
- }
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the ResourceQuotaSpec type
- func (target *ResourceQuotaSpec) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the ResourceQuotaSpec type
- func (target *ResourceQuotaSpec) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the ResourceQuotaSpec type
- func (target *ResourceQuotaSpec) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling ResourceQuotaSpec. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Hard = nil
- } else {
- // --- [begin][read][struct](ResourceQuotaSpecHard) ---
- a := new(ResourceQuotaSpecHard)
- buff.ReadInt() // [compatibility, unused]
- errA := a.UnmarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- target.Hard = a
- // --- [end][read][struct](ResourceQuotaSpecHard) ---
- }
- } else {
- target.Hard = nil
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // ResourceQuotaSpecHard
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this ResourceQuotaSpecHard instance
- // into a byte array
- func (target *ResourceQuotaSpecHard) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this ResourceQuotaSpecHard instance
- // into an io.Writer.
- func (target *ResourceQuotaSpecHard) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaSpecHard instance
- // into a byte array leveraging a predefined context.
- func (target *ResourceQuotaSpecHard) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- // --- [begin][write][alias](ResourceQuantities) ---
- if map[Resource]ResourceQuantity(target.Requests) == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][map](map[Resource]ResourceQuantity) ---
- buff.WriteInt(len(map[Resource]ResourceQuantity(target.Requests))) // map length
- for v, z := range map[Resource]ResourceQuantity(target.Requests) {
- // --- [begin][write][alias](Resource) ---
- if ctx.IsStringTable() {
- a := ctx.Table.AddOrGet(string(v))
- buff.WriteInt(a) // write table index
- } else {
- buff.WriteString(string(v)) // write string
- }
- // --- [end][write][alias](Resource) ---
- // --- [begin][write][struct](ResourceQuantity) ---
- buff.WriteInt(0) // [compatibility, unused]
- errA := z.MarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- // --- [end][write][struct](ResourceQuantity) ---
- }
- // --- [end][write][map](map[Resource]ResourceQuantity) ---
- }
- // --- [end][write][alias](ResourceQuantities) ---
- // --- [begin][write][alias](ResourceQuantities) ---
- if map[Resource]ResourceQuantity(target.Limits) == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][map](map[Resource]ResourceQuantity) ---
- buff.WriteInt(len(map[Resource]ResourceQuantity(target.Limits))) // map length
- for vv, zz := range map[Resource]ResourceQuantity(target.Limits) {
- // --- [begin][write][alias](Resource) ---
- if ctx.IsStringTable() {
- b := ctx.Table.AddOrGet(string(vv))
- buff.WriteInt(b) // write table index
- } else {
- buff.WriteString(string(vv)) // write string
- }
- // --- [end][write][alias](Resource) ---
- // --- [begin][write][struct](ResourceQuantity) ---
- buff.WriteInt(0) // [compatibility, unused]
- errB := zz.MarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- // --- [end][write][struct](ResourceQuantity) ---
- }
- // --- [end][write][map](map[Resource]ResourceQuantity) ---
- }
- // --- [end][write][alias](ResourceQuantities) ---
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the ResourceQuotaSpecHard type
- func (target *ResourceQuotaSpecHard) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the ResourceQuotaSpecHard type
- func (target *ResourceQuotaSpecHard) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the ResourceQuotaSpecHard type
- func (target *ResourceQuotaSpecHard) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling ResourceQuotaSpecHard. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](ResourceQuantities) ---
- var a map[Resource]ResourceQuantity
- if buff.ReadUInt8() == uint8(0) {
- a = nil
- } else {
- // --- [begin][read][map](map[Resource]ResourceQuantity) ---
- c := buff.ReadInt() // map len
- b := make(map[Resource]ResourceQuantity, c)
- for range c {
- // --- [begin][read][alias](Resource) ---
- var d string
- var f string
- if ctx.IsStringTable() {
- g := buff.ReadInt() // read string index
- f = ctx.Table.At(g)
- } else {
- f = buff.ReadString() // read string
- }
- e := f
- d = e
- v := Resource(d)
- // --- [end][read][alias](Resource) ---
- // --- [begin][read][struct](ResourceQuantity) ---
- h := new(ResourceQuantity)
- buff.ReadInt() // [compatibility, unused]
- errA := h.UnmarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- z := *h
- // --- [end][read][struct](ResourceQuantity) ---
- b[v] = z
- }
- a = b
- // --- [end][read][map](map[Resource]ResourceQuantity) ---
- }
- target.Requests = ResourceQuantities(a)
- // --- [end][read][alias](ResourceQuantities) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](ResourceQuantities) ---
- var l map[Resource]ResourceQuantity
- if buff.ReadUInt8() == uint8(0) {
- l = nil
- } else {
- // --- [begin][read][map](map[Resource]ResourceQuantity) ---
- n := buff.ReadInt() // map len
- m := make(map[Resource]ResourceQuantity, n)
- for range n {
- // --- [begin][read][alias](Resource) ---
- var o string
- var q string
- if ctx.IsStringTable() {
- r := buff.ReadInt() // read string index
- q = ctx.Table.At(r)
- } else {
- q = buff.ReadString() // read string
- }
- p := q
- o = p
- vv := Resource(o)
- // --- [end][read][alias](Resource) ---
- // --- [begin][read][struct](ResourceQuantity) ---
- s := new(ResourceQuantity)
- buff.ReadInt() // [compatibility, unused]
- errB := s.UnmarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- zz := *s
- // --- [end][read][struct](ResourceQuantity) ---
- m[vv] = zz
- }
- l = m
- // --- [end][read][map](map[Resource]ResourceQuantity) ---
- }
- target.Limits = ResourceQuantities(l)
- // --- [end][read][alias](ResourceQuantities) ---
- } else {
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // ResourceQuotaStatus
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this ResourceQuotaStatus instance
- // into a byte array
- func (target *ResourceQuotaStatus) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this ResourceQuotaStatus instance
- // into an io.Writer.
- func (target *ResourceQuotaStatus) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaStatus instance
- // into a byte array leveraging a predefined context.
- func (target *ResourceQuotaStatus) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- if target.Used == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][struct](ResourceQuotaStatusUsed) ---
- buff.WriteInt(0) // [compatibility, unused]
- errA := target.Used.MarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- // --- [end][write][struct](ResourceQuotaStatusUsed) ---
- }
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the ResourceQuotaStatus type
- func (target *ResourceQuotaStatus) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the ResourceQuotaStatus type
- func (target *ResourceQuotaStatus) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the ResourceQuotaStatus type
- func (target *ResourceQuotaStatus) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling ResourceQuotaStatus. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- if buff.ReadUInt8() == uint8(0) {
- target.Used = nil
- } else {
- // --- [begin][read][struct](ResourceQuotaStatusUsed) ---
- a := new(ResourceQuotaStatusUsed)
- buff.ReadInt() // [compatibility, unused]
- errA := a.UnmarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- target.Used = a
- // --- [end][read][struct](ResourceQuotaStatusUsed) ---
- }
- } else {
- target.Used = nil
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // ResourceQuotaStatusUsed
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this ResourceQuotaStatusUsed instance
- // into a byte array
- func (target *ResourceQuotaStatusUsed) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this ResourceQuotaStatusUsed instance
- // into an io.Writer.
- func (target *ResourceQuotaStatusUsed) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this ResourceQuotaStatusUsed instance
- // into a byte array leveraging a predefined context.
- func (target *ResourceQuotaStatusUsed) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- // --- [begin][write][alias](ResourceQuantities) ---
- if map[Resource]ResourceQuantity(target.Requests) == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][map](map[Resource]ResourceQuantity) ---
- buff.WriteInt(len(map[Resource]ResourceQuantity(target.Requests))) // map length
- for v, z := range map[Resource]ResourceQuantity(target.Requests) {
- // --- [begin][write][alias](Resource) ---
- if ctx.IsStringTable() {
- a := ctx.Table.AddOrGet(string(v))
- buff.WriteInt(a) // write table index
- } else {
- buff.WriteString(string(v)) // write string
- }
- // --- [end][write][alias](Resource) ---
- // --- [begin][write][struct](ResourceQuantity) ---
- buff.WriteInt(0) // [compatibility, unused]
- errA := z.MarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- // --- [end][write][struct](ResourceQuantity) ---
- }
- // --- [end][write][map](map[Resource]ResourceQuantity) ---
- }
- // --- [end][write][alias](ResourceQuantities) ---
- // --- [begin][write][alias](ResourceQuantities) ---
- if map[Resource]ResourceQuantity(target.Limits) == nil {
- buff.WriteUInt8(uint8(0)) // write nil byte
- } else {
- buff.WriteUInt8(uint8(1)) // write non-nil byte
- // --- [begin][write][map](map[Resource]ResourceQuantity) ---
- buff.WriteInt(len(map[Resource]ResourceQuantity(target.Limits))) // map length
- for vv, zz := range map[Resource]ResourceQuantity(target.Limits) {
- // --- [begin][write][alias](Resource) ---
- if ctx.IsStringTable() {
- b := ctx.Table.AddOrGet(string(vv))
- buff.WriteInt(b) // write table index
- } else {
- buff.WriteString(string(vv)) // write string
- }
- // --- [end][write][alias](Resource) ---
- // --- [begin][write][struct](ResourceQuantity) ---
- buff.WriteInt(0) // [compatibility, unused]
- errB := zz.MarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- // --- [end][write][struct](ResourceQuantity) ---
- }
- // --- [end][write][map](map[Resource]ResourceQuantity) ---
- }
- // --- [end][write][alias](ResourceQuantities) ---
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the ResourceQuotaStatusUsed type
- func (target *ResourceQuotaStatusUsed) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the ResourceQuotaStatusUsed type
- func (target *ResourceQuotaStatusUsed) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the ResourceQuotaStatusUsed type
- func (target *ResourceQuotaStatusUsed) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling ResourceQuotaStatusUsed. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](ResourceQuantities) ---
- var a map[Resource]ResourceQuantity
- if buff.ReadUInt8() == uint8(0) {
- a = nil
- } else {
- // --- [begin][read][map](map[Resource]ResourceQuantity) ---
- c := buff.ReadInt() // map len
- b := make(map[Resource]ResourceQuantity, c)
- for range c {
- // --- [begin][read][alias](Resource) ---
- var d string
- var f string
- if ctx.IsStringTable() {
- g := buff.ReadInt() // read string index
- f = ctx.Table.At(g)
- } else {
- f = buff.ReadString() // read string
- }
- e := f
- d = e
- v := Resource(d)
- // --- [end][read][alias](Resource) ---
- // --- [begin][read][struct](ResourceQuantity) ---
- h := new(ResourceQuantity)
- buff.ReadInt() // [compatibility, unused]
- errA := h.UnmarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- z := *h
- // --- [end][read][struct](ResourceQuantity) ---
- b[v] = z
- }
- a = b
- // --- [end][read][map](map[Resource]ResourceQuantity) ---
- }
- target.Requests = ResourceQuantities(a)
- // --- [end][read][alias](ResourceQuantities) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](ResourceQuantities) ---
- var l map[Resource]ResourceQuantity
- if buff.ReadUInt8() == uint8(0) {
- l = nil
- } else {
- // --- [begin][read][map](map[Resource]ResourceQuantity) ---
- n := buff.ReadInt() // map len
- m := make(map[Resource]ResourceQuantity, n)
- for range n {
- // --- [begin][read][alias](Resource) ---
- var o string
- var q string
- if ctx.IsStringTable() {
- r := buff.ReadInt() // read string index
- q = ctx.Table.At(r)
- } else {
- q = buff.ReadString() // read string
- }
- p := q
- o = p
- vv := Resource(o)
- // --- [end][read][alias](Resource) ---
- // --- [begin][read][struct](ResourceQuantity) ---
- s := new(ResourceQuantity)
- buff.ReadInt() // [compatibility, unused]
- errB := s.UnmarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- zz := *s
- // --- [end][read][struct](ResourceQuantity) ---
- m[vv] = zz
- }
- l = m
- // --- [end][read][map](map[Resource]ResourceQuantity) ---
- }
- target.Limits = ResourceQuantities(l)
- // --- [end][read][alias](ResourceQuantities) ---
- } else {
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // Window
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this Window instance
- // into a byte array
- func (target *Window) MarshalBinary() (data []byte, err error) {
- ctx := NewEncodingContext(nil)
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- return ctx.ToBytes(), nil
- }
- // MarshalBinary serializes the internal properties of this Window instance
- // into an io.Writer.
- func (target *Window) MarshalBinaryTo(writer io.Writer) error {
- buff := util.NewBufferFromWriter(writer)
- defer buff.Flush()
- ctx := NewEncodingContextFromBuffer(buff, nil)
- return target.MarshalBinaryWithContext(ctx)
- }
- // MarshalBinaryWithContext serializes the internal properties of this Window instance
- // into a byte array leveraging a predefined context.
- func (target *Window) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- buff.WriteUInt8(DefaultCodecVersion) // version
- // --- [begin][write][reference](time.Time) ---
- a, errA := target.Start.MarshalBinary()
- if errA != nil {
- return errA
- }
- buff.WriteInt(len(a))
- buff.WriteBytes(a)
- // --- [end][write][reference](time.Time) ---
- // --- [begin][write][reference](time.Time) ---
- b, errB := target.End.MarshalBinary()
- if errB != nil {
- return errB
- }
- buff.WriteInt(len(b))
- buff.WriteBytes(b)
- // --- [end][write][reference](time.Time) ---
- return nil
- }
- // UnmarshalBinary uses the data passed byte array to set all the internal properties of
- // the Window type
- func (target *Window) UnmarshalBinary(data []byte) error {
- ctx := NewDecodingContextFromBytes(data)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryFromReader uses the io.Reader data to set all the internal properties of
- // the Window type
- func (target *Window) UnmarshalBinaryFromReader(reader io.Reader) error {
- ctx := NewDecodingContextFromReader(reader)
- defer ctx.Close()
- err := target.UnmarshalBinaryWithContext(ctx)
- if err != nil {
- return err
- }
- return nil
- }
- // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
- // the Window type
- func (target *Window) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
- // panics are recovered and propagated as errors
- defer func() {
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else if s, ok := r.(string); ok {
- err = fmt.Errorf("unexpected panic: %s", s)
- } else {
- err = fmt.Errorf("unexpected panic: %+v", r)
- }
- }
- }()
- buff := ctx.Buffer
- version := buff.ReadUInt8()
- if version > DefaultCodecVersion {
- return fmt.Errorf("Invalid Version Unmarshalling Window. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- a := new(time.Time)
- b := buff.ReadInt() // byte array length
- c := buff.ReadBytes(b)
- errA := a.UnmarshalBinary(c)
- if errA != nil {
- return errA
- }
- target.Start = *a
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- d := new(time.Time)
- e := buff.ReadInt() // byte array length
- f := buff.ReadBytes(e)
- errB := d.UnmarshalBinary(f)
- if errB != nil {
- return errB
- }
- target.End = *d
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- return nil
- }
|