kubecost_codecs.go 144 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // DO NOT MODIFY
  4. //
  5. // ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻
  6. //
  7. //
  8. // This source file was automatically generated by bingen.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. package kubecost
  12. import (
  13. "fmt"
  14. util "github.com/kubecost/cost-model/pkg/util"
  15. "reflect"
  16. "strings"
  17. "sync"
  18. "time"
  19. )
  20. const (
  21. // GeneratorPackageName is the package the generator is targetting
  22. GeneratorPackageName string = "kubecost"
  23. )
  24. // BinaryTags represent the formatting tag used for specific optimization features
  25. const (
  26. // BinaryTagStringTable is written and/or read prior to the existence of a string
  27. // table (where each index is encoded as a string entry in the resource
  28. BinaryTagStringTable string = "BGST"
  29. )
  30. const (
  31. // DefaultCodecVersion is used for any resources listed in the Default version set
  32. DefaultCodecVersion uint8 = 15
  33. // AssetsCodecVersion is used for any resources listed in the Assets version set
  34. AssetsCodecVersion uint8 = 15
  35. // AllocationCodecVersion is used for any resources listed in the Allocation version set
  36. AllocationCodecVersion uint8 = 15
  37. )
  38. //--------------------------------------------------------------------------
  39. // Type Map
  40. //--------------------------------------------------------------------------
  41. // Generated type map for resolving interface implementations to
  42. // to concrete types
  43. var typeMap map[string]reflect.Type = map[string]reflect.Type{
  44. "Allocation": reflect.TypeOf((*Allocation)(nil)).Elem(),
  45. "AllocationProperties": reflect.TypeOf((*AllocationProperties)(nil)).Elem(),
  46. "AllocationSet": reflect.TypeOf((*AllocationSet)(nil)).Elem(),
  47. "AllocationSetRange": reflect.TypeOf((*AllocationSetRange)(nil)).Elem(),
  48. "Any": reflect.TypeOf((*Any)(nil)).Elem(),
  49. "AssetProperties": reflect.TypeOf((*AssetProperties)(nil)).Elem(),
  50. "AssetSet": reflect.TypeOf((*AssetSet)(nil)).Elem(),
  51. "AssetSetRange": reflect.TypeOf((*AssetSetRange)(nil)).Elem(),
  52. "Breakdown": reflect.TypeOf((*Breakdown)(nil)).Elem(),
  53. "Cloud": reflect.TypeOf((*Cloud)(nil)).Elem(),
  54. "ClusterManagement": reflect.TypeOf((*ClusterManagement)(nil)).Elem(),
  55. "Disk": reflect.TypeOf((*Disk)(nil)).Elem(),
  56. "LoadBalancer": reflect.TypeOf((*LoadBalancer)(nil)).Elem(),
  57. "Network": reflect.TypeOf((*Network)(nil)).Elem(),
  58. "Node": reflect.TypeOf((*Node)(nil)).Elem(),
  59. "PVAllocation": reflect.TypeOf((*PVAllocation)(nil)).Elem(),
  60. "PVKey": reflect.TypeOf((*PVKey)(nil)).Elem(),
  61. "RawAllocationOnlyData": reflect.TypeOf((*RawAllocationOnlyData)(nil)).Elem(),
  62. "SharedAsset": reflect.TypeOf((*SharedAsset)(nil)).Elem(),
  63. "Window": reflect.TypeOf((*Window)(nil)).Elem(),
  64. }
  65. //--------------------------------------------------------------------------
  66. // Type Helpers
  67. //--------------------------------------------------------------------------
  68. // isBinaryTag returns true when the first bytes in the provided binary matches the tag
  69. func isBinaryTag(data []byte, tag string) bool {
  70. return string(data[:len(tag)]) == tag
  71. }
  72. // appendBytes combines a and b into a new byte array
  73. func appendBytes(a []byte, b []byte) []byte {
  74. al := len(a)
  75. bl := len(b)
  76. tl := al + bl
  77. // allocate a new byte array for the combined
  78. // use native copy for speedy byte copying
  79. result := make([]byte, tl, tl)
  80. copy(result, a)
  81. copy(result[al:], b)
  82. return result
  83. }
  84. // typeToString determines the basic properties of the type, the qualifier, package path, and
  85. // type name, and returns the qualified type
  86. func typeToString(f interface{}) string {
  87. qual := ""
  88. t := reflect.TypeOf(f)
  89. if t.Kind() == reflect.Ptr {
  90. t = t.Elem()
  91. qual = "*"
  92. }
  93. return fmt.Sprintf("%s%s.%s", qual, t.PkgPath(), t.Name())
  94. }
  95. // resolveType uses the name of a type and returns the package, base type name, and whether
  96. // or not it's a pointer.
  97. func resolveType(t string) (pkg string, name string, isPtr bool) {
  98. isPtr = t[:1] == "*"
  99. if isPtr {
  100. t = t[1:]
  101. }
  102. slashIndex := strings.LastIndex(t, "/")
  103. if slashIndex >= 0 {
  104. t = t[slashIndex+1:]
  105. }
  106. parts := strings.Split(t, ".")
  107. if parts[0] == GeneratorPackageName {
  108. parts[0] = ""
  109. }
  110. pkg = parts[0]
  111. name = parts[1]
  112. return
  113. }
  114. //--------------------------------------------------------------------------
  115. // StringTable
  116. //--------------------------------------------------------------------------
  117. // StringTable maps strings to specific indices for encoding
  118. type StringTable struct {
  119. l *sync.Mutex
  120. indices map[string]int
  121. next int
  122. }
  123. // NewStringTable Creates a new StringTable instance with provided contents
  124. func NewStringTable(contents ...string) *StringTable {
  125. st := &StringTable{
  126. l: new(sync.Mutex),
  127. indices: make(map[string]int),
  128. next: len(contents),
  129. }
  130. for i, entry := range contents {
  131. st.indices[entry] = i
  132. }
  133. return st
  134. }
  135. // AddOrGet atomically retrieves a string entry's index if it exist. Otherwise, it will
  136. // add the entry and return the index.
  137. func (st *StringTable) AddOrGet(s string) int {
  138. st.l.Lock()
  139. defer st.l.Unlock()
  140. if ind, ok := st.indices[s]; ok {
  141. return ind
  142. }
  143. current := st.next
  144. st.next++
  145. st.indices[s] = current
  146. return current
  147. }
  148. // ToSlice Converts the contents to a string array for encoding.
  149. func (st *StringTable) ToSlice() []string {
  150. st.l.Lock()
  151. defer st.l.Unlock()
  152. if st.next == 0 {
  153. return []string{}
  154. }
  155. sl := make([]string, st.next, st.next)
  156. for s, i := range st.indices {
  157. sl[i] = s
  158. }
  159. return sl
  160. }
  161. // ToBytes Converts the contents to a binary encoded representation
  162. func (st *StringTable) ToBytes() []byte {
  163. buff := util.NewBuffer()
  164. buff.WriteBytes([]byte(BinaryTagStringTable)) // bingen table header
  165. strs := st.ToSlice()
  166. buff.WriteInt(len(strs)) // table length
  167. for _, s := range strs {
  168. buff.WriteString(s)
  169. }
  170. return buff.Bytes()
  171. }
  172. //--------------------------------------------------------------------------
  173. // Codec Context
  174. //--------------------------------------------------------------------------
  175. // EncodingContext is a context object passed to the encoders to ensure reuse of buffer
  176. // and table data
  177. type EncodingContext struct {
  178. Buffer *util.Buffer
  179. Table *StringTable
  180. }
  181. // IsStringTable returns true if the table is available
  182. func (ec *EncodingContext) IsStringTable() bool {
  183. return ec.Table != nil
  184. }
  185. // DecodingContext is a context object passed to the decoders to ensure parent objects
  186. // reuse as much data as possible
  187. type DecodingContext struct {
  188. Buffer *util.Buffer
  189. Table []string
  190. }
  191. // IsStringTable returns true if the table is available
  192. func (dc *DecodingContext) IsStringTable() bool {
  193. return len(dc.Table) > 0
  194. }
  195. //--------------------------------------------------------------------------
  196. // Binary Codec
  197. //--------------------------------------------------------------------------
  198. // BinEncoder is an encoding interface which defines a context based marshal contract.
  199. type BinEncoder interface {
  200. MarshalBinaryWithContext(*EncodingContext) error
  201. }
  202. // BinDecoder is a decoding interface which defines a context based unmarshal contract.
  203. type BinDecoder interface {
  204. UnmarshalBinaryWithContext(*DecodingContext) error
  205. }
  206. //--------------------------------------------------------------------------
  207. // Allocation
  208. //--------------------------------------------------------------------------
  209. // MarshalBinary serializes the internal properties of this Allocation instance
  210. // into a byte array
  211. func (target *Allocation) MarshalBinary() (data []byte, err error) {
  212. ctx := &EncodingContext{
  213. Buffer: util.NewBuffer(),
  214. Table: nil,
  215. }
  216. e := target.MarshalBinaryWithContext(ctx)
  217. if e != nil {
  218. return nil, e
  219. }
  220. encBytes := ctx.Buffer.Bytes()
  221. return encBytes, nil
  222. }
  223. // MarshalBinaryWithContext serializes the internal properties of this Allocation instance
  224. // into a byte array leveraging a predefined context.
  225. func (target *Allocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  226. // panics are recovered and propagated as errors
  227. defer func() {
  228. if r := recover(); r != nil {
  229. if e, ok := r.(error); ok {
  230. err = e
  231. } else if s, ok := r.(string); ok {
  232. err = fmt.Errorf("Unexpected panic: %s", s)
  233. } else {
  234. err = fmt.Errorf("Unexpected panic: %+v", r)
  235. }
  236. }
  237. }()
  238. buff := ctx.Buffer
  239. buff.WriteUInt8(AllocationCodecVersion) // version
  240. if ctx.IsStringTable() {
  241. a := ctx.Table.AddOrGet(target.Name)
  242. buff.WriteInt(a) // write table index
  243. } else {
  244. buff.WriteString(target.Name) // write string
  245. }
  246. if target.Properties == nil {
  247. buff.WriteUInt8(uint8(0)) // write nil byte
  248. } else {
  249. buff.WriteUInt8(uint8(1)) // write non-nil byte
  250. // --- [begin][write][struct](AllocationProperties) ---
  251. buff.WriteInt(0) // [compatibility, unused]
  252. errA := target.Properties.MarshalBinaryWithContext(ctx)
  253. if errA != nil {
  254. return errA
  255. }
  256. // --- [end][write][struct](AllocationProperties) ---
  257. }
  258. // --- [begin][write][struct](Window) ---
  259. buff.WriteInt(0) // [compatibility, unused]
  260. errB := target.Window.MarshalBinaryWithContext(ctx)
  261. if errB != nil {
  262. return errB
  263. }
  264. // --- [end][write][struct](Window) ---
  265. // --- [begin][write][reference](time.Time) ---
  266. b, errC := target.Start.MarshalBinary()
  267. if errC != nil {
  268. return errC
  269. }
  270. buff.WriteInt(len(b))
  271. buff.WriteBytes(b)
  272. // --- [end][write][reference](time.Time) ---
  273. // --- [begin][write][reference](time.Time) ---
  274. c, errD := target.End.MarshalBinary()
  275. if errD != nil {
  276. return errD
  277. }
  278. buff.WriteInt(len(c))
  279. buff.WriteBytes(c)
  280. // --- [end][write][reference](time.Time) ---
  281. buff.WriteFloat64(target.CPUCoreHours) // write float64
  282. buff.WriteFloat64(target.CPUCoreRequestAverage) // write float64
  283. buff.WriteFloat64(target.CPUCoreUsageAverage) // write float64
  284. buff.WriteFloat64(target.CPUCost) // write float64
  285. buff.WriteFloat64(target.CPUCostAdjustment) // write float64
  286. buff.WriteFloat64(target.GPUHours) // write float64
  287. buff.WriteFloat64(target.GPUCost) // write float64
  288. buff.WriteFloat64(target.GPUCostAdjustment) // write float64
  289. buff.WriteFloat64(target.NetworkTransferBytes) // write float64
  290. buff.WriteFloat64(target.NetworkReceiveBytes) // write float64
  291. buff.WriteFloat64(target.NetworkCost) // write float64
  292. buff.WriteFloat64(target.NetworkCostAdjustment) // write float64
  293. buff.WriteFloat64(target.LoadBalancerCost) // write float64
  294. buff.WriteFloat64(target.LoadBalancerCostAdjustment) // write float64
  295. // --- [begin][write][alias](PVAllocations) ---
  296. if map[PVKey]*PVAllocation(target.PVs) == nil {
  297. buff.WriteUInt8(uint8(0)) // write nil byte
  298. } else {
  299. buff.WriteUInt8(uint8(1)) // write non-nil byte
  300. // --- [begin][write][map](map[PVKey]*PVAllocation) ---
  301. buff.WriteInt(len(map[PVKey]*PVAllocation(target.PVs))) // map length
  302. for v, z := range map[PVKey]*PVAllocation(target.PVs) {
  303. // --- [begin][write][struct](PVKey) ---
  304. buff.WriteInt(0) // [compatibility, unused]
  305. errE := v.MarshalBinaryWithContext(ctx)
  306. if errE != nil {
  307. return errE
  308. }
  309. // --- [end][write][struct](PVKey) ---
  310. if z == nil {
  311. buff.WriteUInt8(uint8(0)) // write nil byte
  312. } else {
  313. buff.WriteUInt8(uint8(1)) // write non-nil byte
  314. // --- [begin][write][struct](PVAllocation) ---
  315. buff.WriteInt(0) // [compatibility, unused]
  316. errF := z.MarshalBinaryWithContext(ctx)
  317. if errF != nil {
  318. return errF
  319. }
  320. // --- [end][write][struct](PVAllocation) ---
  321. }
  322. }
  323. // --- [end][write][map](map[PVKey]*PVAllocation) ---
  324. }
  325. // --- [end][write][alias](PVAllocations) ---
  326. buff.WriteFloat64(target.PVCostAdjustment) // write float64
  327. buff.WriteFloat64(target.RAMByteHours) // write float64
  328. buff.WriteFloat64(target.RAMBytesRequestAverage) // write float64
  329. buff.WriteFloat64(target.RAMBytesUsageAverage) // write float64
  330. buff.WriteFloat64(target.RAMCost) // write float64
  331. buff.WriteFloat64(target.RAMCostAdjustment) // write float64
  332. buff.WriteFloat64(target.SharedCost) // write float64
  333. buff.WriteFloat64(target.ExternalCost) // write float64
  334. if target.RawAllocationOnly == nil {
  335. buff.WriteUInt8(uint8(0)) // write nil byte
  336. } else {
  337. buff.WriteUInt8(uint8(1)) // write non-nil byte
  338. // --- [begin][write][struct](RawAllocationOnlyData) ---
  339. buff.WriteInt(0) // [compatibility, unused]
  340. errG := target.RawAllocationOnly.MarshalBinaryWithContext(ctx)
  341. if errG != nil {
  342. return errG
  343. }
  344. // --- [end][write][struct](RawAllocationOnlyData) ---
  345. }
  346. return nil
  347. }
  348. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  349. // the Allocation type
  350. func (target *Allocation) UnmarshalBinary(data []byte) error {
  351. var table []string
  352. buff := util.NewBufferFromBytes(data)
  353. // string table header validation
  354. if isBinaryTag(data, BinaryTagStringTable) {
  355. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  356. tl := buff.ReadInt() // table length
  357. if tl > 0 {
  358. table = make([]string, tl, tl)
  359. for i := 0; i < tl; i++ {
  360. table[i] = buff.ReadString()
  361. }
  362. }
  363. }
  364. ctx := &DecodingContext{
  365. Buffer: buff,
  366. Table: table,
  367. }
  368. err := target.UnmarshalBinaryWithContext(ctx)
  369. if err != nil {
  370. return err
  371. }
  372. return nil
  373. }
  374. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  375. // the Allocation type
  376. func (target *Allocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  377. // panics are recovered and propagated as errors
  378. defer func() {
  379. if r := recover(); r != nil {
  380. if e, ok := r.(error); ok {
  381. err = e
  382. } else if s, ok := r.(string); ok {
  383. err = fmt.Errorf("Unexpected panic: %s", s)
  384. } else {
  385. err = fmt.Errorf("Unexpected panic: %+v", r)
  386. }
  387. }
  388. }()
  389. buff := ctx.Buffer
  390. version := buff.ReadUInt8()
  391. if version > AllocationCodecVersion {
  392. return fmt.Errorf("Invalid Version Unmarshaling Allocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  393. }
  394. if uint8(0) /* field version */ <= version {
  395. var b string
  396. if ctx.IsStringTable() {
  397. c := buff.ReadInt() // read string index
  398. b = ctx.Table[c]
  399. } else {
  400. b = buff.ReadString() // read string
  401. }
  402. a := b
  403. target.Name = a
  404. } else {
  405. target.Name = "" // default
  406. }
  407. if uint8(0) /* field version */ <= version {
  408. if buff.ReadUInt8() == uint8(0) {
  409. target.Properties = nil
  410. } else {
  411. // --- [begin][read][struct](AllocationProperties) ---
  412. d := &AllocationProperties{}
  413. buff.ReadInt() // [compatibility, unused]
  414. errA := d.UnmarshalBinaryWithContext(ctx)
  415. if errA != nil {
  416. return errA
  417. }
  418. target.Properties = d
  419. // --- [end][read][struct](AllocationProperties) ---
  420. }
  421. } else {
  422. target.Properties = nil
  423. }
  424. if uint8(0) /* field version */ <= version {
  425. // --- [begin][read][struct](Window) ---
  426. e := &Window{}
  427. buff.ReadInt() // [compatibility, unused]
  428. errB := e.UnmarshalBinaryWithContext(ctx)
  429. if errB != nil {
  430. return errB
  431. }
  432. target.Window = *e
  433. // --- [end][read][struct](Window) ---
  434. } else {
  435. }
  436. if uint8(0) /* field version */ <= version {
  437. // --- [begin][read][reference](time.Time) ---
  438. f := &time.Time{}
  439. g := buff.ReadInt() // byte array length
  440. h := buff.ReadBytes(g) // byte array
  441. errC := f.UnmarshalBinary(h)
  442. if errC != nil {
  443. return errC
  444. }
  445. target.Start = *f
  446. // --- [end][read][reference](time.Time) ---
  447. } else {
  448. }
  449. if uint8(0) /* field version */ <= version {
  450. // --- [begin][read][reference](time.Time) ---
  451. k := &time.Time{}
  452. l := buff.ReadInt() // byte array length
  453. m := buff.ReadBytes(l) // byte array
  454. errD := k.UnmarshalBinary(m)
  455. if errD != nil {
  456. return errD
  457. }
  458. target.End = *k
  459. // --- [end][read][reference](time.Time) ---
  460. } else {
  461. }
  462. if uint8(0) /* field version */ <= version {
  463. n := buff.ReadFloat64() // read float64
  464. target.CPUCoreHours = n
  465. } else {
  466. target.CPUCoreHours = float64(0) // default
  467. }
  468. if uint8(0) /* field version */ <= version {
  469. o := buff.ReadFloat64() // read float64
  470. target.CPUCoreRequestAverage = o
  471. } else {
  472. target.CPUCoreRequestAverage = float64(0) // default
  473. }
  474. if uint8(0) /* field version */ <= version {
  475. p := buff.ReadFloat64() // read float64
  476. target.CPUCoreUsageAverage = p
  477. } else {
  478. target.CPUCoreUsageAverage = float64(0) // default
  479. }
  480. if uint8(0) /* field version */ <= version {
  481. q := buff.ReadFloat64() // read float64
  482. target.CPUCost = q
  483. } else {
  484. target.CPUCost = float64(0) // default
  485. }
  486. if uint8(0) /* field version */ <= version {
  487. r := buff.ReadFloat64() // read float64
  488. target.CPUCostAdjustment = r
  489. } else {
  490. target.CPUCostAdjustment = float64(0) // default
  491. }
  492. if uint8(0) /* field version */ <= version {
  493. s := buff.ReadFloat64() // read float64
  494. target.GPUHours = s
  495. } else {
  496. target.GPUHours = float64(0) // default
  497. }
  498. if uint8(0) /* field version */ <= version {
  499. t := buff.ReadFloat64() // read float64
  500. target.GPUCost = t
  501. } else {
  502. target.GPUCost = float64(0) // default
  503. }
  504. if uint8(0) /* field version */ <= version {
  505. u := buff.ReadFloat64() // read float64
  506. target.GPUCostAdjustment = u
  507. } else {
  508. target.GPUCostAdjustment = float64(0) // default
  509. }
  510. if uint8(0) /* field version */ <= version {
  511. w := buff.ReadFloat64() // read float64
  512. target.NetworkTransferBytes = w
  513. } else {
  514. target.NetworkTransferBytes = float64(0) // default
  515. }
  516. if uint8(0) /* field version */ <= version {
  517. x := buff.ReadFloat64() // read float64
  518. target.NetworkReceiveBytes = x
  519. } else {
  520. target.NetworkReceiveBytes = float64(0) // default
  521. }
  522. if uint8(0) /* field version */ <= version {
  523. y := buff.ReadFloat64() // read float64
  524. target.NetworkCost = y
  525. } else {
  526. target.NetworkCost = float64(0) // default
  527. }
  528. if uint8(0) /* field version */ <= version {
  529. aa := buff.ReadFloat64() // read float64
  530. target.NetworkCostAdjustment = aa
  531. } else {
  532. target.NetworkCostAdjustment = float64(0) // default
  533. }
  534. if uint8(0) /* field version */ <= version {
  535. bb := buff.ReadFloat64() // read float64
  536. target.LoadBalancerCost = bb
  537. } else {
  538. target.LoadBalancerCost = float64(0) // default
  539. }
  540. if uint8(0) /* field version */ <= version {
  541. cc := buff.ReadFloat64() // read float64
  542. target.LoadBalancerCostAdjustment = cc
  543. } else {
  544. target.LoadBalancerCostAdjustment = float64(0) // default
  545. }
  546. if uint8(0) /* field version */ <= version {
  547. // --- [begin][read][alias](PVAllocations) ---
  548. var dd map[PVKey]*PVAllocation
  549. if buff.ReadUInt8() == uint8(0) {
  550. dd = nil
  551. } else {
  552. // --- [begin][read][map](map[PVKey]*PVAllocation) ---
  553. ff := buff.ReadInt() // map len
  554. ee := make(map[PVKey]*PVAllocation, ff)
  555. for i := 0; i < ff; i++ {
  556. // --- [begin][read][struct](PVKey) ---
  557. gg := &PVKey{}
  558. buff.ReadInt() // [compatibility, unused]
  559. errE := gg.UnmarshalBinaryWithContext(ctx)
  560. if errE != nil {
  561. return errE
  562. }
  563. v := *gg
  564. // --- [end][read][struct](PVKey) ---
  565. var z *PVAllocation
  566. if buff.ReadUInt8() == uint8(0) {
  567. z = nil
  568. } else {
  569. // --- [begin][read][struct](PVAllocation) ---
  570. hh := &PVAllocation{}
  571. buff.ReadInt() // [compatibility, unused]
  572. errF := hh.UnmarshalBinaryWithContext(ctx)
  573. if errF != nil {
  574. return errF
  575. }
  576. z = hh
  577. // --- [end][read][struct](PVAllocation) ---
  578. }
  579. ee[v] = z
  580. }
  581. dd = ee
  582. // --- [end][read][map](map[PVKey]*PVAllocation) ---
  583. }
  584. target.PVs = PVAllocations(dd)
  585. // --- [end][read][alias](PVAllocations) ---
  586. } else {
  587. }
  588. if uint8(0) /* field version */ <= version {
  589. kk := buff.ReadFloat64() // read float64
  590. target.PVCostAdjustment = kk
  591. } else {
  592. target.PVCostAdjustment = float64(0) // default
  593. }
  594. if uint8(0) /* field version */ <= version {
  595. ll := buff.ReadFloat64() // read float64
  596. target.RAMByteHours = ll
  597. } else {
  598. target.RAMByteHours = float64(0) // default
  599. }
  600. if uint8(0) /* field version */ <= version {
  601. mm := buff.ReadFloat64() // read float64
  602. target.RAMBytesRequestAverage = mm
  603. } else {
  604. target.RAMBytesRequestAverage = float64(0) // default
  605. }
  606. if uint8(0) /* field version */ <= version {
  607. nn := buff.ReadFloat64() // read float64
  608. target.RAMBytesUsageAverage = nn
  609. } else {
  610. target.RAMBytesUsageAverage = float64(0) // default
  611. }
  612. if uint8(0) /* field version */ <= version {
  613. oo := buff.ReadFloat64() // read float64
  614. target.RAMCost = oo
  615. } else {
  616. target.RAMCost = float64(0) // default
  617. }
  618. if uint8(0) /* field version */ <= version {
  619. pp := buff.ReadFloat64() // read float64
  620. target.RAMCostAdjustment = pp
  621. } else {
  622. target.RAMCostAdjustment = float64(0) // default
  623. }
  624. if uint8(0) /* field version */ <= version {
  625. qq := buff.ReadFloat64() // read float64
  626. target.SharedCost = qq
  627. } else {
  628. target.SharedCost = float64(0) // default
  629. }
  630. if uint8(0) /* field version */ <= version {
  631. rr := buff.ReadFloat64() // read float64
  632. target.ExternalCost = rr
  633. } else {
  634. target.ExternalCost = float64(0) // default
  635. }
  636. if uint8(0) /* field version */ <= version {
  637. if buff.ReadUInt8() == uint8(0) {
  638. target.RawAllocationOnly = nil
  639. } else {
  640. // --- [begin][read][struct](RawAllocationOnlyData) ---
  641. ss := &RawAllocationOnlyData{}
  642. buff.ReadInt() // [compatibility, unused]
  643. errG := ss.UnmarshalBinaryWithContext(ctx)
  644. if errG != nil {
  645. return errG
  646. }
  647. target.RawAllocationOnly = ss
  648. // --- [end][read][struct](RawAllocationOnlyData) ---
  649. }
  650. } else {
  651. target.RawAllocationOnly = nil
  652. }
  653. return nil
  654. }
  655. //--------------------------------------------------------------------------
  656. // AllocationProperties
  657. //--------------------------------------------------------------------------
  658. // MarshalBinary serializes the internal properties of this AllocationProperties instance
  659. // into a byte array
  660. func (target *AllocationProperties) MarshalBinary() (data []byte, err error) {
  661. ctx := &EncodingContext{
  662. Buffer: util.NewBuffer(),
  663. Table: nil,
  664. }
  665. e := target.MarshalBinaryWithContext(ctx)
  666. if e != nil {
  667. return nil, e
  668. }
  669. encBytes := ctx.Buffer.Bytes()
  670. return encBytes, nil
  671. }
  672. // MarshalBinaryWithContext serializes the internal properties of this AllocationProperties instance
  673. // into a byte array leveraging a predefined context.
  674. func (target *AllocationProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  675. // panics are recovered and propagated as errors
  676. defer func() {
  677. if r := recover(); r != nil {
  678. if e, ok := r.(error); ok {
  679. err = e
  680. } else if s, ok := r.(string); ok {
  681. err = fmt.Errorf("Unexpected panic: %s", s)
  682. } else {
  683. err = fmt.Errorf("Unexpected panic: %+v", r)
  684. }
  685. }
  686. }()
  687. buff := ctx.Buffer
  688. buff.WriteUInt8(AllocationCodecVersion) // version
  689. if ctx.IsStringTable() {
  690. a := ctx.Table.AddOrGet(target.Cluster)
  691. buff.WriteInt(a) // write table index
  692. } else {
  693. buff.WriteString(target.Cluster) // write string
  694. }
  695. if ctx.IsStringTable() {
  696. b := ctx.Table.AddOrGet(target.Node)
  697. buff.WriteInt(b) // write table index
  698. } else {
  699. buff.WriteString(target.Node) // write string
  700. }
  701. if ctx.IsStringTable() {
  702. c := ctx.Table.AddOrGet(target.Container)
  703. buff.WriteInt(c) // write table index
  704. } else {
  705. buff.WriteString(target.Container) // write string
  706. }
  707. if ctx.IsStringTable() {
  708. d := ctx.Table.AddOrGet(target.Controller)
  709. buff.WriteInt(d) // write table index
  710. } else {
  711. buff.WriteString(target.Controller) // write string
  712. }
  713. if ctx.IsStringTable() {
  714. e := ctx.Table.AddOrGet(target.ControllerKind)
  715. buff.WriteInt(e) // write table index
  716. } else {
  717. buff.WriteString(target.ControllerKind) // write string
  718. }
  719. if ctx.IsStringTable() {
  720. f := ctx.Table.AddOrGet(target.Namespace)
  721. buff.WriteInt(f) // write table index
  722. } else {
  723. buff.WriteString(target.Namespace) // write string
  724. }
  725. if ctx.IsStringTable() {
  726. g := ctx.Table.AddOrGet(target.Pod)
  727. buff.WriteInt(g) // write table index
  728. } else {
  729. buff.WriteString(target.Pod) // write string
  730. }
  731. if target.Services == nil {
  732. buff.WriteUInt8(uint8(0)) // write nil byte
  733. } else {
  734. buff.WriteUInt8(uint8(1)) // write non-nil byte
  735. // --- [begin][write][slice]([]string) ---
  736. buff.WriteInt(len(target.Services)) // array length
  737. for i := 0; i < len(target.Services); i++ {
  738. if ctx.IsStringTable() {
  739. h := ctx.Table.AddOrGet(target.Services[i])
  740. buff.WriteInt(h) // write table index
  741. } else {
  742. buff.WriteString(target.Services[i]) // write string
  743. }
  744. }
  745. // --- [end][write][slice]([]string) ---
  746. }
  747. if ctx.IsStringTable() {
  748. k := ctx.Table.AddOrGet(target.ProviderID)
  749. buff.WriteInt(k) // write table index
  750. } else {
  751. buff.WriteString(target.ProviderID) // write string
  752. }
  753. // --- [begin][write][alias](AllocationLabels) ---
  754. if map[string]string(target.Labels) == nil {
  755. buff.WriteUInt8(uint8(0)) // write nil byte
  756. } else {
  757. buff.WriteUInt8(uint8(1)) // write non-nil byte
  758. // --- [begin][write][map](map[string]string) ---
  759. buff.WriteInt(len(map[string]string(target.Labels))) // map length
  760. for v, z := range map[string]string(target.Labels) {
  761. if ctx.IsStringTable() {
  762. l := ctx.Table.AddOrGet(v)
  763. buff.WriteInt(l) // write table index
  764. } else {
  765. buff.WriteString(v) // write string
  766. }
  767. if ctx.IsStringTable() {
  768. m := ctx.Table.AddOrGet(z)
  769. buff.WriteInt(m) // write table index
  770. } else {
  771. buff.WriteString(z) // write string
  772. }
  773. }
  774. // --- [end][write][map](map[string]string) ---
  775. }
  776. // --- [end][write][alias](AllocationLabels) ---
  777. // --- [begin][write][alias](AllocationAnnotations) ---
  778. if map[string]string(target.Annotations) == nil {
  779. buff.WriteUInt8(uint8(0)) // write nil byte
  780. } else {
  781. buff.WriteUInt8(uint8(1)) // write non-nil byte
  782. // --- [begin][write][map](map[string]string) ---
  783. buff.WriteInt(len(map[string]string(target.Annotations))) // map length
  784. for vv, zz := range map[string]string(target.Annotations) {
  785. if ctx.IsStringTable() {
  786. n := ctx.Table.AddOrGet(vv)
  787. buff.WriteInt(n) // write table index
  788. } else {
  789. buff.WriteString(vv) // write string
  790. }
  791. if ctx.IsStringTable() {
  792. o := ctx.Table.AddOrGet(zz)
  793. buff.WriteInt(o) // write table index
  794. } else {
  795. buff.WriteString(zz) // write string
  796. }
  797. }
  798. // --- [end][write][map](map[string]string) ---
  799. }
  800. // --- [end][write][alias](AllocationAnnotations) ---
  801. return nil
  802. }
  803. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  804. // the AllocationProperties type
  805. func (target *AllocationProperties) UnmarshalBinary(data []byte) error {
  806. var table []string
  807. buff := util.NewBufferFromBytes(data)
  808. // string table header validation
  809. if isBinaryTag(data, BinaryTagStringTable) {
  810. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  811. tl := buff.ReadInt() // table length
  812. if tl > 0 {
  813. table = make([]string, tl, tl)
  814. for i := 0; i < tl; i++ {
  815. table[i] = buff.ReadString()
  816. }
  817. }
  818. }
  819. ctx := &DecodingContext{
  820. Buffer: buff,
  821. Table: table,
  822. }
  823. err := target.UnmarshalBinaryWithContext(ctx)
  824. if err != nil {
  825. return err
  826. }
  827. return nil
  828. }
  829. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  830. // the AllocationProperties type
  831. func (target *AllocationProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  832. // panics are recovered and propagated as errors
  833. defer func() {
  834. if r := recover(); r != nil {
  835. if e, ok := r.(error); ok {
  836. err = e
  837. } else if s, ok := r.(string); ok {
  838. err = fmt.Errorf("Unexpected panic: %s", s)
  839. } else {
  840. err = fmt.Errorf("Unexpected panic: %+v", r)
  841. }
  842. }
  843. }()
  844. buff := ctx.Buffer
  845. version := buff.ReadUInt8()
  846. if version > AllocationCodecVersion {
  847. return fmt.Errorf("Invalid Version Unmarshaling AllocationProperties. Expected %d or less, got %d", AllocationCodecVersion, version)
  848. }
  849. if uint8(0) /* field version */ <= version {
  850. var b string
  851. if ctx.IsStringTable() {
  852. c := buff.ReadInt() // read string index
  853. b = ctx.Table[c]
  854. } else {
  855. b = buff.ReadString() // read string
  856. }
  857. a := b
  858. target.Cluster = a
  859. } else {
  860. target.Cluster = "" // default
  861. }
  862. if uint8(0) /* field version */ <= version {
  863. var e string
  864. if ctx.IsStringTable() {
  865. f := buff.ReadInt() // read string index
  866. e = ctx.Table[f]
  867. } else {
  868. e = buff.ReadString() // read string
  869. }
  870. d := e
  871. target.Node = d
  872. } else {
  873. target.Node = "" // default
  874. }
  875. if uint8(0) /* field version */ <= version {
  876. var h string
  877. if ctx.IsStringTable() {
  878. k := buff.ReadInt() // read string index
  879. h = ctx.Table[k]
  880. } else {
  881. h = buff.ReadString() // read string
  882. }
  883. g := h
  884. target.Container = g
  885. } else {
  886. target.Container = "" // default
  887. }
  888. if uint8(0) /* field version */ <= version {
  889. var m string
  890. if ctx.IsStringTable() {
  891. n := buff.ReadInt() // read string index
  892. m = ctx.Table[n]
  893. } else {
  894. m = buff.ReadString() // read string
  895. }
  896. l := m
  897. target.Controller = l
  898. } else {
  899. target.Controller = "" // default
  900. }
  901. if uint8(0) /* field version */ <= version {
  902. var p string
  903. if ctx.IsStringTable() {
  904. q := buff.ReadInt() // read string index
  905. p = ctx.Table[q]
  906. } else {
  907. p = buff.ReadString() // read string
  908. }
  909. o := p
  910. target.ControllerKind = o
  911. } else {
  912. target.ControllerKind = "" // default
  913. }
  914. if uint8(0) /* field version */ <= version {
  915. var s string
  916. if ctx.IsStringTable() {
  917. t := buff.ReadInt() // read string index
  918. s = ctx.Table[t]
  919. } else {
  920. s = buff.ReadString() // read string
  921. }
  922. r := s
  923. target.Namespace = r
  924. } else {
  925. target.Namespace = "" // default
  926. }
  927. if uint8(0) /* field version */ <= version {
  928. var w string
  929. if ctx.IsStringTable() {
  930. x := buff.ReadInt() // read string index
  931. w = ctx.Table[x]
  932. } else {
  933. w = buff.ReadString() // read string
  934. }
  935. u := w
  936. target.Pod = u
  937. } else {
  938. target.Pod = "" // default
  939. }
  940. if uint8(0) /* field version */ <= version {
  941. if buff.ReadUInt8() == uint8(0) {
  942. target.Services = nil
  943. } else {
  944. // --- [begin][read][slice]([]string) ---
  945. aa := buff.ReadInt() // array len
  946. y := make([]string, aa)
  947. for i := 0; i < aa; i++ {
  948. var bb string
  949. var dd string
  950. if ctx.IsStringTable() {
  951. ee := buff.ReadInt() // read string index
  952. dd = ctx.Table[ee]
  953. } else {
  954. dd = buff.ReadString() // read string
  955. }
  956. cc := dd
  957. bb = cc
  958. y[i] = bb
  959. }
  960. target.Services = y
  961. // --- [end][read][slice]([]string) ---
  962. }
  963. } else {
  964. target.Services = nil
  965. }
  966. if uint8(0) /* field version */ <= version {
  967. var gg string
  968. if ctx.IsStringTable() {
  969. hh := buff.ReadInt() // read string index
  970. gg = ctx.Table[hh]
  971. } else {
  972. gg = buff.ReadString() // read string
  973. }
  974. ff := gg
  975. target.ProviderID = ff
  976. } else {
  977. target.ProviderID = "" // default
  978. }
  979. if uint8(0) /* field version */ <= version {
  980. // --- [begin][read][alias](AllocationLabels) ---
  981. var kk map[string]string
  982. if buff.ReadUInt8() == uint8(0) {
  983. kk = nil
  984. } else {
  985. // --- [begin][read][map](map[string]string) ---
  986. mm := buff.ReadInt() // map len
  987. ll := make(map[string]string, mm)
  988. for j := 0; j < mm; j++ {
  989. var v string
  990. var oo string
  991. if ctx.IsStringTable() {
  992. pp := buff.ReadInt() // read string index
  993. oo = ctx.Table[pp]
  994. } else {
  995. oo = buff.ReadString() // read string
  996. }
  997. nn := oo
  998. v = nn
  999. var z string
  1000. var rr string
  1001. if ctx.IsStringTable() {
  1002. ss := buff.ReadInt() // read string index
  1003. rr = ctx.Table[ss]
  1004. } else {
  1005. rr = buff.ReadString() // read string
  1006. }
  1007. qq := rr
  1008. z = qq
  1009. ll[v] = z
  1010. }
  1011. kk = ll
  1012. // --- [end][read][map](map[string]string) ---
  1013. }
  1014. target.Labels = AllocationLabels(kk)
  1015. // --- [end][read][alias](AllocationLabels) ---
  1016. } else {
  1017. }
  1018. if uint8(0) /* field version */ <= version {
  1019. // --- [begin][read][alias](AllocationAnnotations) ---
  1020. var tt map[string]string
  1021. if buff.ReadUInt8() == uint8(0) {
  1022. tt = nil
  1023. } else {
  1024. // --- [begin][read][map](map[string]string) ---
  1025. ww := buff.ReadInt() // map len
  1026. uu := make(map[string]string, ww)
  1027. for ii := 0; ii < ww; ii++ {
  1028. var vv string
  1029. var yy string
  1030. if ctx.IsStringTable() {
  1031. aaa := buff.ReadInt() // read string index
  1032. yy = ctx.Table[aaa]
  1033. } else {
  1034. yy = buff.ReadString() // read string
  1035. }
  1036. xx := yy
  1037. vv = xx
  1038. var zz string
  1039. var ccc string
  1040. if ctx.IsStringTable() {
  1041. ddd := buff.ReadInt() // read string index
  1042. ccc = ctx.Table[ddd]
  1043. } else {
  1044. ccc = buff.ReadString() // read string
  1045. }
  1046. bbb := ccc
  1047. zz = bbb
  1048. uu[vv] = zz
  1049. }
  1050. tt = uu
  1051. // --- [end][read][map](map[string]string) ---
  1052. }
  1053. target.Annotations = AllocationAnnotations(tt)
  1054. // --- [end][read][alias](AllocationAnnotations) ---
  1055. } else {
  1056. }
  1057. return nil
  1058. }
  1059. //--------------------------------------------------------------------------
  1060. // AllocationSet
  1061. //--------------------------------------------------------------------------
  1062. // MarshalBinary serializes the internal properties of this AllocationSet instance
  1063. // into a byte array
  1064. func (target *AllocationSet) MarshalBinary() (data []byte, err error) {
  1065. ctx := &EncodingContext{
  1066. Buffer: util.NewBuffer(),
  1067. Table: NewStringTable(),
  1068. }
  1069. e := target.MarshalBinaryWithContext(ctx)
  1070. if e != nil {
  1071. return nil, e
  1072. }
  1073. encBytes := ctx.Buffer.Bytes()
  1074. sTableBytes := ctx.Table.ToBytes()
  1075. merged := appendBytes(sTableBytes, encBytes)
  1076. return merged, nil
  1077. }
  1078. // MarshalBinaryWithContext serializes the internal properties of this AllocationSet instance
  1079. // into a byte array leveraging a predefined context.
  1080. func (target *AllocationSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1081. // panics are recovered and propagated as errors
  1082. defer func() {
  1083. if r := recover(); r != nil {
  1084. if e, ok := r.(error); ok {
  1085. err = e
  1086. } else if s, ok := r.(string); ok {
  1087. err = fmt.Errorf("Unexpected panic: %s", s)
  1088. } else {
  1089. err = fmt.Errorf("Unexpected panic: %+v", r)
  1090. }
  1091. }
  1092. }()
  1093. buff := ctx.Buffer
  1094. buff.WriteUInt8(AllocationCodecVersion) // version
  1095. if target.allocations == nil {
  1096. buff.WriteUInt8(uint8(0)) // write nil byte
  1097. } else {
  1098. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1099. // --- [begin][write][map](map[string]*Allocation) ---
  1100. buff.WriteInt(len(target.allocations)) // map length
  1101. for v, z := range target.allocations {
  1102. if ctx.IsStringTable() {
  1103. a := ctx.Table.AddOrGet(v)
  1104. buff.WriteInt(a) // write table index
  1105. } else {
  1106. buff.WriteString(v) // write string
  1107. }
  1108. if z == nil {
  1109. buff.WriteUInt8(uint8(0)) // write nil byte
  1110. } else {
  1111. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1112. // --- [begin][write][struct](Allocation) ---
  1113. buff.WriteInt(0) // [compatibility, unused]
  1114. errA := z.MarshalBinaryWithContext(ctx)
  1115. if errA != nil {
  1116. return errA
  1117. }
  1118. // --- [end][write][struct](Allocation) ---
  1119. }
  1120. }
  1121. // --- [end][write][map](map[string]*Allocation) ---
  1122. }
  1123. if target.externalKeys == nil {
  1124. buff.WriteUInt8(uint8(0)) // write nil byte
  1125. } else {
  1126. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1127. // --- [begin][write][map](map[string]bool) ---
  1128. buff.WriteInt(len(target.externalKeys)) // map length
  1129. for vv, zz := range target.externalKeys {
  1130. if ctx.IsStringTable() {
  1131. b := ctx.Table.AddOrGet(vv)
  1132. buff.WriteInt(b) // write table index
  1133. } else {
  1134. buff.WriteString(vv) // write string
  1135. }
  1136. buff.WriteBool(zz) // write bool
  1137. }
  1138. // --- [end][write][map](map[string]bool) ---
  1139. }
  1140. if target.idleKeys == nil {
  1141. buff.WriteUInt8(uint8(0)) // write nil byte
  1142. } else {
  1143. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1144. // --- [begin][write][map](map[string]bool) ---
  1145. buff.WriteInt(len(target.idleKeys)) // map length
  1146. for vvv, zzz := range target.idleKeys {
  1147. if ctx.IsStringTable() {
  1148. c := ctx.Table.AddOrGet(vvv)
  1149. buff.WriteInt(c) // write table index
  1150. } else {
  1151. buff.WriteString(vvv) // write string
  1152. }
  1153. buff.WriteBool(zzz) // write bool
  1154. }
  1155. // --- [end][write][map](map[string]bool) ---
  1156. }
  1157. if ctx.IsStringTable() {
  1158. d := ctx.Table.AddOrGet(target.FromSource)
  1159. buff.WriteInt(d) // write table index
  1160. } else {
  1161. buff.WriteString(target.FromSource) // write string
  1162. }
  1163. // --- [begin][write][struct](Window) ---
  1164. buff.WriteInt(0) // [compatibility, unused]
  1165. errB := target.Window.MarshalBinaryWithContext(ctx)
  1166. if errB != nil {
  1167. return errB
  1168. }
  1169. // --- [end][write][struct](Window) ---
  1170. if target.Warnings == nil {
  1171. buff.WriteUInt8(uint8(0)) // write nil byte
  1172. } else {
  1173. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1174. // --- [begin][write][slice]([]string) ---
  1175. buff.WriteInt(len(target.Warnings)) // array length
  1176. for i := 0; i < len(target.Warnings); i++ {
  1177. if ctx.IsStringTable() {
  1178. e := ctx.Table.AddOrGet(target.Warnings[i])
  1179. buff.WriteInt(e) // write table index
  1180. } else {
  1181. buff.WriteString(target.Warnings[i]) // write string
  1182. }
  1183. }
  1184. // --- [end][write][slice]([]string) ---
  1185. }
  1186. if target.Errors == nil {
  1187. buff.WriteUInt8(uint8(0)) // write nil byte
  1188. } else {
  1189. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1190. // --- [begin][write][slice]([]string) ---
  1191. buff.WriteInt(len(target.Errors)) // array length
  1192. for j := 0; j < len(target.Errors); j++ {
  1193. if ctx.IsStringTable() {
  1194. f := ctx.Table.AddOrGet(target.Errors[j])
  1195. buff.WriteInt(f) // write table index
  1196. } else {
  1197. buff.WriteString(target.Errors[j]) // write string
  1198. }
  1199. }
  1200. // --- [end][write][slice]([]string) ---
  1201. }
  1202. return nil
  1203. }
  1204. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1205. // the AllocationSet type
  1206. func (target *AllocationSet) UnmarshalBinary(data []byte) error {
  1207. var table []string
  1208. buff := util.NewBufferFromBytes(data)
  1209. // string table header validation
  1210. if isBinaryTag(data, BinaryTagStringTable) {
  1211. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1212. tl := buff.ReadInt() // table length
  1213. if tl > 0 {
  1214. table = make([]string, tl, tl)
  1215. for i := 0; i < tl; i++ {
  1216. table[i] = buff.ReadString()
  1217. }
  1218. }
  1219. }
  1220. ctx := &DecodingContext{
  1221. Buffer: buff,
  1222. Table: table,
  1223. }
  1224. err := target.UnmarshalBinaryWithContext(ctx)
  1225. if err != nil {
  1226. return err
  1227. }
  1228. return nil
  1229. }
  1230. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1231. // the AllocationSet type
  1232. func (target *AllocationSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1233. // panics are recovered and propagated as errors
  1234. defer func() {
  1235. if r := recover(); r != nil {
  1236. if e, ok := r.(error); ok {
  1237. err = e
  1238. } else if s, ok := r.(string); ok {
  1239. err = fmt.Errorf("Unexpected panic: %s", s)
  1240. } else {
  1241. err = fmt.Errorf("Unexpected panic: %+v", r)
  1242. }
  1243. }
  1244. }()
  1245. buff := ctx.Buffer
  1246. version := buff.ReadUInt8()
  1247. if version > AllocationCodecVersion {
  1248. return fmt.Errorf("Invalid Version Unmarshaling AllocationSet. Expected %d or less, got %d", AllocationCodecVersion, version)
  1249. }
  1250. if uint8(0) /* field version */ <= version {
  1251. if buff.ReadUInt8() == uint8(0) {
  1252. target.allocations = nil
  1253. } else {
  1254. // --- [begin][read][map](map[string]*Allocation) ---
  1255. b := buff.ReadInt() // map len
  1256. a := make(map[string]*Allocation, b)
  1257. for i := 0; i < b; i++ {
  1258. var v string
  1259. var d string
  1260. if ctx.IsStringTable() {
  1261. e := buff.ReadInt() // read string index
  1262. d = ctx.Table[e]
  1263. } else {
  1264. d = buff.ReadString() // read string
  1265. }
  1266. c := d
  1267. v = c
  1268. var z *Allocation
  1269. if buff.ReadUInt8() == uint8(0) {
  1270. z = nil
  1271. } else {
  1272. // --- [begin][read][struct](Allocation) ---
  1273. f := &Allocation{}
  1274. buff.ReadInt() // [compatibility, unused]
  1275. errA := f.UnmarshalBinaryWithContext(ctx)
  1276. if errA != nil {
  1277. return errA
  1278. }
  1279. z = f
  1280. // --- [end][read][struct](Allocation) ---
  1281. }
  1282. a[v] = z
  1283. }
  1284. target.allocations = a
  1285. // --- [end][read][map](map[string]*Allocation) ---
  1286. }
  1287. } else {
  1288. target.allocations = nil
  1289. }
  1290. if uint8(0) /* field version */ <= version {
  1291. if buff.ReadUInt8() == uint8(0) {
  1292. target.externalKeys = nil
  1293. } else {
  1294. // --- [begin][read][map](map[string]bool) ---
  1295. h := buff.ReadInt() // map len
  1296. g := make(map[string]bool, h)
  1297. for j := 0; j < h; j++ {
  1298. var vv string
  1299. var l string
  1300. if ctx.IsStringTable() {
  1301. m := buff.ReadInt() // read string index
  1302. l = ctx.Table[m]
  1303. } else {
  1304. l = buff.ReadString() // read string
  1305. }
  1306. k := l
  1307. vv = k
  1308. var zz bool
  1309. n := buff.ReadBool() // read bool
  1310. zz = n
  1311. g[vv] = zz
  1312. }
  1313. target.externalKeys = g
  1314. // --- [end][read][map](map[string]bool) ---
  1315. }
  1316. } else {
  1317. target.externalKeys = nil
  1318. }
  1319. if uint8(0) /* field version */ <= version {
  1320. if buff.ReadUInt8() == uint8(0) {
  1321. target.idleKeys = nil
  1322. } else {
  1323. // --- [begin][read][map](map[string]bool) ---
  1324. p := buff.ReadInt() // map len
  1325. o := make(map[string]bool, p)
  1326. for ii := 0; ii < p; ii++ {
  1327. var vvv string
  1328. var r string
  1329. if ctx.IsStringTable() {
  1330. s := buff.ReadInt() // read string index
  1331. r = ctx.Table[s]
  1332. } else {
  1333. r = buff.ReadString() // read string
  1334. }
  1335. q := r
  1336. vvv = q
  1337. var zzz bool
  1338. t := buff.ReadBool() // read bool
  1339. zzz = t
  1340. o[vvv] = zzz
  1341. }
  1342. target.idleKeys = o
  1343. // --- [end][read][map](map[string]bool) ---
  1344. }
  1345. } else {
  1346. target.idleKeys = nil
  1347. }
  1348. if uint8(0) /* field version */ <= version {
  1349. var w string
  1350. if ctx.IsStringTable() {
  1351. x := buff.ReadInt() // read string index
  1352. w = ctx.Table[x]
  1353. } else {
  1354. w = buff.ReadString() // read string
  1355. }
  1356. u := w
  1357. target.FromSource = u
  1358. } else {
  1359. target.FromSource = "" // default
  1360. }
  1361. if uint8(0) /* field version */ <= version {
  1362. // --- [begin][read][struct](Window) ---
  1363. y := &Window{}
  1364. buff.ReadInt() // [compatibility, unused]
  1365. errB := y.UnmarshalBinaryWithContext(ctx)
  1366. if errB != nil {
  1367. return errB
  1368. }
  1369. target.Window = *y
  1370. // --- [end][read][struct](Window) ---
  1371. } else {
  1372. }
  1373. if uint8(0) /* field version */ <= version {
  1374. if buff.ReadUInt8() == uint8(0) {
  1375. target.Warnings = nil
  1376. } else {
  1377. // --- [begin][read][slice]([]string) ---
  1378. bb := buff.ReadInt() // array len
  1379. aa := make([]string, bb)
  1380. for jj := 0; jj < bb; jj++ {
  1381. var cc string
  1382. var ee string
  1383. if ctx.IsStringTable() {
  1384. ff := buff.ReadInt() // read string index
  1385. ee = ctx.Table[ff]
  1386. } else {
  1387. ee = buff.ReadString() // read string
  1388. }
  1389. dd := ee
  1390. cc = dd
  1391. aa[jj] = cc
  1392. }
  1393. target.Warnings = aa
  1394. // --- [end][read][slice]([]string) ---
  1395. }
  1396. } else {
  1397. target.Warnings = nil
  1398. }
  1399. if uint8(0) /* field version */ <= version {
  1400. if buff.ReadUInt8() == uint8(0) {
  1401. target.Errors = nil
  1402. } else {
  1403. // --- [begin][read][slice]([]string) ---
  1404. hh := buff.ReadInt() // array len
  1405. gg := make([]string, hh)
  1406. for iii := 0; iii < hh; iii++ {
  1407. var kk string
  1408. var mm string
  1409. if ctx.IsStringTable() {
  1410. nn := buff.ReadInt() // read string index
  1411. mm = ctx.Table[nn]
  1412. } else {
  1413. mm = buff.ReadString() // read string
  1414. }
  1415. ll := mm
  1416. kk = ll
  1417. gg[iii] = kk
  1418. }
  1419. target.Errors = gg
  1420. // --- [end][read][slice]([]string) ---
  1421. }
  1422. } else {
  1423. target.Errors = nil
  1424. }
  1425. return nil
  1426. }
  1427. //--------------------------------------------------------------------------
  1428. // AllocationSetRange
  1429. //--------------------------------------------------------------------------
  1430. // MarshalBinary serializes the internal properties of this AllocationSetRange instance
  1431. // into a byte array
  1432. func (target *AllocationSetRange) MarshalBinary() (data []byte, err error) {
  1433. ctx := &EncodingContext{
  1434. Buffer: util.NewBuffer(),
  1435. Table: nil,
  1436. }
  1437. e := target.MarshalBinaryWithContext(ctx)
  1438. if e != nil {
  1439. return nil, e
  1440. }
  1441. encBytes := ctx.Buffer.Bytes()
  1442. return encBytes, nil
  1443. }
  1444. // MarshalBinaryWithContext serializes the internal properties of this AllocationSetRange instance
  1445. // into a byte array leveraging a predefined context.
  1446. func (target *AllocationSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1447. // panics are recovered and propagated as errors
  1448. defer func() {
  1449. if r := recover(); r != nil {
  1450. if e, ok := r.(error); ok {
  1451. err = e
  1452. } else if s, ok := r.(string); ok {
  1453. err = fmt.Errorf("Unexpected panic: %s", s)
  1454. } else {
  1455. err = fmt.Errorf("Unexpected panic: %+v", r)
  1456. }
  1457. }
  1458. }()
  1459. buff := ctx.Buffer
  1460. buff.WriteUInt8(AllocationCodecVersion) // version
  1461. if target.allocations == nil {
  1462. buff.WriteUInt8(uint8(0)) // write nil byte
  1463. } else {
  1464. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1465. // --- [begin][write][slice]([]*AllocationSet) ---
  1466. buff.WriteInt(len(target.allocations)) // array length
  1467. for i := 0; i < len(target.allocations); i++ {
  1468. if target.allocations[i] == nil {
  1469. buff.WriteUInt8(uint8(0)) // write nil byte
  1470. } else {
  1471. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1472. // --- [begin][write][struct](AllocationSet) ---
  1473. buff.WriteInt(0) // [compatibility, unused]
  1474. errA := target.allocations[i].MarshalBinaryWithContext(ctx)
  1475. if errA != nil {
  1476. return errA
  1477. }
  1478. // --- [end][write][struct](AllocationSet) ---
  1479. }
  1480. }
  1481. // --- [end][write][slice]([]*AllocationSet) ---
  1482. }
  1483. if ctx.IsStringTable() {
  1484. a := ctx.Table.AddOrGet(target.FromStore)
  1485. buff.WriteInt(a) // write table index
  1486. } else {
  1487. buff.WriteString(target.FromStore) // write string
  1488. }
  1489. return nil
  1490. }
  1491. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1492. // the AllocationSetRange type
  1493. func (target *AllocationSetRange) UnmarshalBinary(data []byte) error {
  1494. var table []string
  1495. buff := util.NewBufferFromBytes(data)
  1496. // string table header validation
  1497. if isBinaryTag(data, BinaryTagStringTable) {
  1498. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1499. tl := buff.ReadInt() // table length
  1500. if tl > 0 {
  1501. table = make([]string, tl, tl)
  1502. for i := 0; i < tl; i++ {
  1503. table[i] = buff.ReadString()
  1504. }
  1505. }
  1506. }
  1507. ctx := &DecodingContext{
  1508. Buffer: buff,
  1509. Table: table,
  1510. }
  1511. err := target.UnmarshalBinaryWithContext(ctx)
  1512. if err != nil {
  1513. return err
  1514. }
  1515. return nil
  1516. }
  1517. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1518. // the AllocationSetRange type
  1519. func (target *AllocationSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1520. // panics are recovered and propagated as errors
  1521. defer func() {
  1522. if r := recover(); r != nil {
  1523. if e, ok := r.(error); ok {
  1524. err = e
  1525. } else if s, ok := r.(string); ok {
  1526. err = fmt.Errorf("Unexpected panic: %s", s)
  1527. } else {
  1528. err = fmt.Errorf("Unexpected panic: %+v", r)
  1529. }
  1530. }
  1531. }()
  1532. buff := ctx.Buffer
  1533. version := buff.ReadUInt8()
  1534. if version > AllocationCodecVersion {
  1535. return fmt.Errorf("Invalid Version Unmarshaling AllocationSetRange. Expected %d or less, got %d", AllocationCodecVersion, version)
  1536. }
  1537. if uint8(0) /* field version */ <= version {
  1538. if buff.ReadUInt8() == uint8(0) {
  1539. target.allocations = nil
  1540. } else {
  1541. // --- [begin][read][slice]([]*AllocationSet) ---
  1542. b := buff.ReadInt() // array len
  1543. a := make([]*AllocationSet, b)
  1544. for i := 0; i < b; i++ {
  1545. var c *AllocationSet
  1546. if buff.ReadUInt8() == uint8(0) {
  1547. c = nil
  1548. } else {
  1549. // --- [begin][read][struct](AllocationSet) ---
  1550. d := &AllocationSet{}
  1551. buff.ReadInt() // [compatibility, unused]
  1552. errA := d.UnmarshalBinaryWithContext(ctx)
  1553. if errA != nil {
  1554. return errA
  1555. }
  1556. c = d
  1557. // --- [end][read][struct](AllocationSet) ---
  1558. }
  1559. a[i] = c
  1560. }
  1561. target.allocations = a
  1562. // --- [end][read][slice]([]*AllocationSet) ---
  1563. }
  1564. } else {
  1565. target.allocations = nil
  1566. }
  1567. if uint8(0) /* field version */ <= version {
  1568. var f string
  1569. if ctx.IsStringTable() {
  1570. g := buff.ReadInt() // read string index
  1571. f = ctx.Table[g]
  1572. } else {
  1573. f = buff.ReadString() // read string
  1574. }
  1575. e := f
  1576. target.FromStore = e
  1577. } else {
  1578. target.FromStore = "" // default
  1579. }
  1580. return nil
  1581. }
  1582. //--------------------------------------------------------------------------
  1583. // Any
  1584. //--------------------------------------------------------------------------
  1585. // MarshalBinary serializes the internal properties of this Any instance
  1586. // into a byte array
  1587. func (target *Any) MarshalBinary() (data []byte, err error) {
  1588. ctx := &EncodingContext{
  1589. Buffer: util.NewBuffer(),
  1590. Table: nil,
  1591. }
  1592. e := target.MarshalBinaryWithContext(ctx)
  1593. if e != nil {
  1594. return nil, e
  1595. }
  1596. encBytes := ctx.Buffer.Bytes()
  1597. return encBytes, nil
  1598. }
  1599. // MarshalBinaryWithContext serializes the internal properties of this Any instance
  1600. // into a byte array leveraging a predefined context.
  1601. func (target *Any) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1602. // panics are recovered and propagated as errors
  1603. defer func() {
  1604. if r := recover(); r != nil {
  1605. if e, ok := r.(error); ok {
  1606. err = e
  1607. } else if s, ok := r.(string); ok {
  1608. err = fmt.Errorf("Unexpected panic: %s", s)
  1609. } else {
  1610. err = fmt.Errorf("Unexpected panic: %+v", r)
  1611. }
  1612. }
  1613. }()
  1614. buff := ctx.Buffer
  1615. buff.WriteUInt8(AssetsCodecVersion) // version
  1616. // --- [begin][write][alias](AssetLabels) ---
  1617. if map[string]string(target.labels) == nil {
  1618. buff.WriteUInt8(uint8(0)) // write nil byte
  1619. } else {
  1620. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1621. // --- [begin][write][map](map[string]string) ---
  1622. buff.WriteInt(len(map[string]string(target.labels))) // map length
  1623. for v, z := range map[string]string(target.labels) {
  1624. if ctx.IsStringTable() {
  1625. a := ctx.Table.AddOrGet(v)
  1626. buff.WriteInt(a) // write table index
  1627. } else {
  1628. buff.WriteString(v) // write string
  1629. }
  1630. if ctx.IsStringTable() {
  1631. b := ctx.Table.AddOrGet(z)
  1632. buff.WriteInt(b) // write table index
  1633. } else {
  1634. buff.WriteString(z) // write string
  1635. }
  1636. }
  1637. // --- [end][write][map](map[string]string) ---
  1638. }
  1639. // --- [end][write][alias](AssetLabels) ---
  1640. if target.properties == nil {
  1641. buff.WriteUInt8(uint8(0)) // write nil byte
  1642. } else {
  1643. buff.WriteUInt8(uint8(1)) // write non-nil byte
  1644. // --- [begin][write][struct](AssetProperties) ---
  1645. buff.WriteInt(0) // [compatibility, unused]
  1646. errA := target.properties.MarshalBinaryWithContext(ctx)
  1647. if errA != nil {
  1648. return errA
  1649. }
  1650. // --- [end][write][struct](AssetProperties) ---
  1651. }
  1652. // --- [begin][write][reference](time.Time) ---
  1653. c, errB := target.start.MarshalBinary()
  1654. if errB != nil {
  1655. return errB
  1656. }
  1657. buff.WriteInt(len(c))
  1658. buff.WriteBytes(c)
  1659. // --- [end][write][reference](time.Time) ---
  1660. // --- [begin][write][reference](time.Time) ---
  1661. d, errC := target.end.MarshalBinary()
  1662. if errC != nil {
  1663. return errC
  1664. }
  1665. buff.WriteInt(len(d))
  1666. buff.WriteBytes(d)
  1667. // --- [end][write][reference](time.Time) ---
  1668. // --- [begin][write][struct](Window) ---
  1669. buff.WriteInt(0) // [compatibility, unused]
  1670. errD := target.window.MarshalBinaryWithContext(ctx)
  1671. if errD != nil {
  1672. return errD
  1673. }
  1674. // --- [end][write][struct](Window) ---
  1675. buff.WriteFloat64(target.adjustment) // write float64
  1676. buff.WriteFloat64(target.Cost) // write float64
  1677. return nil
  1678. }
  1679. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1680. // the Any type
  1681. func (target *Any) UnmarshalBinary(data []byte) error {
  1682. var table []string
  1683. buff := util.NewBufferFromBytes(data)
  1684. // string table header validation
  1685. if isBinaryTag(data, BinaryTagStringTable) {
  1686. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1687. tl := buff.ReadInt() // table length
  1688. if tl > 0 {
  1689. table = make([]string, tl, tl)
  1690. for i := 0; i < tl; i++ {
  1691. table[i] = buff.ReadString()
  1692. }
  1693. }
  1694. }
  1695. ctx := &DecodingContext{
  1696. Buffer: buff,
  1697. Table: table,
  1698. }
  1699. err := target.UnmarshalBinaryWithContext(ctx)
  1700. if err != nil {
  1701. return err
  1702. }
  1703. return nil
  1704. }
  1705. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1706. // the Any type
  1707. func (target *Any) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1708. // panics are recovered and propagated as errors
  1709. defer func() {
  1710. if r := recover(); r != nil {
  1711. if e, ok := r.(error); ok {
  1712. err = e
  1713. } else if s, ok := r.(string); ok {
  1714. err = fmt.Errorf("Unexpected panic: %s", s)
  1715. } else {
  1716. err = fmt.Errorf("Unexpected panic: %+v", r)
  1717. }
  1718. }
  1719. }()
  1720. buff := ctx.Buffer
  1721. version := buff.ReadUInt8()
  1722. if version > AssetsCodecVersion {
  1723. return fmt.Errorf("Invalid Version Unmarshaling Any. Expected %d or less, got %d", AssetsCodecVersion, version)
  1724. }
  1725. if uint8(0) /* field version */ <= version {
  1726. // --- [begin][read][alias](AssetLabels) ---
  1727. var a map[string]string
  1728. if buff.ReadUInt8() == uint8(0) {
  1729. a = nil
  1730. } else {
  1731. // --- [begin][read][map](map[string]string) ---
  1732. c := buff.ReadInt() // map len
  1733. b := make(map[string]string, c)
  1734. for i := 0; i < c; i++ {
  1735. var v string
  1736. var e string
  1737. if ctx.IsStringTable() {
  1738. f := buff.ReadInt() // read string index
  1739. e = ctx.Table[f]
  1740. } else {
  1741. e = buff.ReadString() // read string
  1742. }
  1743. d := e
  1744. v = d
  1745. var z string
  1746. var h string
  1747. if ctx.IsStringTable() {
  1748. k := buff.ReadInt() // read string index
  1749. h = ctx.Table[k]
  1750. } else {
  1751. h = buff.ReadString() // read string
  1752. }
  1753. g := h
  1754. z = g
  1755. b[v] = z
  1756. }
  1757. a = b
  1758. // --- [end][read][map](map[string]string) ---
  1759. }
  1760. target.labels = AssetLabels(a)
  1761. // --- [end][read][alias](AssetLabels) ---
  1762. } else {
  1763. }
  1764. if uint8(0) /* field version */ <= version {
  1765. if buff.ReadUInt8() == uint8(0) {
  1766. target.properties = nil
  1767. } else {
  1768. // --- [begin][read][struct](AssetProperties) ---
  1769. l := &AssetProperties{}
  1770. buff.ReadInt() // [compatibility, unused]
  1771. errA := l.UnmarshalBinaryWithContext(ctx)
  1772. if errA != nil {
  1773. return errA
  1774. }
  1775. target.properties = l
  1776. // --- [end][read][struct](AssetProperties) ---
  1777. }
  1778. } else {
  1779. target.properties = nil
  1780. }
  1781. if uint8(0) /* field version */ <= version {
  1782. // --- [begin][read][reference](time.Time) ---
  1783. m := &time.Time{}
  1784. n := buff.ReadInt() // byte array length
  1785. o := buff.ReadBytes(n) // byte array
  1786. errB := m.UnmarshalBinary(o)
  1787. if errB != nil {
  1788. return errB
  1789. }
  1790. target.start = *m
  1791. // --- [end][read][reference](time.Time) ---
  1792. } else {
  1793. }
  1794. if uint8(0) /* field version */ <= version {
  1795. // --- [begin][read][reference](time.Time) ---
  1796. p := &time.Time{}
  1797. q := buff.ReadInt() // byte array length
  1798. r := buff.ReadBytes(q) // byte array
  1799. errC := p.UnmarshalBinary(r)
  1800. if errC != nil {
  1801. return errC
  1802. }
  1803. target.end = *p
  1804. // --- [end][read][reference](time.Time) ---
  1805. } else {
  1806. }
  1807. if uint8(0) /* field version */ <= version {
  1808. // --- [begin][read][struct](Window) ---
  1809. s := &Window{}
  1810. buff.ReadInt() // [compatibility, unused]
  1811. errD := s.UnmarshalBinaryWithContext(ctx)
  1812. if errD != nil {
  1813. return errD
  1814. }
  1815. target.window = *s
  1816. // --- [end][read][struct](Window) ---
  1817. } else {
  1818. }
  1819. if uint8(0) /* field version */ <= version {
  1820. t := buff.ReadFloat64() // read float64
  1821. target.adjustment = t
  1822. } else {
  1823. target.adjustment = float64(0) // default
  1824. }
  1825. if uint8(0) /* field version */ <= version {
  1826. u := buff.ReadFloat64() // read float64
  1827. target.Cost = u
  1828. } else {
  1829. target.Cost = float64(0) // default
  1830. }
  1831. return nil
  1832. }
  1833. //--------------------------------------------------------------------------
  1834. // AssetProperties
  1835. //--------------------------------------------------------------------------
  1836. // MarshalBinary serializes the internal properties of this AssetProperties instance
  1837. // into a byte array
  1838. func (target *AssetProperties) MarshalBinary() (data []byte, err error) {
  1839. ctx := &EncodingContext{
  1840. Buffer: util.NewBuffer(),
  1841. Table: nil,
  1842. }
  1843. e := target.MarshalBinaryWithContext(ctx)
  1844. if e != nil {
  1845. return nil, e
  1846. }
  1847. encBytes := ctx.Buffer.Bytes()
  1848. return encBytes, nil
  1849. }
  1850. // MarshalBinaryWithContext serializes the internal properties of this AssetProperties instance
  1851. // into a byte array leveraging a predefined context.
  1852. func (target *AssetProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  1853. // panics are recovered and propagated as errors
  1854. defer func() {
  1855. if r := recover(); r != nil {
  1856. if e, ok := r.(error); ok {
  1857. err = e
  1858. } else if s, ok := r.(string); ok {
  1859. err = fmt.Errorf("Unexpected panic: %s", s)
  1860. } else {
  1861. err = fmt.Errorf("Unexpected panic: %+v", r)
  1862. }
  1863. }
  1864. }()
  1865. buff := ctx.Buffer
  1866. buff.WriteUInt8(AssetsCodecVersion) // version
  1867. if ctx.IsStringTable() {
  1868. a := ctx.Table.AddOrGet(target.Category)
  1869. buff.WriteInt(a) // write table index
  1870. } else {
  1871. buff.WriteString(target.Category) // write string
  1872. }
  1873. if ctx.IsStringTable() {
  1874. b := ctx.Table.AddOrGet(target.Provider)
  1875. buff.WriteInt(b) // write table index
  1876. } else {
  1877. buff.WriteString(target.Provider) // write string
  1878. }
  1879. if ctx.IsStringTable() {
  1880. c := ctx.Table.AddOrGet(target.Account)
  1881. buff.WriteInt(c) // write table index
  1882. } else {
  1883. buff.WriteString(target.Account) // write string
  1884. }
  1885. if ctx.IsStringTable() {
  1886. d := ctx.Table.AddOrGet(target.Project)
  1887. buff.WriteInt(d) // write table index
  1888. } else {
  1889. buff.WriteString(target.Project) // write string
  1890. }
  1891. if ctx.IsStringTable() {
  1892. e := ctx.Table.AddOrGet(target.Service)
  1893. buff.WriteInt(e) // write table index
  1894. } else {
  1895. buff.WriteString(target.Service) // write string
  1896. }
  1897. if ctx.IsStringTable() {
  1898. f := ctx.Table.AddOrGet(target.Cluster)
  1899. buff.WriteInt(f) // write table index
  1900. } else {
  1901. buff.WriteString(target.Cluster) // write string
  1902. }
  1903. if ctx.IsStringTable() {
  1904. g := ctx.Table.AddOrGet(target.Name)
  1905. buff.WriteInt(g) // write table index
  1906. } else {
  1907. buff.WriteString(target.Name) // write string
  1908. }
  1909. if ctx.IsStringTable() {
  1910. h := ctx.Table.AddOrGet(target.ProviderID)
  1911. buff.WriteInt(h) // write table index
  1912. } else {
  1913. buff.WriteString(target.ProviderID) // write string
  1914. }
  1915. return nil
  1916. }
  1917. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  1918. // the AssetProperties type
  1919. func (target *AssetProperties) UnmarshalBinary(data []byte) error {
  1920. var table []string
  1921. buff := util.NewBufferFromBytes(data)
  1922. // string table header validation
  1923. if isBinaryTag(data, BinaryTagStringTable) {
  1924. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  1925. tl := buff.ReadInt() // table length
  1926. if tl > 0 {
  1927. table = make([]string, tl, tl)
  1928. for i := 0; i < tl; i++ {
  1929. table[i] = buff.ReadString()
  1930. }
  1931. }
  1932. }
  1933. ctx := &DecodingContext{
  1934. Buffer: buff,
  1935. Table: table,
  1936. }
  1937. err := target.UnmarshalBinaryWithContext(ctx)
  1938. if err != nil {
  1939. return err
  1940. }
  1941. return nil
  1942. }
  1943. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  1944. // the AssetProperties type
  1945. func (target *AssetProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  1946. // panics are recovered and propagated as errors
  1947. defer func() {
  1948. if r := recover(); r != nil {
  1949. if e, ok := r.(error); ok {
  1950. err = e
  1951. } else if s, ok := r.(string); ok {
  1952. err = fmt.Errorf("Unexpected panic: %s", s)
  1953. } else {
  1954. err = fmt.Errorf("Unexpected panic: %+v", r)
  1955. }
  1956. }
  1957. }()
  1958. buff := ctx.Buffer
  1959. version := buff.ReadUInt8()
  1960. if version > AssetsCodecVersion {
  1961. return fmt.Errorf("Invalid Version Unmarshaling AssetProperties. Expected %d or less, got %d", AssetsCodecVersion, version)
  1962. }
  1963. if uint8(0) /* field version */ <= version {
  1964. var b string
  1965. if ctx.IsStringTable() {
  1966. c := buff.ReadInt() // read string index
  1967. b = ctx.Table[c]
  1968. } else {
  1969. b = buff.ReadString() // read string
  1970. }
  1971. a := b
  1972. target.Category = a
  1973. } else {
  1974. target.Category = "" // default
  1975. }
  1976. if uint8(0) /* field version */ <= version {
  1977. var e string
  1978. if ctx.IsStringTable() {
  1979. f := buff.ReadInt() // read string index
  1980. e = ctx.Table[f]
  1981. } else {
  1982. e = buff.ReadString() // read string
  1983. }
  1984. d := e
  1985. target.Provider = d
  1986. } else {
  1987. target.Provider = "" // default
  1988. }
  1989. if uint8(0) /* field version */ <= version {
  1990. var h string
  1991. if ctx.IsStringTable() {
  1992. k := buff.ReadInt() // read string index
  1993. h = ctx.Table[k]
  1994. } else {
  1995. h = buff.ReadString() // read string
  1996. }
  1997. g := h
  1998. target.Account = g
  1999. } else {
  2000. target.Account = "" // default
  2001. }
  2002. if uint8(0) /* field version */ <= version {
  2003. var m string
  2004. if ctx.IsStringTable() {
  2005. n := buff.ReadInt() // read string index
  2006. m = ctx.Table[n]
  2007. } else {
  2008. m = buff.ReadString() // read string
  2009. }
  2010. l := m
  2011. target.Project = l
  2012. } else {
  2013. target.Project = "" // default
  2014. }
  2015. if uint8(0) /* field version */ <= version {
  2016. var p string
  2017. if ctx.IsStringTable() {
  2018. q := buff.ReadInt() // read string index
  2019. p = ctx.Table[q]
  2020. } else {
  2021. p = buff.ReadString() // read string
  2022. }
  2023. o := p
  2024. target.Service = o
  2025. } else {
  2026. target.Service = "" // default
  2027. }
  2028. if uint8(0) /* field version */ <= version {
  2029. var s string
  2030. if ctx.IsStringTable() {
  2031. t := buff.ReadInt() // read string index
  2032. s = ctx.Table[t]
  2033. } else {
  2034. s = buff.ReadString() // read string
  2035. }
  2036. r := s
  2037. target.Cluster = r
  2038. } else {
  2039. target.Cluster = "" // default
  2040. }
  2041. if uint8(0) /* field version */ <= version {
  2042. var w string
  2043. if ctx.IsStringTable() {
  2044. x := buff.ReadInt() // read string index
  2045. w = ctx.Table[x]
  2046. } else {
  2047. w = buff.ReadString() // read string
  2048. }
  2049. u := w
  2050. target.Name = u
  2051. } else {
  2052. target.Name = "" // default
  2053. }
  2054. if uint8(0) /* field version */ <= version {
  2055. var aa string
  2056. if ctx.IsStringTable() {
  2057. bb := buff.ReadInt() // read string index
  2058. aa = ctx.Table[bb]
  2059. } else {
  2060. aa = buff.ReadString() // read string
  2061. }
  2062. y := aa
  2063. target.ProviderID = y
  2064. } else {
  2065. target.ProviderID = "" // default
  2066. }
  2067. return nil
  2068. }
  2069. //--------------------------------------------------------------------------
  2070. // AssetSet
  2071. //--------------------------------------------------------------------------
  2072. // MarshalBinary serializes the internal properties of this AssetSet instance
  2073. // into a byte array
  2074. func (target *AssetSet) MarshalBinary() (data []byte, err error) {
  2075. ctx := &EncodingContext{
  2076. Buffer: util.NewBuffer(),
  2077. Table: NewStringTable(),
  2078. }
  2079. e := target.MarshalBinaryWithContext(ctx)
  2080. if e != nil {
  2081. return nil, e
  2082. }
  2083. encBytes := ctx.Buffer.Bytes()
  2084. sTableBytes := ctx.Table.ToBytes()
  2085. merged := appendBytes(sTableBytes, encBytes)
  2086. return merged, nil
  2087. }
  2088. // MarshalBinaryWithContext serializes the internal properties of this AssetSet instance
  2089. // into a byte array leveraging a predefined context.
  2090. func (target *AssetSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2091. // panics are recovered and propagated as errors
  2092. defer func() {
  2093. if r := recover(); r != nil {
  2094. if e, ok := r.(error); ok {
  2095. err = e
  2096. } else if s, ok := r.(string); ok {
  2097. err = fmt.Errorf("Unexpected panic: %s", s)
  2098. } else {
  2099. err = fmt.Errorf("Unexpected panic: %+v", r)
  2100. }
  2101. }
  2102. }()
  2103. buff := ctx.Buffer
  2104. buff.WriteUInt8(AssetsCodecVersion) // version
  2105. if target.aggregateBy == nil {
  2106. buff.WriteUInt8(uint8(0)) // write nil byte
  2107. } else {
  2108. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2109. // --- [begin][write][slice]([]string) ---
  2110. buff.WriteInt(len(target.aggregateBy)) // array length
  2111. for i := 0; i < len(target.aggregateBy); i++ {
  2112. if ctx.IsStringTable() {
  2113. a := ctx.Table.AddOrGet(target.aggregateBy[i])
  2114. buff.WriteInt(a) // write table index
  2115. } else {
  2116. buff.WriteString(target.aggregateBy[i]) // write string
  2117. }
  2118. }
  2119. // --- [end][write][slice]([]string) ---
  2120. }
  2121. if target.assets == nil {
  2122. buff.WriteUInt8(uint8(0)) // write nil byte
  2123. } else {
  2124. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2125. // --- [begin][write][map](map[string]Asset) ---
  2126. buff.WriteInt(len(target.assets)) // map length
  2127. for v, z := range target.assets {
  2128. if ctx.IsStringTable() {
  2129. b := ctx.Table.AddOrGet(v)
  2130. buff.WriteInt(b) // write table index
  2131. } else {
  2132. buff.WriteString(v) // write string
  2133. }
  2134. if z == nil {
  2135. buff.WriteUInt8(uint8(0)) // write nil byte
  2136. } else {
  2137. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2138. // --- [begin][write][interface](Asset) ---
  2139. c := reflect.ValueOf(z).Interface()
  2140. d, okA := c.(BinEncoder)
  2141. if !okA {
  2142. return fmt.Errorf("Type: %s does not implement %s.BinEncoder", typeToString(z), GeneratorPackageName)
  2143. }
  2144. buff.WriteString(typeToString(z))
  2145. buff.WriteInt(0) // [compatibility, unused]
  2146. errA := d.MarshalBinaryWithContext(ctx)
  2147. if errA != nil {
  2148. return errA
  2149. }
  2150. // --- [end][write][interface](Asset) ---
  2151. }
  2152. }
  2153. // --- [end][write][map](map[string]Asset) ---
  2154. }
  2155. if ctx.IsStringTable() {
  2156. e := ctx.Table.AddOrGet(target.FromSource)
  2157. buff.WriteInt(e) // write table index
  2158. } else {
  2159. buff.WriteString(target.FromSource) // write string
  2160. }
  2161. // --- [begin][write][struct](Window) ---
  2162. buff.WriteInt(0) // [compatibility, unused]
  2163. errB := target.Window.MarshalBinaryWithContext(ctx)
  2164. if errB != nil {
  2165. return errB
  2166. }
  2167. // --- [end][write][struct](Window) ---
  2168. if target.Warnings == nil {
  2169. buff.WriteUInt8(uint8(0)) // write nil byte
  2170. } else {
  2171. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2172. // --- [begin][write][slice]([]string) ---
  2173. buff.WriteInt(len(target.Warnings)) // array length
  2174. for j := 0; j < len(target.Warnings); j++ {
  2175. if ctx.IsStringTable() {
  2176. f := ctx.Table.AddOrGet(target.Warnings[j])
  2177. buff.WriteInt(f) // write table index
  2178. } else {
  2179. buff.WriteString(target.Warnings[j]) // write string
  2180. }
  2181. }
  2182. // --- [end][write][slice]([]string) ---
  2183. }
  2184. if target.Errors == nil {
  2185. buff.WriteUInt8(uint8(0)) // write nil byte
  2186. } else {
  2187. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2188. // --- [begin][write][slice]([]string) ---
  2189. buff.WriteInt(len(target.Errors)) // array length
  2190. for ii := 0; ii < len(target.Errors); ii++ {
  2191. if ctx.IsStringTable() {
  2192. g := ctx.Table.AddOrGet(target.Errors[ii])
  2193. buff.WriteInt(g) // write table index
  2194. } else {
  2195. buff.WriteString(target.Errors[ii]) // write string
  2196. }
  2197. }
  2198. // --- [end][write][slice]([]string) ---
  2199. }
  2200. return nil
  2201. }
  2202. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2203. // the AssetSet type
  2204. func (target *AssetSet) UnmarshalBinary(data []byte) error {
  2205. var table []string
  2206. buff := util.NewBufferFromBytes(data)
  2207. // string table header validation
  2208. if isBinaryTag(data, BinaryTagStringTable) {
  2209. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2210. tl := buff.ReadInt() // table length
  2211. if tl > 0 {
  2212. table = make([]string, tl, tl)
  2213. for i := 0; i < tl; i++ {
  2214. table[i] = buff.ReadString()
  2215. }
  2216. }
  2217. }
  2218. ctx := &DecodingContext{
  2219. Buffer: buff,
  2220. Table: table,
  2221. }
  2222. err := target.UnmarshalBinaryWithContext(ctx)
  2223. if err != nil {
  2224. return err
  2225. }
  2226. return nil
  2227. }
  2228. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2229. // the AssetSet type
  2230. func (target *AssetSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2231. // panics are recovered and propagated as errors
  2232. defer func() {
  2233. if r := recover(); r != nil {
  2234. if e, ok := r.(error); ok {
  2235. err = e
  2236. } else if s, ok := r.(string); ok {
  2237. err = fmt.Errorf("Unexpected panic: %s", s)
  2238. } else {
  2239. err = fmt.Errorf("Unexpected panic: %+v", r)
  2240. }
  2241. }
  2242. }()
  2243. buff := ctx.Buffer
  2244. version := buff.ReadUInt8()
  2245. if version > AssetsCodecVersion {
  2246. return fmt.Errorf("Invalid Version Unmarshaling AssetSet. Expected %d or less, got %d", AssetsCodecVersion, version)
  2247. }
  2248. if uint8(0) /* field version */ <= version {
  2249. if buff.ReadUInt8() == uint8(0) {
  2250. target.aggregateBy = nil
  2251. } else {
  2252. // --- [begin][read][slice]([]string) ---
  2253. b := buff.ReadInt() // array len
  2254. a := make([]string, b)
  2255. for i := 0; i < b; i++ {
  2256. var c string
  2257. var e string
  2258. if ctx.IsStringTable() {
  2259. f := buff.ReadInt() // read string index
  2260. e = ctx.Table[f]
  2261. } else {
  2262. e = buff.ReadString() // read string
  2263. }
  2264. d := e
  2265. c = d
  2266. a[i] = c
  2267. }
  2268. target.aggregateBy = a
  2269. // --- [end][read][slice]([]string) ---
  2270. }
  2271. } else {
  2272. target.aggregateBy = nil
  2273. }
  2274. if uint8(0) /* field version */ <= version {
  2275. if buff.ReadUInt8() == uint8(0) {
  2276. target.assets = nil
  2277. } else {
  2278. // --- [begin][read][map](map[string]Asset) ---
  2279. h := buff.ReadInt() // map len
  2280. g := make(map[string]Asset, h)
  2281. for j := 0; j < h; j++ {
  2282. var v string
  2283. var l string
  2284. if ctx.IsStringTable() {
  2285. m := buff.ReadInt() // read string index
  2286. l = ctx.Table[m]
  2287. } else {
  2288. l = buff.ReadString() // read string
  2289. }
  2290. k := l
  2291. v = k
  2292. var z Asset
  2293. if buff.ReadUInt8() == uint8(0) {
  2294. z = nil
  2295. } else {
  2296. // --- [begin][read][interface](Asset) ---
  2297. n := buff.ReadString()
  2298. _, o, _ := resolveType(n)
  2299. if _, ok := typeMap[o]; !ok {
  2300. return fmt.Errorf("Unknown Type: %s", o)
  2301. }
  2302. p, okA := reflect.New(typeMap[o]).Interface().(BinDecoder)
  2303. if !okA {
  2304. return fmt.Errorf("Type: %s does not implement %s.BinDecoder.", o, GeneratorPackageName)
  2305. }
  2306. buff.ReadInt() // [compatibility, unused]
  2307. errA := p.UnmarshalBinaryWithContext(ctx)
  2308. if errA != nil {
  2309. return errA
  2310. }
  2311. z = p.(Asset)
  2312. // --- [end][read][interface](Asset) ---
  2313. }
  2314. g[v] = z
  2315. }
  2316. target.assets = g
  2317. // --- [end][read][map](map[string]Asset) ---
  2318. }
  2319. } else {
  2320. target.assets = nil
  2321. }
  2322. if uint8(0) /* field version */ <= version {
  2323. var r string
  2324. if ctx.IsStringTable() {
  2325. s := buff.ReadInt() // read string index
  2326. r = ctx.Table[s]
  2327. } else {
  2328. r = buff.ReadString() // read string
  2329. }
  2330. q := r
  2331. target.FromSource = q
  2332. } else {
  2333. target.FromSource = "" // default
  2334. }
  2335. if uint8(0) /* field version */ <= version {
  2336. // --- [begin][read][struct](Window) ---
  2337. t := &Window{}
  2338. buff.ReadInt() // [compatibility, unused]
  2339. errB := t.UnmarshalBinaryWithContext(ctx)
  2340. if errB != nil {
  2341. return errB
  2342. }
  2343. target.Window = *t
  2344. // --- [end][read][struct](Window) ---
  2345. } else {
  2346. }
  2347. if uint8(0) /* field version */ <= version {
  2348. if buff.ReadUInt8() == uint8(0) {
  2349. target.Warnings = nil
  2350. } else {
  2351. // --- [begin][read][slice]([]string) ---
  2352. w := buff.ReadInt() // array len
  2353. u := make([]string, w)
  2354. for ii := 0; ii < w; ii++ {
  2355. var x string
  2356. var aa string
  2357. if ctx.IsStringTable() {
  2358. bb := buff.ReadInt() // read string index
  2359. aa = ctx.Table[bb]
  2360. } else {
  2361. aa = buff.ReadString() // read string
  2362. }
  2363. y := aa
  2364. x = y
  2365. u[ii] = x
  2366. }
  2367. target.Warnings = u
  2368. // --- [end][read][slice]([]string) ---
  2369. }
  2370. } else {
  2371. target.Warnings = nil
  2372. }
  2373. if uint8(0) /* field version */ <= version {
  2374. if buff.ReadUInt8() == uint8(0) {
  2375. target.Errors = nil
  2376. } else {
  2377. // --- [begin][read][slice]([]string) ---
  2378. dd := buff.ReadInt() // array len
  2379. cc := make([]string, dd)
  2380. for jj := 0; jj < dd; jj++ {
  2381. var ee string
  2382. var gg string
  2383. if ctx.IsStringTable() {
  2384. hh := buff.ReadInt() // read string index
  2385. gg = ctx.Table[hh]
  2386. } else {
  2387. gg = buff.ReadString() // read string
  2388. }
  2389. ff := gg
  2390. ee = ff
  2391. cc[jj] = ee
  2392. }
  2393. target.Errors = cc
  2394. // --- [end][read][slice]([]string) ---
  2395. }
  2396. } else {
  2397. target.Errors = nil
  2398. }
  2399. return nil
  2400. }
  2401. //--------------------------------------------------------------------------
  2402. // AssetSetRange
  2403. //--------------------------------------------------------------------------
  2404. // MarshalBinary serializes the internal properties of this AssetSetRange instance
  2405. // into a byte array
  2406. func (target *AssetSetRange) MarshalBinary() (data []byte, err error) {
  2407. ctx := &EncodingContext{
  2408. Buffer: util.NewBuffer(),
  2409. Table: nil,
  2410. }
  2411. e := target.MarshalBinaryWithContext(ctx)
  2412. if e != nil {
  2413. return nil, e
  2414. }
  2415. encBytes := ctx.Buffer.Bytes()
  2416. return encBytes, nil
  2417. }
  2418. // MarshalBinaryWithContext serializes the internal properties of this AssetSetRange instance
  2419. // into a byte array leveraging a predefined context.
  2420. func (target *AssetSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2421. // panics are recovered and propagated as errors
  2422. defer func() {
  2423. if r := recover(); r != nil {
  2424. if e, ok := r.(error); ok {
  2425. err = e
  2426. } else if s, ok := r.(string); ok {
  2427. err = fmt.Errorf("Unexpected panic: %s", s)
  2428. } else {
  2429. err = fmt.Errorf("Unexpected panic: %+v", r)
  2430. }
  2431. }
  2432. }()
  2433. buff := ctx.Buffer
  2434. buff.WriteUInt8(AssetsCodecVersion) // version
  2435. if target.assets == nil {
  2436. buff.WriteUInt8(uint8(0)) // write nil byte
  2437. } else {
  2438. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2439. // --- [begin][write][slice]([]*AssetSet) ---
  2440. buff.WriteInt(len(target.assets)) // array length
  2441. for i := 0; i < len(target.assets); i++ {
  2442. if target.assets[i] == nil {
  2443. buff.WriteUInt8(uint8(0)) // write nil byte
  2444. } else {
  2445. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2446. // --- [begin][write][struct](AssetSet) ---
  2447. buff.WriteInt(0) // [compatibility, unused]
  2448. errA := target.assets[i].MarshalBinaryWithContext(ctx)
  2449. if errA != nil {
  2450. return errA
  2451. }
  2452. // --- [end][write][struct](AssetSet) ---
  2453. }
  2454. }
  2455. // --- [end][write][slice]([]*AssetSet) ---
  2456. }
  2457. if ctx.IsStringTable() {
  2458. a := ctx.Table.AddOrGet(target.FromStore)
  2459. buff.WriteInt(a) // write table index
  2460. } else {
  2461. buff.WriteString(target.FromStore) // write string
  2462. }
  2463. return nil
  2464. }
  2465. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2466. // the AssetSetRange type
  2467. func (target *AssetSetRange) UnmarshalBinary(data []byte) error {
  2468. var table []string
  2469. buff := util.NewBufferFromBytes(data)
  2470. // string table header validation
  2471. if isBinaryTag(data, BinaryTagStringTable) {
  2472. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2473. tl := buff.ReadInt() // table length
  2474. if tl > 0 {
  2475. table = make([]string, tl, tl)
  2476. for i := 0; i < tl; i++ {
  2477. table[i] = buff.ReadString()
  2478. }
  2479. }
  2480. }
  2481. ctx := &DecodingContext{
  2482. Buffer: buff,
  2483. Table: table,
  2484. }
  2485. err := target.UnmarshalBinaryWithContext(ctx)
  2486. if err != nil {
  2487. return err
  2488. }
  2489. return nil
  2490. }
  2491. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2492. // the AssetSetRange type
  2493. func (target *AssetSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2494. // panics are recovered and propagated as errors
  2495. defer func() {
  2496. if r := recover(); r != nil {
  2497. if e, ok := r.(error); ok {
  2498. err = e
  2499. } else if s, ok := r.(string); ok {
  2500. err = fmt.Errorf("Unexpected panic: %s", s)
  2501. } else {
  2502. err = fmt.Errorf("Unexpected panic: %+v", r)
  2503. }
  2504. }
  2505. }()
  2506. buff := ctx.Buffer
  2507. version := buff.ReadUInt8()
  2508. if version > AssetsCodecVersion {
  2509. return fmt.Errorf("Invalid Version Unmarshaling AssetSetRange. Expected %d or less, got %d", AssetsCodecVersion, version)
  2510. }
  2511. if uint8(0) /* field version */ <= version {
  2512. if buff.ReadUInt8() == uint8(0) {
  2513. target.assets = nil
  2514. } else {
  2515. // --- [begin][read][slice]([]*AssetSet) ---
  2516. b := buff.ReadInt() // array len
  2517. a := make([]*AssetSet, b)
  2518. for i := 0; i < b; i++ {
  2519. var c *AssetSet
  2520. if buff.ReadUInt8() == uint8(0) {
  2521. c = nil
  2522. } else {
  2523. // --- [begin][read][struct](AssetSet) ---
  2524. d := &AssetSet{}
  2525. buff.ReadInt() // [compatibility, unused]
  2526. errA := d.UnmarshalBinaryWithContext(ctx)
  2527. if errA != nil {
  2528. return errA
  2529. }
  2530. c = d
  2531. // --- [end][read][struct](AssetSet) ---
  2532. }
  2533. a[i] = c
  2534. }
  2535. target.assets = a
  2536. // --- [end][read][slice]([]*AssetSet) ---
  2537. }
  2538. } else {
  2539. target.assets = nil
  2540. }
  2541. if uint8(0) /* field version */ <= version {
  2542. var f string
  2543. if ctx.IsStringTable() {
  2544. g := buff.ReadInt() // read string index
  2545. f = ctx.Table[g]
  2546. } else {
  2547. f = buff.ReadString() // read string
  2548. }
  2549. e := f
  2550. target.FromStore = e
  2551. } else {
  2552. target.FromStore = "" // default
  2553. }
  2554. return nil
  2555. }
  2556. //--------------------------------------------------------------------------
  2557. // Breakdown
  2558. //--------------------------------------------------------------------------
  2559. // MarshalBinary serializes the internal properties of this Breakdown instance
  2560. // into a byte array
  2561. func (target *Breakdown) MarshalBinary() (data []byte, err error) {
  2562. ctx := &EncodingContext{
  2563. Buffer: util.NewBuffer(),
  2564. Table: nil,
  2565. }
  2566. e := target.MarshalBinaryWithContext(ctx)
  2567. if e != nil {
  2568. return nil, e
  2569. }
  2570. encBytes := ctx.Buffer.Bytes()
  2571. return encBytes, nil
  2572. }
  2573. // MarshalBinaryWithContext serializes the internal properties of this Breakdown instance
  2574. // into a byte array leveraging a predefined context.
  2575. func (target *Breakdown) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2576. // panics are recovered and propagated as errors
  2577. defer func() {
  2578. if r := recover(); r != nil {
  2579. if e, ok := r.(error); ok {
  2580. err = e
  2581. } else if s, ok := r.(string); ok {
  2582. err = fmt.Errorf("Unexpected panic: %s", s)
  2583. } else {
  2584. err = fmt.Errorf("Unexpected panic: %+v", r)
  2585. }
  2586. }
  2587. }()
  2588. buff := ctx.Buffer
  2589. buff.WriteUInt8(AssetsCodecVersion) // version
  2590. buff.WriteFloat64(target.Idle) // write float64
  2591. buff.WriteFloat64(target.Other) // write float64
  2592. buff.WriteFloat64(target.System) // write float64
  2593. buff.WriteFloat64(target.User) // write float64
  2594. return nil
  2595. }
  2596. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2597. // the Breakdown type
  2598. func (target *Breakdown) UnmarshalBinary(data []byte) error {
  2599. var table []string
  2600. buff := util.NewBufferFromBytes(data)
  2601. // string table header validation
  2602. if isBinaryTag(data, BinaryTagStringTable) {
  2603. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2604. tl := buff.ReadInt() // table length
  2605. if tl > 0 {
  2606. table = make([]string, tl, tl)
  2607. for i := 0; i < tl; i++ {
  2608. table[i] = buff.ReadString()
  2609. }
  2610. }
  2611. }
  2612. ctx := &DecodingContext{
  2613. Buffer: buff,
  2614. Table: table,
  2615. }
  2616. err := target.UnmarshalBinaryWithContext(ctx)
  2617. if err != nil {
  2618. return err
  2619. }
  2620. return nil
  2621. }
  2622. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2623. // the Breakdown type
  2624. func (target *Breakdown) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2625. // panics are recovered and propagated as errors
  2626. defer func() {
  2627. if r := recover(); r != nil {
  2628. if e, ok := r.(error); ok {
  2629. err = e
  2630. } else if s, ok := r.(string); ok {
  2631. err = fmt.Errorf("Unexpected panic: %s", s)
  2632. } else {
  2633. err = fmt.Errorf("Unexpected panic: %+v", r)
  2634. }
  2635. }
  2636. }()
  2637. buff := ctx.Buffer
  2638. version := buff.ReadUInt8()
  2639. if version > AssetsCodecVersion {
  2640. return fmt.Errorf("Invalid Version Unmarshaling Breakdown. Expected %d or less, got %d", AssetsCodecVersion, version)
  2641. }
  2642. if uint8(0) /* field version */ <= version {
  2643. a := buff.ReadFloat64() // read float64
  2644. target.Idle = a
  2645. } else {
  2646. target.Idle = float64(0) // default
  2647. }
  2648. if uint8(0) /* field version */ <= version {
  2649. b := buff.ReadFloat64() // read float64
  2650. target.Other = b
  2651. } else {
  2652. target.Other = float64(0) // default
  2653. }
  2654. if uint8(0) /* field version */ <= version {
  2655. c := buff.ReadFloat64() // read float64
  2656. target.System = c
  2657. } else {
  2658. target.System = float64(0) // default
  2659. }
  2660. if uint8(0) /* field version */ <= version {
  2661. d := buff.ReadFloat64() // read float64
  2662. target.User = d
  2663. } else {
  2664. target.User = float64(0) // default
  2665. }
  2666. return nil
  2667. }
  2668. //--------------------------------------------------------------------------
  2669. // Cloud
  2670. //--------------------------------------------------------------------------
  2671. // MarshalBinary serializes the internal properties of this Cloud instance
  2672. // into a byte array
  2673. func (target *Cloud) MarshalBinary() (data []byte, err error) {
  2674. ctx := &EncodingContext{
  2675. Buffer: util.NewBuffer(),
  2676. Table: nil,
  2677. }
  2678. e := target.MarshalBinaryWithContext(ctx)
  2679. if e != nil {
  2680. return nil, e
  2681. }
  2682. encBytes := ctx.Buffer.Bytes()
  2683. return encBytes, nil
  2684. }
  2685. // MarshalBinaryWithContext serializes the internal properties of this Cloud instance
  2686. // into a byte array leveraging a predefined context.
  2687. func (target *Cloud) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2688. // panics are recovered and propagated as errors
  2689. defer func() {
  2690. if r := recover(); r != nil {
  2691. if e, ok := r.(error); ok {
  2692. err = e
  2693. } else if s, ok := r.(string); ok {
  2694. err = fmt.Errorf("Unexpected panic: %s", s)
  2695. } else {
  2696. err = fmt.Errorf("Unexpected panic: %+v", r)
  2697. }
  2698. }
  2699. }()
  2700. buff := ctx.Buffer
  2701. buff.WriteUInt8(AssetsCodecVersion) // version
  2702. // --- [begin][write][alias](AssetLabels) ---
  2703. if map[string]string(target.labels) == nil {
  2704. buff.WriteUInt8(uint8(0)) // write nil byte
  2705. } else {
  2706. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2707. // --- [begin][write][map](map[string]string) ---
  2708. buff.WriteInt(len(map[string]string(target.labels))) // map length
  2709. for v, z := range map[string]string(target.labels) {
  2710. if ctx.IsStringTable() {
  2711. a := ctx.Table.AddOrGet(v)
  2712. buff.WriteInt(a) // write table index
  2713. } else {
  2714. buff.WriteString(v) // write string
  2715. }
  2716. if ctx.IsStringTable() {
  2717. b := ctx.Table.AddOrGet(z)
  2718. buff.WriteInt(b) // write table index
  2719. } else {
  2720. buff.WriteString(z) // write string
  2721. }
  2722. }
  2723. // --- [end][write][map](map[string]string) ---
  2724. }
  2725. // --- [end][write][alias](AssetLabels) ---
  2726. if target.properties == nil {
  2727. buff.WriteUInt8(uint8(0)) // write nil byte
  2728. } else {
  2729. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2730. // --- [begin][write][struct](AssetProperties) ---
  2731. buff.WriteInt(0) // [compatibility, unused]
  2732. errA := target.properties.MarshalBinaryWithContext(ctx)
  2733. if errA != nil {
  2734. return errA
  2735. }
  2736. // --- [end][write][struct](AssetProperties) ---
  2737. }
  2738. // --- [begin][write][reference](time.Time) ---
  2739. c, errB := target.start.MarshalBinary()
  2740. if errB != nil {
  2741. return errB
  2742. }
  2743. buff.WriteInt(len(c))
  2744. buff.WriteBytes(c)
  2745. // --- [end][write][reference](time.Time) ---
  2746. // --- [begin][write][reference](time.Time) ---
  2747. d, errC := target.end.MarshalBinary()
  2748. if errC != nil {
  2749. return errC
  2750. }
  2751. buff.WriteInt(len(d))
  2752. buff.WriteBytes(d)
  2753. // --- [end][write][reference](time.Time) ---
  2754. // --- [begin][write][struct](Window) ---
  2755. buff.WriteInt(0) // [compatibility, unused]
  2756. errD := target.window.MarshalBinaryWithContext(ctx)
  2757. if errD != nil {
  2758. return errD
  2759. }
  2760. // --- [end][write][struct](Window) ---
  2761. buff.WriteFloat64(target.adjustment) // write float64
  2762. buff.WriteFloat64(target.Cost) // write float64
  2763. buff.WriteFloat64(target.Credit) // write float64
  2764. return nil
  2765. }
  2766. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  2767. // the Cloud type
  2768. func (target *Cloud) UnmarshalBinary(data []byte) error {
  2769. var table []string
  2770. buff := util.NewBufferFromBytes(data)
  2771. // string table header validation
  2772. if isBinaryTag(data, BinaryTagStringTable) {
  2773. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  2774. tl := buff.ReadInt() // table length
  2775. if tl > 0 {
  2776. table = make([]string, tl, tl)
  2777. for i := 0; i < tl; i++ {
  2778. table[i] = buff.ReadString()
  2779. }
  2780. }
  2781. }
  2782. ctx := &DecodingContext{
  2783. Buffer: buff,
  2784. Table: table,
  2785. }
  2786. err := target.UnmarshalBinaryWithContext(ctx)
  2787. if err != nil {
  2788. return err
  2789. }
  2790. return nil
  2791. }
  2792. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  2793. // the Cloud type
  2794. func (target *Cloud) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  2795. // panics are recovered and propagated as errors
  2796. defer func() {
  2797. if r := recover(); r != nil {
  2798. if e, ok := r.(error); ok {
  2799. err = e
  2800. } else if s, ok := r.(string); ok {
  2801. err = fmt.Errorf("Unexpected panic: %s", s)
  2802. } else {
  2803. err = fmt.Errorf("Unexpected panic: %+v", r)
  2804. }
  2805. }
  2806. }()
  2807. buff := ctx.Buffer
  2808. version := buff.ReadUInt8()
  2809. if version > AssetsCodecVersion {
  2810. return fmt.Errorf("Invalid Version Unmarshaling Cloud. Expected %d or less, got %d", AssetsCodecVersion, version)
  2811. }
  2812. if uint8(0) /* field version */ <= version {
  2813. // --- [begin][read][alias](AssetLabels) ---
  2814. var a map[string]string
  2815. if buff.ReadUInt8() == uint8(0) {
  2816. a = nil
  2817. } else {
  2818. // --- [begin][read][map](map[string]string) ---
  2819. c := buff.ReadInt() // map len
  2820. b := make(map[string]string, c)
  2821. for i := 0; i < c; i++ {
  2822. var v string
  2823. var e string
  2824. if ctx.IsStringTable() {
  2825. f := buff.ReadInt() // read string index
  2826. e = ctx.Table[f]
  2827. } else {
  2828. e = buff.ReadString() // read string
  2829. }
  2830. d := e
  2831. v = d
  2832. var z string
  2833. var h string
  2834. if ctx.IsStringTable() {
  2835. k := buff.ReadInt() // read string index
  2836. h = ctx.Table[k]
  2837. } else {
  2838. h = buff.ReadString() // read string
  2839. }
  2840. g := h
  2841. z = g
  2842. b[v] = z
  2843. }
  2844. a = b
  2845. // --- [end][read][map](map[string]string) ---
  2846. }
  2847. target.labels = AssetLabels(a)
  2848. // --- [end][read][alias](AssetLabels) ---
  2849. } else {
  2850. }
  2851. if uint8(0) /* field version */ <= version {
  2852. if buff.ReadUInt8() == uint8(0) {
  2853. target.properties = nil
  2854. } else {
  2855. // --- [begin][read][struct](AssetProperties) ---
  2856. l := &AssetProperties{}
  2857. buff.ReadInt() // [compatibility, unused]
  2858. errA := l.UnmarshalBinaryWithContext(ctx)
  2859. if errA != nil {
  2860. return errA
  2861. }
  2862. target.properties = l
  2863. // --- [end][read][struct](AssetProperties) ---
  2864. }
  2865. } else {
  2866. target.properties = nil
  2867. }
  2868. if uint8(0) /* field version */ <= version {
  2869. // --- [begin][read][reference](time.Time) ---
  2870. m := &time.Time{}
  2871. n := buff.ReadInt() // byte array length
  2872. o := buff.ReadBytes(n) // byte array
  2873. errB := m.UnmarshalBinary(o)
  2874. if errB != nil {
  2875. return errB
  2876. }
  2877. target.start = *m
  2878. // --- [end][read][reference](time.Time) ---
  2879. } else {
  2880. }
  2881. if uint8(0) /* field version */ <= version {
  2882. // --- [begin][read][reference](time.Time) ---
  2883. p := &time.Time{}
  2884. q := buff.ReadInt() // byte array length
  2885. r := buff.ReadBytes(q) // byte array
  2886. errC := p.UnmarshalBinary(r)
  2887. if errC != nil {
  2888. return errC
  2889. }
  2890. target.end = *p
  2891. // --- [end][read][reference](time.Time) ---
  2892. } else {
  2893. }
  2894. if uint8(0) /* field version */ <= version {
  2895. // --- [begin][read][struct](Window) ---
  2896. s := &Window{}
  2897. buff.ReadInt() // [compatibility, unused]
  2898. errD := s.UnmarshalBinaryWithContext(ctx)
  2899. if errD != nil {
  2900. return errD
  2901. }
  2902. target.window = *s
  2903. // --- [end][read][struct](Window) ---
  2904. } else {
  2905. }
  2906. if uint8(0) /* field version */ <= version {
  2907. t := buff.ReadFloat64() // read float64
  2908. target.adjustment = t
  2909. } else {
  2910. target.adjustment = float64(0) // default
  2911. }
  2912. if uint8(0) /* field version */ <= version {
  2913. u := buff.ReadFloat64() // read float64
  2914. target.Cost = u
  2915. } else {
  2916. target.Cost = float64(0) // default
  2917. }
  2918. if uint8(0) /* field version */ <= version {
  2919. w := buff.ReadFloat64() // read float64
  2920. target.Credit = w
  2921. } else {
  2922. target.Credit = float64(0) // default
  2923. }
  2924. return nil
  2925. }
  2926. //--------------------------------------------------------------------------
  2927. // ClusterManagement
  2928. //--------------------------------------------------------------------------
  2929. // MarshalBinary serializes the internal properties of this ClusterManagement instance
  2930. // into a byte array
  2931. func (target *ClusterManagement) MarshalBinary() (data []byte, err error) {
  2932. ctx := &EncodingContext{
  2933. Buffer: util.NewBuffer(),
  2934. Table: nil,
  2935. }
  2936. e := target.MarshalBinaryWithContext(ctx)
  2937. if e != nil {
  2938. return nil, e
  2939. }
  2940. encBytes := ctx.Buffer.Bytes()
  2941. return encBytes, nil
  2942. }
  2943. // MarshalBinaryWithContext serializes the internal properties of this ClusterManagement instance
  2944. // into a byte array leveraging a predefined context.
  2945. func (target *ClusterManagement) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  2946. // panics are recovered and propagated as errors
  2947. defer func() {
  2948. if r := recover(); r != nil {
  2949. if e, ok := r.(error); ok {
  2950. err = e
  2951. } else if s, ok := r.(string); ok {
  2952. err = fmt.Errorf("Unexpected panic: %s", s)
  2953. } else {
  2954. err = fmt.Errorf("Unexpected panic: %+v", r)
  2955. }
  2956. }
  2957. }()
  2958. buff := ctx.Buffer
  2959. buff.WriteUInt8(AssetsCodecVersion) // version
  2960. // --- [begin][write][alias](AssetLabels) ---
  2961. if map[string]string(target.labels) == nil {
  2962. buff.WriteUInt8(uint8(0)) // write nil byte
  2963. } else {
  2964. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2965. // --- [begin][write][map](map[string]string) ---
  2966. buff.WriteInt(len(map[string]string(target.labels))) // map length
  2967. for v, z := range map[string]string(target.labels) {
  2968. if ctx.IsStringTable() {
  2969. a := ctx.Table.AddOrGet(v)
  2970. buff.WriteInt(a) // write table index
  2971. } else {
  2972. buff.WriteString(v) // write string
  2973. }
  2974. if ctx.IsStringTable() {
  2975. b := ctx.Table.AddOrGet(z)
  2976. buff.WriteInt(b) // write table index
  2977. } else {
  2978. buff.WriteString(z) // write string
  2979. }
  2980. }
  2981. // --- [end][write][map](map[string]string) ---
  2982. }
  2983. // --- [end][write][alias](AssetLabels) ---
  2984. if target.properties == nil {
  2985. buff.WriteUInt8(uint8(0)) // write nil byte
  2986. } else {
  2987. buff.WriteUInt8(uint8(1)) // write non-nil byte
  2988. // --- [begin][write][struct](AssetProperties) ---
  2989. buff.WriteInt(0) // [compatibility, unused]
  2990. errA := target.properties.MarshalBinaryWithContext(ctx)
  2991. if errA != nil {
  2992. return errA
  2993. }
  2994. // --- [end][write][struct](AssetProperties) ---
  2995. }
  2996. // --- [begin][write][struct](Window) ---
  2997. buff.WriteInt(0) // [compatibility, unused]
  2998. errB := target.window.MarshalBinaryWithContext(ctx)
  2999. if errB != nil {
  3000. return errB
  3001. }
  3002. // --- [end][write][struct](Window) ---
  3003. buff.WriteFloat64(target.Cost) // write float64
  3004. return nil
  3005. }
  3006. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3007. // the ClusterManagement type
  3008. func (target *ClusterManagement) UnmarshalBinary(data []byte) error {
  3009. var table []string
  3010. buff := util.NewBufferFromBytes(data)
  3011. // string table header validation
  3012. if isBinaryTag(data, BinaryTagStringTable) {
  3013. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3014. tl := buff.ReadInt() // table length
  3015. if tl > 0 {
  3016. table = make([]string, tl, tl)
  3017. for i := 0; i < tl; i++ {
  3018. table[i] = buff.ReadString()
  3019. }
  3020. }
  3021. }
  3022. ctx := &DecodingContext{
  3023. Buffer: buff,
  3024. Table: table,
  3025. }
  3026. err := target.UnmarshalBinaryWithContext(ctx)
  3027. if err != nil {
  3028. return err
  3029. }
  3030. return nil
  3031. }
  3032. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3033. // the ClusterManagement type
  3034. func (target *ClusterManagement) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3035. // panics are recovered and propagated as errors
  3036. defer func() {
  3037. if r := recover(); r != nil {
  3038. if e, ok := r.(error); ok {
  3039. err = e
  3040. } else if s, ok := r.(string); ok {
  3041. err = fmt.Errorf("Unexpected panic: %s", s)
  3042. } else {
  3043. err = fmt.Errorf("Unexpected panic: %+v", r)
  3044. }
  3045. }
  3046. }()
  3047. buff := ctx.Buffer
  3048. version := buff.ReadUInt8()
  3049. if version > AssetsCodecVersion {
  3050. return fmt.Errorf("Invalid Version Unmarshaling ClusterManagement. Expected %d or less, got %d", AssetsCodecVersion, version)
  3051. }
  3052. if uint8(0) /* field version */ <= version {
  3053. // --- [begin][read][alias](AssetLabels) ---
  3054. var a map[string]string
  3055. if buff.ReadUInt8() == uint8(0) {
  3056. a = nil
  3057. } else {
  3058. // --- [begin][read][map](map[string]string) ---
  3059. c := buff.ReadInt() // map len
  3060. b := make(map[string]string, c)
  3061. for i := 0; i < c; i++ {
  3062. var v string
  3063. var e string
  3064. if ctx.IsStringTable() {
  3065. f := buff.ReadInt() // read string index
  3066. e = ctx.Table[f]
  3067. } else {
  3068. e = buff.ReadString() // read string
  3069. }
  3070. d := e
  3071. v = d
  3072. var z string
  3073. var h string
  3074. if ctx.IsStringTable() {
  3075. k := buff.ReadInt() // read string index
  3076. h = ctx.Table[k]
  3077. } else {
  3078. h = buff.ReadString() // read string
  3079. }
  3080. g := h
  3081. z = g
  3082. b[v] = z
  3083. }
  3084. a = b
  3085. // --- [end][read][map](map[string]string) ---
  3086. }
  3087. target.labels = AssetLabels(a)
  3088. // --- [end][read][alias](AssetLabels) ---
  3089. } else {
  3090. }
  3091. if uint8(0) /* field version */ <= version {
  3092. if buff.ReadUInt8() == uint8(0) {
  3093. target.properties = nil
  3094. } else {
  3095. // --- [begin][read][struct](AssetProperties) ---
  3096. l := &AssetProperties{}
  3097. buff.ReadInt() // [compatibility, unused]
  3098. errA := l.UnmarshalBinaryWithContext(ctx)
  3099. if errA != nil {
  3100. return errA
  3101. }
  3102. target.properties = l
  3103. // --- [end][read][struct](AssetProperties) ---
  3104. }
  3105. } else {
  3106. target.properties = nil
  3107. }
  3108. if uint8(0) /* field version */ <= version {
  3109. // --- [begin][read][struct](Window) ---
  3110. m := &Window{}
  3111. buff.ReadInt() // [compatibility, unused]
  3112. errB := m.UnmarshalBinaryWithContext(ctx)
  3113. if errB != nil {
  3114. return errB
  3115. }
  3116. target.window = *m
  3117. // --- [end][read][struct](Window) ---
  3118. } else {
  3119. }
  3120. if uint8(0) /* field version */ <= version {
  3121. n := buff.ReadFloat64() // read float64
  3122. target.Cost = n
  3123. } else {
  3124. target.Cost = float64(0) // default
  3125. }
  3126. return nil
  3127. }
  3128. //--------------------------------------------------------------------------
  3129. // Disk
  3130. //--------------------------------------------------------------------------
  3131. // MarshalBinary serializes the internal properties of this Disk instance
  3132. // into a byte array
  3133. func (target *Disk) MarshalBinary() (data []byte, err error) {
  3134. ctx := &EncodingContext{
  3135. Buffer: util.NewBuffer(),
  3136. Table: nil,
  3137. }
  3138. e := target.MarshalBinaryWithContext(ctx)
  3139. if e != nil {
  3140. return nil, e
  3141. }
  3142. encBytes := ctx.Buffer.Bytes()
  3143. return encBytes, nil
  3144. }
  3145. // MarshalBinaryWithContext serializes the internal properties of this Disk instance
  3146. // into a byte array leveraging a predefined context.
  3147. func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3148. // panics are recovered and propagated as errors
  3149. defer func() {
  3150. if r := recover(); r != nil {
  3151. if e, ok := r.(error); ok {
  3152. err = e
  3153. } else if s, ok := r.(string); ok {
  3154. err = fmt.Errorf("Unexpected panic: %s", s)
  3155. } else {
  3156. err = fmt.Errorf("Unexpected panic: %+v", r)
  3157. }
  3158. }
  3159. }()
  3160. buff := ctx.Buffer
  3161. buff.WriteUInt8(AssetsCodecVersion) // version
  3162. // --- [begin][write][alias](AssetLabels) ---
  3163. if map[string]string(target.labels) == nil {
  3164. buff.WriteUInt8(uint8(0)) // write nil byte
  3165. } else {
  3166. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3167. // --- [begin][write][map](map[string]string) ---
  3168. buff.WriteInt(len(map[string]string(target.labels))) // map length
  3169. for v, z := range map[string]string(target.labels) {
  3170. if ctx.IsStringTable() {
  3171. a := ctx.Table.AddOrGet(v)
  3172. buff.WriteInt(a) // write table index
  3173. } else {
  3174. buff.WriteString(v) // write string
  3175. }
  3176. if ctx.IsStringTable() {
  3177. b := ctx.Table.AddOrGet(z)
  3178. buff.WriteInt(b) // write table index
  3179. } else {
  3180. buff.WriteString(z) // write string
  3181. }
  3182. }
  3183. // --- [end][write][map](map[string]string) ---
  3184. }
  3185. // --- [end][write][alias](AssetLabels) ---
  3186. if target.properties == nil {
  3187. buff.WriteUInt8(uint8(0)) // write nil byte
  3188. } else {
  3189. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3190. // --- [begin][write][struct](AssetProperties) ---
  3191. buff.WriteInt(0) // [compatibility, unused]
  3192. errA := target.properties.MarshalBinaryWithContext(ctx)
  3193. if errA != nil {
  3194. return errA
  3195. }
  3196. // --- [end][write][struct](AssetProperties) ---
  3197. }
  3198. // --- [begin][write][reference](time.Time) ---
  3199. c, errB := target.start.MarshalBinary()
  3200. if errB != nil {
  3201. return errB
  3202. }
  3203. buff.WriteInt(len(c))
  3204. buff.WriteBytes(c)
  3205. // --- [end][write][reference](time.Time) ---
  3206. // --- [begin][write][reference](time.Time) ---
  3207. d, errC := target.end.MarshalBinary()
  3208. if errC != nil {
  3209. return errC
  3210. }
  3211. buff.WriteInt(len(d))
  3212. buff.WriteBytes(d)
  3213. // --- [end][write][reference](time.Time) ---
  3214. // --- [begin][write][struct](Window) ---
  3215. buff.WriteInt(0) // [compatibility, unused]
  3216. errD := target.window.MarshalBinaryWithContext(ctx)
  3217. if errD != nil {
  3218. return errD
  3219. }
  3220. // --- [end][write][struct](Window) ---
  3221. buff.WriteFloat64(target.adjustment) // write float64
  3222. buff.WriteFloat64(target.Cost) // write float64
  3223. buff.WriteFloat64(target.ByteHours) // write float64
  3224. buff.WriteFloat64(target.Local) // write float64
  3225. if target.Breakdown == nil {
  3226. buff.WriteUInt8(uint8(0)) // write nil byte
  3227. } else {
  3228. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3229. // --- [begin][write][struct](Breakdown) ---
  3230. buff.WriteInt(0) // [compatibility, unused]
  3231. errE := target.Breakdown.MarshalBinaryWithContext(ctx)
  3232. if errE != nil {
  3233. return errE
  3234. }
  3235. // --- [end][write][struct](Breakdown) ---
  3236. }
  3237. return nil
  3238. }
  3239. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3240. // the Disk type
  3241. func (target *Disk) UnmarshalBinary(data []byte) error {
  3242. var table []string
  3243. buff := util.NewBufferFromBytes(data)
  3244. // string table header validation
  3245. if isBinaryTag(data, BinaryTagStringTable) {
  3246. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3247. tl := buff.ReadInt() // table length
  3248. if tl > 0 {
  3249. table = make([]string, tl, tl)
  3250. for i := 0; i < tl; i++ {
  3251. table[i] = buff.ReadString()
  3252. }
  3253. }
  3254. }
  3255. ctx := &DecodingContext{
  3256. Buffer: buff,
  3257. Table: table,
  3258. }
  3259. err := target.UnmarshalBinaryWithContext(ctx)
  3260. if err != nil {
  3261. return err
  3262. }
  3263. return nil
  3264. }
  3265. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3266. // the Disk type
  3267. func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3268. // panics are recovered and propagated as errors
  3269. defer func() {
  3270. if r := recover(); r != nil {
  3271. if e, ok := r.(error); ok {
  3272. err = e
  3273. } else if s, ok := r.(string); ok {
  3274. err = fmt.Errorf("Unexpected panic: %s", s)
  3275. } else {
  3276. err = fmt.Errorf("Unexpected panic: %+v", r)
  3277. }
  3278. }
  3279. }()
  3280. buff := ctx.Buffer
  3281. version := buff.ReadUInt8()
  3282. if version > AssetsCodecVersion {
  3283. return fmt.Errorf("Invalid Version Unmarshaling Disk. Expected %d or less, got %d", AssetsCodecVersion, version)
  3284. }
  3285. if uint8(0) /* field version */ <= version {
  3286. // --- [begin][read][alias](AssetLabels) ---
  3287. var a map[string]string
  3288. if buff.ReadUInt8() == uint8(0) {
  3289. a = nil
  3290. } else {
  3291. // --- [begin][read][map](map[string]string) ---
  3292. c := buff.ReadInt() // map len
  3293. b := make(map[string]string, c)
  3294. for i := 0; i < c; i++ {
  3295. var v string
  3296. var e string
  3297. if ctx.IsStringTable() {
  3298. f := buff.ReadInt() // read string index
  3299. e = ctx.Table[f]
  3300. } else {
  3301. e = buff.ReadString() // read string
  3302. }
  3303. d := e
  3304. v = d
  3305. var z string
  3306. var h string
  3307. if ctx.IsStringTable() {
  3308. k := buff.ReadInt() // read string index
  3309. h = ctx.Table[k]
  3310. } else {
  3311. h = buff.ReadString() // read string
  3312. }
  3313. g := h
  3314. z = g
  3315. b[v] = z
  3316. }
  3317. a = b
  3318. // --- [end][read][map](map[string]string) ---
  3319. }
  3320. target.labels = AssetLabels(a)
  3321. // --- [end][read][alias](AssetLabels) ---
  3322. } else {
  3323. }
  3324. if uint8(0) /* field version */ <= version {
  3325. if buff.ReadUInt8() == uint8(0) {
  3326. target.properties = nil
  3327. } else {
  3328. // --- [begin][read][struct](AssetProperties) ---
  3329. l := &AssetProperties{}
  3330. buff.ReadInt() // [compatibility, unused]
  3331. errA := l.UnmarshalBinaryWithContext(ctx)
  3332. if errA != nil {
  3333. return errA
  3334. }
  3335. target.properties = l
  3336. // --- [end][read][struct](AssetProperties) ---
  3337. }
  3338. } else {
  3339. target.properties = nil
  3340. }
  3341. if uint8(0) /* field version */ <= version {
  3342. // --- [begin][read][reference](time.Time) ---
  3343. m := &time.Time{}
  3344. n := buff.ReadInt() // byte array length
  3345. o := buff.ReadBytes(n) // byte array
  3346. errB := m.UnmarshalBinary(o)
  3347. if errB != nil {
  3348. return errB
  3349. }
  3350. target.start = *m
  3351. // --- [end][read][reference](time.Time) ---
  3352. } else {
  3353. }
  3354. if uint8(0) /* field version */ <= version {
  3355. // --- [begin][read][reference](time.Time) ---
  3356. p := &time.Time{}
  3357. q := buff.ReadInt() // byte array length
  3358. r := buff.ReadBytes(q) // byte array
  3359. errC := p.UnmarshalBinary(r)
  3360. if errC != nil {
  3361. return errC
  3362. }
  3363. target.end = *p
  3364. // --- [end][read][reference](time.Time) ---
  3365. } else {
  3366. }
  3367. if uint8(0) /* field version */ <= version {
  3368. // --- [begin][read][struct](Window) ---
  3369. s := &Window{}
  3370. buff.ReadInt() // [compatibility, unused]
  3371. errD := s.UnmarshalBinaryWithContext(ctx)
  3372. if errD != nil {
  3373. return errD
  3374. }
  3375. target.window = *s
  3376. // --- [end][read][struct](Window) ---
  3377. } else {
  3378. }
  3379. if uint8(0) /* field version */ <= version {
  3380. t := buff.ReadFloat64() // read float64
  3381. target.adjustment = t
  3382. } else {
  3383. target.adjustment = float64(0) // default
  3384. }
  3385. if uint8(0) /* field version */ <= version {
  3386. u := buff.ReadFloat64() // read float64
  3387. target.Cost = u
  3388. } else {
  3389. target.Cost = float64(0) // default
  3390. }
  3391. if uint8(0) /* field version */ <= version {
  3392. w := buff.ReadFloat64() // read float64
  3393. target.ByteHours = w
  3394. } else {
  3395. target.ByteHours = float64(0) // default
  3396. }
  3397. if uint8(0) /* field version */ <= version {
  3398. x := buff.ReadFloat64() // read float64
  3399. target.Local = x
  3400. } else {
  3401. target.Local = float64(0) // default
  3402. }
  3403. if uint8(0) /* field version */ <= version {
  3404. if buff.ReadUInt8() == uint8(0) {
  3405. target.Breakdown = nil
  3406. } else {
  3407. // --- [begin][read][struct](Breakdown) ---
  3408. y := &Breakdown{}
  3409. buff.ReadInt() // [compatibility, unused]
  3410. errE := y.UnmarshalBinaryWithContext(ctx)
  3411. if errE != nil {
  3412. return errE
  3413. }
  3414. target.Breakdown = y
  3415. // --- [end][read][struct](Breakdown) ---
  3416. }
  3417. } else {
  3418. target.Breakdown = nil
  3419. }
  3420. return nil
  3421. }
  3422. //--------------------------------------------------------------------------
  3423. // LoadBalancer
  3424. //--------------------------------------------------------------------------
  3425. // MarshalBinary serializes the internal properties of this LoadBalancer instance
  3426. // into a byte array
  3427. func (target *LoadBalancer) MarshalBinary() (data []byte, err error) {
  3428. ctx := &EncodingContext{
  3429. Buffer: util.NewBuffer(),
  3430. Table: nil,
  3431. }
  3432. e := target.MarshalBinaryWithContext(ctx)
  3433. if e != nil {
  3434. return nil, e
  3435. }
  3436. encBytes := ctx.Buffer.Bytes()
  3437. return encBytes, nil
  3438. }
  3439. // MarshalBinaryWithContext serializes the internal properties of this LoadBalancer instance
  3440. // into a byte array leveraging a predefined context.
  3441. func (target *LoadBalancer) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3442. // panics are recovered and propagated as errors
  3443. defer func() {
  3444. if r := recover(); r != nil {
  3445. if e, ok := r.(error); ok {
  3446. err = e
  3447. } else if s, ok := r.(string); ok {
  3448. err = fmt.Errorf("Unexpected panic: %s", s)
  3449. } else {
  3450. err = fmt.Errorf("Unexpected panic: %+v", r)
  3451. }
  3452. }
  3453. }()
  3454. buff := ctx.Buffer
  3455. buff.WriteUInt8(AssetsCodecVersion) // version
  3456. if target.properties == nil {
  3457. buff.WriteUInt8(uint8(0)) // write nil byte
  3458. } else {
  3459. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3460. // --- [begin][write][struct](AssetProperties) ---
  3461. buff.WriteInt(0) // [compatibility, unused]
  3462. errA := target.properties.MarshalBinaryWithContext(ctx)
  3463. if errA != nil {
  3464. return errA
  3465. }
  3466. // --- [end][write][struct](AssetProperties) ---
  3467. }
  3468. // --- [begin][write][alias](AssetLabels) ---
  3469. if map[string]string(target.labels) == nil {
  3470. buff.WriteUInt8(uint8(0)) // write nil byte
  3471. } else {
  3472. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3473. // --- [begin][write][map](map[string]string) ---
  3474. buff.WriteInt(len(map[string]string(target.labels))) // map length
  3475. for v, z := range map[string]string(target.labels) {
  3476. if ctx.IsStringTable() {
  3477. a := ctx.Table.AddOrGet(v)
  3478. buff.WriteInt(a) // write table index
  3479. } else {
  3480. buff.WriteString(v) // write string
  3481. }
  3482. if ctx.IsStringTable() {
  3483. b := ctx.Table.AddOrGet(z)
  3484. buff.WriteInt(b) // write table index
  3485. } else {
  3486. buff.WriteString(z) // write string
  3487. }
  3488. }
  3489. // --- [end][write][map](map[string]string) ---
  3490. }
  3491. // --- [end][write][alias](AssetLabels) ---
  3492. // --- [begin][write][reference](time.Time) ---
  3493. c, errB := target.start.MarshalBinary()
  3494. if errB != nil {
  3495. return errB
  3496. }
  3497. buff.WriteInt(len(c))
  3498. buff.WriteBytes(c)
  3499. // --- [end][write][reference](time.Time) ---
  3500. // --- [begin][write][reference](time.Time) ---
  3501. d, errC := target.end.MarshalBinary()
  3502. if errC != nil {
  3503. return errC
  3504. }
  3505. buff.WriteInt(len(d))
  3506. buff.WriteBytes(d)
  3507. // --- [end][write][reference](time.Time) ---
  3508. // --- [begin][write][struct](Window) ---
  3509. buff.WriteInt(0) // [compatibility, unused]
  3510. errD := target.window.MarshalBinaryWithContext(ctx)
  3511. if errD != nil {
  3512. return errD
  3513. }
  3514. // --- [end][write][struct](Window) ---
  3515. buff.WriteFloat64(target.adjustment) // write float64
  3516. buff.WriteFloat64(target.Cost) // write float64
  3517. return nil
  3518. }
  3519. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3520. // the LoadBalancer type
  3521. func (target *LoadBalancer) UnmarshalBinary(data []byte) error {
  3522. var table []string
  3523. buff := util.NewBufferFromBytes(data)
  3524. // string table header validation
  3525. if isBinaryTag(data, BinaryTagStringTable) {
  3526. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3527. tl := buff.ReadInt() // table length
  3528. if tl > 0 {
  3529. table = make([]string, tl, tl)
  3530. for i := 0; i < tl; i++ {
  3531. table[i] = buff.ReadString()
  3532. }
  3533. }
  3534. }
  3535. ctx := &DecodingContext{
  3536. Buffer: buff,
  3537. Table: table,
  3538. }
  3539. err := target.UnmarshalBinaryWithContext(ctx)
  3540. if err != nil {
  3541. return err
  3542. }
  3543. return nil
  3544. }
  3545. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3546. // the LoadBalancer type
  3547. func (target *LoadBalancer) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3548. // panics are recovered and propagated as errors
  3549. defer func() {
  3550. if r := recover(); r != nil {
  3551. if e, ok := r.(error); ok {
  3552. err = e
  3553. } else if s, ok := r.(string); ok {
  3554. err = fmt.Errorf("Unexpected panic: %s", s)
  3555. } else {
  3556. err = fmt.Errorf("Unexpected panic: %+v", r)
  3557. }
  3558. }
  3559. }()
  3560. buff := ctx.Buffer
  3561. version := buff.ReadUInt8()
  3562. if version > AssetsCodecVersion {
  3563. return fmt.Errorf("Invalid Version Unmarshaling LoadBalancer. Expected %d or less, got %d", AssetsCodecVersion, version)
  3564. }
  3565. if uint8(0) /* field version */ <= version {
  3566. if buff.ReadUInt8() == uint8(0) {
  3567. target.properties = nil
  3568. } else {
  3569. // --- [begin][read][struct](AssetProperties) ---
  3570. a := &AssetProperties{}
  3571. buff.ReadInt() // [compatibility, unused]
  3572. errA := a.UnmarshalBinaryWithContext(ctx)
  3573. if errA != nil {
  3574. return errA
  3575. }
  3576. target.properties = a
  3577. // --- [end][read][struct](AssetProperties) ---
  3578. }
  3579. } else {
  3580. target.properties = nil
  3581. }
  3582. if uint8(0) /* field version */ <= version {
  3583. // --- [begin][read][alias](AssetLabels) ---
  3584. var b map[string]string
  3585. if buff.ReadUInt8() == uint8(0) {
  3586. b = nil
  3587. } else {
  3588. // --- [begin][read][map](map[string]string) ---
  3589. d := buff.ReadInt() // map len
  3590. c := make(map[string]string, d)
  3591. for i := 0; i < d; i++ {
  3592. var v string
  3593. var f string
  3594. if ctx.IsStringTable() {
  3595. g := buff.ReadInt() // read string index
  3596. f = ctx.Table[g]
  3597. } else {
  3598. f = buff.ReadString() // read string
  3599. }
  3600. e := f
  3601. v = e
  3602. var z string
  3603. var k string
  3604. if ctx.IsStringTable() {
  3605. l := buff.ReadInt() // read string index
  3606. k = ctx.Table[l]
  3607. } else {
  3608. k = buff.ReadString() // read string
  3609. }
  3610. h := k
  3611. z = h
  3612. c[v] = z
  3613. }
  3614. b = c
  3615. // --- [end][read][map](map[string]string) ---
  3616. }
  3617. target.labels = AssetLabels(b)
  3618. // --- [end][read][alias](AssetLabels) ---
  3619. } else {
  3620. }
  3621. if uint8(0) /* field version */ <= version {
  3622. // --- [begin][read][reference](time.Time) ---
  3623. m := &time.Time{}
  3624. n := buff.ReadInt() // byte array length
  3625. o := buff.ReadBytes(n) // byte array
  3626. errB := m.UnmarshalBinary(o)
  3627. if errB != nil {
  3628. return errB
  3629. }
  3630. target.start = *m
  3631. // --- [end][read][reference](time.Time) ---
  3632. } else {
  3633. }
  3634. if uint8(0) /* field version */ <= version {
  3635. // --- [begin][read][reference](time.Time) ---
  3636. p := &time.Time{}
  3637. q := buff.ReadInt() // byte array length
  3638. r := buff.ReadBytes(q) // byte array
  3639. errC := p.UnmarshalBinary(r)
  3640. if errC != nil {
  3641. return errC
  3642. }
  3643. target.end = *p
  3644. // --- [end][read][reference](time.Time) ---
  3645. } else {
  3646. }
  3647. if uint8(0) /* field version */ <= version {
  3648. // --- [begin][read][struct](Window) ---
  3649. s := &Window{}
  3650. buff.ReadInt() // [compatibility, unused]
  3651. errD := s.UnmarshalBinaryWithContext(ctx)
  3652. if errD != nil {
  3653. return errD
  3654. }
  3655. target.window = *s
  3656. // --- [end][read][struct](Window) ---
  3657. } else {
  3658. }
  3659. if uint8(0) /* field version */ <= version {
  3660. t := buff.ReadFloat64() // read float64
  3661. target.adjustment = t
  3662. } else {
  3663. target.adjustment = float64(0) // default
  3664. }
  3665. if uint8(0) /* field version */ <= version {
  3666. u := buff.ReadFloat64() // read float64
  3667. target.Cost = u
  3668. } else {
  3669. target.Cost = float64(0) // default
  3670. }
  3671. return nil
  3672. }
  3673. //--------------------------------------------------------------------------
  3674. // Network
  3675. //--------------------------------------------------------------------------
  3676. // MarshalBinary serializes the internal properties of this Network instance
  3677. // into a byte array
  3678. func (target *Network) MarshalBinary() (data []byte, err error) {
  3679. ctx := &EncodingContext{
  3680. Buffer: util.NewBuffer(),
  3681. Table: nil,
  3682. }
  3683. e := target.MarshalBinaryWithContext(ctx)
  3684. if e != nil {
  3685. return nil, e
  3686. }
  3687. encBytes := ctx.Buffer.Bytes()
  3688. return encBytes, nil
  3689. }
  3690. // MarshalBinaryWithContext serializes the internal properties of this Network instance
  3691. // into a byte array leveraging a predefined context.
  3692. func (target *Network) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3693. // panics are recovered and propagated as errors
  3694. defer func() {
  3695. if r := recover(); r != nil {
  3696. if e, ok := r.(error); ok {
  3697. err = e
  3698. } else if s, ok := r.(string); ok {
  3699. err = fmt.Errorf("Unexpected panic: %s", s)
  3700. } else {
  3701. err = fmt.Errorf("Unexpected panic: %+v", r)
  3702. }
  3703. }
  3704. }()
  3705. buff := ctx.Buffer
  3706. buff.WriteUInt8(AssetsCodecVersion) // version
  3707. if target.properties == nil {
  3708. buff.WriteUInt8(uint8(0)) // write nil byte
  3709. } else {
  3710. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3711. // --- [begin][write][struct](AssetProperties) ---
  3712. buff.WriteInt(0) // [compatibility, unused]
  3713. errA := target.properties.MarshalBinaryWithContext(ctx)
  3714. if errA != nil {
  3715. return errA
  3716. }
  3717. // --- [end][write][struct](AssetProperties) ---
  3718. }
  3719. // --- [begin][write][alias](AssetLabels) ---
  3720. if map[string]string(target.labels) == nil {
  3721. buff.WriteUInt8(uint8(0)) // write nil byte
  3722. } else {
  3723. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3724. // --- [begin][write][map](map[string]string) ---
  3725. buff.WriteInt(len(map[string]string(target.labels))) // map length
  3726. for v, z := range map[string]string(target.labels) {
  3727. if ctx.IsStringTable() {
  3728. a := ctx.Table.AddOrGet(v)
  3729. buff.WriteInt(a) // write table index
  3730. } else {
  3731. buff.WriteString(v) // write string
  3732. }
  3733. if ctx.IsStringTable() {
  3734. b := ctx.Table.AddOrGet(z)
  3735. buff.WriteInt(b) // write table index
  3736. } else {
  3737. buff.WriteString(z) // write string
  3738. }
  3739. }
  3740. // --- [end][write][map](map[string]string) ---
  3741. }
  3742. // --- [end][write][alias](AssetLabels) ---
  3743. // --- [begin][write][reference](time.Time) ---
  3744. c, errB := target.start.MarshalBinary()
  3745. if errB != nil {
  3746. return errB
  3747. }
  3748. buff.WriteInt(len(c))
  3749. buff.WriteBytes(c)
  3750. // --- [end][write][reference](time.Time) ---
  3751. // --- [begin][write][reference](time.Time) ---
  3752. d, errC := target.end.MarshalBinary()
  3753. if errC != nil {
  3754. return errC
  3755. }
  3756. buff.WriteInt(len(d))
  3757. buff.WriteBytes(d)
  3758. // --- [end][write][reference](time.Time) ---
  3759. // --- [begin][write][struct](Window) ---
  3760. buff.WriteInt(0) // [compatibility, unused]
  3761. errD := target.window.MarshalBinaryWithContext(ctx)
  3762. if errD != nil {
  3763. return errD
  3764. }
  3765. // --- [end][write][struct](Window) ---
  3766. buff.WriteFloat64(target.adjustment) // write float64
  3767. buff.WriteFloat64(target.Cost) // write float64
  3768. return nil
  3769. }
  3770. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  3771. // the Network type
  3772. func (target *Network) UnmarshalBinary(data []byte) error {
  3773. var table []string
  3774. buff := util.NewBufferFromBytes(data)
  3775. // string table header validation
  3776. if isBinaryTag(data, BinaryTagStringTable) {
  3777. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  3778. tl := buff.ReadInt() // table length
  3779. if tl > 0 {
  3780. table = make([]string, tl, tl)
  3781. for i := 0; i < tl; i++ {
  3782. table[i] = buff.ReadString()
  3783. }
  3784. }
  3785. }
  3786. ctx := &DecodingContext{
  3787. Buffer: buff,
  3788. Table: table,
  3789. }
  3790. err := target.UnmarshalBinaryWithContext(ctx)
  3791. if err != nil {
  3792. return err
  3793. }
  3794. return nil
  3795. }
  3796. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  3797. // the Network type
  3798. func (target *Network) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  3799. // panics are recovered and propagated as errors
  3800. defer func() {
  3801. if r := recover(); r != nil {
  3802. if e, ok := r.(error); ok {
  3803. err = e
  3804. } else if s, ok := r.(string); ok {
  3805. err = fmt.Errorf("Unexpected panic: %s", s)
  3806. } else {
  3807. err = fmt.Errorf("Unexpected panic: %+v", r)
  3808. }
  3809. }
  3810. }()
  3811. buff := ctx.Buffer
  3812. version := buff.ReadUInt8()
  3813. if version > AssetsCodecVersion {
  3814. return fmt.Errorf("Invalid Version Unmarshaling Network. Expected %d or less, got %d", AssetsCodecVersion, version)
  3815. }
  3816. if uint8(0) /* field version */ <= version {
  3817. if buff.ReadUInt8() == uint8(0) {
  3818. target.properties = nil
  3819. } else {
  3820. // --- [begin][read][struct](AssetProperties) ---
  3821. a := &AssetProperties{}
  3822. buff.ReadInt() // [compatibility, unused]
  3823. errA := a.UnmarshalBinaryWithContext(ctx)
  3824. if errA != nil {
  3825. return errA
  3826. }
  3827. target.properties = a
  3828. // --- [end][read][struct](AssetProperties) ---
  3829. }
  3830. } else {
  3831. target.properties = nil
  3832. }
  3833. if uint8(0) /* field version */ <= version {
  3834. // --- [begin][read][alias](AssetLabels) ---
  3835. var b map[string]string
  3836. if buff.ReadUInt8() == uint8(0) {
  3837. b = nil
  3838. } else {
  3839. // --- [begin][read][map](map[string]string) ---
  3840. d := buff.ReadInt() // map len
  3841. c := make(map[string]string, d)
  3842. for i := 0; i < d; i++ {
  3843. var v string
  3844. var f string
  3845. if ctx.IsStringTable() {
  3846. g := buff.ReadInt() // read string index
  3847. f = ctx.Table[g]
  3848. } else {
  3849. f = buff.ReadString() // read string
  3850. }
  3851. e := f
  3852. v = e
  3853. var z string
  3854. var k string
  3855. if ctx.IsStringTable() {
  3856. l := buff.ReadInt() // read string index
  3857. k = ctx.Table[l]
  3858. } else {
  3859. k = buff.ReadString() // read string
  3860. }
  3861. h := k
  3862. z = h
  3863. c[v] = z
  3864. }
  3865. b = c
  3866. // --- [end][read][map](map[string]string) ---
  3867. }
  3868. target.labels = AssetLabels(b)
  3869. // --- [end][read][alias](AssetLabels) ---
  3870. } else {
  3871. }
  3872. if uint8(0) /* field version */ <= version {
  3873. // --- [begin][read][reference](time.Time) ---
  3874. m := &time.Time{}
  3875. n := buff.ReadInt() // byte array length
  3876. o := buff.ReadBytes(n) // byte array
  3877. errB := m.UnmarshalBinary(o)
  3878. if errB != nil {
  3879. return errB
  3880. }
  3881. target.start = *m
  3882. // --- [end][read][reference](time.Time) ---
  3883. } else {
  3884. }
  3885. if uint8(0) /* field version */ <= version {
  3886. // --- [begin][read][reference](time.Time) ---
  3887. p := &time.Time{}
  3888. q := buff.ReadInt() // byte array length
  3889. r := buff.ReadBytes(q) // byte array
  3890. errC := p.UnmarshalBinary(r)
  3891. if errC != nil {
  3892. return errC
  3893. }
  3894. target.end = *p
  3895. // --- [end][read][reference](time.Time) ---
  3896. } else {
  3897. }
  3898. if uint8(0) /* field version */ <= version {
  3899. // --- [begin][read][struct](Window) ---
  3900. s := &Window{}
  3901. buff.ReadInt() // [compatibility, unused]
  3902. errD := s.UnmarshalBinaryWithContext(ctx)
  3903. if errD != nil {
  3904. return errD
  3905. }
  3906. target.window = *s
  3907. // --- [end][read][struct](Window) ---
  3908. } else {
  3909. }
  3910. if uint8(0) /* field version */ <= version {
  3911. t := buff.ReadFloat64() // read float64
  3912. target.adjustment = t
  3913. } else {
  3914. target.adjustment = float64(0) // default
  3915. }
  3916. if uint8(0) /* field version */ <= version {
  3917. u := buff.ReadFloat64() // read float64
  3918. target.Cost = u
  3919. } else {
  3920. target.Cost = float64(0) // default
  3921. }
  3922. return nil
  3923. }
  3924. //--------------------------------------------------------------------------
  3925. // Node
  3926. //--------------------------------------------------------------------------
  3927. // MarshalBinary serializes the internal properties of this Node instance
  3928. // into a byte array
  3929. func (target *Node) MarshalBinary() (data []byte, err error) {
  3930. ctx := &EncodingContext{
  3931. Buffer: util.NewBuffer(),
  3932. Table: nil,
  3933. }
  3934. e := target.MarshalBinaryWithContext(ctx)
  3935. if e != nil {
  3936. return nil, e
  3937. }
  3938. encBytes := ctx.Buffer.Bytes()
  3939. return encBytes, nil
  3940. }
  3941. // MarshalBinaryWithContext serializes the internal properties of this Node instance
  3942. // into a byte array leveraging a predefined context.
  3943. func (target *Node) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  3944. // panics are recovered and propagated as errors
  3945. defer func() {
  3946. if r := recover(); r != nil {
  3947. if e, ok := r.(error); ok {
  3948. err = e
  3949. } else if s, ok := r.(string); ok {
  3950. err = fmt.Errorf("Unexpected panic: %s", s)
  3951. } else {
  3952. err = fmt.Errorf("Unexpected panic: %+v", r)
  3953. }
  3954. }
  3955. }()
  3956. buff := ctx.Buffer
  3957. buff.WriteUInt8(AssetsCodecVersion) // version
  3958. if target.properties == nil {
  3959. buff.WriteUInt8(uint8(0)) // write nil byte
  3960. } else {
  3961. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3962. // --- [begin][write][struct](AssetProperties) ---
  3963. buff.WriteInt(0) // [compatibility, unused]
  3964. errA := target.properties.MarshalBinaryWithContext(ctx)
  3965. if errA != nil {
  3966. return errA
  3967. }
  3968. // --- [end][write][struct](AssetProperties) ---
  3969. }
  3970. // --- [begin][write][alias](AssetLabels) ---
  3971. if map[string]string(target.labels) == nil {
  3972. buff.WriteUInt8(uint8(0)) // write nil byte
  3973. } else {
  3974. buff.WriteUInt8(uint8(1)) // write non-nil byte
  3975. // --- [begin][write][map](map[string]string) ---
  3976. buff.WriteInt(len(map[string]string(target.labels))) // map length
  3977. for v, z := range map[string]string(target.labels) {
  3978. if ctx.IsStringTable() {
  3979. a := ctx.Table.AddOrGet(v)
  3980. buff.WriteInt(a) // write table index
  3981. } else {
  3982. buff.WriteString(v) // write string
  3983. }
  3984. if ctx.IsStringTable() {
  3985. b := ctx.Table.AddOrGet(z)
  3986. buff.WriteInt(b) // write table index
  3987. } else {
  3988. buff.WriteString(z) // write string
  3989. }
  3990. }
  3991. // --- [end][write][map](map[string]string) ---
  3992. }
  3993. // --- [end][write][alias](AssetLabels) ---
  3994. // --- [begin][write][reference](time.Time) ---
  3995. c, errB := target.start.MarshalBinary()
  3996. if errB != nil {
  3997. return errB
  3998. }
  3999. buff.WriteInt(len(c))
  4000. buff.WriteBytes(c)
  4001. // --- [end][write][reference](time.Time) ---
  4002. // --- [begin][write][reference](time.Time) ---
  4003. d, errC := target.end.MarshalBinary()
  4004. if errC != nil {
  4005. return errC
  4006. }
  4007. buff.WriteInt(len(d))
  4008. buff.WriteBytes(d)
  4009. // --- [end][write][reference](time.Time) ---
  4010. // --- [begin][write][struct](Window) ---
  4011. buff.WriteInt(0) // [compatibility, unused]
  4012. errD := target.window.MarshalBinaryWithContext(ctx)
  4013. if errD != nil {
  4014. return errD
  4015. }
  4016. // --- [end][write][struct](Window) ---
  4017. buff.WriteFloat64(target.adjustment) // write float64
  4018. if ctx.IsStringTable() {
  4019. e := ctx.Table.AddOrGet(target.NodeType)
  4020. buff.WriteInt(e) // write table index
  4021. } else {
  4022. buff.WriteString(target.NodeType) // write string
  4023. }
  4024. buff.WriteFloat64(target.CPUCoreHours) // write float64
  4025. buff.WriteFloat64(target.RAMByteHours) // write float64
  4026. buff.WriteFloat64(target.GPUHours) // write float64
  4027. if target.CPUBreakdown == nil {
  4028. buff.WriteUInt8(uint8(0)) // write nil byte
  4029. } else {
  4030. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4031. // --- [begin][write][struct](Breakdown) ---
  4032. buff.WriteInt(0) // [compatibility, unused]
  4033. errE := target.CPUBreakdown.MarshalBinaryWithContext(ctx)
  4034. if errE != nil {
  4035. return errE
  4036. }
  4037. // --- [end][write][struct](Breakdown) ---
  4038. }
  4039. if target.RAMBreakdown == nil {
  4040. buff.WriteUInt8(uint8(0)) // write nil byte
  4041. } else {
  4042. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4043. // --- [begin][write][struct](Breakdown) ---
  4044. buff.WriteInt(0) // [compatibility, unused]
  4045. errF := target.RAMBreakdown.MarshalBinaryWithContext(ctx)
  4046. if errF != nil {
  4047. return errF
  4048. }
  4049. // --- [end][write][struct](Breakdown) ---
  4050. }
  4051. buff.WriteFloat64(target.CPUCost) // write float64
  4052. buff.WriteFloat64(target.GPUCost) // write float64
  4053. buff.WriteFloat64(target.GPUCount) // write float64
  4054. buff.WriteFloat64(target.RAMCost) // write float64
  4055. buff.WriteFloat64(target.Discount) // write float64
  4056. buff.WriteFloat64(target.Preemptible) // write float64
  4057. return nil
  4058. }
  4059. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4060. // the Node type
  4061. func (target *Node) UnmarshalBinary(data []byte) error {
  4062. var table []string
  4063. buff := util.NewBufferFromBytes(data)
  4064. // string table header validation
  4065. if isBinaryTag(data, BinaryTagStringTable) {
  4066. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4067. tl := buff.ReadInt() // table length
  4068. if tl > 0 {
  4069. table = make([]string, tl, tl)
  4070. for i := 0; i < tl; i++ {
  4071. table[i] = buff.ReadString()
  4072. }
  4073. }
  4074. }
  4075. ctx := &DecodingContext{
  4076. Buffer: buff,
  4077. Table: table,
  4078. }
  4079. err := target.UnmarshalBinaryWithContext(ctx)
  4080. if err != nil {
  4081. return err
  4082. }
  4083. return nil
  4084. }
  4085. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4086. // the Node type
  4087. func (target *Node) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4088. // panics are recovered and propagated as errors
  4089. defer func() {
  4090. if r := recover(); r != nil {
  4091. if e, ok := r.(error); ok {
  4092. err = e
  4093. } else if s, ok := r.(string); ok {
  4094. err = fmt.Errorf("Unexpected panic: %s", s)
  4095. } else {
  4096. err = fmt.Errorf("Unexpected panic: %+v", r)
  4097. }
  4098. }
  4099. }()
  4100. buff := ctx.Buffer
  4101. version := buff.ReadUInt8()
  4102. if version > AssetsCodecVersion {
  4103. return fmt.Errorf("Invalid Version Unmarshaling Node. Expected %d or less, got %d", AssetsCodecVersion, version)
  4104. }
  4105. if uint8(0) /* field version */ <= version {
  4106. if buff.ReadUInt8() == uint8(0) {
  4107. target.properties = nil
  4108. } else {
  4109. // --- [begin][read][struct](AssetProperties) ---
  4110. a := &AssetProperties{}
  4111. buff.ReadInt() // [compatibility, unused]
  4112. errA := a.UnmarshalBinaryWithContext(ctx)
  4113. if errA != nil {
  4114. return errA
  4115. }
  4116. target.properties = a
  4117. // --- [end][read][struct](AssetProperties) ---
  4118. }
  4119. } else {
  4120. target.properties = nil
  4121. }
  4122. if uint8(0) /* field version */ <= version {
  4123. // --- [begin][read][alias](AssetLabels) ---
  4124. var b map[string]string
  4125. if buff.ReadUInt8() == uint8(0) {
  4126. b = nil
  4127. } else {
  4128. // --- [begin][read][map](map[string]string) ---
  4129. d := buff.ReadInt() // map len
  4130. c := make(map[string]string, d)
  4131. for i := 0; i < d; i++ {
  4132. var v string
  4133. var f string
  4134. if ctx.IsStringTable() {
  4135. g := buff.ReadInt() // read string index
  4136. f = ctx.Table[g]
  4137. } else {
  4138. f = buff.ReadString() // read string
  4139. }
  4140. e := f
  4141. v = e
  4142. var z string
  4143. var k string
  4144. if ctx.IsStringTable() {
  4145. l := buff.ReadInt() // read string index
  4146. k = ctx.Table[l]
  4147. } else {
  4148. k = buff.ReadString() // read string
  4149. }
  4150. h := k
  4151. z = h
  4152. c[v] = z
  4153. }
  4154. b = c
  4155. // --- [end][read][map](map[string]string) ---
  4156. }
  4157. target.labels = AssetLabels(b)
  4158. // --- [end][read][alias](AssetLabels) ---
  4159. } else {
  4160. }
  4161. if uint8(0) /* field version */ <= version {
  4162. // --- [begin][read][reference](time.Time) ---
  4163. m := &time.Time{}
  4164. n := buff.ReadInt() // byte array length
  4165. o := buff.ReadBytes(n) // byte array
  4166. errB := m.UnmarshalBinary(o)
  4167. if errB != nil {
  4168. return errB
  4169. }
  4170. target.start = *m
  4171. // --- [end][read][reference](time.Time) ---
  4172. } else {
  4173. }
  4174. if uint8(0) /* field version */ <= version {
  4175. // --- [begin][read][reference](time.Time) ---
  4176. p := &time.Time{}
  4177. q := buff.ReadInt() // byte array length
  4178. r := buff.ReadBytes(q) // byte array
  4179. errC := p.UnmarshalBinary(r)
  4180. if errC != nil {
  4181. return errC
  4182. }
  4183. target.end = *p
  4184. // --- [end][read][reference](time.Time) ---
  4185. } else {
  4186. }
  4187. if uint8(0) /* field version */ <= version {
  4188. // --- [begin][read][struct](Window) ---
  4189. s := &Window{}
  4190. buff.ReadInt() // [compatibility, unused]
  4191. errD := s.UnmarshalBinaryWithContext(ctx)
  4192. if errD != nil {
  4193. return errD
  4194. }
  4195. target.window = *s
  4196. // --- [end][read][struct](Window) ---
  4197. } else {
  4198. }
  4199. if uint8(0) /* field version */ <= version {
  4200. t := buff.ReadFloat64() // read float64
  4201. target.adjustment = t
  4202. } else {
  4203. target.adjustment = float64(0) // default
  4204. }
  4205. if uint8(0) /* field version */ <= version {
  4206. var w string
  4207. if ctx.IsStringTable() {
  4208. x := buff.ReadInt() // read string index
  4209. w = ctx.Table[x]
  4210. } else {
  4211. w = buff.ReadString() // read string
  4212. }
  4213. u := w
  4214. target.NodeType = u
  4215. } else {
  4216. target.NodeType = "" // default
  4217. }
  4218. if uint8(0) /* field version */ <= version {
  4219. y := buff.ReadFloat64() // read float64
  4220. target.CPUCoreHours = y
  4221. } else {
  4222. target.CPUCoreHours = float64(0) // default
  4223. }
  4224. if uint8(0) /* field version */ <= version {
  4225. aa := buff.ReadFloat64() // read float64
  4226. target.RAMByteHours = aa
  4227. } else {
  4228. target.RAMByteHours = float64(0) // default
  4229. }
  4230. if uint8(0) /* field version */ <= version {
  4231. bb := buff.ReadFloat64() // read float64
  4232. target.GPUHours = bb
  4233. } else {
  4234. target.GPUHours = float64(0) // default
  4235. }
  4236. if uint8(0) /* field version */ <= version {
  4237. if buff.ReadUInt8() == uint8(0) {
  4238. target.CPUBreakdown = nil
  4239. } else {
  4240. // --- [begin][read][struct](Breakdown) ---
  4241. cc := &Breakdown{}
  4242. buff.ReadInt() // [compatibility, unused]
  4243. errE := cc.UnmarshalBinaryWithContext(ctx)
  4244. if errE != nil {
  4245. return errE
  4246. }
  4247. target.CPUBreakdown = cc
  4248. // --- [end][read][struct](Breakdown) ---
  4249. }
  4250. } else {
  4251. target.CPUBreakdown = nil
  4252. }
  4253. if uint8(0) /* field version */ <= version {
  4254. if buff.ReadUInt8() == uint8(0) {
  4255. target.RAMBreakdown = nil
  4256. } else {
  4257. // --- [begin][read][struct](Breakdown) ---
  4258. dd := &Breakdown{}
  4259. buff.ReadInt() // [compatibility, unused]
  4260. errF := dd.UnmarshalBinaryWithContext(ctx)
  4261. if errF != nil {
  4262. return errF
  4263. }
  4264. target.RAMBreakdown = dd
  4265. // --- [end][read][struct](Breakdown) ---
  4266. }
  4267. } else {
  4268. target.RAMBreakdown = nil
  4269. }
  4270. if uint8(0) /* field version */ <= version {
  4271. ee := buff.ReadFloat64() // read float64
  4272. target.CPUCost = ee
  4273. } else {
  4274. target.CPUCost = float64(0) // default
  4275. }
  4276. if uint8(0) /* field version */ <= version {
  4277. ff := buff.ReadFloat64() // read float64
  4278. target.GPUCost = ff
  4279. } else {
  4280. target.GPUCost = float64(0) // default
  4281. }
  4282. if uint8(0) /* field version */ <= version {
  4283. gg := buff.ReadFloat64() // read float64
  4284. target.GPUCount = gg
  4285. } else {
  4286. target.GPUCount = float64(0) // default
  4287. }
  4288. if uint8(0) /* field version */ <= version {
  4289. hh := buff.ReadFloat64() // read float64
  4290. target.RAMCost = hh
  4291. } else {
  4292. target.RAMCost = float64(0) // default
  4293. }
  4294. if uint8(0) /* field version */ <= version {
  4295. kk := buff.ReadFloat64() // read float64
  4296. target.Discount = kk
  4297. } else {
  4298. target.Discount = float64(0) // default
  4299. }
  4300. if uint8(0) /* field version */ <= version {
  4301. ll := buff.ReadFloat64() // read float64
  4302. target.Preemptible = ll
  4303. } else {
  4304. target.Preemptible = float64(0) // default
  4305. }
  4306. return nil
  4307. }
  4308. //--------------------------------------------------------------------------
  4309. // PVAllocation
  4310. //--------------------------------------------------------------------------
  4311. // MarshalBinary serializes the internal properties of this PVAllocation instance
  4312. // into a byte array
  4313. func (target *PVAllocation) MarshalBinary() (data []byte, err error) {
  4314. ctx := &EncodingContext{
  4315. Buffer: util.NewBuffer(),
  4316. Table: nil,
  4317. }
  4318. e := target.MarshalBinaryWithContext(ctx)
  4319. if e != nil {
  4320. return nil, e
  4321. }
  4322. encBytes := ctx.Buffer.Bytes()
  4323. return encBytes, nil
  4324. }
  4325. // MarshalBinaryWithContext serializes the internal properties of this PVAllocation instance
  4326. // into a byte array leveraging a predefined context.
  4327. func (target *PVAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4328. // panics are recovered and propagated as errors
  4329. defer func() {
  4330. if r := recover(); r != nil {
  4331. if e, ok := r.(error); ok {
  4332. err = e
  4333. } else if s, ok := r.(string); ok {
  4334. err = fmt.Errorf("Unexpected panic: %s", s)
  4335. } else {
  4336. err = fmt.Errorf("Unexpected panic: %+v", r)
  4337. }
  4338. }
  4339. }()
  4340. buff := ctx.Buffer
  4341. buff.WriteUInt8(AllocationCodecVersion) // version
  4342. buff.WriteFloat64(target.ByteHours) // write float64
  4343. buff.WriteFloat64(target.Cost) // write float64
  4344. return nil
  4345. }
  4346. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4347. // the PVAllocation type
  4348. func (target *PVAllocation) UnmarshalBinary(data []byte) error {
  4349. var table []string
  4350. buff := util.NewBufferFromBytes(data)
  4351. // string table header validation
  4352. if isBinaryTag(data, BinaryTagStringTable) {
  4353. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4354. tl := buff.ReadInt() // table length
  4355. if tl > 0 {
  4356. table = make([]string, tl, tl)
  4357. for i := 0; i < tl; i++ {
  4358. table[i] = buff.ReadString()
  4359. }
  4360. }
  4361. }
  4362. ctx := &DecodingContext{
  4363. Buffer: buff,
  4364. Table: table,
  4365. }
  4366. err := target.UnmarshalBinaryWithContext(ctx)
  4367. if err != nil {
  4368. return err
  4369. }
  4370. return nil
  4371. }
  4372. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4373. // the PVAllocation type
  4374. func (target *PVAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4375. // panics are recovered and propagated as errors
  4376. defer func() {
  4377. if r := recover(); r != nil {
  4378. if e, ok := r.(error); ok {
  4379. err = e
  4380. } else if s, ok := r.(string); ok {
  4381. err = fmt.Errorf("Unexpected panic: %s", s)
  4382. } else {
  4383. err = fmt.Errorf("Unexpected panic: %+v", r)
  4384. }
  4385. }
  4386. }()
  4387. buff := ctx.Buffer
  4388. version := buff.ReadUInt8()
  4389. if version > AllocationCodecVersion {
  4390. return fmt.Errorf("Invalid Version Unmarshaling PVAllocation. Expected %d or less, got %d", AllocationCodecVersion, version)
  4391. }
  4392. if uint8(0) /* field version */ <= version {
  4393. a := buff.ReadFloat64() // read float64
  4394. target.ByteHours = a
  4395. } else {
  4396. target.ByteHours = float64(0) // default
  4397. }
  4398. if uint8(0) /* field version */ <= version {
  4399. b := buff.ReadFloat64() // read float64
  4400. target.Cost = b
  4401. } else {
  4402. target.Cost = float64(0) // default
  4403. }
  4404. return nil
  4405. }
  4406. //--------------------------------------------------------------------------
  4407. // PVKey
  4408. //--------------------------------------------------------------------------
  4409. // MarshalBinary serializes the internal properties of this PVKey instance
  4410. // into a byte array
  4411. func (target *PVKey) MarshalBinary() (data []byte, err error) {
  4412. ctx := &EncodingContext{
  4413. Buffer: util.NewBuffer(),
  4414. Table: nil,
  4415. }
  4416. e := target.MarshalBinaryWithContext(ctx)
  4417. if e != nil {
  4418. return nil, e
  4419. }
  4420. encBytes := ctx.Buffer.Bytes()
  4421. return encBytes, nil
  4422. }
  4423. // MarshalBinaryWithContext serializes the internal properties of this PVKey instance
  4424. // into a byte array leveraging a predefined context.
  4425. func (target *PVKey) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4426. // panics are recovered and propagated as errors
  4427. defer func() {
  4428. if r := recover(); r != nil {
  4429. if e, ok := r.(error); ok {
  4430. err = e
  4431. } else if s, ok := r.(string); ok {
  4432. err = fmt.Errorf("Unexpected panic: %s", s)
  4433. } else {
  4434. err = fmt.Errorf("Unexpected panic: %+v", r)
  4435. }
  4436. }
  4437. }()
  4438. buff := ctx.Buffer
  4439. buff.WriteUInt8(AllocationCodecVersion) // version
  4440. if ctx.IsStringTable() {
  4441. a := ctx.Table.AddOrGet(target.Cluster)
  4442. buff.WriteInt(a) // write table index
  4443. } else {
  4444. buff.WriteString(target.Cluster) // write string
  4445. }
  4446. if ctx.IsStringTable() {
  4447. b := ctx.Table.AddOrGet(target.Name)
  4448. buff.WriteInt(b) // write table index
  4449. } else {
  4450. buff.WriteString(target.Name) // write string
  4451. }
  4452. return nil
  4453. }
  4454. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4455. // the PVKey type
  4456. func (target *PVKey) UnmarshalBinary(data []byte) error {
  4457. var table []string
  4458. buff := util.NewBufferFromBytes(data)
  4459. // string table header validation
  4460. if isBinaryTag(data, BinaryTagStringTable) {
  4461. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4462. tl := buff.ReadInt() // table length
  4463. if tl > 0 {
  4464. table = make([]string, tl, tl)
  4465. for i := 0; i < tl; i++ {
  4466. table[i] = buff.ReadString()
  4467. }
  4468. }
  4469. }
  4470. ctx := &DecodingContext{
  4471. Buffer: buff,
  4472. Table: table,
  4473. }
  4474. err := target.UnmarshalBinaryWithContext(ctx)
  4475. if err != nil {
  4476. return err
  4477. }
  4478. return nil
  4479. }
  4480. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4481. // the PVKey type
  4482. func (target *PVKey) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4483. // panics are recovered and propagated as errors
  4484. defer func() {
  4485. if r := recover(); r != nil {
  4486. if e, ok := r.(error); ok {
  4487. err = e
  4488. } else if s, ok := r.(string); ok {
  4489. err = fmt.Errorf("Unexpected panic: %s", s)
  4490. } else {
  4491. err = fmt.Errorf("Unexpected panic: %+v", r)
  4492. }
  4493. }
  4494. }()
  4495. buff := ctx.Buffer
  4496. version := buff.ReadUInt8()
  4497. if version > AllocationCodecVersion {
  4498. return fmt.Errorf("Invalid Version Unmarshaling PVKey. Expected %d or less, got %d", AllocationCodecVersion, version)
  4499. }
  4500. if uint8(0) /* field version */ <= version {
  4501. var b string
  4502. if ctx.IsStringTable() {
  4503. c := buff.ReadInt() // read string index
  4504. b = ctx.Table[c]
  4505. } else {
  4506. b = buff.ReadString() // read string
  4507. }
  4508. a := b
  4509. target.Cluster = a
  4510. } else {
  4511. target.Cluster = "" // default
  4512. }
  4513. if uint8(0) /* field version */ <= version {
  4514. var e string
  4515. if ctx.IsStringTable() {
  4516. f := buff.ReadInt() // read string index
  4517. e = ctx.Table[f]
  4518. } else {
  4519. e = buff.ReadString() // read string
  4520. }
  4521. d := e
  4522. target.Name = d
  4523. } else {
  4524. target.Name = "" // default
  4525. }
  4526. return nil
  4527. }
  4528. //--------------------------------------------------------------------------
  4529. // RawAllocationOnlyData
  4530. //--------------------------------------------------------------------------
  4531. // MarshalBinary serializes the internal properties of this RawAllocationOnlyData instance
  4532. // into a byte array
  4533. func (target *RawAllocationOnlyData) MarshalBinary() (data []byte, err error) {
  4534. ctx := &EncodingContext{
  4535. Buffer: util.NewBuffer(),
  4536. Table: nil,
  4537. }
  4538. e := target.MarshalBinaryWithContext(ctx)
  4539. if e != nil {
  4540. return nil, e
  4541. }
  4542. encBytes := ctx.Buffer.Bytes()
  4543. return encBytes, nil
  4544. }
  4545. // MarshalBinaryWithContext serializes the internal properties of this RawAllocationOnlyData instance
  4546. // into a byte array leveraging a predefined context.
  4547. func (target *RawAllocationOnlyData) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4548. // panics are recovered and propagated as errors
  4549. defer func() {
  4550. if r := recover(); r != nil {
  4551. if e, ok := r.(error); ok {
  4552. err = e
  4553. } else if s, ok := r.(string); ok {
  4554. err = fmt.Errorf("Unexpected panic: %s", s)
  4555. } else {
  4556. err = fmt.Errorf("Unexpected panic: %+v", r)
  4557. }
  4558. }
  4559. }()
  4560. buff := ctx.Buffer
  4561. buff.WriteUInt8(AllocationCodecVersion) // version
  4562. buff.WriteFloat64(target.CPUCoreUsageMax) // write float64
  4563. buff.WriteFloat64(target.RAMBytesUsageMax) // write float64
  4564. return nil
  4565. }
  4566. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4567. // the RawAllocationOnlyData type
  4568. func (target *RawAllocationOnlyData) UnmarshalBinary(data []byte) error {
  4569. var table []string
  4570. buff := util.NewBufferFromBytes(data)
  4571. // string table header validation
  4572. if isBinaryTag(data, BinaryTagStringTable) {
  4573. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4574. tl := buff.ReadInt() // table length
  4575. if tl > 0 {
  4576. table = make([]string, tl, tl)
  4577. for i := 0; i < tl; i++ {
  4578. table[i] = buff.ReadString()
  4579. }
  4580. }
  4581. }
  4582. ctx := &DecodingContext{
  4583. Buffer: buff,
  4584. Table: table,
  4585. }
  4586. err := target.UnmarshalBinaryWithContext(ctx)
  4587. if err != nil {
  4588. return err
  4589. }
  4590. return nil
  4591. }
  4592. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4593. // the RawAllocationOnlyData type
  4594. func (target *RawAllocationOnlyData) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4595. // panics are recovered and propagated as errors
  4596. defer func() {
  4597. if r := recover(); r != nil {
  4598. if e, ok := r.(error); ok {
  4599. err = e
  4600. } else if s, ok := r.(string); ok {
  4601. err = fmt.Errorf("Unexpected panic: %s", s)
  4602. } else {
  4603. err = fmt.Errorf("Unexpected panic: %+v", r)
  4604. }
  4605. }
  4606. }()
  4607. buff := ctx.Buffer
  4608. version := buff.ReadUInt8()
  4609. if version > AllocationCodecVersion {
  4610. return fmt.Errorf("Invalid Version Unmarshaling RawAllocationOnlyData. Expected %d or less, got %d", AllocationCodecVersion, version)
  4611. }
  4612. if uint8(0) /* field version */ <= version {
  4613. a := buff.ReadFloat64() // read float64
  4614. target.CPUCoreUsageMax = a
  4615. } else {
  4616. target.CPUCoreUsageMax = float64(0) // default
  4617. }
  4618. if uint8(0) /* field version */ <= version {
  4619. b := buff.ReadFloat64() // read float64
  4620. target.RAMBytesUsageMax = b
  4621. } else {
  4622. target.RAMBytesUsageMax = float64(0) // default
  4623. }
  4624. return nil
  4625. }
  4626. //--------------------------------------------------------------------------
  4627. // SharedAsset
  4628. //--------------------------------------------------------------------------
  4629. // MarshalBinary serializes the internal properties of this SharedAsset instance
  4630. // into a byte array
  4631. func (target *SharedAsset) MarshalBinary() (data []byte, err error) {
  4632. ctx := &EncodingContext{
  4633. Buffer: util.NewBuffer(),
  4634. Table: nil,
  4635. }
  4636. e := target.MarshalBinaryWithContext(ctx)
  4637. if e != nil {
  4638. return nil, e
  4639. }
  4640. encBytes := ctx.Buffer.Bytes()
  4641. return encBytes, nil
  4642. }
  4643. // MarshalBinaryWithContext serializes the internal properties of this SharedAsset instance
  4644. // into a byte array leveraging a predefined context.
  4645. func (target *SharedAsset) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4646. // panics are recovered and propagated as errors
  4647. defer func() {
  4648. if r := recover(); r != nil {
  4649. if e, ok := r.(error); ok {
  4650. err = e
  4651. } else if s, ok := r.(string); ok {
  4652. err = fmt.Errorf("Unexpected panic: %s", s)
  4653. } else {
  4654. err = fmt.Errorf("Unexpected panic: %+v", r)
  4655. }
  4656. }
  4657. }()
  4658. buff := ctx.Buffer
  4659. buff.WriteUInt8(AssetsCodecVersion) // version
  4660. if target.properties == nil {
  4661. buff.WriteUInt8(uint8(0)) // write nil byte
  4662. } else {
  4663. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4664. // --- [begin][write][struct](AssetProperties) ---
  4665. buff.WriteInt(0) // [compatibility, unused]
  4666. errA := target.properties.MarshalBinaryWithContext(ctx)
  4667. if errA != nil {
  4668. return errA
  4669. }
  4670. // --- [end][write][struct](AssetProperties) ---
  4671. }
  4672. // --- [begin][write][alias](AssetLabels) ---
  4673. if map[string]string(target.labels) == nil {
  4674. buff.WriteUInt8(uint8(0)) // write nil byte
  4675. } else {
  4676. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4677. // --- [begin][write][map](map[string]string) ---
  4678. buff.WriteInt(len(map[string]string(target.labels))) // map length
  4679. for v, z := range map[string]string(target.labels) {
  4680. if ctx.IsStringTable() {
  4681. a := ctx.Table.AddOrGet(v)
  4682. buff.WriteInt(a) // write table index
  4683. } else {
  4684. buff.WriteString(v) // write string
  4685. }
  4686. if ctx.IsStringTable() {
  4687. b := ctx.Table.AddOrGet(z)
  4688. buff.WriteInt(b) // write table index
  4689. } else {
  4690. buff.WriteString(z) // write string
  4691. }
  4692. }
  4693. // --- [end][write][map](map[string]string) ---
  4694. }
  4695. // --- [end][write][alias](AssetLabels) ---
  4696. // --- [begin][write][struct](Window) ---
  4697. buff.WriteInt(0) // [compatibility, unused]
  4698. errB := target.window.MarshalBinaryWithContext(ctx)
  4699. if errB != nil {
  4700. return errB
  4701. }
  4702. // --- [end][write][struct](Window) ---
  4703. buff.WriteFloat64(target.Cost) // write float64
  4704. return nil
  4705. }
  4706. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4707. // the SharedAsset type
  4708. func (target *SharedAsset) UnmarshalBinary(data []byte) error {
  4709. var table []string
  4710. buff := util.NewBufferFromBytes(data)
  4711. // string table header validation
  4712. if isBinaryTag(data, BinaryTagStringTable) {
  4713. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4714. tl := buff.ReadInt() // table length
  4715. if tl > 0 {
  4716. table = make([]string, tl, tl)
  4717. for i := 0; i < tl; i++ {
  4718. table[i] = buff.ReadString()
  4719. }
  4720. }
  4721. }
  4722. ctx := &DecodingContext{
  4723. Buffer: buff,
  4724. Table: table,
  4725. }
  4726. err := target.UnmarshalBinaryWithContext(ctx)
  4727. if err != nil {
  4728. return err
  4729. }
  4730. return nil
  4731. }
  4732. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4733. // the SharedAsset type
  4734. func (target *SharedAsset) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4735. // panics are recovered and propagated as errors
  4736. defer func() {
  4737. if r := recover(); r != nil {
  4738. if e, ok := r.(error); ok {
  4739. err = e
  4740. } else if s, ok := r.(string); ok {
  4741. err = fmt.Errorf("Unexpected panic: %s", s)
  4742. } else {
  4743. err = fmt.Errorf("Unexpected panic: %+v", r)
  4744. }
  4745. }
  4746. }()
  4747. buff := ctx.Buffer
  4748. version := buff.ReadUInt8()
  4749. if version > AssetsCodecVersion {
  4750. return fmt.Errorf("Invalid Version Unmarshaling SharedAsset. Expected %d or less, got %d", AssetsCodecVersion, version)
  4751. }
  4752. if uint8(0) /* field version */ <= version {
  4753. if buff.ReadUInt8() == uint8(0) {
  4754. target.properties = nil
  4755. } else {
  4756. // --- [begin][read][struct](AssetProperties) ---
  4757. a := &AssetProperties{}
  4758. buff.ReadInt() // [compatibility, unused]
  4759. errA := a.UnmarshalBinaryWithContext(ctx)
  4760. if errA != nil {
  4761. return errA
  4762. }
  4763. target.properties = a
  4764. // --- [end][read][struct](AssetProperties) ---
  4765. }
  4766. } else {
  4767. target.properties = nil
  4768. }
  4769. if uint8(0) /* field version */ <= version {
  4770. // --- [begin][read][alias](AssetLabels) ---
  4771. var b map[string]string
  4772. if buff.ReadUInt8() == uint8(0) {
  4773. b = nil
  4774. } else {
  4775. // --- [begin][read][map](map[string]string) ---
  4776. d := buff.ReadInt() // map len
  4777. c := make(map[string]string, d)
  4778. for i := 0; i < d; i++ {
  4779. var v string
  4780. var f string
  4781. if ctx.IsStringTable() {
  4782. g := buff.ReadInt() // read string index
  4783. f = ctx.Table[g]
  4784. } else {
  4785. f = buff.ReadString() // read string
  4786. }
  4787. e := f
  4788. v = e
  4789. var z string
  4790. var k string
  4791. if ctx.IsStringTable() {
  4792. l := buff.ReadInt() // read string index
  4793. k = ctx.Table[l]
  4794. } else {
  4795. k = buff.ReadString() // read string
  4796. }
  4797. h := k
  4798. z = h
  4799. c[v] = z
  4800. }
  4801. b = c
  4802. // --- [end][read][map](map[string]string) ---
  4803. }
  4804. target.labels = AssetLabels(b)
  4805. // --- [end][read][alias](AssetLabels) ---
  4806. } else {
  4807. }
  4808. if uint8(0) /* field version */ <= version {
  4809. // --- [begin][read][struct](Window) ---
  4810. m := &Window{}
  4811. buff.ReadInt() // [compatibility, unused]
  4812. errB := m.UnmarshalBinaryWithContext(ctx)
  4813. if errB != nil {
  4814. return errB
  4815. }
  4816. target.window = *m
  4817. // --- [end][read][struct](Window) ---
  4818. } else {
  4819. }
  4820. if uint8(0) /* field version */ <= version {
  4821. n := buff.ReadFloat64() // read float64
  4822. target.Cost = n
  4823. } else {
  4824. target.Cost = float64(0) // default
  4825. }
  4826. return nil
  4827. }
  4828. //--------------------------------------------------------------------------
  4829. // Window
  4830. //--------------------------------------------------------------------------
  4831. // MarshalBinary serializes the internal properties of this Window instance
  4832. // into a byte array
  4833. func (target *Window) MarshalBinary() (data []byte, err error) {
  4834. ctx := &EncodingContext{
  4835. Buffer: util.NewBuffer(),
  4836. Table: nil,
  4837. }
  4838. e := target.MarshalBinaryWithContext(ctx)
  4839. if e != nil {
  4840. return nil, e
  4841. }
  4842. encBytes := ctx.Buffer.Bytes()
  4843. return encBytes, nil
  4844. }
  4845. // MarshalBinaryWithContext serializes the internal properties of this Window instance
  4846. // into a byte array leveraging a predefined context.
  4847. func (target *Window) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
  4848. // panics are recovered and propagated as errors
  4849. defer func() {
  4850. if r := recover(); r != nil {
  4851. if e, ok := r.(error); ok {
  4852. err = e
  4853. } else if s, ok := r.(string); ok {
  4854. err = fmt.Errorf("Unexpected panic: %s", s)
  4855. } else {
  4856. err = fmt.Errorf("Unexpected panic: %+v", r)
  4857. }
  4858. }
  4859. }()
  4860. buff := ctx.Buffer
  4861. buff.WriteUInt8(DefaultCodecVersion) // version
  4862. if target.start == nil {
  4863. buff.WriteUInt8(uint8(0)) // write nil byte
  4864. } else {
  4865. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4866. // --- [begin][write][reference](time.Time) ---
  4867. a, errA := target.start.MarshalBinary()
  4868. if errA != nil {
  4869. return errA
  4870. }
  4871. buff.WriteInt(len(a))
  4872. buff.WriteBytes(a)
  4873. // --- [end][write][reference](time.Time) ---
  4874. }
  4875. if target.end == nil {
  4876. buff.WriteUInt8(uint8(0)) // write nil byte
  4877. } else {
  4878. buff.WriteUInt8(uint8(1)) // write non-nil byte
  4879. // --- [begin][write][reference](time.Time) ---
  4880. b, errB := target.end.MarshalBinary()
  4881. if errB != nil {
  4882. return errB
  4883. }
  4884. buff.WriteInt(len(b))
  4885. buff.WriteBytes(b)
  4886. // --- [end][write][reference](time.Time) ---
  4887. }
  4888. return nil
  4889. }
  4890. // UnmarshalBinary uses the data passed byte array to set all the internal properties of
  4891. // the Window type
  4892. func (target *Window) UnmarshalBinary(data []byte) error {
  4893. var table []string
  4894. buff := util.NewBufferFromBytes(data)
  4895. // string table header validation
  4896. if isBinaryTag(data, BinaryTagStringTable) {
  4897. buff.ReadBytes(len(BinaryTagStringTable)) // strip tag length
  4898. tl := buff.ReadInt() // table length
  4899. if tl > 0 {
  4900. table = make([]string, tl, tl)
  4901. for i := 0; i < tl; i++ {
  4902. table[i] = buff.ReadString()
  4903. }
  4904. }
  4905. }
  4906. ctx := &DecodingContext{
  4907. Buffer: buff,
  4908. Table: table,
  4909. }
  4910. err := target.UnmarshalBinaryWithContext(ctx)
  4911. if err != nil {
  4912. return err
  4913. }
  4914. return nil
  4915. }
  4916. // UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of
  4917. // the Window type
  4918. func (target *Window) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error) {
  4919. // panics are recovered and propagated as errors
  4920. defer func() {
  4921. if r := recover(); r != nil {
  4922. if e, ok := r.(error); ok {
  4923. err = e
  4924. } else if s, ok := r.(string); ok {
  4925. err = fmt.Errorf("Unexpected panic: %s", s)
  4926. } else {
  4927. err = fmt.Errorf("Unexpected panic: %+v", r)
  4928. }
  4929. }
  4930. }()
  4931. buff := ctx.Buffer
  4932. version := buff.ReadUInt8()
  4933. if version > DefaultCodecVersion {
  4934. return fmt.Errorf("Invalid Version Unmarshaling Window. Expected %d or less, got %d", DefaultCodecVersion, version)
  4935. }
  4936. if uint8(0) /* field version */ <= version {
  4937. if buff.ReadUInt8() == uint8(0) {
  4938. target.start = nil
  4939. } else {
  4940. // --- [begin][read][reference](time.Time) ---
  4941. a := &time.Time{}
  4942. b := buff.ReadInt() // byte array length
  4943. c := buff.ReadBytes(b) // byte array
  4944. errA := a.UnmarshalBinary(c)
  4945. if errA != nil {
  4946. return errA
  4947. }
  4948. target.start = a
  4949. // --- [end][read][reference](time.Time) ---
  4950. }
  4951. } else {
  4952. target.start = nil
  4953. }
  4954. if uint8(0) /* field version */ <= version {
  4955. if buff.ReadUInt8() == uint8(0) {
  4956. target.end = nil
  4957. } else {
  4958. // --- [begin][read][reference](time.Time) ---
  4959. d := &time.Time{}
  4960. e := buff.ReadInt() // byte array length
  4961. f := buff.ReadBytes(e) // byte array
  4962. errB := d.UnmarshalBinary(f)
  4963. if errB != nil {
  4964. return errB
  4965. }
  4966. target.end = d
  4967. // --- [end][read][reference](time.Time) ---
  4968. }
  4969. } else {
  4970. target.end = nil
  4971. }
  4972. return nil
  4973. }