| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086 |
- ////////////////////////////////////////////////////////////////////////////////
- //
- // DO NOT MODIFY
- //
- // ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻
- //
- //
- // This source file was automatically generated by bingen.
- //
- ////////////////////////////////////////////////////////////////////////////////
- package kubemodel
- import (
- "fmt"
- util "github.com/opencost/opencost/core/pkg/util"
- "reflect"
- "strings"
- "sync"
- "time"
- )
- const (
- // GeneratorPackageName is the package the generator is targetting
- GeneratorPackageName string = "kubemodel"
- )
- // BinaryTags represent the formatting tag used for specific optimization features
- const (
- // 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"
- )
- const (
- // DefaultCodecVersion is used for any resources listed in the Default version set
- DefaultCodecVersion uint8 = 1
- )
- //--------------------------------------------------------------------------
- // 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.TypeOf((*Cluster)(nil)).Elem(),
- "Diagnostic": reflect.TypeOf((*Diagnostic)(nil)).Elem(),
- "KubeModelSet": reflect.TypeOf((*KubeModelSet)(nil)).Elem(),
- "Metadata": reflect.TypeOf((*Metadata)(nil)).Elem(),
- "Namespace": reflect.TypeOf((*Namespace)(nil)).Elem(),
- "ResourceQuantity": reflect.TypeOf((*ResourceQuantity)(nil)).Elem(),
- "ResourceQuota": reflect.TypeOf((*ResourceQuota)(nil)).Elem(),
- "ResourceQuotaSpec": reflect.TypeOf((*ResourceQuotaSpec)(nil)).Elem(),
- "ResourceQuotaSpecHard": reflect.TypeOf((*ResourceQuotaSpecHard)(nil)).Elem(),
- "ResourceQuotaStatus": reflect.TypeOf((*ResourceQuotaStatus)(nil)).Elem(),
- "ResourceQuotaStatusUsed": reflect.TypeOf((*ResourceQuotaStatusUsed)(nil)).Elem(),
- "Window": reflect.TypeOf((*Window)(nil)).Elem(),
- }
- //--------------------------------------------------------------------------
- // Type Helpers
- //--------------------------------------------------------------------------
- // isBinaryTag returns true when the first bytes in the provided binary matches the tag
- func isBinaryTag(data []byte, tag string) bool {
- return string(data[:len(tag)]) == tag
- }
- // appendBytes combines a and b into a new byte array
- func appendBytes(a []byte, b []byte) []byte {
- al := len(a)
- bl := len(b)
- tl := al + bl
- // allocate a new byte array for the combined
- // use native copy for speedy byte copying
- result := make([]byte, tl, tl)
- copy(result, a)
- copy(result[al:], b)
- return result
- }
- // 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
- }
- //--------------------------------------------------------------------------
- // StringTable
- //--------------------------------------------------------------------------
- // StringTable maps strings to specific indices for encoding
- type StringTable struct {
- l *sync.Mutex
- indices map[string]int
- next int
- }
- // NewStringTable Creates a new StringTable instance with provided contents
- func NewStringTable(contents ...string) *StringTable {
- st := &StringTable{
- l: new(sync.Mutex),
- indices: make(map[string]int),
- next: len(contents),
- }
- for i, entry := range contents {
- st.indices[entry] = i
- }
- return st
- }
- // AddOrGet atomically retrieves a string entry's index if it exist. Otherwise, it will
- // add the entry and return the index.
- func (st *StringTable) AddOrGet(s string) int {
- st.l.Lock()
- defer st.l.Unlock()
- 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 *StringTable) ToSlice() []string {
- st.l.Lock()
- defer st.l.Unlock()
- if st.next == 0 {
- return []string{}
- }
- sl := make([]string, st.next, st.next)
- for s, i := range st.indices {
- sl[i] = s
- }
- return sl
- }
- // ToBytes Converts the contents to a binary encoded representation
- func (st *StringTable) ToBytes() []byte {
- buff := util.NewBuffer()
- buff.WriteBytes([]byte(BinaryTagStringTable)) // bingen table header
- strs := st.ToSlice()
- buff.WriteInt(len(strs)) // table length
- for _, s := range strs {
- buff.WriteString(s)
- }
- return buff.Bytes()
- }
- //--------------------------------------------------------------------------
- // 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 *StringTable
- }
- // 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 []string
- }
- // IsStringTable returns true if the table is available
- func (dc *DecodingContext) IsStringTable() bool {
- return len(dc.Table) > 0
- }
- //--------------------------------------------------------------------------
- // 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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling 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[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[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 k string
- if ctx.IsStringTable() {
- l := buff.ReadInt() // read string index
- k = ctx.Table[l]
- } else {
- k = buff.ReadString() // read string
- }
- h := k
- target.Account = h
- } else {
- target.Account = "" // default
- }
- // field version check
- if uint8(1) <= version {
- var n string
- if ctx.IsStringTable() {
- o := buff.ReadInt() // read string index
- n = ctx.Table[o]
- } else {
- n = buff.ReadString() // read string
- }
- m := n
- target.Name = m
- } else {
- target.Name = "" // default
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- p := &time.Time{}
- q := buff.ReadInt() // byte array length
- r := buff.ReadBytes(q) // byte array
- errA := p.UnmarshalBinary(r)
- if errA != nil {
- return errA
- }
- target.Start = *p
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- s := &time.Time{}
- t := buff.ReadInt() // byte array length
- u := buff.ReadBytes(t) // byte array
- errB := s.UnmarshalBinary(u)
- if errB != nil {
- return errB
- }
- target.End = *s
- // --- [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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling Diagnostic. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- a := &time.Time{}
- b := buff.ReadInt() // byte array length
- c := buff.ReadBytes(b) // byte array
- 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[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) ---
- l := buff.ReadInt() // map len
- k := make(map[string]string, l)
- for i := 0; i < l; i++ {
- var v string
- var n string
- if ctx.IsStringTable() {
- o := buff.ReadInt() // read string index
- n = ctx.Table[o]
- } else {
- n = buff.ReadString() // read string
- }
- m := n
- v = m
- var z string
- var q string
- if ctx.IsStringTable() {
- r := buff.ReadInt() // read string index
- q = ctx.Table[r]
- } else {
- q = buff.ReadString() // read string
- }
- p := q
- z = p
- k[v] = z
- }
- target.Details = k
- // --- [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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: NewStringTable(),
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- sTableBytes := ctx.Table.ToBytes()
- merged := appendBytes(sTableBytes, encBytes)
- return merged, nil
- }
- // 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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling 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 := &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 := &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 := &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 i := 0; i < e; i++ {
- var v string
- var g string
- if ctx.IsStringTable() {
- h := buff.ReadInt() // read string index
- g = ctx.Table[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) ---
- k := &Namespace{}
- buff.ReadInt() // [compatibility, unused]
- errD := k.UnmarshalBinaryWithContext(ctx)
- if errD != nil {
- return errD
- }
- z = k
- // --- [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) ---
- m := buff.ReadInt() // map len
- l := make(map[string]*ResourceQuota, m)
- for j := 0; j < m; j++ {
- var vv string
- var o string
- if ctx.IsStringTable() {
- p := buff.ReadInt() // read string index
- o = ctx.Table[p]
- } else {
- o = buff.ReadString() // read string
- }
- n := o
- vv = n
- var zz *ResourceQuota
- if buff.ReadUInt8() == uint8(0) {
- zz = nil
- } else {
- // --- [begin][read][struct](ResourceQuota) ---
- q := &ResourceQuota{}
- buff.ReadInt() // [compatibility, unused]
- errE := q.UnmarshalBinaryWithContext(ctx)
- if errE != nil {
- return errE
- }
- zz = q
- // --- [end][read][struct](ResourceQuota) ---
- }
- l[vv] = zz
- }
- target.ResourceQuotas = l
- // --- [end][read][map](map[string]*ResourceQuota) ---
- }
- } else {
- target.ResourceQuotas = nil
- }
- return nil
- }
- //--------------------------------------------------------------------------
- // Metadata
- //--------------------------------------------------------------------------
- // MarshalBinary serializes the internal properties of this Metadata instance
- // into a byte array
- func (target *Metadata) MarshalBinary() (data []byte, err error) {
- ctx := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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)) // array length
- for i := 0; i < len(target.Diagnostics); i++ {
- // --- [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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling Metadata. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- a := &time.Time{}
- b := buff.ReadInt() // byte array length
- c := buff.ReadBytes(b) // byte array
- 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 := &time.Time{}
- e := buff.ReadInt() // byte array length
- f := buff.ReadBytes(e) // byte array
- 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) ---
- k := buff.ReadInt() // array len
- h := make([]Diagnostic, k)
- for i := 0; i < k; i++ {
- // --- [begin][read][struct](Diagnostic) ---
- m := &Diagnostic{}
- buff.ReadInt() // [compatibility, unused]
- errC := m.UnmarshalBinaryWithContext(ctx)
- if errC != nil {
- return errC
- }
- l := *m
- // --- [end][read][struct](Diagnostic) ---
- h[i] = l
- }
- target.Diagnostics = h
- // --- [end][read][slice]([]Diagnostic) ---
- }
- } else {
- target.Diagnostics = nil
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][alias](DiagnosticLevel) ---
- var n int
- o := buff.ReadInt() // read int
- n = o
- target.DiagnosticLevel = DiagnosticLevel(n)
- // --- [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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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) ---
- k, errB := target.End.MarshalBinary()
- if errB != nil {
- return errB
- }
- buff.WriteInt(len(k))
- buff.WriteBytes(k)
- // --- [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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling 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[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[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() {
- k := buff.ReadInt() // read string index
- h = ctx.Table[k]
- } 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) ---
- m := buff.ReadInt() // map len
- l := make(map[string]string, m)
- for i := 0; i < m; i++ {
- var v string
- var o string
- if ctx.IsStringTable() {
- p := buff.ReadInt() // read string index
- o = ctx.Table[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[s]
- } else {
- r = buff.ReadString() // read string
- }
- q := r
- z = q
- l[v] = z
- }
- target.Labels = l
- // --- [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) ---
- u := buff.ReadInt() // map len
- t := make(map[string]string, u)
- for j := 0; j < u; j++ {
- var vv string
- var x string
- if ctx.IsStringTable() {
- y := buff.ReadInt() // read string index
- x = ctx.Table[y]
- } else {
- x = buff.ReadString() // read string
- }
- w := x
- vv = w
- var zz string
- var bb string
- if ctx.IsStringTable() {
- cc := buff.ReadInt() // read string index
- bb = ctx.Table[cc]
- } else {
- bb = buff.ReadString() // read string
- }
- aa := bb
- zz = aa
- t[vv] = zz
- }
- target.Annotations = t
- // --- [end][read][map](map[string]string) ---
- }
- } else {
- target.Annotations = nil
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- dd := &time.Time{}
- ee := buff.ReadInt() // byte array length
- ff := buff.ReadBytes(ee) // byte array
- errA := dd.UnmarshalBinary(ff)
- if errA != nil {
- return errA
- }
- target.Start = *dd
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- gg := &time.Time{}
- hh := buff.ReadInt() // byte array length
- kk := buff.ReadBytes(hh) // byte array
- errB := gg.UnmarshalBinary(kk)
- if errB != nil {
- return errB
- }
- target.End = *gg
- // --- [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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling 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[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[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 k map[StatType]float64
- if buff.ReadUInt8() == uint8(0) {
- k = nil
- } else {
- // --- [begin][read][map](map[StatType]float64) ---
- m := buff.ReadInt() // map len
- l := make(map[StatType]float64, m)
- for i := 0; i < m; i++ {
- // --- [begin][read][alias](StatType) ---
- var n string
- var p string
- if ctx.IsStringTable() {
- q := buff.ReadInt() // read string index
- p = ctx.Table[q]
- } else {
- p = buff.ReadString() // read string
- }
- o := p
- n = o
- v := StatType(n)
- // --- [end][read][alias](StatType) ---
- var z float64
- r := buff.ReadFloat64() // read float64
- z = r
- l[v] = z
- }
- k = l
- // --- [end][read][map](map[StatType]float64) ---
- }
- target.Values = Stats(k)
- // --- [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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling 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[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[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() {
- k := buff.ReadInt() // read string index
- h = ctx.Table[k]
- } 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) ---
- l := &ResourceQuotaSpec{}
- buff.ReadInt() // [compatibility, unused]
- errA := l.UnmarshalBinaryWithContext(ctx)
- if errA != nil {
- return errA
- }
- target.Spec = l
- // --- [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) ---
- m := &ResourceQuotaStatus{}
- buff.ReadInt() // [compatibility, unused]
- errB := m.UnmarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- target.Status = m
- // --- [end][read][struct](ResourceQuotaStatus) ---
- }
- } else {
- target.Status = nil
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- n := &time.Time{}
- o := buff.ReadInt() // byte array length
- p := buff.ReadBytes(o) // byte array
- errC := n.UnmarshalBinary(p)
- if errC != nil {
- return errC
- }
- target.Start = *n
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- q := &time.Time{}
- r := buff.ReadInt() // byte array length
- s := buff.ReadBytes(r) // byte array
- errD := q.UnmarshalBinary(s)
- if errD != nil {
- return errD
- }
- target.End = *q
- // --- [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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling 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 := &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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling 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 i := 0; i < c; i++ {
- // --- [begin][read][alias](Resource) ---
- var d string
- var f string
- if ctx.IsStringTable() {
- g := buff.ReadInt() // read string index
- f = ctx.Table[g]
- } else {
- f = buff.ReadString() // read string
- }
- e := f
- d = e
- v := Resource(d)
- // --- [end][read][alias](Resource) ---
- // --- [begin][read][struct](ResourceQuantity) ---
- h := &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 k map[Resource]ResourceQuantity
- if buff.ReadUInt8() == uint8(0) {
- k = nil
- } else {
- // --- [begin][read][map](map[Resource]ResourceQuantity) ---
- m := buff.ReadInt() // map len
- l := make(map[Resource]ResourceQuantity, m)
- for j := 0; j < m; j++ {
- // --- [begin][read][alias](Resource) ---
- var n string
- var p string
- if ctx.IsStringTable() {
- q := buff.ReadInt() // read string index
- p = ctx.Table[q]
- } else {
- p = buff.ReadString() // read string
- }
- o := p
- n = o
- vv := Resource(n)
- // --- [end][read][alias](Resource) ---
- // --- [begin][read][struct](ResourceQuantity) ---
- r := &ResourceQuantity{}
- buff.ReadInt() // [compatibility, unused]
- errB := r.UnmarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- zz := *r
- // --- [end][read][struct](ResourceQuantity) ---
- l[vv] = zz
- }
- k = l
- // --- [end][read][map](map[Resource]ResourceQuantity) ---
- }
- target.Limits = ResourceQuantities(k)
- // --- [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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling 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 := &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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling 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 i := 0; i < c; i++ {
- // --- [begin][read][alias](Resource) ---
- var d string
- var f string
- if ctx.IsStringTable() {
- g := buff.ReadInt() // read string index
- f = ctx.Table[g]
- } else {
- f = buff.ReadString() // read string
- }
- e := f
- d = e
- v := Resource(d)
- // --- [end][read][alias](Resource) ---
- // --- [begin][read][struct](ResourceQuantity) ---
- h := &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 k map[Resource]ResourceQuantity
- if buff.ReadUInt8() == uint8(0) {
- k = nil
- } else {
- // --- [begin][read][map](map[Resource]ResourceQuantity) ---
- m := buff.ReadInt() // map len
- l := make(map[Resource]ResourceQuantity, m)
- for j := 0; j < m; j++ {
- // --- [begin][read][alias](Resource) ---
- var n string
- var p string
- if ctx.IsStringTable() {
- q := buff.ReadInt() // read string index
- p = ctx.Table[q]
- } else {
- p = buff.ReadString() // read string
- }
- o := p
- n = o
- vv := Resource(n)
- // --- [end][read][alias](Resource) ---
- // --- [begin][read][struct](ResourceQuantity) ---
- r := &ResourceQuantity{}
- buff.ReadInt() // [compatibility, unused]
- errB := r.UnmarshalBinaryWithContext(ctx)
- if errB != nil {
- return errB
- }
- zz := *r
- // --- [end][read][struct](ResourceQuantity) ---
- l[vv] = zz
- }
- k = l
- // --- [end][read][map](map[Resource]ResourceQuantity) ---
- }
- target.Limits = ResourceQuantities(k)
- // --- [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 := &EncodingContext{
- Buffer: util.NewBuffer(),
- Table: nil,
- }
- e := target.MarshalBinaryWithContext(ctx)
- if e != nil {
- return nil, e
- }
- encBytes := ctx.Buffer.Bytes()
- return encBytes, nil
- }
- // 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 {
- var table []string
- buff := util.NewBufferFromBytes(data)
- // string table header validation
- if isBinaryTag(data, BinaryTagStringTable) {
- buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
- tl := buff.ReadInt() // table length
- if tl > 0 {
- table = make([]string, tl, tl)
- for i := 0; i < tl; i++ {
- table[i] = buff.ReadString()
- }
- }
- }
- ctx := &DecodingContext{
- Buffer: buff,
- Table: table,
- }
- 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 Unmarshaling Window. Expected %d or less, got %d", DefaultCodecVersion, version)
- }
- // field version check
- if uint8(1) <= version {
- // --- [begin][read][reference](time.Time) ---
- a := &time.Time{}
- b := buff.ReadInt() // byte array length
- c := buff.ReadBytes(b) // byte array
- 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 := &time.Time{}
- e := buff.ReadInt() // byte array length
- f := buff.ReadBytes(e) // byte array
- errB := d.UnmarshalBinary(f)
- if errB != nil {
- return errB
- }
- target.End = *d
- // --- [end][read][reference](time.Time) ---
- } else {
- }
- return nil
- }
|