暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FixedString.gen.cs 266KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890
  1. 
  2. //------------------------------------------------------------------------------
  3. // <auto-generated>
  4. // This code was generated by a tool.
  5. //
  6. // TextTransform Samples/Packages/com.unity.collections/Unity.Collections/FixedString.tt
  7. //
  8. // Changes to this file may cause incorrect behavior and will be lost if
  9. // the code is regenerated.
  10. // </auto-generated>
  11. //------------------------------------------------------------------------------
  12. using System.Collections.Generic;
  13. using System.Collections;
  14. using System.Diagnostics;
  15. using System.Runtime.CompilerServices;
  16. using System.Runtime.InteropServices;
  17. using System;
  18. using Unity.Collections.LowLevel.Unsafe;
  19. using Unity.Mathematics;
  20. using UnityEngine.Internal;
  21. using UnityEngine;
  22. #if UNITY_PROPERTIES_EXISTS
  23. using Unity.Properties;
  24. #endif
  25. namespace Unity.Collections
  26. {
  27. // A temporary copy of a struct is made before it is displayed in a C# debugger.
  28. // However, only the first element of data members with names is copied at this time.
  29. // Therefore, it's important that all data visible in the debugger, has a name
  30. // and includes no 'fixed' array. This is why we name every byte in the following struct.
  31. /// <summary>
  32. /// <undoc /> [FixedBytes will be removed]
  33. /// </summary>
  34. [Serializable]
  35. [StructLayout(LayoutKind.Explicit, Size=16)]
  36. [BurstCompatible]
  37. public struct FixedBytes16
  38. {
  39. /// <summary>
  40. /// For internal use only.
  41. /// </summary>
  42. [FieldOffset(0)] public byte byte0000;
  43. /// <summary>
  44. /// For internal use only.
  45. /// </summary>
  46. [FieldOffset(1)] public byte byte0001;
  47. /// <summary>
  48. /// For internal use only.
  49. /// </summary>
  50. [FieldOffset(2)] public byte byte0002;
  51. /// <summary>
  52. /// For internal use only.
  53. /// </summary>
  54. [FieldOffset(3)] public byte byte0003;
  55. /// <summary>
  56. /// For internal use only.
  57. /// </summary>
  58. [FieldOffset(4)] public byte byte0004;
  59. /// <summary>
  60. /// For internal use only.
  61. /// </summary>
  62. [FieldOffset(5)] public byte byte0005;
  63. /// <summary>
  64. /// For internal use only.
  65. /// </summary>
  66. [FieldOffset(6)] public byte byte0006;
  67. /// <summary>
  68. /// For internal use only.
  69. /// </summary>
  70. [FieldOffset(7)] public byte byte0007;
  71. /// <summary>
  72. /// For internal use only.
  73. /// </summary>
  74. [FieldOffset(8)] public byte byte0008;
  75. /// <summary>
  76. /// For internal use only.
  77. /// </summary>
  78. [FieldOffset(9)] public byte byte0009;
  79. /// <summary>
  80. /// For internal use only.
  81. /// </summary>
  82. [FieldOffset(10)] public byte byte0010;
  83. /// <summary>
  84. /// For internal use only.
  85. /// </summary>
  86. [FieldOffset(11)] public byte byte0011;
  87. /// <summary>
  88. /// For internal use only.
  89. /// </summary>
  90. [FieldOffset(12)] public byte byte0012;
  91. /// <summary>
  92. /// For internal use only.
  93. /// </summary>
  94. [FieldOffset(13)] public byte byte0013;
  95. /// <summary>
  96. /// For internal use only.
  97. /// </summary>
  98. [FieldOffset(14)] public byte byte0014;
  99. /// <summary>
  100. /// For internal use only.
  101. /// </summary>
  102. [FieldOffset(15)] public byte byte0015;
  103. }
  104. // A temporary copy of a struct is made before it is displayed in a C# debugger.
  105. // However, only the first element of data members with names is copied at this time.
  106. // Therefore, it's important that all data visible in the debugger, has a name
  107. // and includes no 'fixed' array. This is why we name every byte in the following struct.
  108. /// <summary>
  109. /// For internal use only.
  110. /// </summary>
  111. [Serializable]
  112. [StructLayout(LayoutKind.Explicit, Size=30)]
  113. [BurstCompatible]
  114. public struct FixedBytes30
  115. {
  116. /// <summary>
  117. /// For internal use only.
  118. /// </summary>
  119. [FieldOffset(0)] public FixedBytes16 offset0000;
  120. /// <summary>
  121. /// For internal use only.
  122. /// </summary>
  123. [FieldOffset(16)] public byte byte0016;
  124. /// <summary>
  125. /// For internal use only.
  126. /// </summary>
  127. [FieldOffset(17)] public byte byte0017;
  128. /// <summary>
  129. /// For internal use only.
  130. /// </summary>
  131. [FieldOffset(18)] public byte byte0018;
  132. /// <summary>
  133. /// For internal use only.
  134. /// </summary>
  135. [FieldOffset(19)] public byte byte0019;
  136. /// <summary>
  137. /// For internal use only.
  138. /// </summary>
  139. [FieldOffset(20)] public byte byte0020;
  140. /// <summary>
  141. /// For internal use only.
  142. /// </summary>
  143. [FieldOffset(21)] public byte byte0021;
  144. /// <summary>
  145. /// For internal use only.
  146. /// </summary>
  147. [FieldOffset(22)] public byte byte0022;
  148. /// <summary>
  149. /// For internal use only.
  150. /// </summary>
  151. [FieldOffset(23)] public byte byte0023;
  152. /// <summary>
  153. /// For internal use only.
  154. /// </summary>
  155. [FieldOffset(24)] public byte byte0024;
  156. /// <summary>
  157. /// For internal use only.
  158. /// </summary>
  159. [FieldOffset(25)] public byte byte0025;
  160. /// <summary>
  161. /// For internal use only.
  162. /// </summary>
  163. [FieldOffset(26)] public byte byte0026;
  164. /// <summary>
  165. /// For internal use only.
  166. /// </summary>
  167. [FieldOffset(27)] public byte byte0027;
  168. /// <summary>
  169. /// For internal use only.
  170. /// </summary>
  171. [FieldOffset(28)] public byte byte0028;
  172. /// <summary>
  173. /// For internal use only.
  174. /// </summary>
  175. [FieldOffset(29)] public byte byte0029;
  176. }
  177. [Obsolete("Renamed to FixedString32Bytes (UnityUpgradable) -> FixedString32Bytes", true)]
  178. public partial struct FixedString32 {}
  179. /// <summary>
  180. /// An unmanaged UTF-8 string whose content is stored directly in the 32-byte struct.
  181. /// </summary>
  182. /// <remarks>
  183. /// The binary layout of this string is guaranteed, for now and all time, to be a length (a little-endian two byte integer)
  184. /// followed by the bytes of the characters (with no padding). A zero byte always immediately follows the last character.
  185. /// Effectively, the number of bytes for storing characters is 3 less than 32 (two length bytes and one null byte).
  186. ///
  187. /// This layout is identical to a <see cref="FixedList32Bytes{T}"/> of bytes, thus allowing reinterpretation between FixedString32Bytes and FixedList32Bytes.
  188. ///
  189. /// By virtue of being an unmanaged, non-allocated struct with no pointers, this string is fully compatible with jobs and Burst compilation.
  190. /// Unlike managed string types, these strings can be put in any unmanaged ECS components, FixedList, or any other unmanaged structs.
  191. /// </remarks>
  192. [Serializable]
  193. [StructLayout(LayoutKind.Sequential, Size=32)]
  194. [BurstCompatible]
  195. public partial struct FixedString32Bytes
  196. : INativeList<byte>
  197. , IUTF8Bytes
  198. , IComparable<String>
  199. , IEquatable<String>
  200. , IComparable<FixedString32Bytes>
  201. , IEquatable<FixedString32Bytes>
  202. , IComparable<FixedString64Bytes>
  203. , IEquatable<FixedString64Bytes>
  204. , IComparable<FixedString128Bytes>
  205. , IEquatable<FixedString128Bytes>
  206. , IComparable<FixedString512Bytes>
  207. , IEquatable<FixedString512Bytes>
  208. , IComparable<FixedString4096Bytes>
  209. , IEquatable<FixedString4096Bytes>
  210. {
  211. internal const ushort utf8MaxLengthInBytes = 29;
  212. [SerializeField] internal ushort utf8LengthInBytes;
  213. [SerializeField] internal FixedBytes30 bytes;
  214. /// <summary>
  215. /// Returns the maximum number of UTF-8 bytes that can be stored in this string.
  216. /// </summary>
  217. /// <returns>
  218. /// The maximum number of UTF-8 bytes that can be stored in this string.
  219. /// </returns>
  220. public static int UTF8MaxLengthInBytes => utf8MaxLengthInBytes;
  221. /// <summary>
  222. /// For internal use only. Use <see cref="ToString"/> instead.
  223. /// </summary>
  224. /// <value>For internal use only. Use <see cref="ToString"/> instead.</value>
  225. [CreateProperty]
  226. [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
  227. [NotBurstCompatible]
  228. public string Value => ToString();
  229. /// <summary>
  230. /// Returns a pointer to the character bytes.
  231. /// </summary>
  232. /// <returns>A pointer to the character bytes.</returns>
  233. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  234. public unsafe byte* GetUnsafePtr()
  235. {
  236. return (byte*) UnsafeUtility.AddressOf(ref bytes);
  237. }
  238. /// <summary>
  239. /// The current length in bytes of this string's content.
  240. /// </summary>
  241. /// <remarks>
  242. /// The length value does not include the null-terminator byte.
  243. /// </remarks>
  244. /// <param name="value">The new length in bytes of the string's content.</param>
  245. /// <exception cref="ArgumentOutOfRangeException">Thrown if the new length is out of bounds.</exception>
  246. /// <value>
  247. /// The current length in bytes of this string's content.
  248. /// </value>
  249. public int Length
  250. {
  251. get
  252. {
  253. return utf8LengthInBytes;
  254. }
  255. set
  256. {
  257. CheckLengthInRange(value);
  258. utf8LengthInBytes = (ushort)value;
  259. unsafe
  260. {
  261. GetUnsafePtr()[utf8LengthInBytes] = 0;
  262. }
  263. }
  264. }
  265. /// <summary>
  266. /// The number of bytes this string has for storing UTF-8 characters.
  267. /// </summary>
  268. /// <value>The number of bytes this string has for storing UTF-8 characters.</value>
  269. /// <remarks>
  270. /// Does not include the null-terminator byte.
  271. ///
  272. /// A setter is included for conformity with <see cref="INativeList{T}"/>, but <see cref="Capacity"/> is fixed at 29.
  273. /// Setting the value to anything other than 29 throws an exception.
  274. ///
  275. /// In UTF-8 encoding, each Unicode code point (character) requires 1 to 4 bytes,
  276. /// so the number of characters that can be stored may be less than the capacity.
  277. /// </remarks>
  278. /// <exception cref="ArgumentOutOfRangeException">Thrown if attempting to set the capacity to anything other than 29.</exception>
  279. public int Capacity
  280. {
  281. get
  282. {
  283. return utf8MaxLengthInBytes;
  284. }
  285. set
  286. {
  287. CheckCapacityInRange(value);
  288. }
  289. }
  290. /// <summary>
  291. /// Attempts to set the length in bytes. Does nothing if the new length is invalid.
  292. /// </summary>
  293. /// <param name="newLength">The desired length.</param>
  294. /// <param name="clearOptions">Whether added or removed bytes should be cleared (zeroed). (Increasing the length adds bytes; decreasing the length removes bytes.)</param>
  295. /// <returns>True if the new length is valid.</returns>
  296. public bool TryResize(int newLength, NativeArrayOptions clearOptions = NativeArrayOptions.ClearMemory)
  297. {
  298. if (newLength < 0 || newLength > utf8MaxLengthInBytes)
  299. return false;
  300. if (newLength == utf8LengthInBytes)
  301. return true;
  302. unsafe
  303. {
  304. if (clearOptions == NativeArrayOptions.ClearMemory)
  305. {
  306. if (newLength > utf8LengthInBytes)
  307. UnsafeUtility.MemClear(GetUnsafePtr() + utf8LengthInBytes, newLength - utf8LengthInBytes);
  308. else
  309. UnsafeUtility.MemClear(GetUnsafePtr() + newLength, utf8LengthInBytes - newLength);
  310. }
  311. utf8LengthInBytes = (ushort)newLength;
  312. // always null terminate
  313. GetUnsafePtr()[utf8LengthInBytes] = 0;
  314. }
  315. return true;
  316. }
  317. /// <summary>
  318. /// Returns true if this string is empty (has no characters).
  319. /// </summary>
  320. /// <value>True if this string is empty (has no characters).</value>
  321. public bool IsEmpty => utf8LengthInBytes == 0;
  322. /// <summary>
  323. /// Returns the byte (not character) at an index.
  324. /// </summary>
  325. /// <param name="index">A byte index.</param>
  326. /// <value>The byte at the index.</value>
  327. /// <exception cref="IndexOutOfRangeException">Thrown if the index is out of bounds.</exception>
  328. public byte this[int index]
  329. {
  330. get
  331. {
  332. unsafe
  333. {
  334. CheckIndexInRange(index);
  335. return GetUnsafePtr()[index];
  336. }
  337. }
  338. set
  339. {
  340. unsafe
  341. {
  342. CheckIndexInRange(index);
  343. GetUnsafePtr()[index] = value;
  344. }
  345. }
  346. }
  347. /// <summary>
  348. /// Returns the reference to a byte (not character) at an index.
  349. /// </summary>
  350. /// <param name="index">A byte index.</param>
  351. /// <returns>A reference to the byte at the index.</returns>
  352. /// <exception cref="IndexOutOfRangeException">Thrown if the index is out of bounds.</exception>
  353. public ref byte ElementAt(int index)
  354. {
  355. unsafe
  356. {
  357. CheckIndexInRange(index);
  358. return ref GetUnsafePtr()[index];
  359. }
  360. }
  361. /// <summary>
  362. /// Sets the length to 0.
  363. /// </summary>
  364. public void Clear()
  365. {
  366. Length = 0;
  367. }
  368. /// <summary>
  369. /// Appends a byte.
  370. /// </summary>
  371. /// <remarks>
  372. /// A zero byte will always follow the newly appended byte.
  373. ///
  374. /// No validation is performed: it is your responsibility for the bytes of the string to form valid UTF-8 when you're done appending bytes.
  375. /// </remarks>
  376. /// <param name="value">A byte to append.</param>
  377. public void Add(in byte value)
  378. {
  379. this[Length++] = value;
  380. }
  381. /// <summary>
  382. /// An enumerator over the characters (not bytes) of a FixedString32Bytes.
  383. /// </summary>
  384. /// <remarks>
  385. /// In an enumerator's initial state, <see cref="Current"/> is not valid to read.
  386. /// The first <see cref="MoveNext"/> call advances the enumerator's index to the first character.
  387. /// </remarks>
  388. public struct Enumerator : IEnumerator
  389. {
  390. FixedString32Bytes target;
  391. int offset;
  392. Unicode.Rune current;
  393. /// <summary>
  394. /// Initializes and returns an instance of FixedString32Bytes.Enumerator.
  395. /// </summary>
  396. /// <param name="other">A FixeString32 for which to create an enumerator.</param>
  397. public Enumerator(FixedString32Bytes other)
  398. {
  399. target = other;
  400. offset = 0;
  401. current = default;
  402. }
  403. /// <summary>
  404. /// Does nothing.
  405. /// </summary>
  406. public void Dispose()
  407. {
  408. }
  409. /// <summary>
  410. /// Advances the enumerator to the next character.
  411. /// </summary>
  412. /// <returns>True if <see cref="Current"/> is valid to read after the call.</returns>
  413. public bool MoveNext()
  414. {
  415. if (offset >= target.Length)
  416. return false;
  417. unsafe
  418. {
  419. Unicode.Utf8ToUcs(out current, target.GetUnsafePtr(), ref offset, target.Length);
  420. }
  421. return true;
  422. }
  423. /// <summary>
  424. /// Resets the enumerator to its initial state.
  425. /// </summary>
  426. public void Reset()
  427. {
  428. offset = 0;
  429. current = default;
  430. }
  431. /// <summary>
  432. /// The current character.
  433. /// </summary>
  434. /// <remarks>
  435. /// In an enumerator's initial state, <see cref="Current"/> is not valid to read.
  436. /// </remarks>
  437. /// <value>The current character.</value>
  438. public Unicode.Rune Current => current;
  439. object IEnumerator.Current => Current;
  440. }
  441. /// <summary>
  442. /// Returns an enumerator for iterating over the characters of this string.
  443. /// </summary>
  444. /// <returns>An enumerator for iterating over the characters of the FixedString32Bytes.</returns>
  445. public Enumerator GetEnumerator()
  446. {
  447. return new Enumerator(this);
  448. }
  449. /// <summary>
  450. /// Returns the lexicographical sort order of this string relative to another.
  451. /// </summary>
  452. /// <param name="other">A `System.String` to compare with.</param>
  453. /// <returns>An integer denoting the lexicographical sort order of this string relative to the other:
  454. ///
  455. /// 0 denotes both strings have the same sort position.<br/>
  456. /// -1 denotes that this string should be sorted to precede the other string.<br/>
  457. /// +1 denotes that this string should be sorted to follow the other string.<br/>
  458. /// </returns>
  459. [NotBurstCompatible]
  460. public int CompareTo(String other)
  461. {
  462. return ToString().CompareTo(other);
  463. }
  464. /// <summary>
  465. /// Returns true if this string and another have the same length and all the same characters.
  466. /// </summary>
  467. /// <param name="other">A string to compare for equality.</param>
  468. /// <returns>True if this string and the other have the same length and all the same characters.</returns>
  469. [NotBurstCompatible]
  470. public bool Equals(String other)
  471. {
  472. unsafe {
  473. int alen = utf8LengthInBytes;
  474. int blen = other.Length;
  475. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(bytes);
  476. fixed(char* bptr = other)
  477. {
  478. return UTF8ArrayUnsafeUtility.StrCmp(aptr, alen, bptr, blen) == 0;
  479. }
  480. }
  481. }
  482. /// <summary>
  483. /// Returns a reference to a FixedList32Bytes<byte> representation of this string.
  484. /// </summary>
  485. /// <remarks>
  486. /// The referenced FixedListByte32 is the very same bytes as the original FixedString32Bytes,
  487. /// so it is only valid as long as the original FixedString32Bytes is valid.
  488. /// </remarks>
  489. /// <returns>A ref to a FixedListByte32 representation of the FixedString32Bytes.</returns>
  490. public unsafe ref FixedList32Bytes<byte> AsFixedList()
  491. {
  492. return ref UnsafeUtility.AsRef<FixedList32Bytes<byte>>(UnsafeUtility.AddressOf(ref this));
  493. }
  494. /// <summary>
  495. /// Initializes and returns an instance of FixedString32Bytes with the characters copied from a string.
  496. /// </summary>
  497. /// <param name="source">The source string to copy.</param>
  498. [NotBurstCompatible]
  499. public FixedString32Bytes(String source)
  500. {
  501. this = default;
  502. var error = Initialize(source);
  503. CheckCopyError((CopyError)error, source);
  504. }
  505. /// <summary>
  506. /// Initializes an instance of FixedString32Bytes with the characters copied from a string.
  507. /// </summary>
  508. /// <param name="source">The source string to copy.</param>
  509. /// <returns>zero on success, or non-zero on error.</returns>
  510. [NotBurstCompatible]
  511. internal int Initialize(String source)
  512. {
  513. bytes = default;
  514. utf8LengthInBytes = 0;
  515. unsafe
  516. {
  517. fixed (char* sourceptr = source)
  518. {
  519. var error = UTF8ArrayUnsafeUtility.Copy(GetUnsafePtr(), out utf8LengthInBytes, utf8MaxLengthInBytes, sourceptr, source.Length);
  520. if(error != CopyError.None)
  521. return (int)error;
  522. this.Length = utf8LengthInBytes;
  523. }
  524. }
  525. return 0;
  526. }
  527. /// <summary>
  528. /// Initializes and returns an instance of FixedString32Bytes with a single character repeatedly appended some number of times.
  529. /// </summary>
  530. /// <param name="rune">The Unicode.Rune to repeat.</param>
  531. /// <param name="count">The number of times to repeat the character. Default is 1.</param>
  532. public FixedString32Bytes(Unicode.Rune rune, int count = 1)
  533. {
  534. this = default;
  535. Initialize(rune, count);
  536. }
  537. /// <summary>
  538. /// Initializes an instance of FixedString32Bytes with a single character repeatedly appended some number of times.
  539. /// </summary>
  540. /// <param name="rune">The Unicode.Rune to repeat.</param>
  541. /// <param name="count">The number of times to repeat the character. Default is 1.</param>
  542. /// <returns>zero on success, or non-zero on error.</returns>
  543. internal int Initialize(Unicode.Rune rune, int count = 1)
  544. {
  545. this = default;
  546. return (int)this.Append(rune, count);
  547. }
  548. /// <summary>
  549. /// Returns the lexicographical sort order of this string relative to another.
  550. /// </summary>
  551. /// <param name="other">A string to compare with.</param>
  552. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  553. ///
  554. /// 0 denotes that both strings have the same sort position.<br/>
  555. /// -1 denotes that this string should be sorted to precede the other.<br/>
  556. /// +1 denotes that this string should be sorted to follow the other.<br/>
  557. /// </returns>
  558. public int CompareTo(FixedString32Bytes other)
  559. {
  560. return FixedStringMethods.CompareTo(ref this, other);
  561. }
  562. /// <summary>
  563. /// Initializes and returns an instance of FixedString32Bytes that is a copy of another string.
  564. /// </summary>
  565. /// <param name="other">The string to copy.</param>
  566. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString32Bytes.</exception>
  567. public FixedString32Bytes(in FixedString32Bytes other)
  568. {
  569. this = default;
  570. var error = Initialize(other);
  571. CheckFormatError((FormatError)error);
  572. }
  573. /// <summary>
  574. /// Initializes an instance of FixedString32Bytes that is a copy of another string.
  575. /// </summary>
  576. /// <param name="other">The string to copy.</param>
  577. /// <returns>zero on success, or non-zero on error.</returns>
  578. internal int Initialize(in FixedString32Bytes other)
  579. {
  580. bytes = default;
  581. utf8LengthInBytes = 0;
  582. unsafe {
  583. int len = 0;
  584. byte* dstBytes = GetUnsafePtr();
  585. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  586. var srcLength = other.utf8LengthInBytes;
  587. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  588. if(error != FormatError.None)
  589. return (int)error;
  590. this.Length = len;
  591. }
  592. return 0;
  593. }
  594. /// <summary>
  595. /// Returns true if a FixedString32Bytes and another string are equal.
  596. /// </summary>
  597. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  598. /// <param name="a">A FixedString32Bytes to compare for equality.</param>
  599. /// <param name="b">A FixedString32Bytes to compare for equality.</param>
  600. /// <returns>True if the two strings are equal.</returns>
  601. public static bool operator ==(in FixedString32Bytes a, in FixedString32Bytes b)
  602. {
  603. // this must not call any methods on 'a' or 'b'
  604. unsafe {
  605. int alen = a.utf8LengthInBytes;
  606. int blen = b.utf8LengthInBytes;
  607. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  608. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  609. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  610. }
  611. }
  612. /// <summary>
  613. /// Returns true if a FixedString32Bytes and another string are unequal.
  614. /// </summary>
  615. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  616. /// <param name="a">A FixedString32Bytes to compare for inequality.</param>
  617. /// <param name="b">A FixedString32Bytes to compare for inequality.</param>
  618. /// <returns>True if the two strings are unequal.</returns>
  619. public static bool operator !=(in FixedString32Bytes a, in FixedString32Bytes b)
  620. {
  621. return !(a == b);
  622. }
  623. /// <summary>
  624. /// Returns true if this string and another string are equal.
  625. /// </summary>
  626. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  627. /// <param name="other">A FixedString32Bytes to compare for equality.</param>
  628. /// <returns>True if the two strings are equal.</returns>
  629. public bool Equals(FixedString32Bytes other)
  630. {
  631. return this == other;
  632. }
  633. /// <summary>
  634. /// Returns the lexicographical sort order of this string relative to another.
  635. /// </summary>
  636. /// <param name="other">A string to compare with.</param>
  637. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  638. ///
  639. /// 0 denotes that both strings have the same sort position.<br/>
  640. /// -1 denotes that this string should be sorted to precede the other.<br/>
  641. /// +1 denotes that this string should be sorted to follow the other.<br/>
  642. /// </returns>
  643. public int CompareTo(FixedString64Bytes other)
  644. {
  645. return FixedStringMethods.CompareTo(ref this, other);
  646. }
  647. /// <summary>
  648. /// Initializes and returns an instance of FixedString32Bytes that is a copy of another string.
  649. /// </summary>
  650. /// <param name="other">The string to copy.</param>
  651. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString32Bytes.</exception>
  652. public FixedString32Bytes(in FixedString64Bytes other)
  653. {
  654. this = default;
  655. var error = Initialize(other);
  656. CheckFormatError((FormatError)error);
  657. }
  658. /// <summary>
  659. /// Initializes an instance of FixedString32Bytes that is a copy of another string.
  660. /// </summary>
  661. /// <param name="other">The string to copy.</param>
  662. /// <returns>zero on success, or non-zero on error.</returns>
  663. internal int Initialize(in FixedString64Bytes other)
  664. {
  665. bytes = default;
  666. utf8LengthInBytes = 0;
  667. unsafe {
  668. int len = 0;
  669. byte* dstBytes = GetUnsafePtr();
  670. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  671. var srcLength = other.utf8LengthInBytes;
  672. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  673. if(error != FormatError.None)
  674. return (int)error;
  675. this.Length = len;
  676. }
  677. return 0;
  678. }
  679. /// <summary>
  680. /// Returns true if a FixedString32Bytes and another string are equal.
  681. /// </summary>
  682. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  683. /// <param name="a">A FixedString32Bytes to compare for equality.</param>
  684. /// <param name="b">A FixedString64Bytes to compare for equality.</param>
  685. /// <returns>True if the two strings are equal.</returns>
  686. public static bool operator ==(in FixedString32Bytes a, in FixedString64Bytes b)
  687. {
  688. // this must not call any methods on 'a' or 'b'
  689. unsafe {
  690. int alen = a.utf8LengthInBytes;
  691. int blen = b.utf8LengthInBytes;
  692. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  693. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  694. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  695. }
  696. }
  697. /// <summary>
  698. /// Returns true if a FixedString32Bytes and another string are unequal.
  699. /// </summary>
  700. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  701. /// <param name="a">A FixedString32Bytes to compare for inequality.</param>
  702. /// <param name="b">A FixedString64Bytes to compare for inequality.</param>
  703. /// <returns>True if the two strings are unequal.</returns>
  704. public static bool operator !=(in FixedString32Bytes a, in FixedString64Bytes b)
  705. {
  706. return !(a == b);
  707. }
  708. /// <summary>
  709. /// Returns true if this string and another string are equal.
  710. /// </summary>
  711. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  712. /// <param name="other">A FixedString64Bytes to compare for equality.</param>
  713. /// <returns>True if the two strings are equal.</returns>
  714. public bool Equals(FixedString64Bytes other)
  715. {
  716. return this == other;
  717. }
  718. /// <summary>
  719. /// Returns a new FixedString64Bytes that is a copy of another string.
  720. /// </summary>
  721. /// <param name="fs">A FixedString32Bytes to copy.</param>
  722. /// <returns>A new FixedString64Bytes that is a copy of the other string.</returns>
  723. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString64Bytes.</exception>
  724. public static implicit operator FixedString64Bytes(in FixedString32Bytes fs) => new FixedString64Bytes(in fs);
  725. /// <summary>
  726. /// Returns the lexicographical sort order of this string relative to another.
  727. /// </summary>
  728. /// <param name="other">A string to compare with.</param>
  729. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  730. ///
  731. /// 0 denotes that both strings have the same sort position.<br/>
  732. /// -1 denotes that this string should be sorted to precede the other.<br/>
  733. /// +1 denotes that this string should be sorted to follow the other.<br/>
  734. /// </returns>
  735. public int CompareTo(FixedString128Bytes other)
  736. {
  737. return FixedStringMethods.CompareTo(ref this, other);
  738. }
  739. /// <summary>
  740. /// Initializes and returns an instance of FixedString32Bytes that is a copy of another string.
  741. /// </summary>
  742. /// <param name="other">The string to copy.</param>
  743. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString32Bytes.</exception>
  744. public FixedString32Bytes(in FixedString128Bytes other)
  745. {
  746. this = default;
  747. var error = Initialize(other);
  748. CheckFormatError((FormatError)error);
  749. }
  750. /// <summary>
  751. /// Initializes an instance of FixedString32Bytes that is a copy of another string.
  752. /// </summary>
  753. /// <param name="other">The string to copy.</param>
  754. /// <returns>zero on success, or non-zero on error.</returns>
  755. internal int Initialize(in FixedString128Bytes other)
  756. {
  757. bytes = default;
  758. utf8LengthInBytes = 0;
  759. unsafe {
  760. int len = 0;
  761. byte* dstBytes = GetUnsafePtr();
  762. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  763. var srcLength = other.utf8LengthInBytes;
  764. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  765. if(error != FormatError.None)
  766. return (int)error;
  767. this.Length = len;
  768. }
  769. return 0;
  770. }
  771. /// <summary>
  772. /// Returns true if a FixedString32Bytes and another string are equal.
  773. /// </summary>
  774. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  775. /// <param name="a">A FixedString32Bytes to compare for equality.</param>
  776. /// <param name="b">A FixedString128Bytes to compare for equality.</param>
  777. /// <returns>True if the two strings are equal.</returns>
  778. public static bool operator ==(in FixedString32Bytes a, in FixedString128Bytes b)
  779. {
  780. // this must not call any methods on 'a' or 'b'
  781. unsafe {
  782. int alen = a.utf8LengthInBytes;
  783. int blen = b.utf8LengthInBytes;
  784. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  785. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  786. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  787. }
  788. }
  789. /// <summary>
  790. /// Returns true if a FixedString32Bytes and another string are unequal.
  791. /// </summary>
  792. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  793. /// <param name="a">A FixedString32Bytes to compare for inequality.</param>
  794. /// <param name="b">A FixedString128Bytes to compare for inequality.</param>
  795. /// <returns>True if the two strings are unequal.</returns>
  796. public static bool operator !=(in FixedString32Bytes a, in FixedString128Bytes b)
  797. {
  798. return !(a == b);
  799. }
  800. /// <summary>
  801. /// Returns true if this string and another string are equal.
  802. /// </summary>
  803. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  804. /// <param name="other">A FixedString128Bytes to compare for equality.</param>
  805. /// <returns>True if the two strings are equal.</returns>
  806. public bool Equals(FixedString128Bytes other)
  807. {
  808. return this == other;
  809. }
  810. /// <summary>
  811. /// Returns a new FixedString128Bytes that is a copy of another string.
  812. /// </summary>
  813. /// <param name="fs">A FixedString32Bytes to copy.</param>
  814. /// <returns>A new FixedString128Bytes that is a copy of the other string.</returns>
  815. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString128Bytes.</exception>
  816. public static implicit operator FixedString128Bytes(in FixedString32Bytes fs) => new FixedString128Bytes(in fs);
  817. /// <summary>
  818. /// Returns the lexicographical sort order of this string relative to another.
  819. /// </summary>
  820. /// <param name="other">A string to compare with.</param>
  821. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  822. ///
  823. /// 0 denotes that both strings have the same sort position.<br/>
  824. /// -1 denotes that this string should be sorted to precede the other.<br/>
  825. /// +1 denotes that this string should be sorted to follow the other.<br/>
  826. /// </returns>
  827. public int CompareTo(FixedString512Bytes other)
  828. {
  829. return FixedStringMethods.CompareTo(ref this, other);
  830. }
  831. /// <summary>
  832. /// Initializes and returns an instance of FixedString32Bytes that is a copy of another string.
  833. /// </summary>
  834. /// <param name="other">The string to copy.</param>
  835. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString32Bytes.</exception>
  836. public FixedString32Bytes(in FixedString512Bytes other)
  837. {
  838. this = default;
  839. var error = Initialize(other);
  840. CheckFormatError((FormatError)error);
  841. }
  842. /// <summary>
  843. /// Initializes an instance of FixedString32Bytes that is a copy of another string.
  844. /// </summary>
  845. /// <param name="other">The string to copy.</param>
  846. /// <returns>zero on success, or non-zero on error.</returns>
  847. internal int Initialize(in FixedString512Bytes other)
  848. {
  849. bytes = default;
  850. utf8LengthInBytes = 0;
  851. unsafe {
  852. int len = 0;
  853. byte* dstBytes = GetUnsafePtr();
  854. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  855. var srcLength = other.utf8LengthInBytes;
  856. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  857. if(error != FormatError.None)
  858. return (int)error;
  859. this.Length = len;
  860. }
  861. return 0;
  862. }
  863. /// <summary>
  864. /// Returns true if a FixedString32Bytes and another string are equal.
  865. /// </summary>
  866. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  867. /// <param name="a">A FixedString32Bytes to compare for equality.</param>
  868. /// <param name="b">A FixedString512Bytes to compare for equality.</param>
  869. /// <returns>True if the two strings are equal.</returns>
  870. public static bool operator ==(in FixedString32Bytes a, in FixedString512Bytes b)
  871. {
  872. // this must not call any methods on 'a' or 'b'
  873. unsafe {
  874. int alen = a.utf8LengthInBytes;
  875. int blen = b.utf8LengthInBytes;
  876. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  877. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  878. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  879. }
  880. }
  881. /// <summary>
  882. /// Returns true if a FixedString32Bytes and another string are unequal.
  883. /// </summary>
  884. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  885. /// <param name="a">A FixedString32Bytes to compare for inequality.</param>
  886. /// <param name="b">A FixedString512Bytes to compare for inequality.</param>
  887. /// <returns>True if the two strings are unequal.</returns>
  888. public static bool operator !=(in FixedString32Bytes a, in FixedString512Bytes b)
  889. {
  890. return !(a == b);
  891. }
  892. /// <summary>
  893. /// Returns true if this string and another string are equal.
  894. /// </summary>
  895. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  896. /// <param name="other">A FixedString512Bytes to compare for equality.</param>
  897. /// <returns>True if the two strings are equal.</returns>
  898. public bool Equals(FixedString512Bytes other)
  899. {
  900. return this == other;
  901. }
  902. /// <summary>
  903. /// Returns a new FixedString512Bytes that is a copy of another string.
  904. /// </summary>
  905. /// <param name="fs">A FixedString32Bytes to copy.</param>
  906. /// <returns>A new FixedString512Bytes that is a copy of the other string.</returns>
  907. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString512Bytes.</exception>
  908. public static implicit operator FixedString512Bytes(in FixedString32Bytes fs) => new FixedString512Bytes(in fs);
  909. /// <summary>
  910. /// Returns the lexicographical sort order of this string relative to another.
  911. /// </summary>
  912. /// <param name="other">A string to compare with.</param>
  913. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  914. ///
  915. /// 0 denotes that both strings have the same sort position.<br/>
  916. /// -1 denotes that this string should be sorted to precede the other.<br/>
  917. /// +1 denotes that this string should be sorted to follow the other.<br/>
  918. /// </returns>
  919. public int CompareTo(FixedString4096Bytes other)
  920. {
  921. return FixedStringMethods.CompareTo(ref this, other);
  922. }
  923. /// <summary>
  924. /// Initializes and returns an instance of FixedString32Bytes that is a copy of another string.
  925. /// </summary>
  926. /// <param name="other">The string to copy.</param>
  927. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString32Bytes.</exception>
  928. public FixedString32Bytes(in FixedString4096Bytes other)
  929. {
  930. this = default;
  931. var error = Initialize(other);
  932. CheckFormatError((FormatError)error);
  933. }
  934. /// <summary>
  935. /// Initializes an instance of FixedString32Bytes that is a copy of another string.
  936. /// </summary>
  937. /// <param name="other">The string to copy.</param>
  938. /// <returns>zero on success, or non-zero on error.</returns>
  939. internal int Initialize(in FixedString4096Bytes other)
  940. {
  941. bytes = default;
  942. utf8LengthInBytes = 0;
  943. unsafe {
  944. int len = 0;
  945. byte* dstBytes = GetUnsafePtr();
  946. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  947. var srcLength = other.utf8LengthInBytes;
  948. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  949. if(error != FormatError.None)
  950. return (int)error;
  951. this.Length = len;
  952. }
  953. return 0;
  954. }
  955. /// <summary>
  956. /// Returns true if a FixedString32Bytes and another string are equal.
  957. /// </summary>
  958. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  959. /// <param name="a">A FixedString32Bytes to compare for equality.</param>
  960. /// <param name="b">A FixedString4096Bytes to compare for equality.</param>
  961. /// <returns>True if the two strings are equal.</returns>
  962. public static bool operator ==(in FixedString32Bytes a, in FixedString4096Bytes b)
  963. {
  964. // this must not call any methods on 'a' or 'b'
  965. unsafe {
  966. int alen = a.utf8LengthInBytes;
  967. int blen = b.utf8LengthInBytes;
  968. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  969. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  970. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  971. }
  972. }
  973. /// <summary>
  974. /// Returns true if a FixedString32Bytes and another string are unequal.
  975. /// </summary>
  976. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  977. /// <param name="a">A FixedString32Bytes to compare for inequality.</param>
  978. /// <param name="b">A FixedString4096Bytes to compare for inequality.</param>
  979. /// <returns>True if the two strings are unequal.</returns>
  980. public static bool operator !=(in FixedString32Bytes a, in FixedString4096Bytes b)
  981. {
  982. return !(a == b);
  983. }
  984. /// <summary>
  985. /// Returns true if this string and another string are equal.
  986. /// </summary>
  987. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  988. /// <param name="other">A FixedString4096Bytes to compare for equality.</param>
  989. /// <returns>True if the two strings are equal.</returns>
  990. public bool Equals(FixedString4096Bytes other)
  991. {
  992. return this == other;
  993. }
  994. /// <summary>
  995. /// Returns a new FixedString4096Bytes that is a copy of another string.
  996. /// </summary>
  997. /// <param name="fs">A FixedString32Bytes to copy.</param>
  998. /// <returns>A new FixedString4096Bytes that is a copy of the other string.</returns>
  999. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString4096Bytes.</exception>
  1000. public static implicit operator FixedString4096Bytes(in FixedString32Bytes fs) => new FixedString4096Bytes(in fs);
  1001. /// <summary>
  1002. /// Returns a new FixedString32Bytes that is a copy of another string.
  1003. /// </summary>
  1004. /// <param name="b">A string to copy.</param>
  1005. /// <returns>A new FixedString32Bytes that is a copy of another string.</returns>
  1006. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString32Bytes.</exception>
  1007. [NotBurstCompatible]
  1008. public static implicit operator FixedString32Bytes(string b) => new FixedString32Bytes(b);
  1009. /// <summary>
  1010. /// Returns a new managed string that is a copy of this string.
  1011. /// </summary>
  1012. /// <returns>A new managed string that is a copy of this string.</returns>
  1013. [NotBurstCompatible]
  1014. public override String ToString()
  1015. {
  1016. return this.ConvertToString();
  1017. }
  1018. /// <summary>
  1019. /// Returns a hash code of this string.
  1020. /// </summary>
  1021. /// <remarks>Only the character bytes are included in the hash: any bytes beyond <see cref="Length"/> are not part of the hash.</remarks>
  1022. /// <returns>The hash code of this string.</returns>
  1023. public override int GetHashCode()
  1024. {
  1025. return this.ComputeHashCode();
  1026. }
  1027. /// <summary>
  1028. /// Returns true if this string and an object are equal.
  1029. /// </summary>
  1030. /// <remarks>
  1031. /// Returns false if the object is neither a System.String or a FixedString.
  1032. ///
  1033. /// Two strings are equal if they have equal length and all their characters match.</remarks>
  1034. /// <param name="obj">An object to compare for equality.</param>
  1035. /// <returns>True if this string and the object are equal.</returns>
  1036. [NotBurstCompatible]
  1037. public override bool Equals(object obj)
  1038. {
  1039. if(ReferenceEquals(null, obj)) return false;
  1040. if(obj is String aString) return Equals(aString);
  1041. if(obj is FixedString32Bytes aFixedString32Bytes) return Equals(aFixedString32Bytes);
  1042. if(obj is FixedString64Bytes aFixedString64Bytes) return Equals(aFixedString64Bytes);
  1043. if(obj is FixedString128Bytes aFixedString128Bytes) return Equals(aFixedString128Bytes);
  1044. if(obj is FixedString512Bytes aFixedString512Bytes) return Equals(aFixedString512Bytes);
  1045. if(obj is FixedString4096Bytes aFixedString4096Bytes) return Equals(aFixedString4096Bytes);
  1046. return false;
  1047. }
  1048. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  1049. void CheckIndexInRange(int index)
  1050. {
  1051. if (index < 0)
  1052. throw new IndexOutOfRangeException($"Index {index} must be positive.");
  1053. if (index >= utf8LengthInBytes)
  1054. throw new IndexOutOfRangeException($"Index {index} is out of range in FixedString32Bytes of '{utf8LengthInBytes}' Length.");
  1055. }
  1056. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  1057. void CheckLengthInRange(int length)
  1058. {
  1059. if (length < 0)
  1060. throw new ArgumentOutOfRangeException($"Length {length} must be positive.");
  1061. if (length > utf8MaxLengthInBytes)
  1062. throw new ArgumentOutOfRangeException($"Length {length} is out of range in FixedString32Bytes of '{utf8MaxLengthInBytes}' Capacity.");
  1063. }
  1064. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  1065. void CheckCapacityInRange(int capacity)
  1066. {
  1067. if (capacity > utf8MaxLengthInBytes)
  1068. throw new ArgumentOutOfRangeException($"Capacity {capacity} must be lower than {utf8MaxLengthInBytes}.");
  1069. }
  1070. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  1071. static void CheckCopyError(CopyError error, String source)
  1072. {
  1073. if (error != CopyError.None)
  1074. throw new ArgumentException($"FixedString32Bytes: {error} while copying \"{source}\"");
  1075. }
  1076. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  1077. static void CheckFormatError(FormatError error)
  1078. {
  1079. if (error != FormatError.None)
  1080. throw new ArgumentException("Source is too long to fit into fixed string of this size");
  1081. }
  1082. }
  1083. // A temporary copy of a struct is made before it is displayed in a C# debugger.
  1084. // However, only the first element of data members with names is copied at this time.
  1085. // Therefore, it's important that all data visible in the debugger, has a name
  1086. // and includes no 'fixed' array. This is why we name every byte in the following struct.
  1087. /// <summary>
  1088. /// For internal use only.
  1089. /// </summary>
  1090. [Serializable]
  1091. [StructLayout(LayoutKind.Explicit, Size=62)]
  1092. [BurstCompatible]
  1093. public struct FixedBytes62
  1094. {
  1095. /// <summary>
  1096. /// For internal use only.
  1097. /// </summary>
  1098. [FieldOffset(0)] public FixedBytes16 offset0000;
  1099. /// <summary>
  1100. /// For internal use only.
  1101. /// </summary>
  1102. [FieldOffset(16)] public FixedBytes16 offset0016;
  1103. /// <summary>
  1104. /// For internal use only.
  1105. /// </summary>
  1106. [FieldOffset(32)] public FixedBytes16 offset0032;
  1107. /// <summary>
  1108. /// For internal use only.
  1109. /// </summary>
  1110. [FieldOffset(48)] public byte byte0048;
  1111. /// <summary>
  1112. /// For internal use only.
  1113. /// </summary>
  1114. [FieldOffset(49)] public byte byte0049;
  1115. /// <summary>
  1116. /// For internal use only.
  1117. /// </summary>
  1118. [FieldOffset(50)] public byte byte0050;
  1119. /// <summary>
  1120. /// For internal use only.
  1121. /// </summary>
  1122. [FieldOffset(51)] public byte byte0051;
  1123. /// <summary>
  1124. /// For internal use only.
  1125. /// </summary>
  1126. [FieldOffset(52)] public byte byte0052;
  1127. /// <summary>
  1128. /// For internal use only.
  1129. /// </summary>
  1130. [FieldOffset(53)] public byte byte0053;
  1131. /// <summary>
  1132. /// For internal use only.
  1133. /// </summary>
  1134. [FieldOffset(54)] public byte byte0054;
  1135. /// <summary>
  1136. /// For internal use only.
  1137. /// </summary>
  1138. [FieldOffset(55)] public byte byte0055;
  1139. /// <summary>
  1140. /// For internal use only.
  1141. /// </summary>
  1142. [FieldOffset(56)] public byte byte0056;
  1143. /// <summary>
  1144. /// For internal use only.
  1145. /// </summary>
  1146. [FieldOffset(57)] public byte byte0057;
  1147. /// <summary>
  1148. /// For internal use only.
  1149. /// </summary>
  1150. [FieldOffset(58)] public byte byte0058;
  1151. /// <summary>
  1152. /// For internal use only.
  1153. /// </summary>
  1154. [FieldOffset(59)] public byte byte0059;
  1155. /// <summary>
  1156. /// For internal use only.
  1157. /// </summary>
  1158. [FieldOffset(60)] public byte byte0060;
  1159. /// <summary>
  1160. /// For internal use only.
  1161. /// </summary>
  1162. [FieldOffset(61)] public byte byte0061;
  1163. }
  1164. [Obsolete("Renamed to FixedString64Bytes (UnityUpgradable) -> FixedString64Bytes", true)]
  1165. public partial struct FixedString64 {}
  1166. /// <summary>
  1167. /// An unmanaged UTF-8 string whose content is stored directly in the 64-byte struct.
  1168. /// </summary>
  1169. /// <remarks>
  1170. /// The binary layout of this string is guaranteed, for now and all time, to be a length (a little-endian two byte integer)
  1171. /// followed by the bytes of the characters (with no padding). A zero byte always immediately follows the last character.
  1172. /// Effectively, the number of bytes for storing characters is 3 less than 64 (two length bytes and one null byte).
  1173. ///
  1174. /// This layout is identical to a <see cref="FixedList64Bytes{T}"/> of bytes, thus allowing reinterpretation between FixedString64Bytes and FixedList64Bytes.
  1175. ///
  1176. /// By virtue of being an unmanaged, non-allocated struct with no pointers, this string is fully compatible with jobs and Burst compilation.
  1177. /// Unlike managed string types, these strings can be put in any unmanaged ECS components, FixedList, or any other unmanaged structs.
  1178. /// </remarks>
  1179. [Serializable]
  1180. [StructLayout(LayoutKind.Sequential, Size=64)]
  1181. [BurstCompatible]
  1182. public partial struct FixedString64Bytes
  1183. : INativeList<byte>
  1184. , IUTF8Bytes
  1185. , IComparable<String>
  1186. , IEquatable<String>
  1187. , IComparable<FixedString32Bytes>
  1188. , IEquatable<FixedString32Bytes>
  1189. , IComparable<FixedString64Bytes>
  1190. , IEquatable<FixedString64Bytes>
  1191. , IComparable<FixedString128Bytes>
  1192. , IEquatable<FixedString128Bytes>
  1193. , IComparable<FixedString512Bytes>
  1194. , IEquatable<FixedString512Bytes>
  1195. , IComparable<FixedString4096Bytes>
  1196. , IEquatable<FixedString4096Bytes>
  1197. {
  1198. internal const ushort utf8MaxLengthInBytes = 61;
  1199. [SerializeField] internal ushort utf8LengthInBytes;
  1200. [SerializeField] internal FixedBytes62 bytes;
  1201. /// <summary>
  1202. /// Returns the maximum number of UTF-8 bytes that can be stored in this string.
  1203. /// </summary>
  1204. /// <returns>
  1205. /// The maximum number of UTF-8 bytes that can be stored in this string.
  1206. /// </returns>
  1207. public static int UTF8MaxLengthInBytes => utf8MaxLengthInBytes;
  1208. /// <summary>
  1209. /// For internal use only. Use <see cref="ToString"/> instead.
  1210. /// </summary>
  1211. /// <value>For internal use only. Use <see cref="ToString"/> instead.</value>
  1212. [CreateProperty]
  1213. [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
  1214. [NotBurstCompatible]
  1215. public string Value => ToString();
  1216. /// <summary>
  1217. /// Returns a pointer to the character bytes.
  1218. /// </summary>
  1219. /// <returns>A pointer to the character bytes.</returns>
  1220. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1221. public unsafe byte* GetUnsafePtr()
  1222. {
  1223. return (byte*) UnsafeUtility.AddressOf(ref bytes);
  1224. }
  1225. /// <summary>
  1226. /// The current length in bytes of this string's content.
  1227. /// </summary>
  1228. /// <remarks>
  1229. /// The length value does not include the null-terminator byte.
  1230. /// </remarks>
  1231. /// <param name="value">The new length in bytes of the string's content.</param>
  1232. /// <exception cref="ArgumentOutOfRangeException">Thrown if the new length is out of bounds.</exception>
  1233. /// <value>
  1234. /// The current length in bytes of this string's content.
  1235. /// </value>
  1236. public int Length
  1237. {
  1238. get
  1239. {
  1240. return utf8LengthInBytes;
  1241. }
  1242. set
  1243. {
  1244. CheckLengthInRange(value);
  1245. utf8LengthInBytes = (ushort)value;
  1246. unsafe
  1247. {
  1248. GetUnsafePtr()[utf8LengthInBytes] = 0;
  1249. }
  1250. }
  1251. }
  1252. /// <summary>
  1253. /// The number of bytes this string has for storing UTF-8 characters.
  1254. /// </summary>
  1255. /// <value>The number of bytes this string has for storing UTF-8 characters.</value>
  1256. /// <remarks>
  1257. /// Does not include the null-terminator byte.
  1258. ///
  1259. /// A setter is included for conformity with <see cref="INativeList{T}"/>, but <see cref="Capacity"/> is fixed at 61.
  1260. /// Setting the value to anything other than 61 throws an exception.
  1261. ///
  1262. /// In UTF-8 encoding, each Unicode code point (character) requires 1 to 4 bytes,
  1263. /// so the number of characters that can be stored may be less than the capacity.
  1264. /// </remarks>
  1265. /// <exception cref="ArgumentOutOfRangeException">Thrown if attempting to set the capacity to anything other than 61.</exception>
  1266. public int Capacity
  1267. {
  1268. get
  1269. {
  1270. return utf8MaxLengthInBytes;
  1271. }
  1272. set
  1273. {
  1274. CheckCapacityInRange(value);
  1275. }
  1276. }
  1277. /// <summary>
  1278. /// Attempts to set the length in bytes. Does nothing if the new length is invalid.
  1279. /// </summary>
  1280. /// <param name="newLength">The desired length.</param>
  1281. /// <param name="clearOptions">Whether added or removed bytes should be cleared (zeroed). (Increasing the length adds bytes; decreasing the length removes bytes.)</param>
  1282. /// <returns>True if the new length is valid.</returns>
  1283. public bool TryResize(int newLength, NativeArrayOptions clearOptions = NativeArrayOptions.ClearMemory)
  1284. {
  1285. if (newLength < 0 || newLength > utf8MaxLengthInBytes)
  1286. return false;
  1287. if (newLength == utf8LengthInBytes)
  1288. return true;
  1289. unsafe
  1290. {
  1291. if (clearOptions == NativeArrayOptions.ClearMemory)
  1292. {
  1293. if (newLength > utf8LengthInBytes)
  1294. UnsafeUtility.MemClear(GetUnsafePtr() + utf8LengthInBytes, newLength - utf8LengthInBytes);
  1295. else
  1296. UnsafeUtility.MemClear(GetUnsafePtr() + newLength, utf8LengthInBytes - newLength);
  1297. }
  1298. utf8LengthInBytes = (ushort)newLength;
  1299. // always null terminate
  1300. GetUnsafePtr()[utf8LengthInBytes] = 0;
  1301. }
  1302. return true;
  1303. }
  1304. /// <summary>
  1305. /// Returns true if this string is empty (has no characters).
  1306. /// </summary>
  1307. /// <value>True if this string is empty (has no characters).</value>
  1308. public bool IsEmpty => utf8LengthInBytes == 0;
  1309. /// <summary>
  1310. /// Returns the byte (not character) at an index.
  1311. /// </summary>
  1312. /// <param name="index">A byte index.</param>
  1313. /// <value>The byte at the index.</value>
  1314. /// <exception cref="IndexOutOfRangeException">Thrown if the index is out of bounds.</exception>
  1315. public byte this[int index]
  1316. {
  1317. get
  1318. {
  1319. unsafe
  1320. {
  1321. CheckIndexInRange(index);
  1322. return GetUnsafePtr()[index];
  1323. }
  1324. }
  1325. set
  1326. {
  1327. unsafe
  1328. {
  1329. CheckIndexInRange(index);
  1330. GetUnsafePtr()[index] = value;
  1331. }
  1332. }
  1333. }
  1334. /// <summary>
  1335. /// Returns the reference to a byte (not character) at an index.
  1336. /// </summary>
  1337. /// <param name="index">A byte index.</param>
  1338. /// <returns>A reference to the byte at the index.</returns>
  1339. /// <exception cref="IndexOutOfRangeException">Thrown if the index is out of bounds.</exception>
  1340. public ref byte ElementAt(int index)
  1341. {
  1342. unsafe
  1343. {
  1344. CheckIndexInRange(index);
  1345. return ref GetUnsafePtr()[index];
  1346. }
  1347. }
  1348. /// <summary>
  1349. /// Sets the length to 0.
  1350. /// </summary>
  1351. public void Clear()
  1352. {
  1353. Length = 0;
  1354. }
  1355. /// <summary>
  1356. /// Appends a byte.
  1357. /// </summary>
  1358. /// <remarks>
  1359. /// A zero byte will always follow the newly appended byte.
  1360. ///
  1361. /// No validation is performed: it is your responsibility for the bytes of the string to form valid UTF-8 when you're done appending bytes.
  1362. /// </remarks>
  1363. /// <param name="value">A byte to append.</param>
  1364. public void Add(in byte value)
  1365. {
  1366. this[Length++] = value;
  1367. }
  1368. /// <summary>
  1369. /// An enumerator over the characters (not bytes) of a FixedString64Bytes.
  1370. /// </summary>
  1371. /// <remarks>
  1372. /// In an enumerator's initial state, <see cref="Current"/> is not valid to read.
  1373. /// The first <see cref="MoveNext"/> call advances the enumerator's index to the first character.
  1374. /// </remarks>
  1375. public struct Enumerator : IEnumerator
  1376. {
  1377. FixedString64Bytes target;
  1378. int offset;
  1379. Unicode.Rune current;
  1380. /// <summary>
  1381. /// Initializes and returns an instance of FixedString64Bytes.Enumerator.
  1382. /// </summary>
  1383. /// <param name="other">A FixeString64 for which to create an enumerator.</param>
  1384. public Enumerator(FixedString64Bytes other)
  1385. {
  1386. target = other;
  1387. offset = 0;
  1388. current = default;
  1389. }
  1390. /// <summary>
  1391. /// Does nothing.
  1392. /// </summary>
  1393. public void Dispose()
  1394. {
  1395. }
  1396. /// <summary>
  1397. /// Advances the enumerator to the next character.
  1398. /// </summary>
  1399. /// <returns>True if <see cref="Current"/> is valid to read after the call.</returns>
  1400. public bool MoveNext()
  1401. {
  1402. if (offset >= target.Length)
  1403. return false;
  1404. unsafe
  1405. {
  1406. Unicode.Utf8ToUcs(out current, target.GetUnsafePtr(), ref offset, target.Length);
  1407. }
  1408. return true;
  1409. }
  1410. /// <summary>
  1411. /// Resets the enumerator to its initial state.
  1412. /// </summary>
  1413. public void Reset()
  1414. {
  1415. offset = 0;
  1416. current = default;
  1417. }
  1418. /// <summary>
  1419. /// The current character.
  1420. /// </summary>
  1421. /// <remarks>
  1422. /// In an enumerator's initial state, <see cref="Current"/> is not valid to read.
  1423. /// </remarks>
  1424. /// <value>The current character.</value>
  1425. public Unicode.Rune Current => current;
  1426. object IEnumerator.Current => Current;
  1427. }
  1428. /// <summary>
  1429. /// Returns an enumerator for iterating over the characters of this string.
  1430. /// </summary>
  1431. /// <returns>An enumerator for iterating over the characters of the FixedString64Bytes.</returns>
  1432. public Enumerator GetEnumerator()
  1433. {
  1434. return new Enumerator(this);
  1435. }
  1436. /// <summary>
  1437. /// Returns the lexicographical sort order of this string relative to another.
  1438. /// </summary>
  1439. /// <param name="other">A `System.String` to compare with.</param>
  1440. /// <returns>An integer denoting the lexicographical sort order of this string relative to the other:
  1441. ///
  1442. /// 0 denotes both strings have the same sort position.<br/>
  1443. /// -1 denotes that this string should be sorted to precede the other string.<br/>
  1444. /// +1 denotes that this string should be sorted to follow the other string.<br/>
  1445. /// </returns>
  1446. [NotBurstCompatible]
  1447. public int CompareTo(String other)
  1448. {
  1449. return ToString().CompareTo(other);
  1450. }
  1451. /// <summary>
  1452. /// Returns true if this string and another have the same length and all the same characters.
  1453. /// </summary>
  1454. /// <param name="other">A string to compare for equality.</param>
  1455. /// <returns>True if this string and the other have the same length and all the same characters.</returns>
  1456. [NotBurstCompatible]
  1457. public bool Equals(String other)
  1458. {
  1459. unsafe {
  1460. int alen = utf8LengthInBytes;
  1461. int blen = other.Length;
  1462. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(bytes);
  1463. fixed(char* bptr = other)
  1464. {
  1465. return UTF8ArrayUnsafeUtility.StrCmp(aptr, alen, bptr, blen) == 0;
  1466. }
  1467. }
  1468. }
  1469. /// <summary>
  1470. /// Returns a reference to a FixedList64Bytes<byte> representation of this string.
  1471. /// </summary>
  1472. /// <remarks>
  1473. /// The referenced FixedListByte64 is the very same bytes as the original FixedString64Bytes,
  1474. /// so it is only valid as long as the original FixedString64Bytes is valid.
  1475. /// </remarks>
  1476. /// <returns>A ref to a FixedListByte64 representation of the FixedString64Bytes.</returns>
  1477. public unsafe ref FixedList64Bytes<byte> AsFixedList()
  1478. {
  1479. return ref UnsafeUtility.AsRef<FixedList64Bytes<byte>>(UnsafeUtility.AddressOf(ref this));
  1480. }
  1481. /// <summary>
  1482. /// Initializes and returns an instance of FixedString64Bytes with the characters copied from a string.
  1483. /// </summary>
  1484. /// <param name="source">The source string to copy.</param>
  1485. [NotBurstCompatible]
  1486. public FixedString64Bytes(String source)
  1487. {
  1488. this = default;
  1489. var error = Initialize(source);
  1490. CheckCopyError((CopyError)error, source);
  1491. }
  1492. /// <summary>
  1493. /// Initializes an instance of FixedString64Bytes with the characters copied from a string.
  1494. /// </summary>
  1495. /// <param name="source">The source string to copy.</param>
  1496. /// <returns>zero on success, or non-zero on error.</returns>
  1497. [NotBurstCompatible]
  1498. internal int Initialize(String source)
  1499. {
  1500. bytes = default;
  1501. utf8LengthInBytes = 0;
  1502. unsafe
  1503. {
  1504. fixed (char* sourceptr = source)
  1505. {
  1506. var error = UTF8ArrayUnsafeUtility.Copy(GetUnsafePtr(), out utf8LengthInBytes, utf8MaxLengthInBytes, sourceptr, source.Length);
  1507. if(error != CopyError.None)
  1508. return (int)error;
  1509. this.Length = utf8LengthInBytes;
  1510. }
  1511. }
  1512. return 0;
  1513. }
  1514. /// <summary>
  1515. /// Initializes and returns an instance of FixedString64Bytes with a single character repeatedly appended some number of times.
  1516. /// </summary>
  1517. /// <param name="rune">The Unicode.Rune to repeat.</param>
  1518. /// <param name="count">The number of times to repeat the character. Default is 1.</param>
  1519. public FixedString64Bytes(Unicode.Rune rune, int count = 1)
  1520. {
  1521. this = default;
  1522. Initialize(rune, count);
  1523. }
  1524. /// <summary>
  1525. /// Initializes an instance of FixedString64Bytes with a single character repeatedly appended some number of times.
  1526. /// </summary>
  1527. /// <param name="rune">The Unicode.Rune to repeat.</param>
  1528. /// <param name="count">The number of times to repeat the character. Default is 1.</param>
  1529. /// <returns>zero on success, or non-zero on error.</returns>
  1530. internal int Initialize(Unicode.Rune rune, int count = 1)
  1531. {
  1532. this = default;
  1533. return (int)this.Append(rune, count);
  1534. }
  1535. /// <summary>
  1536. /// Returns the lexicographical sort order of this string relative to another.
  1537. /// </summary>
  1538. /// <param name="other">A string to compare with.</param>
  1539. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  1540. ///
  1541. /// 0 denotes that both strings have the same sort position.<br/>
  1542. /// -1 denotes that this string should be sorted to precede the other.<br/>
  1543. /// +1 denotes that this string should be sorted to follow the other.<br/>
  1544. /// </returns>
  1545. public int CompareTo(FixedString32Bytes other)
  1546. {
  1547. return FixedStringMethods.CompareTo(ref this, other);
  1548. }
  1549. /// <summary>
  1550. /// Initializes and returns an instance of FixedString64Bytes that is a copy of another string.
  1551. /// </summary>
  1552. /// <param name="other">The string to copy.</param>
  1553. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString64Bytes.</exception>
  1554. public FixedString64Bytes(in FixedString32Bytes other)
  1555. {
  1556. this = default;
  1557. var error = Initialize(other);
  1558. CheckFormatError((FormatError)error);
  1559. }
  1560. /// <summary>
  1561. /// Initializes an instance of FixedString64Bytes that is a copy of another string.
  1562. /// </summary>
  1563. /// <param name="other">The string to copy.</param>
  1564. /// <returns>zero on success, or non-zero on error.</returns>
  1565. internal int Initialize(in FixedString32Bytes other)
  1566. {
  1567. bytes = default;
  1568. utf8LengthInBytes = 0;
  1569. unsafe {
  1570. int len = 0;
  1571. byte* dstBytes = GetUnsafePtr();
  1572. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  1573. var srcLength = other.utf8LengthInBytes;
  1574. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  1575. if(error != FormatError.None)
  1576. return (int)error;
  1577. this.Length = len;
  1578. }
  1579. return 0;
  1580. }
  1581. /// <summary>
  1582. /// Returns true if a FixedString64Bytes and another string are equal.
  1583. /// </summary>
  1584. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1585. /// <param name="a">A FixedString64Bytes to compare for equality.</param>
  1586. /// <param name="b">A FixedString32Bytes to compare for equality.</param>
  1587. /// <returns>True if the two strings are equal.</returns>
  1588. public static bool operator ==(in FixedString64Bytes a, in FixedString32Bytes b)
  1589. {
  1590. // this must not call any methods on 'a' or 'b'
  1591. unsafe {
  1592. int alen = a.utf8LengthInBytes;
  1593. int blen = b.utf8LengthInBytes;
  1594. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  1595. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  1596. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  1597. }
  1598. }
  1599. /// <summary>
  1600. /// Returns true if a FixedString64Bytes and another string are unequal.
  1601. /// </summary>
  1602. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1603. /// <param name="a">A FixedString64Bytes to compare for inequality.</param>
  1604. /// <param name="b">A FixedString32Bytes to compare for inequality.</param>
  1605. /// <returns>True if the two strings are unequal.</returns>
  1606. public static bool operator !=(in FixedString64Bytes a, in FixedString32Bytes b)
  1607. {
  1608. return !(a == b);
  1609. }
  1610. /// <summary>
  1611. /// Returns true if this string and another string are equal.
  1612. /// </summary>
  1613. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1614. /// <param name="other">A FixedString32Bytes to compare for equality.</param>
  1615. /// <returns>True if the two strings are equal.</returns>
  1616. public bool Equals(FixedString32Bytes other)
  1617. {
  1618. return this == other;
  1619. }
  1620. /// <summary>
  1621. /// Returns the lexicographical sort order of this string relative to another.
  1622. /// </summary>
  1623. /// <param name="other">A string to compare with.</param>
  1624. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  1625. ///
  1626. /// 0 denotes that both strings have the same sort position.<br/>
  1627. /// -1 denotes that this string should be sorted to precede the other.<br/>
  1628. /// +1 denotes that this string should be sorted to follow the other.<br/>
  1629. /// </returns>
  1630. public int CompareTo(FixedString64Bytes other)
  1631. {
  1632. return FixedStringMethods.CompareTo(ref this, other);
  1633. }
  1634. /// <summary>
  1635. /// Initializes and returns an instance of FixedString64Bytes that is a copy of another string.
  1636. /// </summary>
  1637. /// <param name="other">The string to copy.</param>
  1638. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString64Bytes.</exception>
  1639. public FixedString64Bytes(in FixedString64Bytes other)
  1640. {
  1641. this = default;
  1642. var error = Initialize(other);
  1643. CheckFormatError((FormatError)error);
  1644. }
  1645. /// <summary>
  1646. /// Initializes an instance of FixedString64Bytes that is a copy of another string.
  1647. /// </summary>
  1648. /// <param name="other">The string to copy.</param>
  1649. /// <returns>zero on success, or non-zero on error.</returns>
  1650. internal int Initialize(in FixedString64Bytes other)
  1651. {
  1652. bytes = default;
  1653. utf8LengthInBytes = 0;
  1654. unsafe {
  1655. int len = 0;
  1656. byte* dstBytes = GetUnsafePtr();
  1657. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  1658. var srcLength = other.utf8LengthInBytes;
  1659. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  1660. if(error != FormatError.None)
  1661. return (int)error;
  1662. this.Length = len;
  1663. }
  1664. return 0;
  1665. }
  1666. /// <summary>
  1667. /// Returns true if a FixedString64Bytes and another string are equal.
  1668. /// </summary>
  1669. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1670. /// <param name="a">A FixedString64Bytes to compare for equality.</param>
  1671. /// <param name="b">A FixedString64Bytes to compare for equality.</param>
  1672. /// <returns>True if the two strings are equal.</returns>
  1673. public static bool operator ==(in FixedString64Bytes a, in FixedString64Bytes b)
  1674. {
  1675. // this must not call any methods on 'a' or 'b'
  1676. unsafe {
  1677. int alen = a.utf8LengthInBytes;
  1678. int blen = b.utf8LengthInBytes;
  1679. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  1680. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  1681. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  1682. }
  1683. }
  1684. /// <summary>
  1685. /// Returns true if a FixedString64Bytes and another string are unequal.
  1686. /// </summary>
  1687. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1688. /// <param name="a">A FixedString64Bytes to compare for inequality.</param>
  1689. /// <param name="b">A FixedString64Bytes to compare for inequality.</param>
  1690. /// <returns>True if the two strings are unequal.</returns>
  1691. public static bool operator !=(in FixedString64Bytes a, in FixedString64Bytes b)
  1692. {
  1693. return !(a == b);
  1694. }
  1695. /// <summary>
  1696. /// Returns true if this string and another string are equal.
  1697. /// </summary>
  1698. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1699. /// <param name="other">A FixedString64Bytes to compare for equality.</param>
  1700. /// <returns>True if the two strings are equal.</returns>
  1701. public bool Equals(FixedString64Bytes other)
  1702. {
  1703. return this == other;
  1704. }
  1705. /// <summary>
  1706. /// Returns the lexicographical sort order of this string relative to another.
  1707. /// </summary>
  1708. /// <param name="other">A string to compare with.</param>
  1709. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  1710. ///
  1711. /// 0 denotes that both strings have the same sort position.<br/>
  1712. /// -1 denotes that this string should be sorted to precede the other.<br/>
  1713. /// +1 denotes that this string should be sorted to follow the other.<br/>
  1714. /// </returns>
  1715. public int CompareTo(FixedString128Bytes other)
  1716. {
  1717. return FixedStringMethods.CompareTo(ref this, other);
  1718. }
  1719. /// <summary>
  1720. /// Initializes and returns an instance of FixedString64Bytes that is a copy of another string.
  1721. /// </summary>
  1722. /// <param name="other">The string to copy.</param>
  1723. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString64Bytes.</exception>
  1724. public FixedString64Bytes(in FixedString128Bytes other)
  1725. {
  1726. this = default;
  1727. var error = Initialize(other);
  1728. CheckFormatError((FormatError)error);
  1729. }
  1730. /// <summary>
  1731. /// Initializes an instance of FixedString64Bytes that is a copy of another string.
  1732. /// </summary>
  1733. /// <param name="other">The string to copy.</param>
  1734. /// <returns>zero on success, or non-zero on error.</returns>
  1735. internal int Initialize(in FixedString128Bytes other)
  1736. {
  1737. bytes = default;
  1738. utf8LengthInBytes = 0;
  1739. unsafe {
  1740. int len = 0;
  1741. byte* dstBytes = GetUnsafePtr();
  1742. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  1743. var srcLength = other.utf8LengthInBytes;
  1744. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  1745. if(error != FormatError.None)
  1746. return (int)error;
  1747. this.Length = len;
  1748. }
  1749. return 0;
  1750. }
  1751. /// <summary>
  1752. /// Returns true if a FixedString64Bytes and another string are equal.
  1753. /// </summary>
  1754. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1755. /// <param name="a">A FixedString64Bytes to compare for equality.</param>
  1756. /// <param name="b">A FixedString128Bytes to compare for equality.</param>
  1757. /// <returns>True if the two strings are equal.</returns>
  1758. public static bool operator ==(in FixedString64Bytes a, in FixedString128Bytes b)
  1759. {
  1760. // this must not call any methods on 'a' or 'b'
  1761. unsafe {
  1762. int alen = a.utf8LengthInBytes;
  1763. int blen = b.utf8LengthInBytes;
  1764. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  1765. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  1766. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  1767. }
  1768. }
  1769. /// <summary>
  1770. /// Returns true if a FixedString64Bytes and another string are unequal.
  1771. /// </summary>
  1772. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1773. /// <param name="a">A FixedString64Bytes to compare for inequality.</param>
  1774. /// <param name="b">A FixedString128Bytes to compare for inequality.</param>
  1775. /// <returns>True if the two strings are unequal.</returns>
  1776. public static bool operator !=(in FixedString64Bytes a, in FixedString128Bytes b)
  1777. {
  1778. return !(a == b);
  1779. }
  1780. /// <summary>
  1781. /// Returns true if this string and another string are equal.
  1782. /// </summary>
  1783. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1784. /// <param name="other">A FixedString128Bytes to compare for equality.</param>
  1785. /// <returns>True if the two strings are equal.</returns>
  1786. public bool Equals(FixedString128Bytes other)
  1787. {
  1788. return this == other;
  1789. }
  1790. /// <summary>
  1791. /// Returns a new FixedString128Bytes that is a copy of another string.
  1792. /// </summary>
  1793. /// <param name="fs">A FixedString64Bytes to copy.</param>
  1794. /// <returns>A new FixedString128Bytes that is a copy of the other string.</returns>
  1795. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString128Bytes.</exception>
  1796. public static implicit operator FixedString128Bytes(in FixedString64Bytes fs) => new FixedString128Bytes(in fs);
  1797. /// <summary>
  1798. /// Returns the lexicographical sort order of this string relative to another.
  1799. /// </summary>
  1800. /// <param name="other">A string to compare with.</param>
  1801. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  1802. ///
  1803. /// 0 denotes that both strings have the same sort position.<br/>
  1804. /// -1 denotes that this string should be sorted to precede the other.<br/>
  1805. /// +1 denotes that this string should be sorted to follow the other.<br/>
  1806. /// </returns>
  1807. public int CompareTo(FixedString512Bytes other)
  1808. {
  1809. return FixedStringMethods.CompareTo(ref this, other);
  1810. }
  1811. /// <summary>
  1812. /// Initializes and returns an instance of FixedString64Bytes that is a copy of another string.
  1813. /// </summary>
  1814. /// <param name="other">The string to copy.</param>
  1815. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString64Bytes.</exception>
  1816. public FixedString64Bytes(in FixedString512Bytes other)
  1817. {
  1818. this = default;
  1819. var error = Initialize(other);
  1820. CheckFormatError((FormatError)error);
  1821. }
  1822. /// <summary>
  1823. /// Initializes an instance of FixedString64Bytes that is a copy of another string.
  1824. /// </summary>
  1825. /// <param name="other">The string to copy.</param>
  1826. /// <returns>zero on success, or non-zero on error.</returns>
  1827. internal int Initialize(in FixedString512Bytes other)
  1828. {
  1829. bytes = default;
  1830. utf8LengthInBytes = 0;
  1831. unsafe {
  1832. int len = 0;
  1833. byte* dstBytes = GetUnsafePtr();
  1834. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  1835. var srcLength = other.utf8LengthInBytes;
  1836. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  1837. if(error != FormatError.None)
  1838. return (int)error;
  1839. this.Length = len;
  1840. }
  1841. return 0;
  1842. }
  1843. /// <summary>
  1844. /// Returns true if a FixedString64Bytes and another string are equal.
  1845. /// </summary>
  1846. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1847. /// <param name="a">A FixedString64Bytes to compare for equality.</param>
  1848. /// <param name="b">A FixedString512Bytes to compare for equality.</param>
  1849. /// <returns>True if the two strings are equal.</returns>
  1850. public static bool operator ==(in FixedString64Bytes a, in FixedString512Bytes b)
  1851. {
  1852. // this must not call any methods on 'a' or 'b'
  1853. unsafe {
  1854. int alen = a.utf8LengthInBytes;
  1855. int blen = b.utf8LengthInBytes;
  1856. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  1857. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  1858. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  1859. }
  1860. }
  1861. /// <summary>
  1862. /// Returns true if a FixedString64Bytes and another string are unequal.
  1863. /// </summary>
  1864. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1865. /// <param name="a">A FixedString64Bytes to compare for inequality.</param>
  1866. /// <param name="b">A FixedString512Bytes to compare for inequality.</param>
  1867. /// <returns>True if the two strings are unequal.</returns>
  1868. public static bool operator !=(in FixedString64Bytes a, in FixedString512Bytes b)
  1869. {
  1870. return !(a == b);
  1871. }
  1872. /// <summary>
  1873. /// Returns true if this string and another string are equal.
  1874. /// </summary>
  1875. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1876. /// <param name="other">A FixedString512Bytes to compare for equality.</param>
  1877. /// <returns>True if the two strings are equal.</returns>
  1878. public bool Equals(FixedString512Bytes other)
  1879. {
  1880. return this == other;
  1881. }
  1882. /// <summary>
  1883. /// Returns a new FixedString512Bytes that is a copy of another string.
  1884. /// </summary>
  1885. /// <param name="fs">A FixedString64Bytes to copy.</param>
  1886. /// <returns>A new FixedString512Bytes that is a copy of the other string.</returns>
  1887. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString512Bytes.</exception>
  1888. public static implicit operator FixedString512Bytes(in FixedString64Bytes fs) => new FixedString512Bytes(in fs);
  1889. /// <summary>
  1890. /// Returns the lexicographical sort order of this string relative to another.
  1891. /// </summary>
  1892. /// <param name="other">A string to compare with.</param>
  1893. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  1894. ///
  1895. /// 0 denotes that both strings have the same sort position.<br/>
  1896. /// -1 denotes that this string should be sorted to precede the other.<br/>
  1897. /// +1 denotes that this string should be sorted to follow the other.<br/>
  1898. /// </returns>
  1899. public int CompareTo(FixedString4096Bytes other)
  1900. {
  1901. return FixedStringMethods.CompareTo(ref this, other);
  1902. }
  1903. /// <summary>
  1904. /// Initializes and returns an instance of FixedString64Bytes that is a copy of another string.
  1905. /// </summary>
  1906. /// <param name="other">The string to copy.</param>
  1907. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString64Bytes.</exception>
  1908. public FixedString64Bytes(in FixedString4096Bytes other)
  1909. {
  1910. this = default;
  1911. var error = Initialize(other);
  1912. CheckFormatError((FormatError)error);
  1913. }
  1914. /// <summary>
  1915. /// Initializes an instance of FixedString64Bytes that is a copy of another string.
  1916. /// </summary>
  1917. /// <param name="other">The string to copy.</param>
  1918. /// <returns>zero on success, or non-zero on error.</returns>
  1919. internal int Initialize(in FixedString4096Bytes other)
  1920. {
  1921. bytes = default;
  1922. utf8LengthInBytes = 0;
  1923. unsafe {
  1924. int len = 0;
  1925. byte* dstBytes = GetUnsafePtr();
  1926. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  1927. var srcLength = other.utf8LengthInBytes;
  1928. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  1929. if(error != FormatError.None)
  1930. return (int)error;
  1931. this.Length = len;
  1932. }
  1933. return 0;
  1934. }
  1935. /// <summary>
  1936. /// Returns true if a FixedString64Bytes and another string are equal.
  1937. /// </summary>
  1938. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1939. /// <param name="a">A FixedString64Bytes to compare for equality.</param>
  1940. /// <param name="b">A FixedString4096Bytes to compare for equality.</param>
  1941. /// <returns>True if the two strings are equal.</returns>
  1942. public static bool operator ==(in FixedString64Bytes a, in FixedString4096Bytes b)
  1943. {
  1944. // this must not call any methods on 'a' or 'b'
  1945. unsafe {
  1946. int alen = a.utf8LengthInBytes;
  1947. int blen = b.utf8LengthInBytes;
  1948. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  1949. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  1950. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  1951. }
  1952. }
  1953. /// <summary>
  1954. /// Returns true if a FixedString64Bytes and another string are unequal.
  1955. /// </summary>
  1956. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1957. /// <param name="a">A FixedString64Bytes to compare for inequality.</param>
  1958. /// <param name="b">A FixedString4096Bytes to compare for inequality.</param>
  1959. /// <returns>True if the two strings are unequal.</returns>
  1960. public static bool operator !=(in FixedString64Bytes a, in FixedString4096Bytes b)
  1961. {
  1962. return !(a == b);
  1963. }
  1964. /// <summary>
  1965. /// Returns true if this string and another string are equal.
  1966. /// </summary>
  1967. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  1968. /// <param name="other">A FixedString4096Bytes to compare for equality.</param>
  1969. /// <returns>True if the two strings are equal.</returns>
  1970. public bool Equals(FixedString4096Bytes other)
  1971. {
  1972. return this == other;
  1973. }
  1974. /// <summary>
  1975. /// Returns a new FixedString4096Bytes that is a copy of another string.
  1976. /// </summary>
  1977. /// <param name="fs">A FixedString64Bytes to copy.</param>
  1978. /// <returns>A new FixedString4096Bytes that is a copy of the other string.</returns>
  1979. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString4096Bytes.</exception>
  1980. public static implicit operator FixedString4096Bytes(in FixedString64Bytes fs) => new FixedString4096Bytes(in fs);
  1981. /// <summary>
  1982. /// Returns a new FixedString64Bytes that is a copy of another string.
  1983. /// </summary>
  1984. /// <param name="b">A string to copy.</param>
  1985. /// <returns>A new FixedString64Bytes that is a copy of another string.</returns>
  1986. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString64Bytes.</exception>
  1987. [NotBurstCompatible]
  1988. public static implicit operator FixedString64Bytes(string b) => new FixedString64Bytes(b);
  1989. /// <summary>
  1990. /// Returns a new managed string that is a copy of this string.
  1991. /// </summary>
  1992. /// <returns>A new managed string that is a copy of this string.</returns>
  1993. [NotBurstCompatible]
  1994. public override String ToString()
  1995. {
  1996. return this.ConvertToString();
  1997. }
  1998. /// <summary>
  1999. /// Returns a hash code of this string.
  2000. /// </summary>
  2001. /// <remarks>Only the character bytes are included in the hash: any bytes beyond <see cref="Length"/> are not part of the hash.</remarks>
  2002. /// <returns>The hash code of this string.</returns>
  2003. public override int GetHashCode()
  2004. {
  2005. return this.ComputeHashCode();
  2006. }
  2007. /// <summary>
  2008. /// Returns true if this string and an object are equal.
  2009. /// </summary>
  2010. /// <remarks>
  2011. /// Returns false if the object is neither a System.String or a FixedString.
  2012. ///
  2013. /// Two strings are equal if they have equal length and all their characters match.</remarks>
  2014. /// <param name="obj">An object to compare for equality.</param>
  2015. /// <returns>True if this string and the object are equal.</returns>
  2016. [NotBurstCompatible]
  2017. public override bool Equals(object obj)
  2018. {
  2019. if(ReferenceEquals(null, obj)) return false;
  2020. if(obj is String aString) return Equals(aString);
  2021. if(obj is FixedString32Bytes aFixedString32Bytes) return Equals(aFixedString32Bytes);
  2022. if(obj is FixedString64Bytes aFixedString64Bytes) return Equals(aFixedString64Bytes);
  2023. if(obj is FixedString128Bytes aFixedString128Bytes) return Equals(aFixedString128Bytes);
  2024. if(obj is FixedString512Bytes aFixedString512Bytes) return Equals(aFixedString512Bytes);
  2025. if(obj is FixedString4096Bytes aFixedString4096Bytes) return Equals(aFixedString4096Bytes);
  2026. return false;
  2027. }
  2028. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  2029. void CheckIndexInRange(int index)
  2030. {
  2031. if (index < 0)
  2032. throw new IndexOutOfRangeException($"Index {index} must be positive.");
  2033. if (index >= utf8LengthInBytes)
  2034. throw new IndexOutOfRangeException($"Index {index} is out of range in FixedString64Bytes of '{utf8LengthInBytes}' Length.");
  2035. }
  2036. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  2037. void CheckLengthInRange(int length)
  2038. {
  2039. if (length < 0)
  2040. throw new ArgumentOutOfRangeException($"Length {length} must be positive.");
  2041. if (length > utf8MaxLengthInBytes)
  2042. throw new ArgumentOutOfRangeException($"Length {length} is out of range in FixedString64Bytes of '{utf8MaxLengthInBytes}' Capacity.");
  2043. }
  2044. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  2045. void CheckCapacityInRange(int capacity)
  2046. {
  2047. if (capacity > utf8MaxLengthInBytes)
  2048. throw new ArgumentOutOfRangeException($"Capacity {capacity} must be lower than {utf8MaxLengthInBytes}.");
  2049. }
  2050. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  2051. static void CheckCopyError(CopyError error, String source)
  2052. {
  2053. if (error != CopyError.None)
  2054. throw new ArgumentException($"FixedString64Bytes: {error} while copying \"{source}\"");
  2055. }
  2056. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  2057. static void CheckFormatError(FormatError error)
  2058. {
  2059. if (error != FormatError.None)
  2060. throw new ArgumentException("Source is too long to fit into fixed string of this size");
  2061. }
  2062. }
  2063. // A temporary copy of a struct is made before it is displayed in a C# debugger.
  2064. // However, only the first element of data members with names is copied at this time.
  2065. // Therefore, it's important that all data visible in the debugger, has a name
  2066. // and includes no 'fixed' array. This is why we name every byte in the following struct.
  2067. /// <summary>
  2068. /// For internal use only.
  2069. /// </summary>
  2070. [Serializable]
  2071. [StructLayout(LayoutKind.Explicit, Size=126)]
  2072. [BurstCompatible]
  2073. public struct FixedBytes126
  2074. {
  2075. /// <summary>
  2076. /// For internal use only.
  2077. /// </summary>
  2078. [FieldOffset(0)] public FixedBytes16 offset0000;
  2079. /// <summary>
  2080. /// For internal use only.
  2081. /// </summary>
  2082. [FieldOffset(16)] public FixedBytes16 offset0016;
  2083. /// <summary>
  2084. /// For internal use only.
  2085. /// </summary>
  2086. [FieldOffset(32)] public FixedBytes16 offset0032;
  2087. /// <summary>
  2088. /// For internal use only.
  2089. /// </summary>
  2090. [FieldOffset(48)] public FixedBytes16 offset0048;
  2091. /// <summary>
  2092. /// For internal use only.
  2093. /// </summary>
  2094. [FieldOffset(64)] public FixedBytes16 offset0064;
  2095. /// <summary>
  2096. /// For internal use only.
  2097. /// </summary>
  2098. [FieldOffset(80)] public FixedBytes16 offset0080;
  2099. /// <summary>
  2100. /// For internal use only.
  2101. /// </summary>
  2102. [FieldOffset(96)] public FixedBytes16 offset0096;
  2103. /// <summary>
  2104. /// For internal use only.
  2105. /// </summary>
  2106. [FieldOffset(112)] public byte byte0112;
  2107. /// <summary>
  2108. /// For internal use only.
  2109. /// </summary>
  2110. [FieldOffset(113)] public byte byte0113;
  2111. /// <summary>
  2112. /// For internal use only.
  2113. /// </summary>
  2114. [FieldOffset(114)] public byte byte0114;
  2115. /// <summary>
  2116. /// For internal use only.
  2117. /// </summary>
  2118. [FieldOffset(115)] public byte byte0115;
  2119. /// <summary>
  2120. /// For internal use only.
  2121. /// </summary>
  2122. [FieldOffset(116)] public byte byte0116;
  2123. /// <summary>
  2124. /// For internal use only.
  2125. /// </summary>
  2126. [FieldOffset(117)] public byte byte0117;
  2127. /// <summary>
  2128. /// For internal use only.
  2129. /// </summary>
  2130. [FieldOffset(118)] public byte byte0118;
  2131. /// <summary>
  2132. /// For internal use only.
  2133. /// </summary>
  2134. [FieldOffset(119)] public byte byte0119;
  2135. /// <summary>
  2136. /// For internal use only.
  2137. /// </summary>
  2138. [FieldOffset(120)] public byte byte0120;
  2139. /// <summary>
  2140. /// For internal use only.
  2141. /// </summary>
  2142. [FieldOffset(121)] public byte byte0121;
  2143. /// <summary>
  2144. /// For internal use only.
  2145. /// </summary>
  2146. [FieldOffset(122)] public byte byte0122;
  2147. /// <summary>
  2148. /// For internal use only.
  2149. /// </summary>
  2150. [FieldOffset(123)] public byte byte0123;
  2151. /// <summary>
  2152. /// For internal use only.
  2153. /// </summary>
  2154. [FieldOffset(124)] public byte byte0124;
  2155. /// <summary>
  2156. /// For internal use only.
  2157. /// </summary>
  2158. [FieldOffset(125)] public byte byte0125;
  2159. }
  2160. [Obsolete("Renamed to FixedString128Bytes (UnityUpgradable) -> FixedString128Bytes", true)]
  2161. public partial struct FixedString128 {}
  2162. /// <summary>
  2163. /// An unmanaged UTF-8 string whose content is stored directly in the 128-byte struct.
  2164. /// </summary>
  2165. /// <remarks>
  2166. /// The binary layout of this string is guaranteed, for now and all time, to be a length (a little-endian two byte integer)
  2167. /// followed by the bytes of the characters (with no padding). A zero byte always immediately follows the last character.
  2168. /// Effectively, the number of bytes for storing characters is 3 less than 128 (two length bytes and one null byte).
  2169. ///
  2170. /// This layout is identical to a <see cref="FixedList128Bytes{T}"/> of bytes, thus allowing reinterpretation between FixedString128Bytes and FixedList128Bytes.
  2171. ///
  2172. /// By virtue of being an unmanaged, non-allocated struct with no pointers, this string is fully compatible with jobs and Burst compilation.
  2173. /// Unlike managed string types, these strings can be put in any unmanaged ECS components, FixedList, or any other unmanaged structs.
  2174. /// </remarks>
  2175. [Serializable]
  2176. [StructLayout(LayoutKind.Sequential, Size=128)]
  2177. [BurstCompatible]
  2178. public partial struct FixedString128Bytes
  2179. : INativeList<byte>
  2180. , IUTF8Bytes
  2181. , IComparable<String>
  2182. , IEquatable<String>
  2183. , IComparable<FixedString32Bytes>
  2184. , IEquatable<FixedString32Bytes>
  2185. , IComparable<FixedString64Bytes>
  2186. , IEquatable<FixedString64Bytes>
  2187. , IComparable<FixedString128Bytes>
  2188. , IEquatable<FixedString128Bytes>
  2189. , IComparable<FixedString512Bytes>
  2190. , IEquatable<FixedString512Bytes>
  2191. , IComparable<FixedString4096Bytes>
  2192. , IEquatable<FixedString4096Bytes>
  2193. {
  2194. internal const ushort utf8MaxLengthInBytes = 125;
  2195. [SerializeField] internal ushort utf8LengthInBytes;
  2196. [SerializeField] internal FixedBytes126 bytes;
  2197. /// <summary>
  2198. /// Returns the maximum number of UTF-8 bytes that can be stored in this string.
  2199. /// </summary>
  2200. /// <returns>
  2201. /// The maximum number of UTF-8 bytes that can be stored in this string.
  2202. /// </returns>
  2203. public static int UTF8MaxLengthInBytes => utf8MaxLengthInBytes;
  2204. /// <summary>
  2205. /// For internal use only. Use <see cref="ToString"/> instead.
  2206. /// </summary>
  2207. /// <value>For internal use only. Use <see cref="ToString"/> instead.</value>
  2208. [CreateProperty]
  2209. [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
  2210. [NotBurstCompatible]
  2211. public string Value => ToString();
  2212. /// <summary>
  2213. /// Returns a pointer to the character bytes.
  2214. /// </summary>
  2215. /// <returns>A pointer to the character bytes.</returns>
  2216. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2217. public unsafe byte* GetUnsafePtr()
  2218. {
  2219. return (byte*) UnsafeUtility.AddressOf(ref bytes);
  2220. }
  2221. /// <summary>
  2222. /// The current length in bytes of this string's content.
  2223. /// </summary>
  2224. /// <remarks>
  2225. /// The length value does not include the null-terminator byte.
  2226. /// </remarks>
  2227. /// <param name="value">The new length in bytes of the string's content.</param>
  2228. /// <exception cref="ArgumentOutOfRangeException">Thrown if the new length is out of bounds.</exception>
  2229. /// <value>
  2230. /// The current length in bytes of this string's content.
  2231. /// </value>
  2232. public int Length
  2233. {
  2234. get
  2235. {
  2236. return utf8LengthInBytes;
  2237. }
  2238. set
  2239. {
  2240. CheckLengthInRange(value);
  2241. utf8LengthInBytes = (ushort)value;
  2242. unsafe
  2243. {
  2244. GetUnsafePtr()[utf8LengthInBytes] = 0;
  2245. }
  2246. }
  2247. }
  2248. /// <summary>
  2249. /// The number of bytes this string has for storing UTF-8 characters.
  2250. /// </summary>
  2251. /// <value>The number of bytes this string has for storing UTF-8 characters.</value>
  2252. /// <remarks>
  2253. /// Does not include the null-terminator byte.
  2254. ///
  2255. /// A setter is included for conformity with <see cref="INativeList{T}"/>, but <see cref="Capacity"/> is fixed at 125.
  2256. /// Setting the value to anything other than 125 throws an exception.
  2257. ///
  2258. /// In UTF-8 encoding, each Unicode code point (character) requires 1 to 4 bytes,
  2259. /// so the number of characters that can be stored may be less than the capacity.
  2260. /// </remarks>
  2261. /// <exception cref="ArgumentOutOfRangeException">Thrown if attempting to set the capacity to anything other than 125.</exception>
  2262. public int Capacity
  2263. {
  2264. get
  2265. {
  2266. return utf8MaxLengthInBytes;
  2267. }
  2268. set
  2269. {
  2270. CheckCapacityInRange(value);
  2271. }
  2272. }
  2273. /// <summary>
  2274. /// Attempts to set the length in bytes. Does nothing if the new length is invalid.
  2275. /// </summary>
  2276. /// <param name="newLength">The desired length.</param>
  2277. /// <param name="clearOptions">Whether added or removed bytes should be cleared (zeroed). (Increasing the length adds bytes; decreasing the length removes bytes.)</param>
  2278. /// <returns>True if the new length is valid.</returns>
  2279. public bool TryResize(int newLength, NativeArrayOptions clearOptions = NativeArrayOptions.ClearMemory)
  2280. {
  2281. if (newLength < 0 || newLength > utf8MaxLengthInBytes)
  2282. return false;
  2283. if (newLength == utf8LengthInBytes)
  2284. return true;
  2285. unsafe
  2286. {
  2287. if (clearOptions == NativeArrayOptions.ClearMemory)
  2288. {
  2289. if (newLength > utf8LengthInBytes)
  2290. UnsafeUtility.MemClear(GetUnsafePtr() + utf8LengthInBytes, newLength - utf8LengthInBytes);
  2291. else
  2292. UnsafeUtility.MemClear(GetUnsafePtr() + newLength, utf8LengthInBytes - newLength);
  2293. }
  2294. utf8LengthInBytes = (ushort)newLength;
  2295. // always null terminate
  2296. GetUnsafePtr()[utf8LengthInBytes] = 0;
  2297. }
  2298. return true;
  2299. }
  2300. /// <summary>
  2301. /// Returns true if this string is empty (has no characters).
  2302. /// </summary>
  2303. /// <value>True if this string is empty (has no characters).</value>
  2304. public bool IsEmpty => utf8LengthInBytes == 0;
  2305. /// <summary>
  2306. /// Returns the byte (not character) at an index.
  2307. /// </summary>
  2308. /// <param name="index">A byte index.</param>
  2309. /// <value>The byte at the index.</value>
  2310. /// <exception cref="IndexOutOfRangeException">Thrown if the index is out of bounds.</exception>
  2311. public byte this[int index]
  2312. {
  2313. get
  2314. {
  2315. unsafe
  2316. {
  2317. CheckIndexInRange(index);
  2318. return GetUnsafePtr()[index];
  2319. }
  2320. }
  2321. set
  2322. {
  2323. unsafe
  2324. {
  2325. CheckIndexInRange(index);
  2326. GetUnsafePtr()[index] = value;
  2327. }
  2328. }
  2329. }
  2330. /// <summary>
  2331. /// Returns the reference to a byte (not character) at an index.
  2332. /// </summary>
  2333. /// <param name="index">A byte index.</param>
  2334. /// <returns>A reference to the byte at the index.</returns>
  2335. /// <exception cref="IndexOutOfRangeException">Thrown if the index is out of bounds.</exception>
  2336. public ref byte ElementAt(int index)
  2337. {
  2338. unsafe
  2339. {
  2340. CheckIndexInRange(index);
  2341. return ref GetUnsafePtr()[index];
  2342. }
  2343. }
  2344. /// <summary>
  2345. /// Sets the length to 0.
  2346. /// </summary>
  2347. public void Clear()
  2348. {
  2349. Length = 0;
  2350. }
  2351. /// <summary>
  2352. /// Appends a byte.
  2353. /// </summary>
  2354. /// <remarks>
  2355. /// A zero byte will always follow the newly appended byte.
  2356. ///
  2357. /// No validation is performed: it is your responsibility for the bytes of the string to form valid UTF-8 when you're done appending bytes.
  2358. /// </remarks>
  2359. /// <param name="value">A byte to append.</param>
  2360. public void Add(in byte value)
  2361. {
  2362. this[Length++] = value;
  2363. }
  2364. /// <summary>
  2365. /// An enumerator over the characters (not bytes) of a FixedString128Bytes.
  2366. /// </summary>
  2367. /// <remarks>
  2368. /// In an enumerator's initial state, <see cref="Current"/> is not valid to read.
  2369. /// The first <see cref="MoveNext"/> call advances the enumerator's index to the first character.
  2370. /// </remarks>
  2371. public struct Enumerator : IEnumerator
  2372. {
  2373. FixedString128Bytes target;
  2374. int offset;
  2375. Unicode.Rune current;
  2376. /// <summary>
  2377. /// Initializes and returns an instance of FixedString128Bytes.Enumerator.
  2378. /// </summary>
  2379. /// <param name="other">A FixeString128 for which to create an enumerator.</param>
  2380. public Enumerator(FixedString128Bytes other)
  2381. {
  2382. target = other;
  2383. offset = 0;
  2384. current = default;
  2385. }
  2386. /// <summary>
  2387. /// Does nothing.
  2388. /// </summary>
  2389. public void Dispose()
  2390. {
  2391. }
  2392. /// <summary>
  2393. /// Advances the enumerator to the next character.
  2394. /// </summary>
  2395. /// <returns>True if <see cref="Current"/> is valid to read after the call.</returns>
  2396. public bool MoveNext()
  2397. {
  2398. if (offset >= target.Length)
  2399. return false;
  2400. unsafe
  2401. {
  2402. Unicode.Utf8ToUcs(out current, target.GetUnsafePtr(), ref offset, target.Length);
  2403. }
  2404. return true;
  2405. }
  2406. /// <summary>
  2407. /// Resets the enumerator to its initial state.
  2408. /// </summary>
  2409. public void Reset()
  2410. {
  2411. offset = 0;
  2412. current = default;
  2413. }
  2414. /// <summary>
  2415. /// The current character.
  2416. /// </summary>
  2417. /// <remarks>
  2418. /// In an enumerator's initial state, <see cref="Current"/> is not valid to read.
  2419. /// </remarks>
  2420. /// <value>The current character.</value>
  2421. public Unicode.Rune Current => current;
  2422. object IEnumerator.Current => Current;
  2423. }
  2424. /// <summary>
  2425. /// Returns an enumerator for iterating over the characters of this string.
  2426. /// </summary>
  2427. /// <returns>An enumerator for iterating over the characters of the FixedString128Bytes.</returns>
  2428. public Enumerator GetEnumerator()
  2429. {
  2430. return new Enumerator(this);
  2431. }
  2432. /// <summary>
  2433. /// Returns the lexicographical sort order of this string relative to another.
  2434. /// </summary>
  2435. /// <param name="other">A `System.String` to compare with.</param>
  2436. /// <returns>An integer denoting the lexicographical sort order of this string relative to the other:
  2437. ///
  2438. /// 0 denotes both strings have the same sort position.<br/>
  2439. /// -1 denotes that this string should be sorted to precede the other string.<br/>
  2440. /// +1 denotes that this string should be sorted to follow the other string.<br/>
  2441. /// </returns>
  2442. [NotBurstCompatible]
  2443. public int CompareTo(String other)
  2444. {
  2445. return ToString().CompareTo(other);
  2446. }
  2447. /// <summary>
  2448. /// Returns true if this string and another have the same length and all the same characters.
  2449. /// </summary>
  2450. /// <param name="other">A string to compare for equality.</param>
  2451. /// <returns>True if this string and the other have the same length and all the same characters.</returns>
  2452. [NotBurstCompatible]
  2453. public bool Equals(String other)
  2454. {
  2455. unsafe {
  2456. int alen = utf8LengthInBytes;
  2457. int blen = other.Length;
  2458. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(bytes);
  2459. fixed(char* bptr = other)
  2460. {
  2461. return UTF8ArrayUnsafeUtility.StrCmp(aptr, alen, bptr, blen) == 0;
  2462. }
  2463. }
  2464. }
  2465. /// <summary>
  2466. /// Returns a reference to a FixedList128Bytes<byte> representation of this string.
  2467. /// </summary>
  2468. /// <remarks>
  2469. /// The referenced FixedListByte128 is the very same bytes as the original FixedString128Bytes,
  2470. /// so it is only valid as long as the original FixedString128Bytes is valid.
  2471. /// </remarks>
  2472. /// <returns>A ref to a FixedListByte128 representation of the FixedString128Bytes.</returns>
  2473. public unsafe ref FixedList128Bytes<byte> AsFixedList()
  2474. {
  2475. return ref UnsafeUtility.AsRef<FixedList128Bytes<byte>>(UnsafeUtility.AddressOf(ref this));
  2476. }
  2477. /// <summary>
  2478. /// Initializes and returns an instance of FixedString128Bytes with the characters copied from a string.
  2479. /// </summary>
  2480. /// <param name="source">The source string to copy.</param>
  2481. [NotBurstCompatible]
  2482. public FixedString128Bytes(String source)
  2483. {
  2484. this = default;
  2485. var error = Initialize(source);
  2486. CheckCopyError((CopyError)error, source);
  2487. }
  2488. /// <summary>
  2489. /// Initializes an instance of FixedString128Bytes with the characters copied from a string.
  2490. /// </summary>
  2491. /// <param name="source">The source string to copy.</param>
  2492. /// <returns>zero on success, or non-zero on error.</returns>
  2493. [NotBurstCompatible]
  2494. internal int Initialize(String source)
  2495. {
  2496. bytes = default;
  2497. utf8LengthInBytes = 0;
  2498. unsafe
  2499. {
  2500. fixed (char* sourceptr = source)
  2501. {
  2502. var error = UTF8ArrayUnsafeUtility.Copy(GetUnsafePtr(), out utf8LengthInBytes, utf8MaxLengthInBytes, sourceptr, source.Length);
  2503. if(error != CopyError.None)
  2504. return (int)error;
  2505. this.Length = utf8LengthInBytes;
  2506. }
  2507. }
  2508. return 0;
  2509. }
  2510. /// <summary>
  2511. /// Initializes and returns an instance of FixedString128Bytes with a single character repeatedly appended some number of times.
  2512. /// </summary>
  2513. /// <param name="rune">The Unicode.Rune to repeat.</param>
  2514. /// <param name="count">The number of times to repeat the character. Default is 1.</param>
  2515. public FixedString128Bytes(Unicode.Rune rune, int count = 1)
  2516. {
  2517. this = default;
  2518. Initialize(rune, count);
  2519. }
  2520. /// <summary>
  2521. /// Initializes an instance of FixedString128Bytes with a single character repeatedly appended some number of times.
  2522. /// </summary>
  2523. /// <param name="rune">The Unicode.Rune to repeat.</param>
  2524. /// <param name="count">The number of times to repeat the character. Default is 1.</param>
  2525. /// <returns>zero on success, or non-zero on error.</returns>
  2526. internal int Initialize(Unicode.Rune rune, int count = 1)
  2527. {
  2528. this = default;
  2529. return (int)this.Append(rune, count);
  2530. }
  2531. /// <summary>
  2532. /// Returns the lexicographical sort order of this string relative to another.
  2533. /// </summary>
  2534. /// <param name="other">A string to compare with.</param>
  2535. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  2536. ///
  2537. /// 0 denotes that both strings have the same sort position.<br/>
  2538. /// -1 denotes that this string should be sorted to precede the other.<br/>
  2539. /// +1 denotes that this string should be sorted to follow the other.<br/>
  2540. /// </returns>
  2541. public int CompareTo(FixedString32Bytes other)
  2542. {
  2543. return FixedStringMethods.CompareTo(ref this, other);
  2544. }
  2545. /// <summary>
  2546. /// Initializes and returns an instance of FixedString128Bytes that is a copy of another string.
  2547. /// </summary>
  2548. /// <param name="other">The string to copy.</param>
  2549. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString128Bytes.</exception>
  2550. public FixedString128Bytes(in FixedString32Bytes other)
  2551. {
  2552. this = default;
  2553. var error = Initialize(other);
  2554. CheckFormatError((FormatError)error);
  2555. }
  2556. /// <summary>
  2557. /// Initializes an instance of FixedString128Bytes that is a copy of another string.
  2558. /// </summary>
  2559. /// <param name="other">The string to copy.</param>
  2560. /// <returns>zero on success, or non-zero on error.</returns>
  2561. internal int Initialize(in FixedString32Bytes other)
  2562. {
  2563. bytes = default;
  2564. utf8LengthInBytes = 0;
  2565. unsafe {
  2566. int len = 0;
  2567. byte* dstBytes = GetUnsafePtr();
  2568. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  2569. var srcLength = other.utf8LengthInBytes;
  2570. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  2571. if(error != FormatError.None)
  2572. return (int)error;
  2573. this.Length = len;
  2574. }
  2575. return 0;
  2576. }
  2577. /// <summary>
  2578. /// Returns true if a FixedString128Bytes and another string are equal.
  2579. /// </summary>
  2580. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2581. /// <param name="a">A FixedString128Bytes to compare for equality.</param>
  2582. /// <param name="b">A FixedString32Bytes to compare for equality.</param>
  2583. /// <returns>True if the two strings are equal.</returns>
  2584. public static bool operator ==(in FixedString128Bytes a, in FixedString32Bytes b)
  2585. {
  2586. // this must not call any methods on 'a' or 'b'
  2587. unsafe {
  2588. int alen = a.utf8LengthInBytes;
  2589. int blen = b.utf8LengthInBytes;
  2590. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  2591. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  2592. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  2593. }
  2594. }
  2595. /// <summary>
  2596. /// Returns true if a FixedString128Bytes and another string are unequal.
  2597. /// </summary>
  2598. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2599. /// <param name="a">A FixedString128Bytes to compare for inequality.</param>
  2600. /// <param name="b">A FixedString32Bytes to compare for inequality.</param>
  2601. /// <returns>True if the two strings are unequal.</returns>
  2602. public static bool operator !=(in FixedString128Bytes a, in FixedString32Bytes b)
  2603. {
  2604. return !(a == b);
  2605. }
  2606. /// <summary>
  2607. /// Returns true if this string and another string are equal.
  2608. /// </summary>
  2609. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2610. /// <param name="other">A FixedString32Bytes to compare for equality.</param>
  2611. /// <returns>True if the two strings are equal.</returns>
  2612. public bool Equals(FixedString32Bytes other)
  2613. {
  2614. return this == other;
  2615. }
  2616. /// <summary>
  2617. /// Returns the lexicographical sort order of this string relative to another.
  2618. /// </summary>
  2619. /// <param name="other">A string to compare with.</param>
  2620. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  2621. ///
  2622. /// 0 denotes that both strings have the same sort position.<br/>
  2623. /// -1 denotes that this string should be sorted to precede the other.<br/>
  2624. /// +1 denotes that this string should be sorted to follow the other.<br/>
  2625. /// </returns>
  2626. public int CompareTo(FixedString64Bytes other)
  2627. {
  2628. return FixedStringMethods.CompareTo(ref this, other);
  2629. }
  2630. /// <summary>
  2631. /// Initializes and returns an instance of FixedString128Bytes that is a copy of another string.
  2632. /// </summary>
  2633. /// <param name="other">The string to copy.</param>
  2634. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString128Bytes.</exception>
  2635. public FixedString128Bytes(in FixedString64Bytes other)
  2636. {
  2637. this = default;
  2638. var error = Initialize(other);
  2639. CheckFormatError((FormatError)error);
  2640. }
  2641. /// <summary>
  2642. /// Initializes an instance of FixedString128Bytes that is a copy of another string.
  2643. /// </summary>
  2644. /// <param name="other">The string to copy.</param>
  2645. /// <returns>zero on success, or non-zero on error.</returns>
  2646. internal int Initialize(in FixedString64Bytes other)
  2647. {
  2648. bytes = default;
  2649. utf8LengthInBytes = 0;
  2650. unsafe {
  2651. int len = 0;
  2652. byte* dstBytes = GetUnsafePtr();
  2653. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  2654. var srcLength = other.utf8LengthInBytes;
  2655. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  2656. if(error != FormatError.None)
  2657. return (int)error;
  2658. this.Length = len;
  2659. }
  2660. return 0;
  2661. }
  2662. /// <summary>
  2663. /// Returns true if a FixedString128Bytes and another string are equal.
  2664. /// </summary>
  2665. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2666. /// <param name="a">A FixedString128Bytes to compare for equality.</param>
  2667. /// <param name="b">A FixedString64Bytes to compare for equality.</param>
  2668. /// <returns>True if the two strings are equal.</returns>
  2669. public static bool operator ==(in FixedString128Bytes a, in FixedString64Bytes b)
  2670. {
  2671. // this must not call any methods on 'a' or 'b'
  2672. unsafe {
  2673. int alen = a.utf8LengthInBytes;
  2674. int blen = b.utf8LengthInBytes;
  2675. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  2676. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  2677. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  2678. }
  2679. }
  2680. /// <summary>
  2681. /// Returns true if a FixedString128Bytes and another string are unequal.
  2682. /// </summary>
  2683. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2684. /// <param name="a">A FixedString128Bytes to compare for inequality.</param>
  2685. /// <param name="b">A FixedString64Bytes to compare for inequality.</param>
  2686. /// <returns>True if the two strings are unequal.</returns>
  2687. public static bool operator !=(in FixedString128Bytes a, in FixedString64Bytes b)
  2688. {
  2689. return !(a == b);
  2690. }
  2691. /// <summary>
  2692. /// Returns true if this string and another string are equal.
  2693. /// </summary>
  2694. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2695. /// <param name="other">A FixedString64Bytes to compare for equality.</param>
  2696. /// <returns>True if the two strings are equal.</returns>
  2697. public bool Equals(FixedString64Bytes other)
  2698. {
  2699. return this == other;
  2700. }
  2701. /// <summary>
  2702. /// Returns the lexicographical sort order of this string relative to another.
  2703. /// </summary>
  2704. /// <param name="other">A string to compare with.</param>
  2705. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  2706. ///
  2707. /// 0 denotes that both strings have the same sort position.<br/>
  2708. /// -1 denotes that this string should be sorted to precede the other.<br/>
  2709. /// +1 denotes that this string should be sorted to follow the other.<br/>
  2710. /// </returns>
  2711. public int CompareTo(FixedString128Bytes other)
  2712. {
  2713. return FixedStringMethods.CompareTo(ref this, other);
  2714. }
  2715. /// <summary>
  2716. /// Initializes and returns an instance of FixedString128Bytes that is a copy of another string.
  2717. /// </summary>
  2718. /// <param name="other">The string to copy.</param>
  2719. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString128Bytes.</exception>
  2720. public FixedString128Bytes(in FixedString128Bytes other)
  2721. {
  2722. this = default;
  2723. var error = Initialize(other);
  2724. CheckFormatError((FormatError)error);
  2725. }
  2726. /// <summary>
  2727. /// Initializes an instance of FixedString128Bytes that is a copy of another string.
  2728. /// </summary>
  2729. /// <param name="other">The string to copy.</param>
  2730. /// <returns>zero on success, or non-zero on error.</returns>
  2731. internal int Initialize(in FixedString128Bytes other)
  2732. {
  2733. bytes = default;
  2734. utf8LengthInBytes = 0;
  2735. unsafe {
  2736. int len = 0;
  2737. byte* dstBytes = GetUnsafePtr();
  2738. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  2739. var srcLength = other.utf8LengthInBytes;
  2740. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  2741. if(error != FormatError.None)
  2742. return (int)error;
  2743. this.Length = len;
  2744. }
  2745. return 0;
  2746. }
  2747. /// <summary>
  2748. /// Returns true if a FixedString128Bytes and another string are equal.
  2749. /// </summary>
  2750. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2751. /// <param name="a">A FixedString128Bytes to compare for equality.</param>
  2752. /// <param name="b">A FixedString128Bytes to compare for equality.</param>
  2753. /// <returns>True if the two strings are equal.</returns>
  2754. public static bool operator ==(in FixedString128Bytes a, in FixedString128Bytes b)
  2755. {
  2756. // this must not call any methods on 'a' or 'b'
  2757. unsafe {
  2758. int alen = a.utf8LengthInBytes;
  2759. int blen = b.utf8LengthInBytes;
  2760. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  2761. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  2762. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  2763. }
  2764. }
  2765. /// <summary>
  2766. /// Returns true if a FixedString128Bytes and another string are unequal.
  2767. /// </summary>
  2768. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2769. /// <param name="a">A FixedString128Bytes to compare for inequality.</param>
  2770. /// <param name="b">A FixedString128Bytes to compare for inequality.</param>
  2771. /// <returns>True if the two strings are unequal.</returns>
  2772. public static bool operator !=(in FixedString128Bytes a, in FixedString128Bytes b)
  2773. {
  2774. return !(a == b);
  2775. }
  2776. /// <summary>
  2777. /// Returns true if this string and another string are equal.
  2778. /// </summary>
  2779. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2780. /// <param name="other">A FixedString128Bytes to compare for equality.</param>
  2781. /// <returns>True if the two strings are equal.</returns>
  2782. public bool Equals(FixedString128Bytes other)
  2783. {
  2784. return this == other;
  2785. }
  2786. /// <summary>
  2787. /// Returns the lexicographical sort order of this string relative to another.
  2788. /// </summary>
  2789. /// <param name="other">A string to compare with.</param>
  2790. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  2791. ///
  2792. /// 0 denotes that both strings have the same sort position.<br/>
  2793. /// -1 denotes that this string should be sorted to precede the other.<br/>
  2794. /// +1 denotes that this string should be sorted to follow the other.<br/>
  2795. /// </returns>
  2796. public int CompareTo(FixedString512Bytes other)
  2797. {
  2798. return FixedStringMethods.CompareTo(ref this, other);
  2799. }
  2800. /// <summary>
  2801. /// Initializes and returns an instance of FixedString128Bytes that is a copy of another string.
  2802. /// </summary>
  2803. /// <param name="other">The string to copy.</param>
  2804. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString128Bytes.</exception>
  2805. public FixedString128Bytes(in FixedString512Bytes other)
  2806. {
  2807. this = default;
  2808. var error = Initialize(other);
  2809. CheckFormatError((FormatError)error);
  2810. }
  2811. /// <summary>
  2812. /// Initializes an instance of FixedString128Bytes that is a copy of another string.
  2813. /// </summary>
  2814. /// <param name="other">The string to copy.</param>
  2815. /// <returns>zero on success, or non-zero on error.</returns>
  2816. internal int Initialize(in FixedString512Bytes other)
  2817. {
  2818. bytes = default;
  2819. utf8LengthInBytes = 0;
  2820. unsafe {
  2821. int len = 0;
  2822. byte* dstBytes = GetUnsafePtr();
  2823. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  2824. var srcLength = other.utf8LengthInBytes;
  2825. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  2826. if(error != FormatError.None)
  2827. return (int)error;
  2828. this.Length = len;
  2829. }
  2830. return 0;
  2831. }
  2832. /// <summary>
  2833. /// Returns true if a FixedString128Bytes and another string are equal.
  2834. /// </summary>
  2835. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2836. /// <param name="a">A FixedString128Bytes to compare for equality.</param>
  2837. /// <param name="b">A FixedString512Bytes to compare for equality.</param>
  2838. /// <returns>True if the two strings are equal.</returns>
  2839. public static bool operator ==(in FixedString128Bytes a, in FixedString512Bytes b)
  2840. {
  2841. // this must not call any methods on 'a' or 'b'
  2842. unsafe {
  2843. int alen = a.utf8LengthInBytes;
  2844. int blen = b.utf8LengthInBytes;
  2845. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  2846. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  2847. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  2848. }
  2849. }
  2850. /// <summary>
  2851. /// Returns true if a FixedString128Bytes and another string are unequal.
  2852. /// </summary>
  2853. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2854. /// <param name="a">A FixedString128Bytes to compare for inequality.</param>
  2855. /// <param name="b">A FixedString512Bytes to compare for inequality.</param>
  2856. /// <returns>True if the two strings are unequal.</returns>
  2857. public static bool operator !=(in FixedString128Bytes a, in FixedString512Bytes b)
  2858. {
  2859. return !(a == b);
  2860. }
  2861. /// <summary>
  2862. /// Returns true if this string and another string are equal.
  2863. /// </summary>
  2864. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2865. /// <param name="other">A FixedString512Bytes to compare for equality.</param>
  2866. /// <returns>True if the two strings are equal.</returns>
  2867. public bool Equals(FixedString512Bytes other)
  2868. {
  2869. return this == other;
  2870. }
  2871. /// <summary>
  2872. /// Returns a new FixedString512Bytes that is a copy of another string.
  2873. /// </summary>
  2874. /// <param name="fs">A FixedString128Bytes to copy.</param>
  2875. /// <returns>A new FixedString512Bytes that is a copy of the other string.</returns>
  2876. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString512Bytes.</exception>
  2877. public static implicit operator FixedString512Bytes(in FixedString128Bytes fs) => new FixedString512Bytes(in fs);
  2878. /// <summary>
  2879. /// Returns the lexicographical sort order of this string relative to another.
  2880. /// </summary>
  2881. /// <param name="other">A string to compare with.</param>
  2882. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  2883. ///
  2884. /// 0 denotes that both strings have the same sort position.<br/>
  2885. /// -1 denotes that this string should be sorted to precede the other.<br/>
  2886. /// +1 denotes that this string should be sorted to follow the other.<br/>
  2887. /// </returns>
  2888. public int CompareTo(FixedString4096Bytes other)
  2889. {
  2890. return FixedStringMethods.CompareTo(ref this, other);
  2891. }
  2892. /// <summary>
  2893. /// Initializes and returns an instance of FixedString128Bytes that is a copy of another string.
  2894. /// </summary>
  2895. /// <param name="other">The string to copy.</param>
  2896. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString128Bytes.</exception>
  2897. public FixedString128Bytes(in FixedString4096Bytes other)
  2898. {
  2899. this = default;
  2900. var error = Initialize(other);
  2901. CheckFormatError((FormatError)error);
  2902. }
  2903. /// <summary>
  2904. /// Initializes an instance of FixedString128Bytes that is a copy of another string.
  2905. /// </summary>
  2906. /// <param name="other">The string to copy.</param>
  2907. /// <returns>zero on success, or non-zero on error.</returns>
  2908. internal int Initialize(in FixedString4096Bytes other)
  2909. {
  2910. bytes = default;
  2911. utf8LengthInBytes = 0;
  2912. unsafe {
  2913. int len = 0;
  2914. byte* dstBytes = GetUnsafePtr();
  2915. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  2916. var srcLength = other.utf8LengthInBytes;
  2917. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  2918. if(error != FormatError.None)
  2919. return (int)error;
  2920. this.Length = len;
  2921. }
  2922. return 0;
  2923. }
  2924. /// <summary>
  2925. /// Returns true if a FixedString128Bytes and another string are equal.
  2926. /// </summary>
  2927. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2928. /// <param name="a">A FixedString128Bytes to compare for equality.</param>
  2929. /// <param name="b">A FixedString4096Bytes to compare for equality.</param>
  2930. /// <returns>True if the two strings are equal.</returns>
  2931. public static bool operator ==(in FixedString128Bytes a, in FixedString4096Bytes b)
  2932. {
  2933. // this must not call any methods on 'a' or 'b'
  2934. unsafe {
  2935. int alen = a.utf8LengthInBytes;
  2936. int blen = b.utf8LengthInBytes;
  2937. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  2938. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  2939. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  2940. }
  2941. }
  2942. /// <summary>
  2943. /// Returns true if a FixedString128Bytes and another string are unequal.
  2944. /// </summary>
  2945. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2946. /// <param name="a">A FixedString128Bytes to compare for inequality.</param>
  2947. /// <param name="b">A FixedString4096Bytes to compare for inequality.</param>
  2948. /// <returns>True if the two strings are unequal.</returns>
  2949. public static bool operator !=(in FixedString128Bytes a, in FixedString4096Bytes b)
  2950. {
  2951. return !(a == b);
  2952. }
  2953. /// <summary>
  2954. /// Returns true if this string and another string are equal.
  2955. /// </summary>
  2956. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  2957. /// <param name="other">A FixedString4096Bytes to compare for equality.</param>
  2958. /// <returns>True if the two strings are equal.</returns>
  2959. public bool Equals(FixedString4096Bytes other)
  2960. {
  2961. return this == other;
  2962. }
  2963. /// <summary>
  2964. /// Returns a new FixedString4096Bytes that is a copy of another string.
  2965. /// </summary>
  2966. /// <param name="fs">A FixedString128Bytes to copy.</param>
  2967. /// <returns>A new FixedString4096Bytes that is a copy of the other string.</returns>
  2968. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString4096Bytes.</exception>
  2969. public static implicit operator FixedString4096Bytes(in FixedString128Bytes fs) => new FixedString4096Bytes(in fs);
  2970. /// <summary>
  2971. /// Returns a new FixedString128Bytes that is a copy of another string.
  2972. /// </summary>
  2973. /// <param name="b">A string to copy.</param>
  2974. /// <returns>A new FixedString128Bytes that is a copy of another string.</returns>
  2975. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString128Bytes.</exception>
  2976. [NotBurstCompatible]
  2977. public static implicit operator FixedString128Bytes(string b) => new FixedString128Bytes(b);
  2978. /// <summary>
  2979. /// Returns a new managed string that is a copy of this string.
  2980. /// </summary>
  2981. /// <returns>A new managed string that is a copy of this string.</returns>
  2982. [NotBurstCompatible]
  2983. public override String ToString()
  2984. {
  2985. return this.ConvertToString();
  2986. }
  2987. /// <summary>
  2988. /// Returns a hash code of this string.
  2989. /// </summary>
  2990. /// <remarks>Only the character bytes are included in the hash: any bytes beyond <see cref="Length"/> are not part of the hash.</remarks>
  2991. /// <returns>The hash code of this string.</returns>
  2992. public override int GetHashCode()
  2993. {
  2994. return this.ComputeHashCode();
  2995. }
  2996. /// <summary>
  2997. /// Returns true if this string and an object are equal.
  2998. /// </summary>
  2999. /// <remarks>
  3000. /// Returns false if the object is neither a System.String or a FixedString.
  3001. ///
  3002. /// Two strings are equal if they have equal length and all their characters match.</remarks>
  3003. /// <param name="obj">An object to compare for equality.</param>
  3004. /// <returns>True if this string and the object are equal.</returns>
  3005. [NotBurstCompatible]
  3006. public override bool Equals(object obj)
  3007. {
  3008. if(ReferenceEquals(null, obj)) return false;
  3009. if(obj is String aString) return Equals(aString);
  3010. if(obj is FixedString32Bytes aFixedString32Bytes) return Equals(aFixedString32Bytes);
  3011. if(obj is FixedString64Bytes aFixedString64Bytes) return Equals(aFixedString64Bytes);
  3012. if(obj is FixedString128Bytes aFixedString128Bytes) return Equals(aFixedString128Bytes);
  3013. if(obj is FixedString512Bytes aFixedString512Bytes) return Equals(aFixedString512Bytes);
  3014. if(obj is FixedString4096Bytes aFixedString4096Bytes) return Equals(aFixedString4096Bytes);
  3015. return false;
  3016. }
  3017. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  3018. void CheckIndexInRange(int index)
  3019. {
  3020. if (index < 0)
  3021. throw new IndexOutOfRangeException($"Index {index} must be positive.");
  3022. if (index >= utf8LengthInBytes)
  3023. throw new IndexOutOfRangeException($"Index {index} is out of range in FixedString128Bytes of '{utf8LengthInBytes}' Length.");
  3024. }
  3025. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  3026. void CheckLengthInRange(int length)
  3027. {
  3028. if (length < 0)
  3029. throw new ArgumentOutOfRangeException($"Length {length} must be positive.");
  3030. if (length > utf8MaxLengthInBytes)
  3031. throw new ArgumentOutOfRangeException($"Length {length} is out of range in FixedString128Bytes of '{utf8MaxLengthInBytes}' Capacity.");
  3032. }
  3033. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  3034. void CheckCapacityInRange(int capacity)
  3035. {
  3036. if (capacity > utf8MaxLengthInBytes)
  3037. throw new ArgumentOutOfRangeException($"Capacity {capacity} must be lower than {utf8MaxLengthInBytes}.");
  3038. }
  3039. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  3040. static void CheckCopyError(CopyError error, String source)
  3041. {
  3042. if (error != CopyError.None)
  3043. throw new ArgumentException($"FixedString128Bytes: {error} while copying \"{source}\"");
  3044. }
  3045. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  3046. static void CheckFormatError(FormatError error)
  3047. {
  3048. if (error != FormatError.None)
  3049. throw new ArgumentException("Source is too long to fit into fixed string of this size");
  3050. }
  3051. }
  3052. // A temporary copy of a struct is made before it is displayed in a C# debugger.
  3053. // However, only the first element of data members with names is copied at this time.
  3054. // Therefore, it's important that all data visible in the debugger, has a name
  3055. // and includes no 'fixed' array. This is why we name every byte in the following struct.
  3056. /// <summary>
  3057. /// For internal use only.
  3058. /// </summary>
  3059. [Serializable]
  3060. [StructLayout(LayoutKind.Explicit, Size=510)]
  3061. [BurstCompatible]
  3062. public struct FixedBytes510
  3063. {
  3064. /// <summary>
  3065. /// For internal use only.
  3066. /// </summary>
  3067. [FieldOffset(0)] public FixedBytes16 offset0000;
  3068. /// <summary>
  3069. /// For internal use only.
  3070. /// </summary>
  3071. [FieldOffset(16)] public FixedBytes16 offset0016;
  3072. /// <summary>
  3073. /// For internal use only.
  3074. /// </summary>
  3075. [FieldOffset(32)] public FixedBytes16 offset0032;
  3076. /// <summary>
  3077. /// For internal use only.
  3078. /// </summary>
  3079. [FieldOffset(48)] public FixedBytes16 offset0048;
  3080. /// <summary>
  3081. /// For internal use only.
  3082. /// </summary>
  3083. [FieldOffset(64)] public FixedBytes16 offset0064;
  3084. /// <summary>
  3085. /// For internal use only.
  3086. /// </summary>
  3087. [FieldOffset(80)] public FixedBytes16 offset0080;
  3088. /// <summary>
  3089. /// For internal use only.
  3090. /// </summary>
  3091. [FieldOffset(96)] public FixedBytes16 offset0096;
  3092. /// <summary>
  3093. /// For internal use only.
  3094. /// </summary>
  3095. [FieldOffset(112)] public FixedBytes16 offset0112;
  3096. /// <summary>
  3097. /// For internal use only.
  3098. /// </summary>
  3099. [FieldOffset(128)] public FixedBytes16 offset0128;
  3100. /// <summary>
  3101. /// For internal use only.
  3102. /// </summary>
  3103. [FieldOffset(144)] public FixedBytes16 offset0144;
  3104. /// <summary>
  3105. /// For internal use only.
  3106. /// </summary>
  3107. [FieldOffset(160)] public FixedBytes16 offset0160;
  3108. /// <summary>
  3109. /// For internal use only.
  3110. /// </summary>
  3111. [FieldOffset(176)] public FixedBytes16 offset0176;
  3112. /// <summary>
  3113. /// For internal use only.
  3114. /// </summary>
  3115. [FieldOffset(192)] public FixedBytes16 offset0192;
  3116. /// <summary>
  3117. /// For internal use only.
  3118. /// </summary>
  3119. [FieldOffset(208)] public FixedBytes16 offset0208;
  3120. /// <summary>
  3121. /// For internal use only.
  3122. /// </summary>
  3123. [FieldOffset(224)] public FixedBytes16 offset0224;
  3124. /// <summary>
  3125. /// For internal use only.
  3126. /// </summary>
  3127. [FieldOffset(240)] public FixedBytes16 offset0240;
  3128. /// <summary>
  3129. /// For internal use only.
  3130. /// </summary>
  3131. [FieldOffset(256)] public FixedBytes16 offset0256;
  3132. /// <summary>
  3133. /// For internal use only.
  3134. /// </summary>
  3135. [FieldOffset(272)] public FixedBytes16 offset0272;
  3136. /// <summary>
  3137. /// For internal use only.
  3138. /// </summary>
  3139. [FieldOffset(288)] public FixedBytes16 offset0288;
  3140. /// <summary>
  3141. /// For internal use only.
  3142. /// </summary>
  3143. [FieldOffset(304)] public FixedBytes16 offset0304;
  3144. /// <summary>
  3145. /// For internal use only.
  3146. /// </summary>
  3147. [FieldOffset(320)] public FixedBytes16 offset0320;
  3148. /// <summary>
  3149. /// For internal use only.
  3150. /// </summary>
  3151. [FieldOffset(336)] public FixedBytes16 offset0336;
  3152. /// <summary>
  3153. /// For internal use only.
  3154. /// </summary>
  3155. [FieldOffset(352)] public FixedBytes16 offset0352;
  3156. /// <summary>
  3157. /// For internal use only.
  3158. /// </summary>
  3159. [FieldOffset(368)] public FixedBytes16 offset0368;
  3160. /// <summary>
  3161. /// For internal use only.
  3162. /// </summary>
  3163. [FieldOffset(384)] public FixedBytes16 offset0384;
  3164. /// <summary>
  3165. /// For internal use only.
  3166. /// </summary>
  3167. [FieldOffset(400)] public FixedBytes16 offset0400;
  3168. /// <summary>
  3169. /// For internal use only.
  3170. /// </summary>
  3171. [FieldOffset(416)] public FixedBytes16 offset0416;
  3172. /// <summary>
  3173. /// For internal use only.
  3174. /// </summary>
  3175. [FieldOffset(432)] public FixedBytes16 offset0432;
  3176. /// <summary>
  3177. /// For internal use only.
  3178. /// </summary>
  3179. [FieldOffset(448)] public FixedBytes16 offset0448;
  3180. /// <summary>
  3181. /// For internal use only.
  3182. /// </summary>
  3183. [FieldOffset(464)] public FixedBytes16 offset0464;
  3184. /// <summary>
  3185. /// For internal use only.
  3186. /// </summary>
  3187. [FieldOffset(480)] public FixedBytes16 offset0480;
  3188. /// <summary>
  3189. /// For internal use only.
  3190. /// </summary>
  3191. [FieldOffset(496)] public byte byte0496;
  3192. /// <summary>
  3193. /// For internal use only.
  3194. /// </summary>
  3195. [FieldOffset(497)] public byte byte0497;
  3196. /// <summary>
  3197. /// For internal use only.
  3198. /// </summary>
  3199. [FieldOffset(498)] public byte byte0498;
  3200. /// <summary>
  3201. /// For internal use only.
  3202. /// </summary>
  3203. [FieldOffset(499)] public byte byte0499;
  3204. /// <summary>
  3205. /// For internal use only.
  3206. /// </summary>
  3207. [FieldOffset(500)] public byte byte0500;
  3208. /// <summary>
  3209. /// For internal use only.
  3210. /// </summary>
  3211. [FieldOffset(501)] public byte byte0501;
  3212. /// <summary>
  3213. /// For internal use only.
  3214. /// </summary>
  3215. [FieldOffset(502)] public byte byte0502;
  3216. /// <summary>
  3217. /// For internal use only.
  3218. /// </summary>
  3219. [FieldOffset(503)] public byte byte0503;
  3220. /// <summary>
  3221. /// For internal use only.
  3222. /// </summary>
  3223. [FieldOffset(504)] public byte byte0504;
  3224. /// <summary>
  3225. /// For internal use only.
  3226. /// </summary>
  3227. [FieldOffset(505)] public byte byte0505;
  3228. /// <summary>
  3229. /// For internal use only.
  3230. /// </summary>
  3231. [FieldOffset(506)] public byte byte0506;
  3232. /// <summary>
  3233. /// For internal use only.
  3234. /// </summary>
  3235. [FieldOffset(507)] public byte byte0507;
  3236. /// <summary>
  3237. /// For internal use only.
  3238. /// </summary>
  3239. [FieldOffset(508)] public byte byte0508;
  3240. /// <summary>
  3241. /// For internal use only.
  3242. /// </summary>
  3243. [FieldOffset(509)] public byte byte0509;
  3244. }
  3245. [Obsolete("Renamed to FixedString512Bytes (UnityUpgradable) -> FixedString512Bytes", true)]
  3246. public partial struct FixedString512 {}
  3247. /// <summary>
  3248. /// An unmanaged UTF-8 string whose content is stored directly in the 512-byte struct.
  3249. /// </summary>
  3250. /// <remarks>
  3251. /// The binary layout of this string is guaranteed, for now and all time, to be a length (a little-endian two byte integer)
  3252. /// followed by the bytes of the characters (with no padding). A zero byte always immediately follows the last character.
  3253. /// Effectively, the number of bytes for storing characters is 3 less than 512 (two length bytes and one null byte).
  3254. ///
  3255. /// This layout is identical to a <see cref="FixedList512Bytes{T}"/> of bytes, thus allowing reinterpretation between FixedString512Bytes and FixedList512Bytes.
  3256. ///
  3257. /// By virtue of being an unmanaged, non-allocated struct with no pointers, this string is fully compatible with jobs and Burst compilation.
  3258. /// Unlike managed string types, these strings can be put in any unmanaged ECS components, FixedList, or any other unmanaged structs.
  3259. /// </remarks>
  3260. [Serializable]
  3261. [StructLayout(LayoutKind.Sequential, Size=512)]
  3262. [BurstCompatible]
  3263. public partial struct FixedString512Bytes
  3264. : INativeList<byte>
  3265. , IUTF8Bytes
  3266. , IComparable<String>
  3267. , IEquatable<String>
  3268. , IComparable<FixedString32Bytes>
  3269. , IEquatable<FixedString32Bytes>
  3270. , IComparable<FixedString64Bytes>
  3271. , IEquatable<FixedString64Bytes>
  3272. , IComparable<FixedString128Bytes>
  3273. , IEquatable<FixedString128Bytes>
  3274. , IComparable<FixedString512Bytes>
  3275. , IEquatable<FixedString512Bytes>
  3276. , IComparable<FixedString4096Bytes>
  3277. , IEquatable<FixedString4096Bytes>
  3278. {
  3279. internal const ushort utf8MaxLengthInBytes = 509;
  3280. [SerializeField] internal ushort utf8LengthInBytes;
  3281. [SerializeField] internal FixedBytes510 bytes;
  3282. /// <summary>
  3283. /// Returns the maximum number of UTF-8 bytes that can be stored in this string.
  3284. /// </summary>
  3285. /// <returns>
  3286. /// The maximum number of UTF-8 bytes that can be stored in this string.
  3287. /// </returns>
  3288. public static int UTF8MaxLengthInBytes => utf8MaxLengthInBytes;
  3289. /// <summary>
  3290. /// For internal use only. Use <see cref="ToString"/> instead.
  3291. /// </summary>
  3292. /// <value>For internal use only. Use <see cref="ToString"/> instead.</value>
  3293. [CreateProperty]
  3294. [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
  3295. [NotBurstCompatible]
  3296. public string Value => ToString();
  3297. /// <summary>
  3298. /// Returns a pointer to the character bytes.
  3299. /// </summary>
  3300. /// <returns>A pointer to the character bytes.</returns>
  3301. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3302. public unsafe byte* GetUnsafePtr()
  3303. {
  3304. return (byte*) UnsafeUtility.AddressOf(ref bytes);
  3305. }
  3306. /// <summary>
  3307. /// The current length in bytes of this string's content.
  3308. /// </summary>
  3309. /// <remarks>
  3310. /// The length value does not include the null-terminator byte.
  3311. /// </remarks>
  3312. /// <param name="value">The new length in bytes of the string's content.</param>
  3313. /// <exception cref="ArgumentOutOfRangeException">Thrown if the new length is out of bounds.</exception>
  3314. /// <value>
  3315. /// The current length in bytes of this string's content.
  3316. /// </value>
  3317. public int Length
  3318. {
  3319. get
  3320. {
  3321. return utf8LengthInBytes;
  3322. }
  3323. set
  3324. {
  3325. CheckLengthInRange(value);
  3326. utf8LengthInBytes = (ushort)value;
  3327. unsafe
  3328. {
  3329. GetUnsafePtr()[utf8LengthInBytes] = 0;
  3330. }
  3331. }
  3332. }
  3333. /// <summary>
  3334. /// The number of bytes this string has for storing UTF-8 characters.
  3335. /// </summary>
  3336. /// <value>The number of bytes this string has for storing UTF-8 characters.</value>
  3337. /// <remarks>
  3338. /// Does not include the null-terminator byte.
  3339. ///
  3340. /// A setter is included for conformity with <see cref="INativeList{T}"/>, but <see cref="Capacity"/> is fixed at 509.
  3341. /// Setting the value to anything other than 509 throws an exception.
  3342. ///
  3343. /// In UTF-8 encoding, each Unicode code point (character) requires 1 to 4 bytes,
  3344. /// so the number of characters that can be stored may be less than the capacity.
  3345. /// </remarks>
  3346. /// <exception cref="ArgumentOutOfRangeException">Thrown if attempting to set the capacity to anything other than 509.</exception>
  3347. public int Capacity
  3348. {
  3349. get
  3350. {
  3351. return utf8MaxLengthInBytes;
  3352. }
  3353. set
  3354. {
  3355. CheckCapacityInRange(value);
  3356. }
  3357. }
  3358. /// <summary>
  3359. /// Attempts to set the length in bytes. Does nothing if the new length is invalid.
  3360. /// </summary>
  3361. /// <param name="newLength">The desired length.</param>
  3362. /// <param name="clearOptions">Whether added or removed bytes should be cleared (zeroed). (Increasing the length adds bytes; decreasing the length removes bytes.)</param>
  3363. /// <returns>True if the new length is valid.</returns>
  3364. public bool TryResize(int newLength, NativeArrayOptions clearOptions = NativeArrayOptions.ClearMemory)
  3365. {
  3366. if (newLength < 0 || newLength > utf8MaxLengthInBytes)
  3367. return false;
  3368. if (newLength == utf8LengthInBytes)
  3369. return true;
  3370. unsafe
  3371. {
  3372. if (clearOptions == NativeArrayOptions.ClearMemory)
  3373. {
  3374. if (newLength > utf8LengthInBytes)
  3375. UnsafeUtility.MemClear(GetUnsafePtr() + utf8LengthInBytes, newLength - utf8LengthInBytes);
  3376. else
  3377. UnsafeUtility.MemClear(GetUnsafePtr() + newLength, utf8LengthInBytes - newLength);
  3378. }
  3379. utf8LengthInBytes = (ushort)newLength;
  3380. // always null terminate
  3381. GetUnsafePtr()[utf8LengthInBytes] = 0;
  3382. }
  3383. return true;
  3384. }
  3385. /// <summary>
  3386. /// Returns true if this string is empty (has no characters).
  3387. /// </summary>
  3388. /// <value>True if this string is empty (has no characters).</value>
  3389. public bool IsEmpty => utf8LengthInBytes == 0;
  3390. /// <summary>
  3391. /// Returns the byte (not character) at an index.
  3392. /// </summary>
  3393. /// <param name="index">A byte index.</param>
  3394. /// <value>The byte at the index.</value>
  3395. /// <exception cref="IndexOutOfRangeException">Thrown if the index is out of bounds.</exception>
  3396. public byte this[int index]
  3397. {
  3398. get
  3399. {
  3400. unsafe
  3401. {
  3402. CheckIndexInRange(index);
  3403. return GetUnsafePtr()[index];
  3404. }
  3405. }
  3406. set
  3407. {
  3408. unsafe
  3409. {
  3410. CheckIndexInRange(index);
  3411. GetUnsafePtr()[index] = value;
  3412. }
  3413. }
  3414. }
  3415. /// <summary>
  3416. /// Returns the reference to a byte (not character) at an index.
  3417. /// </summary>
  3418. /// <param name="index">A byte index.</param>
  3419. /// <returns>A reference to the byte at the index.</returns>
  3420. /// <exception cref="IndexOutOfRangeException">Thrown if the index is out of bounds.</exception>
  3421. public ref byte ElementAt(int index)
  3422. {
  3423. unsafe
  3424. {
  3425. CheckIndexInRange(index);
  3426. return ref GetUnsafePtr()[index];
  3427. }
  3428. }
  3429. /// <summary>
  3430. /// Sets the length to 0.
  3431. /// </summary>
  3432. public void Clear()
  3433. {
  3434. Length = 0;
  3435. }
  3436. /// <summary>
  3437. /// Appends a byte.
  3438. /// </summary>
  3439. /// <remarks>
  3440. /// A zero byte will always follow the newly appended byte.
  3441. ///
  3442. /// No validation is performed: it is your responsibility for the bytes of the string to form valid UTF-8 when you're done appending bytes.
  3443. /// </remarks>
  3444. /// <param name="value">A byte to append.</param>
  3445. public void Add(in byte value)
  3446. {
  3447. this[Length++] = value;
  3448. }
  3449. /// <summary>
  3450. /// An enumerator over the characters (not bytes) of a FixedString512Bytes.
  3451. /// </summary>
  3452. /// <remarks>
  3453. /// In an enumerator's initial state, <see cref="Current"/> is not valid to read.
  3454. /// The first <see cref="MoveNext"/> call advances the enumerator's index to the first character.
  3455. /// </remarks>
  3456. public struct Enumerator : IEnumerator
  3457. {
  3458. FixedString512Bytes target;
  3459. int offset;
  3460. Unicode.Rune current;
  3461. /// <summary>
  3462. /// Initializes and returns an instance of FixedString512Bytes.Enumerator.
  3463. /// </summary>
  3464. /// <param name="other">A FixeString512 for which to create an enumerator.</param>
  3465. public Enumerator(FixedString512Bytes other)
  3466. {
  3467. target = other;
  3468. offset = 0;
  3469. current = default;
  3470. }
  3471. /// <summary>
  3472. /// Does nothing.
  3473. /// </summary>
  3474. public void Dispose()
  3475. {
  3476. }
  3477. /// <summary>
  3478. /// Advances the enumerator to the next character.
  3479. /// </summary>
  3480. /// <returns>True if <see cref="Current"/> is valid to read after the call.</returns>
  3481. public bool MoveNext()
  3482. {
  3483. if (offset >= target.Length)
  3484. return false;
  3485. unsafe
  3486. {
  3487. Unicode.Utf8ToUcs(out current, target.GetUnsafePtr(), ref offset, target.Length);
  3488. }
  3489. return true;
  3490. }
  3491. /// <summary>
  3492. /// Resets the enumerator to its initial state.
  3493. /// </summary>
  3494. public void Reset()
  3495. {
  3496. offset = 0;
  3497. current = default;
  3498. }
  3499. /// <summary>
  3500. /// The current character.
  3501. /// </summary>
  3502. /// <remarks>
  3503. /// In an enumerator's initial state, <see cref="Current"/> is not valid to read.
  3504. /// </remarks>
  3505. /// <value>The current character.</value>
  3506. public Unicode.Rune Current => current;
  3507. object IEnumerator.Current => Current;
  3508. }
  3509. /// <summary>
  3510. /// Returns an enumerator for iterating over the characters of this string.
  3511. /// </summary>
  3512. /// <returns>An enumerator for iterating over the characters of the FixedString512Bytes.</returns>
  3513. public Enumerator GetEnumerator()
  3514. {
  3515. return new Enumerator(this);
  3516. }
  3517. /// <summary>
  3518. /// Returns the lexicographical sort order of this string relative to another.
  3519. /// </summary>
  3520. /// <param name="other">A `System.String` to compare with.</param>
  3521. /// <returns>An integer denoting the lexicographical sort order of this string relative to the other:
  3522. ///
  3523. /// 0 denotes both strings have the same sort position.<br/>
  3524. /// -1 denotes that this string should be sorted to precede the other string.<br/>
  3525. /// +1 denotes that this string should be sorted to follow the other string.<br/>
  3526. /// </returns>
  3527. [NotBurstCompatible]
  3528. public int CompareTo(String other)
  3529. {
  3530. return ToString().CompareTo(other);
  3531. }
  3532. /// <summary>
  3533. /// Returns true if this string and another have the same length and all the same characters.
  3534. /// </summary>
  3535. /// <param name="other">A string to compare for equality.</param>
  3536. /// <returns>True if this string and the other have the same length and all the same characters.</returns>
  3537. [NotBurstCompatible]
  3538. public bool Equals(String other)
  3539. {
  3540. unsafe {
  3541. int alen = utf8LengthInBytes;
  3542. int blen = other.Length;
  3543. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(bytes);
  3544. fixed(char* bptr = other)
  3545. {
  3546. return UTF8ArrayUnsafeUtility.StrCmp(aptr, alen, bptr, blen) == 0;
  3547. }
  3548. }
  3549. }
  3550. /// <summary>
  3551. /// Returns a reference to a FixedList512Bytes<byte> representation of this string.
  3552. /// </summary>
  3553. /// <remarks>
  3554. /// The referenced FixedListByte512 is the very same bytes as the original FixedString512Bytes,
  3555. /// so it is only valid as long as the original FixedString512Bytes is valid.
  3556. /// </remarks>
  3557. /// <returns>A ref to a FixedListByte512 representation of the FixedString512Bytes.</returns>
  3558. public unsafe ref FixedList512Bytes<byte> AsFixedList()
  3559. {
  3560. return ref UnsafeUtility.AsRef<FixedList512Bytes<byte>>(UnsafeUtility.AddressOf(ref this));
  3561. }
  3562. /// <summary>
  3563. /// Initializes and returns an instance of FixedString512Bytes with the characters copied from a string.
  3564. /// </summary>
  3565. /// <param name="source">The source string to copy.</param>
  3566. [NotBurstCompatible]
  3567. public FixedString512Bytes(String source)
  3568. {
  3569. this = default;
  3570. var error = Initialize(source);
  3571. CheckCopyError((CopyError)error, source);
  3572. }
  3573. /// <summary>
  3574. /// Initializes an instance of FixedString512Bytes with the characters copied from a string.
  3575. /// </summary>
  3576. /// <param name="source">The source string to copy.</param>
  3577. /// <returns>zero on success, or non-zero on error.</returns>
  3578. [NotBurstCompatible]
  3579. internal int Initialize(String source)
  3580. {
  3581. bytes = default;
  3582. utf8LengthInBytes = 0;
  3583. unsafe
  3584. {
  3585. fixed (char* sourceptr = source)
  3586. {
  3587. var error = UTF8ArrayUnsafeUtility.Copy(GetUnsafePtr(), out utf8LengthInBytes, utf8MaxLengthInBytes, sourceptr, source.Length);
  3588. if(error != CopyError.None)
  3589. return (int)error;
  3590. this.Length = utf8LengthInBytes;
  3591. }
  3592. }
  3593. return 0;
  3594. }
  3595. /// <summary>
  3596. /// Initializes and returns an instance of FixedString512Bytes with a single character repeatedly appended some number of times.
  3597. /// </summary>
  3598. /// <param name="rune">The Unicode.Rune to repeat.</param>
  3599. /// <param name="count">The number of times to repeat the character. Default is 1.</param>
  3600. public FixedString512Bytes(Unicode.Rune rune, int count = 1)
  3601. {
  3602. this = default;
  3603. Initialize(rune, count);
  3604. }
  3605. /// <summary>
  3606. /// Initializes an instance of FixedString512Bytes with a single character repeatedly appended some number of times.
  3607. /// </summary>
  3608. /// <param name="rune">The Unicode.Rune to repeat.</param>
  3609. /// <param name="count">The number of times to repeat the character. Default is 1.</param>
  3610. /// <returns>zero on success, or non-zero on error.</returns>
  3611. internal int Initialize(Unicode.Rune rune, int count = 1)
  3612. {
  3613. this = default;
  3614. return (int)this.Append(rune, count);
  3615. }
  3616. /// <summary>
  3617. /// Returns the lexicographical sort order of this string relative to another.
  3618. /// </summary>
  3619. /// <param name="other">A string to compare with.</param>
  3620. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  3621. ///
  3622. /// 0 denotes that both strings have the same sort position.<br/>
  3623. /// -1 denotes that this string should be sorted to precede the other.<br/>
  3624. /// +1 denotes that this string should be sorted to follow the other.<br/>
  3625. /// </returns>
  3626. public int CompareTo(FixedString32Bytes other)
  3627. {
  3628. return FixedStringMethods.CompareTo(ref this, other);
  3629. }
  3630. /// <summary>
  3631. /// Initializes and returns an instance of FixedString512Bytes that is a copy of another string.
  3632. /// </summary>
  3633. /// <param name="other">The string to copy.</param>
  3634. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString512Bytes.</exception>
  3635. public FixedString512Bytes(in FixedString32Bytes other)
  3636. {
  3637. this = default;
  3638. var error = Initialize(other);
  3639. CheckFormatError((FormatError)error);
  3640. }
  3641. /// <summary>
  3642. /// Initializes an instance of FixedString512Bytes that is a copy of another string.
  3643. /// </summary>
  3644. /// <param name="other">The string to copy.</param>
  3645. /// <returns>zero on success, or non-zero on error.</returns>
  3646. internal int Initialize(in FixedString32Bytes other)
  3647. {
  3648. bytes = default;
  3649. utf8LengthInBytes = 0;
  3650. unsafe {
  3651. int len = 0;
  3652. byte* dstBytes = GetUnsafePtr();
  3653. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  3654. var srcLength = other.utf8LengthInBytes;
  3655. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  3656. if(error != FormatError.None)
  3657. return (int)error;
  3658. this.Length = len;
  3659. }
  3660. return 0;
  3661. }
  3662. /// <summary>
  3663. /// Returns true if a FixedString512Bytes and another string are equal.
  3664. /// </summary>
  3665. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3666. /// <param name="a">A FixedString512Bytes to compare for equality.</param>
  3667. /// <param name="b">A FixedString32Bytes to compare for equality.</param>
  3668. /// <returns>True if the two strings are equal.</returns>
  3669. public static bool operator ==(in FixedString512Bytes a, in FixedString32Bytes b)
  3670. {
  3671. // this must not call any methods on 'a' or 'b'
  3672. unsafe {
  3673. int alen = a.utf8LengthInBytes;
  3674. int blen = b.utf8LengthInBytes;
  3675. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  3676. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  3677. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  3678. }
  3679. }
  3680. /// <summary>
  3681. /// Returns true if a FixedString512Bytes and another string are unequal.
  3682. /// </summary>
  3683. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3684. /// <param name="a">A FixedString512Bytes to compare for inequality.</param>
  3685. /// <param name="b">A FixedString32Bytes to compare for inequality.</param>
  3686. /// <returns>True if the two strings are unequal.</returns>
  3687. public static bool operator !=(in FixedString512Bytes a, in FixedString32Bytes b)
  3688. {
  3689. return !(a == b);
  3690. }
  3691. /// <summary>
  3692. /// Returns true if this string and another string are equal.
  3693. /// </summary>
  3694. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3695. /// <param name="other">A FixedString32Bytes to compare for equality.</param>
  3696. /// <returns>True if the two strings are equal.</returns>
  3697. public bool Equals(FixedString32Bytes other)
  3698. {
  3699. return this == other;
  3700. }
  3701. /// <summary>
  3702. /// Returns the lexicographical sort order of this string relative to another.
  3703. /// </summary>
  3704. /// <param name="other">A string to compare with.</param>
  3705. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  3706. ///
  3707. /// 0 denotes that both strings have the same sort position.<br/>
  3708. /// -1 denotes that this string should be sorted to precede the other.<br/>
  3709. /// +1 denotes that this string should be sorted to follow the other.<br/>
  3710. /// </returns>
  3711. public int CompareTo(FixedString64Bytes other)
  3712. {
  3713. return FixedStringMethods.CompareTo(ref this, other);
  3714. }
  3715. /// <summary>
  3716. /// Initializes and returns an instance of FixedString512Bytes that is a copy of another string.
  3717. /// </summary>
  3718. /// <param name="other">The string to copy.</param>
  3719. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString512Bytes.</exception>
  3720. public FixedString512Bytes(in FixedString64Bytes other)
  3721. {
  3722. this = default;
  3723. var error = Initialize(other);
  3724. CheckFormatError((FormatError)error);
  3725. }
  3726. /// <summary>
  3727. /// Initializes an instance of FixedString512Bytes that is a copy of another string.
  3728. /// </summary>
  3729. /// <param name="other">The string to copy.</param>
  3730. /// <returns>zero on success, or non-zero on error.</returns>
  3731. internal int Initialize(in FixedString64Bytes other)
  3732. {
  3733. bytes = default;
  3734. utf8LengthInBytes = 0;
  3735. unsafe {
  3736. int len = 0;
  3737. byte* dstBytes = GetUnsafePtr();
  3738. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  3739. var srcLength = other.utf8LengthInBytes;
  3740. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  3741. if(error != FormatError.None)
  3742. return (int)error;
  3743. this.Length = len;
  3744. }
  3745. return 0;
  3746. }
  3747. /// <summary>
  3748. /// Returns true if a FixedString512Bytes and another string are equal.
  3749. /// </summary>
  3750. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3751. /// <param name="a">A FixedString512Bytes to compare for equality.</param>
  3752. /// <param name="b">A FixedString64Bytes to compare for equality.</param>
  3753. /// <returns>True if the two strings are equal.</returns>
  3754. public static bool operator ==(in FixedString512Bytes a, in FixedString64Bytes b)
  3755. {
  3756. // this must not call any methods on 'a' or 'b'
  3757. unsafe {
  3758. int alen = a.utf8LengthInBytes;
  3759. int blen = b.utf8LengthInBytes;
  3760. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  3761. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  3762. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  3763. }
  3764. }
  3765. /// <summary>
  3766. /// Returns true if a FixedString512Bytes and another string are unequal.
  3767. /// </summary>
  3768. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3769. /// <param name="a">A FixedString512Bytes to compare for inequality.</param>
  3770. /// <param name="b">A FixedString64Bytes to compare for inequality.</param>
  3771. /// <returns>True if the two strings are unequal.</returns>
  3772. public static bool operator !=(in FixedString512Bytes a, in FixedString64Bytes b)
  3773. {
  3774. return !(a == b);
  3775. }
  3776. /// <summary>
  3777. /// Returns true if this string and another string are equal.
  3778. /// </summary>
  3779. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3780. /// <param name="other">A FixedString64Bytes to compare for equality.</param>
  3781. /// <returns>True if the two strings are equal.</returns>
  3782. public bool Equals(FixedString64Bytes other)
  3783. {
  3784. return this == other;
  3785. }
  3786. /// <summary>
  3787. /// Returns the lexicographical sort order of this string relative to another.
  3788. /// </summary>
  3789. /// <param name="other">A string to compare with.</param>
  3790. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  3791. ///
  3792. /// 0 denotes that both strings have the same sort position.<br/>
  3793. /// -1 denotes that this string should be sorted to precede the other.<br/>
  3794. /// +1 denotes that this string should be sorted to follow the other.<br/>
  3795. /// </returns>
  3796. public int CompareTo(FixedString128Bytes other)
  3797. {
  3798. return FixedStringMethods.CompareTo(ref this, other);
  3799. }
  3800. /// <summary>
  3801. /// Initializes and returns an instance of FixedString512Bytes that is a copy of another string.
  3802. /// </summary>
  3803. /// <param name="other">The string to copy.</param>
  3804. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString512Bytes.</exception>
  3805. public FixedString512Bytes(in FixedString128Bytes other)
  3806. {
  3807. this = default;
  3808. var error = Initialize(other);
  3809. CheckFormatError((FormatError)error);
  3810. }
  3811. /// <summary>
  3812. /// Initializes an instance of FixedString512Bytes that is a copy of another string.
  3813. /// </summary>
  3814. /// <param name="other">The string to copy.</param>
  3815. /// <returns>zero on success, or non-zero on error.</returns>
  3816. internal int Initialize(in FixedString128Bytes other)
  3817. {
  3818. bytes = default;
  3819. utf8LengthInBytes = 0;
  3820. unsafe {
  3821. int len = 0;
  3822. byte* dstBytes = GetUnsafePtr();
  3823. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  3824. var srcLength = other.utf8LengthInBytes;
  3825. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  3826. if(error != FormatError.None)
  3827. return (int)error;
  3828. this.Length = len;
  3829. }
  3830. return 0;
  3831. }
  3832. /// <summary>
  3833. /// Returns true if a FixedString512Bytes and another string are equal.
  3834. /// </summary>
  3835. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3836. /// <param name="a">A FixedString512Bytes to compare for equality.</param>
  3837. /// <param name="b">A FixedString128Bytes to compare for equality.</param>
  3838. /// <returns>True if the two strings are equal.</returns>
  3839. public static bool operator ==(in FixedString512Bytes a, in FixedString128Bytes b)
  3840. {
  3841. // this must not call any methods on 'a' or 'b'
  3842. unsafe {
  3843. int alen = a.utf8LengthInBytes;
  3844. int blen = b.utf8LengthInBytes;
  3845. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  3846. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  3847. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  3848. }
  3849. }
  3850. /// <summary>
  3851. /// Returns true if a FixedString512Bytes and another string are unequal.
  3852. /// </summary>
  3853. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3854. /// <param name="a">A FixedString512Bytes to compare for inequality.</param>
  3855. /// <param name="b">A FixedString128Bytes to compare for inequality.</param>
  3856. /// <returns>True if the two strings are unequal.</returns>
  3857. public static bool operator !=(in FixedString512Bytes a, in FixedString128Bytes b)
  3858. {
  3859. return !(a == b);
  3860. }
  3861. /// <summary>
  3862. /// Returns true if this string and another string are equal.
  3863. /// </summary>
  3864. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3865. /// <param name="other">A FixedString128Bytes to compare for equality.</param>
  3866. /// <returns>True if the two strings are equal.</returns>
  3867. public bool Equals(FixedString128Bytes other)
  3868. {
  3869. return this == other;
  3870. }
  3871. /// <summary>
  3872. /// Returns the lexicographical sort order of this string relative to another.
  3873. /// </summary>
  3874. /// <param name="other">A string to compare with.</param>
  3875. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  3876. ///
  3877. /// 0 denotes that both strings have the same sort position.<br/>
  3878. /// -1 denotes that this string should be sorted to precede the other.<br/>
  3879. /// +1 denotes that this string should be sorted to follow the other.<br/>
  3880. /// </returns>
  3881. public int CompareTo(FixedString512Bytes other)
  3882. {
  3883. return FixedStringMethods.CompareTo(ref this, other);
  3884. }
  3885. /// <summary>
  3886. /// Initializes and returns an instance of FixedString512Bytes that is a copy of another string.
  3887. /// </summary>
  3888. /// <param name="other">The string to copy.</param>
  3889. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString512Bytes.</exception>
  3890. public FixedString512Bytes(in FixedString512Bytes other)
  3891. {
  3892. this = default;
  3893. var error = Initialize(other);
  3894. CheckFormatError((FormatError)error);
  3895. }
  3896. /// <summary>
  3897. /// Initializes an instance of FixedString512Bytes that is a copy of another string.
  3898. /// </summary>
  3899. /// <param name="other">The string to copy.</param>
  3900. /// <returns>zero on success, or non-zero on error.</returns>
  3901. internal int Initialize(in FixedString512Bytes other)
  3902. {
  3903. bytes = default;
  3904. utf8LengthInBytes = 0;
  3905. unsafe {
  3906. int len = 0;
  3907. byte* dstBytes = GetUnsafePtr();
  3908. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  3909. var srcLength = other.utf8LengthInBytes;
  3910. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  3911. if(error != FormatError.None)
  3912. return (int)error;
  3913. this.Length = len;
  3914. }
  3915. return 0;
  3916. }
  3917. /// <summary>
  3918. /// Returns true if a FixedString512Bytes and another string are equal.
  3919. /// </summary>
  3920. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3921. /// <param name="a">A FixedString512Bytes to compare for equality.</param>
  3922. /// <param name="b">A FixedString512Bytes to compare for equality.</param>
  3923. /// <returns>True if the two strings are equal.</returns>
  3924. public static bool operator ==(in FixedString512Bytes a, in FixedString512Bytes b)
  3925. {
  3926. // this must not call any methods on 'a' or 'b'
  3927. unsafe {
  3928. int alen = a.utf8LengthInBytes;
  3929. int blen = b.utf8LengthInBytes;
  3930. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  3931. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  3932. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  3933. }
  3934. }
  3935. /// <summary>
  3936. /// Returns true if a FixedString512Bytes and another string are unequal.
  3937. /// </summary>
  3938. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3939. /// <param name="a">A FixedString512Bytes to compare for inequality.</param>
  3940. /// <param name="b">A FixedString512Bytes to compare for inequality.</param>
  3941. /// <returns>True if the two strings are unequal.</returns>
  3942. public static bool operator !=(in FixedString512Bytes a, in FixedString512Bytes b)
  3943. {
  3944. return !(a == b);
  3945. }
  3946. /// <summary>
  3947. /// Returns true if this string and another string are equal.
  3948. /// </summary>
  3949. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  3950. /// <param name="other">A FixedString512Bytes to compare for equality.</param>
  3951. /// <returns>True if the two strings are equal.</returns>
  3952. public bool Equals(FixedString512Bytes other)
  3953. {
  3954. return this == other;
  3955. }
  3956. /// <summary>
  3957. /// Returns the lexicographical sort order of this string relative to another.
  3958. /// </summary>
  3959. /// <param name="other">A string to compare with.</param>
  3960. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  3961. ///
  3962. /// 0 denotes that both strings have the same sort position.<br/>
  3963. /// -1 denotes that this string should be sorted to precede the other.<br/>
  3964. /// +1 denotes that this string should be sorted to follow the other.<br/>
  3965. /// </returns>
  3966. public int CompareTo(FixedString4096Bytes other)
  3967. {
  3968. return FixedStringMethods.CompareTo(ref this, other);
  3969. }
  3970. /// <summary>
  3971. /// Initializes and returns an instance of FixedString512Bytes that is a copy of another string.
  3972. /// </summary>
  3973. /// <param name="other">The string to copy.</param>
  3974. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString512Bytes.</exception>
  3975. public FixedString512Bytes(in FixedString4096Bytes other)
  3976. {
  3977. this = default;
  3978. var error = Initialize(other);
  3979. CheckFormatError((FormatError)error);
  3980. }
  3981. /// <summary>
  3982. /// Initializes an instance of FixedString512Bytes that is a copy of another string.
  3983. /// </summary>
  3984. /// <param name="other">The string to copy.</param>
  3985. /// <returns>zero on success, or non-zero on error.</returns>
  3986. internal int Initialize(in FixedString4096Bytes other)
  3987. {
  3988. bytes = default;
  3989. utf8LengthInBytes = 0;
  3990. unsafe {
  3991. int len = 0;
  3992. byte* dstBytes = GetUnsafePtr();
  3993. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  3994. var srcLength = other.utf8LengthInBytes;
  3995. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  3996. if(error != FormatError.None)
  3997. return (int)error;
  3998. this.Length = len;
  3999. }
  4000. return 0;
  4001. }
  4002. /// <summary>
  4003. /// Returns true if a FixedString512Bytes and another string are equal.
  4004. /// </summary>
  4005. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  4006. /// <param name="a">A FixedString512Bytes to compare for equality.</param>
  4007. /// <param name="b">A FixedString4096Bytes to compare for equality.</param>
  4008. /// <returns>True if the two strings are equal.</returns>
  4009. public static bool operator ==(in FixedString512Bytes a, in FixedString4096Bytes b)
  4010. {
  4011. // this must not call any methods on 'a' or 'b'
  4012. unsafe {
  4013. int alen = a.utf8LengthInBytes;
  4014. int blen = b.utf8LengthInBytes;
  4015. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  4016. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  4017. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  4018. }
  4019. }
  4020. /// <summary>
  4021. /// Returns true if a FixedString512Bytes and another string are unequal.
  4022. /// </summary>
  4023. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  4024. /// <param name="a">A FixedString512Bytes to compare for inequality.</param>
  4025. /// <param name="b">A FixedString4096Bytes to compare for inequality.</param>
  4026. /// <returns>True if the two strings are unequal.</returns>
  4027. public static bool operator !=(in FixedString512Bytes a, in FixedString4096Bytes b)
  4028. {
  4029. return !(a == b);
  4030. }
  4031. /// <summary>
  4032. /// Returns true if this string and another string are equal.
  4033. /// </summary>
  4034. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  4035. /// <param name="other">A FixedString4096Bytes to compare for equality.</param>
  4036. /// <returns>True if the two strings are equal.</returns>
  4037. public bool Equals(FixedString4096Bytes other)
  4038. {
  4039. return this == other;
  4040. }
  4041. /// <summary>
  4042. /// Returns a new FixedString4096Bytes that is a copy of another string.
  4043. /// </summary>
  4044. /// <param name="fs">A FixedString512Bytes to copy.</param>
  4045. /// <returns>A new FixedString4096Bytes that is a copy of the other string.</returns>
  4046. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString4096Bytes.</exception>
  4047. public static implicit operator FixedString4096Bytes(in FixedString512Bytes fs) => new FixedString4096Bytes(in fs);
  4048. /// <summary>
  4049. /// Returns a new FixedString512Bytes that is a copy of another string.
  4050. /// </summary>
  4051. /// <param name="b">A string to copy.</param>
  4052. /// <returns>A new FixedString512Bytes that is a copy of another string.</returns>
  4053. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString512Bytes.</exception>
  4054. [NotBurstCompatible]
  4055. public static implicit operator FixedString512Bytes(string b) => new FixedString512Bytes(b);
  4056. /// <summary>
  4057. /// Returns a new managed string that is a copy of this string.
  4058. /// </summary>
  4059. /// <returns>A new managed string that is a copy of this string.</returns>
  4060. [NotBurstCompatible]
  4061. public override String ToString()
  4062. {
  4063. return this.ConvertToString();
  4064. }
  4065. /// <summary>
  4066. /// Returns a hash code of this string.
  4067. /// </summary>
  4068. /// <remarks>Only the character bytes are included in the hash: any bytes beyond <see cref="Length"/> are not part of the hash.</remarks>
  4069. /// <returns>The hash code of this string.</returns>
  4070. public override int GetHashCode()
  4071. {
  4072. return this.ComputeHashCode();
  4073. }
  4074. /// <summary>
  4075. /// Returns true if this string and an object are equal.
  4076. /// </summary>
  4077. /// <remarks>
  4078. /// Returns false if the object is neither a System.String or a FixedString.
  4079. ///
  4080. /// Two strings are equal if they have equal length and all their characters match.</remarks>
  4081. /// <param name="obj">An object to compare for equality.</param>
  4082. /// <returns>True if this string and the object are equal.</returns>
  4083. [NotBurstCompatible]
  4084. public override bool Equals(object obj)
  4085. {
  4086. if(ReferenceEquals(null, obj)) return false;
  4087. if(obj is String aString) return Equals(aString);
  4088. if(obj is FixedString32Bytes aFixedString32Bytes) return Equals(aFixedString32Bytes);
  4089. if(obj is FixedString64Bytes aFixedString64Bytes) return Equals(aFixedString64Bytes);
  4090. if(obj is FixedString128Bytes aFixedString128Bytes) return Equals(aFixedString128Bytes);
  4091. if(obj is FixedString512Bytes aFixedString512Bytes) return Equals(aFixedString512Bytes);
  4092. if(obj is FixedString4096Bytes aFixedString4096Bytes) return Equals(aFixedString4096Bytes);
  4093. return false;
  4094. }
  4095. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  4096. void CheckIndexInRange(int index)
  4097. {
  4098. if (index < 0)
  4099. throw new IndexOutOfRangeException($"Index {index} must be positive.");
  4100. if (index >= utf8LengthInBytes)
  4101. throw new IndexOutOfRangeException($"Index {index} is out of range in FixedString512Bytes of '{utf8LengthInBytes}' Length.");
  4102. }
  4103. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  4104. void CheckLengthInRange(int length)
  4105. {
  4106. if (length < 0)
  4107. throw new ArgumentOutOfRangeException($"Length {length} must be positive.");
  4108. if (length > utf8MaxLengthInBytes)
  4109. throw new ArgumentOutOfRangeException($"Length {length} is out of range in FixedString512Bytes of '{utf8MaxLengthInBytes}' Capacity.");
  4110. }
  4111. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  4112. void CheckCapacityInRange(int capacity)
  4113. {
  4114. if (capacity > utf8MaxLengthInBytes)
  4115. throw new ArgumentOutOfRangeException($"Capacity {capacity} must be lower than {utf8MaxLengthInBytes}.");
  4116. }
  4117. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  4118. static void CheckCopyError(CopyError error, String source)
  4119. {
  4120. if (error != CopyError.None)
  4121. throw new ArgumentException($"FixedString512Bytes: {error} while copying \"{source}\"");
  4122. }
  4123. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  4124. static void CheckFormatError(FormatError error)
  4125. {
  4126. if (error != FormatError.None)
  4127. throw new ArgumentException("Source is too long to fit into fixed string of this size");
  4128. }
  4129. }
  4130. // A temporary copy of a struct is made before it is displayed in a C# debugger.
  4131. // However, only the first element of data members with names is copied at this time.
  4132. // Therefore, it's important that all data visible in the debugger, has a name
  4133. // and includes no 'fixed' array. This is why we name every byte in the following struct.
  4134. /// <summary>
  4135. /// For internal use only.
  4136. /// </summary>
  4137. [Serializable]
  4138. [StructLayout(LayoutKind.Explicit, Size=4094)]
  4139. [BurstCompatible]
  4140. public struct FixedBytes4094
  4141. {
  4142. /// <summary>
  4143. /// For internal use only.
  4144. /// </summary>
  4145. [FieldOffset(0)] public FixedBytes16 offset0000;
  4146. /// <summary>
  4147. /// For internal use only.
  4148. /// </summary>
  4149. [FieldOffset(16)] public FixedBytes16 offset0016;
  4150. /// <summary>
  4151. /// For internal use only.
  4152. /// </summary>
  4153. [FieldOffset(32)] public FixedBytes16 offset0032;
  4154. /// <summary>
  4155. /// For internal use only.
  4156. /// </summary>
  4157. [FieldOffset(48)] public FixedBytes16 offset0048;
  4158. /// <summary>
  4159. /// For internal use only.
  4160. /// </summary>
  4161. [FieldOffset(64)] public FixedBytes16 offset0064;
  4162. /// <summary>
  4163. /// For internal use only.
  4164. /// </summary>
  4165. [FieldOffset(80)] public FixedBytes16 offset0080;
  4166. /// <summary>
  4167. /// For internal use only.
  4168. /// </summary>
  4169. [FieldOffset(96)] public FixedBytes16 offset0096;
  4170. /// <summary>
  4171. /// For internal use only.
  4172. /// </summary>
  4173. [FieldOffset(112)] public FixedBytes16 offset0112;
  4174. /// <summary>
  4175. /// For internal use only.
  4176. /// </summary>
  4177. [FieldOffset(128)] public FixedBytes16 offset0128;
  4178. /// <summary>
  4179. /// For internal use only.
  4180. /// </summary>
  4181. [FieldOffset(144)] public FixedBytes16 offset0144;
  4182. /// <summary>
  4183. /// For internal use only.
  4184. /// </summary>
  4185. [FieldOffset(160)] public FixedBytes16 offset0160;
  4186. /// <summary>
  4187. /// For internal use only.
  4188. /// </summary>
  4189. [FieldOffset(176)] public FixedBytes16 offset0176;
  4190. /// <summary>
  4191. /// For internal use only.
  4192. /// </summary>
  4193. [FieldOffset(192)] public FixedBytes16 offset0192;
  4194. /// <summary>
  4195. /// For internal use only.
  4196. /// </summary>
  4197. [FieldOffset(208)] public FixedBytes16 offset0208;
  4198. /// <summary>
  4199. /// For internal use only.
  4200. /// </summary>
  4201. [FieldOffset(224)] public FixedBytes16 offset0224;
  4202. /// <summary>
  4203. /// For internal use only.
  4204. /// </summary>
  4205. [FieldOffset(240)] public FixedBytes16 offset0240;
  4206. /// <summary>
  4207. /// For internal use only.
  4208. /// </summary>
  4209. [FieldOffset(256)] public FixedBytes16 offset0256;
  4210. /// <summary>
  4211. /// For internal use only.
  4212. /// </summary>
  4213. [FieldOffset(272)] public FixedBytes16 offset0272;
  4214. /// <summary>
  4215. /// For internal use only.
  4216. /// </summary>
  4217. [FieldOffset(288)] public FixedBytes16 offset0288;
  4218. /// <summary>
  4219. /// For internal use only.
  4220. /// </summary>
  4221. [FieldOffset(304)] public FixedBytes16 offset0304;
  4222. /// <summary>
  4223. /// For internal use only.
  4224. /// </summary>
  4225. [FieldOffset(320)] public FixedBytes16 offset0320;
  4226. /// <summary>
  4227. /// For internal use only.
  4228. /// </summary>
  4229. [FieldOffset(336)] public FixedBytes16 offset0336;
  4230. /// <summary>
  4231. /// For internal use only.
  4232. /// </summary>
  4233. [FieldOffset(352)] public FixedBytes16 offset0352;
  4234. /// <summary>
  4235. /// For internal use only.
  4236. /// </summary>
  4237. [FieldOffset(368)] public FixedBytes16 offset0368;
  4238. /// <summary>
  4239. /// For internal use only.
  4240. /// </summary>
  4241. [FieldOffset(384)] public FixedBytes16 offset0384;
  4242. /// <summary>
  4243. /// For internal use only.
  4244. /// </summary>
  4245. [FieldOffset(400)] public FixedBytes16 offset0400;
  4246. /// <summary>
  4247. /// For internal use only.
  4248. /// </summary>
  4249. [FieldOffset(416)] public FixedBytes16 offset0416;
  4250. /// <summary>
  4251. /// For internal use only.
  4252. /// </summary>
  4253. [FieldOffset(432)] public FixedBytes16 offset0432;
  4254. /// <summary>
  4255. /// For internal use only.
  4256. /// </summary>
  4257. [FieldOffset(448)] public FixedBytes16 offset0448;
  4258. /// <summary>
  4259. /// For internal use only.
  4260. /// </summary>
  4261. [FieldOffset(464)] public FixedBytes16 offset0464;
  4262. /// <summary>
  4263. /// For internal use only.
  4264. /// </summary>
  4265. [FieldOffset(480)] public FixedBytes16 offset0480;
  4266. /// <summary>
  4267. /// For internal use only.
  4268. /// </summary>
  4269. [FieldOffset(496)] public FixedBytes16 offset0496;
  4270. /// <summary>
  4271. /// For internal use only.
  4272. /// </summary>
  4273. [FieldOffset(512)] public FixedBytes16 offset0512;
  4274. /// <summary>
  4275. /// For internal use only.
  4276. /// </summary>
  4277. [FieldOffset(528)] public FixedBytes16 offset0528;
  4278. /// <summary>
  4279. /// For internal use only.
  4280. /// </summary>
  4281. [FieldOffset(544)] public FixedBytes16 offset0544;
  4282. /// <summary>
  4283. /// For internal use only.
  4284. /// </summary>
  4285. [FieldOffset(560)] public FixedBytes16 offset0560;
  4286. /// <summary>
  4287. /// For internal use only.
  4288. /// </summary>
  4289. [FieldOffset(576)] public FixedBytes16 offset0576;
  4290. /// <summary>
  4291. /// For internal use only.
  4292. /// </summary>
  4293. [FieldOffset(592)] public FixedBytes16 offset0592;
  4294. /// <summary>
  4295. /// For internal use only.
  4296. /// </summary>
  4297. [FieldOffset(608)] public FixedBytes16 offset0608;
  4298. /// <summary>
  4299. /// For internal use only.
  4300. /// </summary>
  4301. [FieldOffset(624)] public FixedBytes16 offset0624;
  4302. /// <summary>
  4303. /// For internal use only.
  4304. /// </summary>
  4305. [FieldOffset(640)] public FixedBytes16 offset0640;
  4306. /// <summary>
  4307. /// For internal use only.
  4308. /// </summary>
  4309. [FieldOffset(656)] public FixedBytes16 offset0656;
  4310. /// <summary>
  4311. /// For internal use only.
  4312. /// </summary>
  4313. [FieldOffset(672)] public FixedBytes16 offset0672;
  4314. /// <summary>
  4315. /// For internal use only.
  4316. /// </summary>
  4317. [FieldOffset(688)] public FixedBytes16 offset0688;
  4318. /// <summary>
  4319. /// For internal use only.
  4320. /// </summary>
  4321. [FieldOffset(704)] public FixedBytes16 offset0704;
  4322. /// <summary>
  4323. /// For internal use only.
  4324. /// </summary>
  4325. [FieldOffset(720)] public FixedBytes16 offset0720;
  4326. /// <summary>
  4327. /// For internal use only.
  4328. /// </summary>
  4329. [FieldOffset(736)] public FixedBytes16 offset0736;
  4330. /// <summary>
  4331. /// For internal use only.
  4332. /// </summary>
  4333. [FieldOffset(752)] public FixedBytes16 offset0752;
  4334. /// <summary>
  4335. /// For internal use only.
  4336. /// </summary>
  4337. [FieldOffset(768)] public FixedBytes16 offset0768;
  4338. /// <summary>
  4339. /// For internal use only.
  4340. /// </summary>
  4341. [FieldOffset(784)] public FixedBytes16 offset0784;
  4342. /// <summary>
  4343. /// For internal use only.
  4344. /// </summary>
  4345. [FieldOffset(800)] public FixedBytes16 offset0800;
  4346. /// <summary>
  4347. /// For internal use only.
  4348. /// </summary>
  4349. [FieldOffset(816)] public FixedBytes16 offset0816;
  4350. /// <summary>
  4351. /// For internal use only.
  4352. /// </summary>
  4353. [FieldOffset(832)] public FixedBytes16 offset0832;
  4354. /// <summary>
  4355. /// For internal use only.
  4356. /// </summary>
  4357. [FieldOffset(848)] public FixedBytes16 offset0848;
  4358. /// <summary>
  4359. /// For internal use only.
  4360. /// </summary>
  4361. [FieldOffset(864)] public FixedBytes16 offset0864;
  4362. /// <summary>
  4363. /// For internal use only.
  4364. /// </summary>
  4365. [FieldOffset(880)] public FixedBytes16 offset0880;
  4366. /// <summary>
  4367. /// For internal use only.
  4368. /// </summary>
  4369. [FieldOffset(896)] public FixedBytes16 offset0896;
  4370. /// <summary>
  4371. /// For internal use only.
  4372. /// </summary>
  4373. [FieldOffset(912)] public FixedBytes16 offset0912;
  4374. /// <summary>
  4375. /// For internal use only.
  4376. /// </summary>
  4377. [FieldOffset(928)] public FixedBytes16 offset0928;
  4378. /// <summary>
  4379. /// For internal use only.
  4380. /// </summary>
  4381. [FieldOffset(944)] public FixedBytes16 offset0944;
  4382. /// <summary>
  4383. /// For internal use only.
  4384. /// </summary>
  4385. [FieldOffset(960)] public FixedBytes16 offset0960;
  4386. /// <summary>
  4387. /// For internal use only.
  4388. /// </summary>
  4389. [FieldOffset(976)] public FixedBytes16 offset0976;
  4390. /// <summary>
  4391. /// For internal use only.
  4392. /// </summary>
  4393. [FieldOffset(992)] public FixedBytes16 offset0992;
  4394. /// <summary>
  4395. /// For internal use only.
  4396. /// </summary>
  4397. [FieldOffset(1008)] public FixedBytes16 offset1008;
  4398. /// <summary>
  4399. /// For internal use only.
  4400. /// </summary>
  4401. [FieldOffset(1024)] public FixedBytes16 offset1024;
  4402. /// <summary>
  4403. /// For internal use only.
  4404. /// </summary>
  4405. [FieldOffset(1040)] public FixedBytes16 offset1040;
  4406. /// <summary>
  4407. /// For internal use only.
  4408. /// </summary>
  4409. [FieldOffset(1056)] public FixedBytes16 offset1056;
  4410. /// <summary>
  4411. /// For internal use only.
  4412. /// </summary>
  4413. [FieldOffset(1072)] public FixedBytes16 offset1072;
  4414. /// <summary>
  4415. /// For internal use only.
  4416. /// </summary>
  4417. [FieldOffset(1088)] public FixedBytes16 offset1088;
  4418. /// <summary>
  4419. /// For internal use only.
  4420. /// </summary>
  4421. [FieldOffset(1104)] public FixedBytes16 offset1104;
  4422. /// <summary>
  4423. /// For internal use only.
  4424. /// </summary>
  4425. [FieldOffset(1120)] public FixedBytes16 offset1120;
  4426. /// <summary>
  4427. /// For internal use only.
  4428. /// </summary>
  4429. [FieldOffset(1136)] public FixedBytes16 offset1136;
  4430. /// <summary>
  4431. /// For internal use only.
  4432. /// </summary>
  4433. [FieldOffset(1152)] public FixedBytes16 offset1152;
  4434. /// <summary>
  4435. /// For internal use only.
  4436. /// </summary>
  4437. [FieldOffset(1168)] public FixedBytes16 offset1168;
  4438. /// <summary>
  4439. /// For internal use only.
  4440. /// </summary>
  4441. [FieldOffset(1184)] public FixedBytes16 offset1184;
  4442. /// <summary>
  4443. /// For internal use only.
  4444. /// </summary>
  4445. [FieldOffset(1200)] public FixedBytes16 offset1200;
  4446. /// <summary>
  4447. /// For internal use only.
  4448. /// </summary>
  4449. [FieldOffset(1216)] public FixedBytes16 offset1216;
  4450. /// <summary>
  4451. /// For internal use only.
  4452. /// </summary>
  4453. [FieldOffset(1232)] public FixedBytes16 offset1232;
  4454. /// <summary>
  4455. /// For internal use only.
  4456. /// </summary>
  4457. [FieldOffset(1248)] public FixedBytes16 offset1248;
  4458. /// <summary>
  4459. /// For internal use only.
  4460. /// </summary>
  4461. [FieldOffset(1264)] public FixedBytes16 offset1264;
  4462. /// <summary>
  4463. /// For internal use only.
  4464. /// </summary>
  4465. [FieldOffset(1280)] public FixedBytes16 offset1280;
  4466. /// <summary>
  4467. /// For internal use only.
  4468. /// </summary>
  4469. [FieldOffset(1296)] public FixedBytes16 offset1296;
  4470. /// <summary>
  4471. /// For internal use only.
  4472. /// </summary>
  4473. [FieldOffset(1312)] public FixedBytes16 offset1312;
  4474. /// <summary>
  4475. /// For internal use only.
  4476. /// </summary>
  4477. [FieldOffset(1328)] public FixedBytes16 offset1328;
  4478. /// <summary>
  4479. /// For internal use only.
  4480. /// </summary>
  4481. [FieldOffset(1344)] public FixedBytes16 offset1344;
  4482. /// <summary>
  4483. /// For internal use only.
  4484. /// </summary>
  4485. [FieldOffset(1360)] public FixedBytes16 offset1360;
  4486. /// <summary>
  4487. /// For internal use only.
  4488. /// </summary>
  4489. [FieldOffset(1376)] public FixedBytes16 offset1376;
  4490. /// <summary>
  4491. /// For internal use only.
  4492. /// </summary>
  4493. [FieldOffset(1392)] public FixedBytes16 offset1392;
  4494. /// <summary>
  4495. /// For internal use only.
  4496. /// </summary>
  4497. [FieldOffset(1408)] public FixedBytes16 offset1408;
  4498. /// <summary>
  4499. /// For internal use only.
  4500. /// </summary>
  4501. [FieldOffset(1424)] public FixedBytes16 offset1424;
  4502. /// <summary>
  4503. /// For internal use only.
  4504. /// </summary>
  4505. [FieldOffset(1440)] public FixedBytes16 offset1440;
  4506. /// <summary>
  4507. /// For internal use only.
  4508. /// </summary>
  4509. [FieldOffset(1456)] public FixedBytes16 offset1456;
  4510. /// <summary>
  4511. /// For internal use only.
  4512. /// </summary>
  4513. [FieldOffset(1472)] public FixedBytes16 offset1472;
  4514. /// <summary>
  4515. /// For internal use only.
  4516. /// </summary>
  4517. [FieldOffset(1488)] public FixedBytes16 offset1488;
  4518. /// <summary>
  4519. /// For internal use only.
  4520. /// </summary>
  4521. [FieldOffset(1504)] public FixedBytes16 offset1504;
  4522. /// <summary>
  4523. /// For internal use only.
  4524. /// </summary>
  4525. [FieldOffset(1520)] public FixedBytes16 offset1520;
  4526. /// <summary>
  4527. /// For internal use only.
  4528. /// </summary>
  4529. [FieldOffset(1536)] public FixedBytes16 offset1536;
  4530. /// <summary>
  4531. /// For internal use only.
  4532. /// </summary>
  4533. [FieldOffset(1552)] public FixedBytes16 offset1552;
  4534. /// <summary>
  4535. /// For internal use only.
  4536. /// </summary>
  4537. [FieldOffset(1568)] public FixedBytes16 offset1568;
  4538. /// <summary>
  4539. /// For internal use only.
  4540. /// </summary>
  4541. [FieldOffset(1584)] public FixedBytes16 offset1584;
  4542. /// <summary>
  4543. /// For internal use only.
  4544. /// </summary>
  4545. [FieldOffset(1600)] public FixedBytes16 offset1600;
  4546. /// <summary>
  4547. /// For internal use only.
  4548. /// </summary>
  4549. [FieldOffset(1616)] public FixedBytes16 offset1616;
  4550. /// <summary>
  4551. /// For internal use only.
  4552. /// </summary>
  4553. [FieldOffset(1632)] public FixedBytes16 offset1632;
  4554. /// <summary>
  4555. /// For internal use only.
  4556. /// </summary>
  4557. [FieldOffset(1648)] public FixedBytes16 offset1648;
  4558. /// <summary>
  4559. /// For internal use only.
  4560. /// </summary>
  4561. [FieldOffset(1664)] public FixedBytes16 offset1664;
  4562. /// <summary>
  4563. /// For internal use only.
  4564. /// </summary>
  4565. [FieldOffset(1680)] public FixedBytes16 offset1680;
  4566. /// <summary>
  4567. /// For internal use only.
  4568. /// </summary>
  4569. [FieldOffset(1696)] public FixedBytes16 offset1696;
  4570. /// <summary>
  4571. /// For internal use only.
  4572. /// </summary>
  4573. [FieldOffset(1712)] public FixedBytes16 offset1712;
  4574. /// <summary>
  4575. /// For internal use only.
  4576. /// </summary>
  4577. [FieldOffset(1728)] public FixedBytes16 offset1728;
  4578. /// <summary>
  4579. /// For internal use only.
  4580. /// </summary>
  4581. [FieldOffset(1744)] public FixedBytes16 offset1744;
  4582. /// <summary>
  4583. /// For internal use only.
  4584. /// </summary>
  4585. [FieldOffset(1760)] public FixedBytes16 offset1760;
  4586. /// <summary>
  4587. /// For internal use only.
  4588. /// </summary>
  4589. [FieldOffset(1776)] public FixedBytes16 offset1776;
  4590. /// <summary>
  4591. /// For internal use only.
  4592. /// </summary>
  4593. [FieldOffset(1792)] public FixedBytes16 offset1792;
  4594. /// <summary>
  4595. /// For internal use only.
  4596. /// </summary>
  4597. [FieldOffset(1808)] public FixedBytes16 offset1808;
  4598. /// <summary>
  4599. /// For internal use only.
  4600. /// </summary>
  4601. [FieldOffset(1824)] public FixedBytes16 offset1824;
  4602. /// <summary>
  4603. /// For internal use only.
  4604. /// </summary>
  4605. [FieldOffset(1840)] public FixedBytes16 offset1840;
  4606. /// <summary>
  4607. /// For internal use only.
  4608. /// </summary>
  4609. [FieldOffset(1856)] public FixedBytes16 offset1856;
  4610. /// <summary>
  4611. /// For internal use only.
  4612. /// </summary>
  4613. [FieldOffset(1872)] public FixedBytes16 offset1872;
  4614. /// <summary>
  4615. /// For internal use only.
  4616. /// </summary>
  4617. [FieldOffset(1888)] public FixedBytes16 offset1888;
  4618. /// <summary>
  4619. /// For internal use only.
  4620. /// </summary>
  4621. [FieldOffset(1904)] public FixedBytes16 offset1904;
  4622. /// <summary>
  4623. /// For internal use only.
  4624. /// </summary>
  4625. [FieldOffset(1920)] public FixedBytes16 offset1920;
  4626. /// <summary>
  4627. /// For internal use only.
  4628. /// </summary>
  4629. [FieldOffset(1936)] public FixedBytes16 offset1936;
  4630. /// <summary>
  4631. /// For internal use only.
  4632. /// </summary>
  4633. [FieldOffset(1952)] public FixedBytes16 offset1952;
  4634. /// <summary>
  4635. /// For internal use only.
  4636. /// </summary>
  4637. [FieldOffset(1968)] public FixedBytes16 offset1968;
  4638. /// <summary>
  4639. /// For internal use only.
  4640. /// </summary>
  4641. [FieldOffset(1984)] public FixedBytes16 offset1984;
  4642. /// <summary>
  4643. /// For internal use only.
  4644. /// </summary>
  4645. [FieldOffset(2000)] public FixedBytes16 offset2000;
  4646. /// <summary>
  4647. /// For internal use only.
  4648. /// </summary>
  4649. [FieldOffset(2016)] public FixedBytes16 offset2016;
  4650. /// <summary>
  4651. /// For internal use only.
  4652. /// </summary>
  4653. [FieldOffset(2032)] public FixedBytes16 offset2032;
  4654. /// <summary>
  4655. /// For internal use only.
  4656. /// </summary>
  4657. [FieldOffset(2048)] public FixedBytes16 offset2048;
  4658. /// <summary>
  4659. /// For internal use only.
  4660. /// </summary>
  4661. [FieldOffset(2064)] public FixedBytes16 offset2064;
  4662. /// <summary>
  4663. /// For internal use only.
  4664. /// </summary>
  4665. [FieldOffset(2080)] public FixedBytes16 offset2080;
  4666. /// <summary>
  4667. /// For internal use only.
  4668. /// </summary>
  4669. [FieldOffset(2096)] public FixedBytes16 offset2096;
  4670. /// <summary>
  4671. /// For internal use only.
  4672. /// </summary>
  4673. [FieldOffset(2112)] public FixedBytes16 offset2112;
  4674. /// <summary>
  4675. /// For internal use only.
  4676. /// </summary>
  4677. [FieldOffset(2128)] public FixedBytes16 offset2128;
  4678. /// <summary>
  4679. /// For internal use only.
  4680. /// </summary>
  4681. [FieldOffset(2144)] public FixedBytes16 offset2144;
  4682. /// <summary>
  4683. /// For internal use only.
  4684. /// </summary>
  4685. [FieldOffset(2160)] public FixedBytes16 offset2160;
  4686. /// <summary>
  4687. /// For internal use only.
  4688. /// </summary>
  4689. [FieldOffset(2176)] public FixedBytes16 offset2176;
  4690. /// <summary>
  4691. /// For internal use only.
  4692. /// </summary>
  4693. [FieldOffset(2192)] public FixedBytes16 offset2192;
  4694. /// <summary>
  4695. /// For internal use only.
  4696. /// </summary>
  4697. [FieldOffset(2208)] public FixedBytes16 offset2208;
  4698. /// <summary>
  4699. /// For internal use only.
  4700. /// </summary>
  4701. [FieldOffset(2224)] public FixedBytes16 offset2224;
  4702. /// <summary>
  4703. /// For internal use only.
  4704. /// </summary>
  4705. [FieldOffset(2240)] public FixedBytes16 offset2240;
  4706. /// <summary>
  4707. /// For internal use only.
  4708. /// </summary>
  4709. [FieldOffset(2256)] public FixedBytes16 offset2256;
  4710. /// <summary>
  4711. /// For internal use only.
  4712. /// </summary>
  4713. [FieldOffset(2272)] public FixedBytes16 offset2272;
  4714. /// <summary>
  4715. /// For internal use only.
  4716. /// </summary>
  4717. [FieldOffset(2288)] public FixedBytes16 offset2288;
  4718. /// <summary>
  4719. /// For internal use only.
  4720. /// </summary>
  4721. [FieldOffset(2304)] public FixedBytes16 offset2304;
  4722. /// <summary>
  4723. /// For internal use only.
  4724. /// </summary>
  4725. [FieldOffset(2320)] public FixedBytes16 offset2320;
  4726. /// <summary>
  4727. /// For internal use only.
  4728. /// </summary>
  4729. [FieldOffset(2336)] public FixedBytes16 offset2336;
  4730. /// <summary>
  4731. /// For internal use only.
  4732. /// </summary>
  4733. [FieldOffset(2352)] public FixedBytes16 offset2352;
  4734. /// <summary>
  4735. /// For internal use only.
  4736. /// </summary>
  4737. [FieldOffset(2368)] public FixedBytes16 offset2368;
  4738. /// <summary>
  4739. /// For internal use only.
  4740. /// </summary>
  4741. [FieldOffset(2384)] public FixedBytes16 offset2384;
  4742. /// <summary>
  4743. /// For internal use only.
  4744. /// </summary>
  4745. [FieldOffset(2400)] public FixedBytes16 offset2400;
  4746. /// <summary>
  4747. /// For internal use only.
  4748. /// </summary>
  4749. [FieldOffset(2416)] public FixedBytes16 offset2416;
  4750. /// <summary>
  4751. /// For internal use only.
  4752. /// </summary>
  4753. [FieldOffset(2432)] public FixedBytes16 offset2432;
  4754. /// <summary>
  4755. /// For internal use only.
  4756. /// </summary>
  4757. [FieldOffset(2448)] public FixedBytes16 offset2448;
  4758. /// <summary>
  4759. /// For internal use only.
  4760. /// </summary>
  4761. [FieldOffset(2464)] public FixedBytes16 offset2464;
  4762. /// <summary>
  4763. /// For internal use only.
  4764. /// </summary>
  4765. [FieldOffset(2480)] public FixedBytes16 offset2480;
  4766. /// <summary>
  4767. /// For internal use only.
  4768. /// </summary>
  4769. [FieldOffset(2496)] public FixedBytes16 offset2496;
  4770. /// <summary>
  4771. /// For internal use only.
  4772. /// </summary>
  4773. [FieldOffset(2512)] public FixedBytes16 offset2512;
  4774. /// <summary>
  4775. /// For internal use only.
  4776. /// </summary>
  4777. [FieldOffset(2528)] public FixedBytes16 offset2528;
  4778. /// <summary>
  4779. /// For internal use only.
  4780. /// </summary>
  4781. [FieldOffset(2544)] public FixedBytes16 offset2544;
  4782. /// <summary>
  4783. /// For internal use only.
  4784. /// </summary>
  4785. [FieldOffset(2560)] public FixedBytes16 offset2560;
  4786. /// <summary>
  4787. /// For internal use only.
  4788. /// </summary>
  4789. [FieldOffset(2576)] public FixedBytes16 offset2576;
  4790. /// <summary>
  4791. /// For internal use only.
  4792. /// </summary>
  4793. [FieldOffset(2592)] public FixedBytes16 offset2592;
  4794. /// <summary>
  4795. /// For internal use only.
  4796. /// </summary>
  4797. [FieldOffset(2608)] public FixedBytes16 offset2608;
  4798. /// <summary>
  4799. /// For internal use only.
  4800. /// </summary>
  4801. [FieldOffset(2624)] public FixedBytes16 offset2624;
  4802. /// <summary>
  4803. /// For internal use only.
  4804. /// </summary>
  4805. [FieldOffset(2640)] public FixedBytes16 offset2640;
  4806. /// <summary>
  4807. /// For internal use only.
  4808. /// </summary>
  4809. [FieldOffset(2656)] public FixedBytes16 offset2656;
  4810. /// <summary>
  4811. /// For internal use only.
  4812. /// </summary>
  4813. [FieldOffset(2672)] public FixedBytes16 offset2672;
  4814. /// <summary>
  4815. /// For internal use only.
  4816. /// </summary>
  4817. [FieldOffset(2688)] public FixedBytes16 offset2688;
  4818. /// <summary>
  4819. /// For internal use only.
  4820. /// </summary>
  4821. [FieldOffset(2704)] public FixedBytes16 offset2704;
  4822. /// <summary>
  4823. /// For internal use only.
  4824. /// </summary>
  4825. [FieldOffset(2720)] public FixedBytes16 offset2720;
  4826. /// <summary>
  4827. /// For internal use only.
  4828. /// </summary>
  4829. [FieldOffset(2736)] public FixedBytes16 offset2736;
  4830. /// <summary>
  4831. /// For internal use only.
  4832. /// </summary>
  4833. [FieldOffset(2752)] public FixedBytes16 offset2752;
  4834. /// <summary>
  4835. /// For internal use only.
  4836. /// </summary>
  4837. [FieldOffset(2768)] public FixedBytes16 offset2768;
  4838. /// <summary>
  4839. /// For internal use only.
  4840. /// </summary>
  4841. [FieldOffset(2784)] public FixedBytes16 offset2784;
  4842. /// <summary>
  4843. /// For internal use only.
  4844. /// </summary>
  4845. [FieldOffset(2800)] public FixedBytes16 offset2800;
  4846. /// <summary>
  4847. /// For internal use only.
  4848. /// </summary>
  4849. [FieldOffset(2816)] public FixedBytes16 offset2816;
  4850. /// <summary>
  4851. /// For internal use only.
  4852. /// </summary>
  4853. [FieldOffset(2832)] public FixedBytes16 offset2832;
  4854. /// <summary>
  4855. /// For internal use only.
  4856. /// </summary>
  4857. [FieldOffset(2848)] public FixedBytes16 offset2848;
  4858. /// <summary>
  4859. /// For internal use only.
  4860. /// </summary>
  4861. [FieldOffset(2864)] public FixedBytes16 offset2864;
  4862. /// <summary>
  4863. /// For internal use only.
  4864. /// </summary>
  4865. [FieldOffset(2880)] public FixedBytes16 offset2880;
  4866. /// <summary>
  4867. /// For internal use only.
  4868. /// </summary>
  4869. [FieldOffset(2896)] public FixedBytes16 offset2896;
  4870. /// <summary>
  4871. /// For internal use only.
  4872. /// </summary>
  4873. [FieldOffset(2912)] public FixedBytes16 offset2912;
  4874. /// <summary>
  4875. /// For internal use only.
  4876. /// </summary>
  4877. [FieldOffset(2928)] public FixedBytes16 offset2928;
  4878. /// <summary>
  4879. /// For internal use only.
  4880. /// </summary>
  4881. [FieldOffset(2944)] public FixedBytes16 offset2944;
  4882. /// <summary>
  4883. /// For internal use only.
  4884. /// </summary>
  4885. [FieldOffset(2960)] public FixedBytes16 offset2960;
  4886. /// <summary>
  4887. /// For internal use only.
  4888. /// </summary>
  4889. [FieldOffset(2976)] public FixedBytes16 offset2976;
  4890. /// <summary>
  4891. /// For internal use only.
  4892. /// </summary>
  4893. [FieldOffset(2992)] public FixedBytes16 offset2992;
  4894. /// <summary>
  4895. /// For internal use only.
  4896. /// </summary>
  4897. [FieldOffset(3008)] public FixedBytes16 offset3008;
  4898. /// <summary>
  4899. /// For internal use only.
  4900. /// </summary>
  4901. [FieldOffset(3024)] public FixedBytes16 offset3024;
  4902. /// <summary>
  4903. /// For internal use only.
  4904. /// </summary>
  4905. [FieldOffset(3040)] public FixedBytes16 offset3040;
  4906. /// <summary>
  4907. /// For internal use only.
  4908. /// </summary>
  4909. [FieldOffset(3056)] public FixedBytes16 offset3056;
  4910. /// <summary>
  4911. /// For internal use only.
  4912. /// </summary>
  4913. [FieldOffset(3072)] public FixedBytes16 offset3072;
  4914. /// <summary>
  4915. /// For internal use only.
  4916. /// </summary>
  4917. [FieldOffset(3088)] public FixedBytes16 offset3088;
  4918. /// <summary>
  4919. /// For internal use only.
  4920. /// </summary>
  4921. [FieldOffset(3104)] public FixedBytes16 offset3104;
  4922. /// <summary>
  4923. /// For internal use only.
  4924. /// </summary>
  4925. [FieldOffset(3120)] public FixedBytes16 offset3120;
  4926. /// <summary>
  4927. /// For internal use only.
  4928. /// </summary>
  4929. [FieldOffset(3136)] public FixedBytes16 offset3136;
  4930. /// <summary>
  4931. /// For internal use only.
  4932. /// </summary>
  4933. [FieldOffset(3152)] public FixedBytes16 offset3152;
  4934. /// <summary>
  4935. /// For internal use only.
  4936. /// </summary>
  4937. [FieldOffset(3168)] public FixedBytes16 offset3168;
  4938. /// <summary>
  4939. /// For internal use only.
  4940. /// </summary>
  4941. [FieldOffset(3184)] public FixedBytes16 offset3184;
  4942. /// <summary>
  4943. /// For internal use only.
  4944. /// </summary>
  4945. [FieldOffset(3200)] public FixedBytes16 offset3200;
  4946. /// <summary>
  4947. /// For internal use only.
  4948. /// </summary>
  4949. [FieldOffset(3216)] public FixedBytes16 offset3216;
  4950. /// <summary>
  4951. /// For internal use only.
  4952. /// </summary>
  4953. [FieldOffset(3232)] public FixedBytes16 offset3232;
  4954. /// <summary>
  4955. /// For internal use only.
  4956. /// </summary>
  4957. [FieldOffset(3248)] public FixedBytes16 offset3248;
  4958. /// <summary>
  4959. /// For internal use only.
  4960. /// </summary>
  4961. [FieldOffset(3264)] public FixedBytes16 offset3264;
  4962. /// <summary>
  4963. /// For internal use only.
  4964. /// </summary>
  4965. [FieldOffset(3280)] public FixedBytes16 offset3280;
  4966. /// <summary>
  4967. /// For internal use only.
  4968. /// </summary>
  4969. [FieldOffset(3296)] public FixedBytes16 offset3296;
  4970. /// <summary>
  4971. /// For internal use only.
  4972. /// </summary>
  4973. [FieldOffset(3312)] public FixedBytes16 offset3312;
  4974. /// <summary>
  4975. /// For internal use only.
  4976. /// </summary>
  4977. [FieldOffset(3328)] public FixedBytes16 offset3328;
  4978. /// <summary>
  4979. /// For internal use only.
  4980. /// </summary>
  4981. [FieldOffset(3344)] public FixedBytes16 offset3344;
  4982. /// <summary>
  4983. /// For internal use only.
  4984. /// </summary>
  4985. [FieldOffset(3360)] public FixedBytes16 offset3360;
  4986. /// <summary>
  4987. /// For internal use only.
  4988. /// </summary>
  4989. [FieldOffset(3376)] public FixedBytes16 offset3376;
  4990. /// <summary>
  4991. /// For internal use only.
  4992. /// </summary>
  4993. [FieldOffset(3392)] public FixedBytes16 offset3392;
  4994. /// <summary>
  4995. /// For internal use only.
  4996. /// </summary>
  4997. [FieldOffset(3408)] public FixedBytes16 offset3408;
  4998. /// <summary>
  4999. /// For internal use only.
  5000. /// </summary>
  5001. [FieldOffset(3424)] public FixedBytes16 offset3424;
  5002. /// <summary>
  5003. /// For internal use only.
  5004. /// </summary>
  5005. [FieldOffset(3440)] public FixedBytes16 offset3440;
  5006. /// <summary>
  5007. /// For internal use only.
  5008. /// </summary>
  5009. [FieldOffset(3456)] public FixedBytes16 offset3456;
  5010. /// <summary>
  5011. /// For internal use only.
  5012. /// </summary>
  5013. [FieldOffset(3472)] public FixedBytes16 offset3472;
  5014. /// <summary>
  5015. /// For internal use only.
  5016. /// </summary>
  5017. [FieldOffset(3488)] public FixedBytes16 offset3488;
  5018. /// <summary>
  5019. /// For internal use only.
  5020. /// </summary>
  5021. [FieldOffset(3504)] public FixedBytes16 offset3504;
  5022. /// <summary>
  5023. /// For internal use only.
  5024. /// </summary>
  5025. [FieldOffset(3520)] public FixedBytes16 offset3520;
  5026. /// <summary>
  5027. /// For internal use only.
  5028. /// </summary>
  5029. [FieldOffset(3536)] public FixedBytes16 offset3536;
  5030. /// <summary>
  5031. /// For internal use only.
  5032. /// </summary>
  5033. [FieldOffset(3552)] public FixedBytes16 offset3552;
  5034. /// <summary>
  5035. /// For internal use only.
  5036. /// </summary>
  5037. [FieldOffset(3568)] public FixedBytes16 offset3568;
  5038. /// <summary>
  5039. /// For internal use only.
  5040. /// </summary>
  5041. [FieldOffset(3584)] public FixedBytes16 offset3584;
  5042. /// <summary>
  5043. /// For internal use only.
  5044. /// </summary>
  5045. [FieldOffset(3600)] public FixedBytes16 offset3600;
  5046. /// <summary>
  5047. /// For internal use only.
  5048. /// </summary>
  5049. [FieldOffset(3616)] public FixedBytes16 offset3616;
  5050. /// <summary>
  5051. /// For internal use only.
  5052. /// </summary>
  5053. [FieldOffset(3632)] public FixedBytes16 offset3632;
  5054. /// <summary>
  5055. /// For internal use only.
  5056. /// </summary>
  5057. [FieldOffset(3648)] public FixedBytes16 offset3648;
  5058. /// <summary>
  5059. /// For internal use only.
  5060. /// </summary>
  5061. [FieldOffset(3664)] public FixedBytes16 offset3664;
  5062. /// <summary>
  5063. /// For internal use only.
  5064. /// </summary>
  5065. [FieldOffset(3680)] public FixedBytes16 offset3680;
  5066. /// <summary>
  5067. /// For internal use only.
  5068. /// </summary>
  5069. [FieldOffset(3696)] public FixedBytes16 offset3696;
  5070. /// <summary>
  5071. /// For internal use only.
  5072. /// </summary>
  5073. [FieldOffset(3712)] public FixedBytes16 offset3712;
  5074. /// <summary>
  5075. /// For internal use only.
  5076. /// </summary>
  5077. [FieldOffset(3728)] public FixedBytes16 offset3728;
  5078. /// <summary>
  5079. /// For internal use only.
  5080. /// </summary>
  5081. [FieldOffset(3744)] public FixedBytes16 offset3744;
  5082. /// <summary>
  5083. /// For internal use only.
  5084. /// </summary>
  5085. [FieldOffset(3760)] public FixedBytes16 offset3760;
  5086. /// <summary>
  5087. /// For internal use only.
  5088. /// </summary>
  5089. [FieldOffset(3776)] public FixedBytes16 offset3776;
  5090. /// <summary>
  5091. /// For internal use only.
  5092. /// </summary>
  5093. [FieldOffset(3792)] public FixedBytes16 offset3792;
  5094. /// <summary>
  5095. /// For internal use only.
  5096. /// </summary>
  5097. [FieldOffset(3808)] public FixedBytes16 offset3808;
  5098. /// <summary>
  5099. /// For internal use only.
  5100. /// </summary>
  5101. [FieldOffset(3824)] public FixedBytes16 offset3824;
  5102. /// <summary>
  5103. /// For internal use only.
  5104. /// </summary>
  5105. [FieldOffset(3840)] public FixedBytes16 offset3840;
  5106. /// <summary>
  5107. /// For internal use only.
  5108. /// </summary>
  5109. [FieldOffset(3856)] public FixedBytes16 offset3856;
  5110. /// <summary>
  5111. /// For internal use only.
  5112. /// </summary>
  5113. [FieldOffset(3872)] public FixedBytes16 offset3872;
  5114. /// <summary>
  5115. /// For internal use only.
  5116. /// </summary>
  5117. [FieldOffset(3888)] public FixedBytes16 offset3888;
  5118. /// <summary>
  5119. /// For internal use only.
  5120. /// </summary>
  5121. [FieldOffset(3904)] public FixedBytes16 offset3904;
  5122. /// <summary>
  5123. /// For internal use only.
  5124. /// </summary>
  5125. [FieldOffset(3920)] public FixedBytes16 offset3920;
  5126. /// <summary>
  5127. /// For internal use only.
  5128. /// </summary>
  5129. [FieldOffset(3936)] public FixedBytes16 offset3936;
  5130. /// <summary>
  5131. /// For internal use only.
  5132. /// </summary>
  5133. [FieldOffset(3952)] public FixedBytes16 offset3952;
  5134. /// <summary>
  5135. /// For internal use only.
  5136. /// </summary>
  5137. [FieldOffset(3968)] public FixedBytes16 offset3968;
  5138. /// <summary>
  5139. /// For internal use only.
  5140. /// </summary>
  5141. [FieldOffset(3984)] public FixedBytes16 offset3984;
  5142. /// <summary>
  5143. /// For internal use only.
  5144. /// </summary>
  5145. [FieldOffset(4000)] public FixedBytes16 offset4000;
  5146. /// <summary>
  5147. /// For internal use only.
  5148. /// </summary>
  5149. [FieldOffset(4016)] public FixedBytes16 offset4016;
  5150. /// <summary>
  5151. /// For internal use only.
  5152. /// </summary>
  5153. [FieldOffset(4032)] public FixedBytes16 offset4032;
  5154. /// <summary>
  5155. /// For internal use only.
  5156. /// </summary>
  5157. [FieldOffset(4048)] public FixedBytes16 offset4048;
  5158. /// <summary>
  5159. /// For internal use only.
  5160. /// </summary>
  5161. [FieldOffset(4064)] public FixedBytes16 offset4064;
  5162. /// <summary>
  5163. /// For internal use only.
  5164. /// </summary>
  5165. [FieldOffset(4080)] public byte byte4080;
  5166. /// <summary>
  5167. /// For internal use only.
  5168. /// </summary>
  5169. [FieldOffset(4081)] public byte byte4081;
  5170. /// <summary>
  5171. /// For internal use only.
  5172. /// </summary>
  5173. [FieldOffset(4082)] public byte byte4082;
  5174. /// <summary>
  5175. /// For internal use only.
  5176. /// </summary>
  5177. [FieldOffset(4083)] public byte byte4083;
  5178. /// <summary>
  5179. /// For internal use only.
  5180. /// </summary>
  5181. [FieldOffset(4084)] public byte byte4084;
  5182. /// <summary>
  5183. /// For internal use only.
  5184. /// </summary>
  5185. [FieldOffset(4085)] public byte byte4085;
  5186. /// <summary>
  5187. /// For internal use only.
  5188. /// </summary>
  5189. [FieldOffset(4086)] public byte byte4086;
  5190. /// <summary>
  5191. /// For internal use only.
  5192. /// </summary>
  5193. [FieldOffset(4087)] public byte byte4087;
  5194. /// <summary>
  5195. /// For internal use only.
  5196. /// </summary>
  5197. [FieldOffset(4088)] public byte byte4088;
  5198. /// <summary>
  5199. /// For internal use only.
  5200. /// </summary>
  5201. [FieldOffset(4089)] public byte byte4089;
  5202. /// <summary>
  5203. /// For internal use only.
  5204. /// </summary>
  5205. [FieldOffset(4090)] public byte byte4090;
  5206. /// <summary>
  5207. /// For internal use only.
  5208. /// </summary>
  5209. [FieldOffset(4091)] public byte byte4091;
  5210. /// <summary>
  5211. /// For internal use only.
  5212. /// </summary>
  5213. [FieldOffset(4092)] public byte byte4092;
  5214. /// <summary>
  5215. /// For internal use only.
  5216. /// </summary>
  5217. [FieldOffset(4093)] public byte byte4093;
  5218. }
  5219. [Obsolete("Renamed to FixedString4096Bytes (UnityUpgradable) -> FixedString4096Bytes", true)]
  5220. public partial struct FixedString4096 {}
  5221. /// <summary>
  5222. /// An unmanaged UTF-8 string whose content is stored directly in the 4096-byte struct.
  5223. /// </summary>
  5224. /// <remarks>
  5225. /// The binary layout of this string is guaranteed, for now and all time, to be a length (a little-endian two byte integer)
  5226. /// followed by the bytes of the characters (with no padding). A zero byte always immediately follows the last character.
  5227. /// Effectively, the number of bytes for storing characters is 3 less than 4096 (two length bytes and one null byte).
  5228. ///
  5229. /// This layout is identical to a <see cref="FixedList4096Bytes{T}"/> of bytes, thus allowing reinterpretation between FixedString4096Bytes and FixedList4096Bytes.
  5230. ///
  5231. /// By virtue of being an unmanaged, non-allocated struct with no pointers, this string is fully compatible with jobs and Burst compilation.
  5232. /// Unlike managed string types, these strings can be put in any unmanaged ECS components, FixedList, or any other unmanaged structs.
  5233. /// </remarks>
  5234. [Serializable]
  5235. [StructLayout(LayoutKind.Sequential, Size=4096)]
  5236. [BurstCompatible]
  5237. public partial struct FixedString4096Bytes
  5238. : INativeList<byte>
  5239. , IUTF8Bytes
  5240. , IComparable<String>
  5241. , IEquatable<String>
  5242. , IComparable<FixedString32Bytes>
  5243. , IEquatable<FixedString32Bytes>
  5244. , IComparable<FixedString64Bytes>
  5245. , IEquatable<FixedString64Bytes>
  5246. , IComparable<FixedString128Bytes>
  5247. , IEquatable<FixedString128Bytes>
  5248. , IComparable<FixedString512Bytes>
  5249. , IEquatable<FixedString512Bytes>
  5250. , IComparable<FixedString4096Bytes>
  5251. , IEquatable<FixedString4096Bytes>
  5252. {
  5253. internal const ushort utf8MaxLengthInBytes = 4093;
  5254. [SerializeField] internal ushort utf8LengthInBytes;
  5255. [SerializeField] internal FixedBytes4094 bytes;
  5256. /// <summary>
  5257. /// Returns the maximum number of UTF-8 bytes that can be stored in this string.
  5258. /// </summary>
  5259. /// <returns>
  5260. /// The maximum number of UTF-8 bytes that can be stored in this string.
  5261. /// </returns>
  5262. public static int UTF8MaxLengthInBytes => utf8MaxLengthInBytes;
  5263. /// <summary>
  5264. /// For internal use only. Use <see cref="ToString"/> instead.
  5265. /// </summary>
  5266. /// <value>For internal use only. Use <see cref="ToString"/> instead.</value>
  5267. [CreateProperty]
  5268. [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
  5269. [NotBurstCompatible]
  5270. public string Value => ToString();
  5271. /// <summary>
  5272. /// Returns a pointer to the character bytes.
  5273. /// </summary>
  5274. /// <returns>A pointer to the character bytes.</returns>
  5275. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5276. public unsafe byte* GetUnsafePtr()
  5277. {
  5278. return (byte*) UnsafeUtility.AddressOf(ref bytes);
  5279. }
  5280. /// <summary>
  5281. /// The current length in bytes of this string's content.
  5282. /// </summary>
  5283. /// <remarks>
  5284. /// The length value does not include the null-terminator byte.
  5285. /// </remarks>
  5286. /// <param name="value">The new length in bytes of the string's content.</param>
  5287. /// <exception cref="ArgumentOutOfRangeException">Thrown if the new length is out of bounds.</exception>
  5288. /// <value>
  5289. /// The current length in bytes of this string's content.
  5290. /// </value>
  5291. public int Length
  5292. {
  5293. get
  5294. {
  5295. return utf8LengthInBytes;
  5296. }
  5297. set
  5298. {
  5299. CheckLengthInRange(value);
  5300. utf8LengthInBytes = (ushort)value;
  5301. unsafe
  5302. {
  5303. GetUnsafePtr()[utf8LengthInBytes] = 0;
  5304. }
  5305. }
  5306. }
  5307. /// <summary>
  5308. /// The number of bytes this string has for storing UTF-8 characters.
  5309. /// </summary>
  5310. /// <value>The number of bytes this string has for storing UTF-8 characters.</value>
  5311. /// <remarks>
  5312. /// Does not include the null-terminator byte.
  5313. ///
  5314. /// A setter is included for conformity with <see cref="INativeList{T}"/>, but <see cref="Capacity"/> is fixed at 4093.
  5315. /// Setting the value to anything other than 4093 throws an exception.
  5316. ///
  5317. /// In UTF-8 encoding, each Unicode code point (character) requires 1 to 4 bytes,
  5318. /// so the number of characters that can be stored may be less than the capacity.
  5319. /// </remarks>
  5320. /// <exception cref="ArgumentOutOfRangeException">Thrown if attempting to set the capacity to anything other than 4093.</exception>
  5321. public int Capacity
  5322. {
  5323. get
  5324. {
  5325. return utf8MaxLengthInBytes;
  5326. }
  5327. set
  5328. {
  5329. CheckCapacityInRange(value);
  5330. }
  5331. }
  5332. /// <summary>
  5333. /// Attempts to set the length in bytes. Does nothing if the new length is invalid.
  5334. /// </summary>
  5335. /// <param name="newLength">The desired length.</param>
  5336. /// <param name="clearOptions">Whether added or removed bytes should be cleared (zeroed). (Increasing the length adds bytes; decreasing the length removes bytes.)</param>
  5337. /// <returns>True if the new length is valid.</returns>
  5338. public bool TryResize(int newLength, NativeArrayOptions clearOptions = NativeArrayOptions.ClearMemory)
  5339. {
  5340. if (newLength < 0 || newLength > utf8MaxLengthInBytes)
  5341. return false;
  5342. if (newLength == utf8LengthInBytes)
  5343. return true;
  5344. unsafe
  5345. {
  5346. if (clearOptions == NativeArrayOptions.ClearMemory)
  5347. {
  5348. if (newLength > utf8LengthInBytes)
  5349. UnsafeUtility.MemClear(GetUnsafePtr() + utf8LengthInBytes, newLength - utf8LengthInBytes);
  5350. else
  5351. UnsafeUtility.MemClear(GetUnsafePtr() + newLength, utf8LengthInBytes - newLength);
  5352. }
  5353. utf8LengthInBytes = (ushort)newLength;
  5354. // always null terminate
  5355. GetUnsafePtr()[utf8LengthInBytes] = 0;
  5356. }
  5357. return true;
  5358. }
  5359. /// <summary>
  5360. /// Returns true if this string is empty (has no characters).
  5361. /// </summary>
  5362. /// <value>True if this string is empty (has no characters).</value>
  5363. public bool IsEmpty => utf8LengthInBytes == 0;
  5364. /// <summary>
  5365. /// Returns the byte (not character) at an index.
  5366. /// </summary>
  5367. /// <param name="index">A byte index.</param>
  5368. /// <value>The byte at the index.</value>
  5369. /// <exception cref="IndexOutOfRangeException">Thrown if the index is out of bounds.</exception>
  5370. public byte this[int index]
  5371. {
  5372. get
  5373. {
  5374. unsafe
  5375. {
  5376. CheckIndexInRange(index);
  5377. return GetUnsafePtr()[index];
  5378. }
  5379. }
  5380. set
  5381. {
  5382. unsafe
  5383. {
  5384. CheckIndexInRange(index);
  5385. GetUnsafePtr()[index] = value;
  5386. }
  5387. }
  5388. }
  5389. /// <summary>
  5390. /// Returns the reference to a byte (not character) at an index.
  5391. /// </summary>
  5392. /// <param name="index">A byte index.</param>
  5393. /// <returns>A reference to the byte at the index.</returns>
  5394. /// <exception cref="IndexOutOfRangeException">Thrown if the index is out of bounds.</exception>
  5395. public ref byte ElementAt(int index)
  5396. {
  5397. unsafe
  5398. {
  5399. CheckIndexInRange(index);
  5400. return ref GetUnsafePtr()[index];
  5401. }
  5402. }
  5403. /// <summary>
  5404. /// Sets the length to 0.
  5405. /// </summary>
  5406. public void Clear()
  5407. {
  5408. Length = 0;
  5409. }
  5410. /// <summary>
  5411. /// Appends a byte.
  5412. /// </summary>
  5413. /// <remarks>
  5414. /// A zero byte will always follow the newly appended byte.
  5415. ///
  5416. /// No validation is performed: it is your responsibility for the bytes of the string to form valid UTF-8 when you're done appending bytes.
  5417. /// </remarks>
  5418. /// <param name="value">A byte to append.</param>
  5419. public void Add(in byte value)
  5420. {
  5421. this[Length++] = value;
  5422. }
  5423. /// <summary>
  5424. /// An enumerator over the characters (not bytes) of a FixedString4096Bytes.
  5425. /// </summary>
  5426. /// <remarks>
  5427. /// In an enumerator's initial state, <see cref="Current"/> is not valid to read.
  5428. /// The first <see cref="MoveNext"/> call advances the enumerator's index to the first character.
  5429. /// </remarks>
  5430. public struct Enumerator : IEnumerator
  5431. {
  5432. FixedString4096Bytes target;
  5433. int offset;
  5434. Unicode.Rune current;
  5435. /// <summary>
  5436. /// Initializes and returns an instance of FixedString4096Bytes.Enumerator.
  5437. /// </summary>
  5438. /// <param name="other">A FixeString4096 for which to create an enumerator.</param>
  5439. public Enumerator(FixedString4096Bytes other)
  5440. {
  5441. target = other;
  5442. offset = 0;
  5443. current = default;
  5444. }
  5445. /// <summary>
  5446. /// Does nothing.
  5447. /// </summary>
  5448. public void Dispose()
  5449. {
  5450. }
  5451. /// <summary>
  5452. /// Advances the enumerator to the next character.
  5453. /// </summary>
  5454. /// <returns>True if <see cref="Current"/> is valid to read after the call.</returns>
  5455. public bool MoveNext()
  5456. {
  5457. if (offset >= target.Length)
  5458. return false;
  5459. unsafe
  5460. {
  5461. Unicode.Utf8ToUcs(out current, target.GetUnsafePtr(), ref offset, target.Length);
  5462. }
  5463. return true;
  5464. }
  5465. /// <summary>
  5466. /// Resets the enumerator to its initial state.
  5467. /// </summary>
  5468. public void Reset()
  5469. {
  5470. offset = 0;
  5471. current = default;
  5472. }
  5473. /// <summary>
  5474. /// The current character.
  5475. /// </summary>
  5476. /// <remarks>
  5477. /// In an enumerator's initial state, <see cref="Current"/> is not valid to read.
  5478. /// </remarks>
  5479. /// <value>The current character.</value>
  5480. public Unicode.Rune Current => current;
  5481. object IEnumerator.Current => Current;
  5482. }
  5483. /// <summary>
  5484. /// Returns an enumerator for iterating over the characters of this string.
  5485. /// </summary>
  5486. /// <returns>An enumerator for iterating over the characters of the FixedString4096Bytes.</returns>
  5487. public Enumerator GetEnumerator()
  5488. {
  5489. return new Enumerator(this);
  5490. }
  5491. /// <summary>
  5492. /// Returns the lexicographical sort order of this string relative to another.
  5493. /// </summary>
  5494. /// <param name="other">A `System.String` to compare with.</param>
  5495. /// <returns>An integer denoting the lexicographical sort order of this string relative to the other:
  5496. ///
  5497. /// 0 denotes both strings have the same sort position.<br/>
  5498. /// -1 denotes that this string should be sorted to precede the other string.<br/>
  5499. /// +1 denotes that this string should be sorted to follow the other string.<br/>
  5500. /// </returns>
  5501. [NotBurstCompatible]
  5502. public int CompareTo(String other)
  5503. {
  5504. return ToString().CompareTo(other);
  5505. }
  5506. /// <summary>
  5507. /// Returns true if this string and another have the same length and all the same characters.
  5508. /// </summary>
  5509. /// <param name="other">A string to compare for equality.</param>
  5510. /// <returns>True if this string and the other have the same length and all the same characters.</returns>
  5511. [NotBurstCompatible]
  5512. public bool Equals(String other)
  5513. {
  5514. unsafe {
  5515. int alen = utf8LengthInBytes;
  5516. int blen = other.Length;
  5517. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(bytes);
  5518. fixed(char* bptr = other)
  5519. {
  5520. return UTF8ArrayUnsafeUtility.StrCmp(aptr, alen, bptr, blen) == 0;
  5521. }
  5522. }
  5523. }
  5524. /// <summary>
  5525. /// Returns a reference to a FixedList4096Bytes<byte> representation of this string.
  5526. /// </summary>
  5527. /// <remarks>
  5528. /// The referenced FixedListByte4096 is the very same bytes as the original FixedString4096Bytes,
  5529. /// so it is only valid as long as the original FixedString4096Bytes is valid.
  5530. /// </remarks>
  5531. /// <returns>A ref to a FixedListByte4096 representation of the FixedString4096Bytes.</returns>
  5532. public unsafe ref FixedList4096Bytes<byte> AsFixedList()
  5533. {
  5534. return ref UnsafeUtility.AsRef<FixedList4096Bytes<byte>>(UnsafeUtility.AddressOf(ref this));
  5535. }
  5536. /// <summary>
  5537. /// Initializes and returns an instance of FixedString4096Bytes with the characters copied from a string.
  5538. /// </summary>
  5539. /// <param name="source">The source string to copy.</param>
  5540. [NotBurstCompatible]
  5541. public FixedString4096Bytes(String source)
  5542. {
  5543. this = default;
  5544. var error = Initialize(source);
  5545. CheckCopyError((CopyError)error, source);
  5546. }
  5547. /// <summary>
  5548. /// Initializes an instance of FixedString4096Bytes with the characters copied from a string.
  5549. /// </summary>
  5550. /// <param name="source">The source string to copy.</param>
  5551. /// <returns>zero on success, or non-zero on error.</returns>
  5552. [NotBurstCompatible]
  5553. internal int Initialize(String source)
  5554. {
  5555. bytes = default;
  5556. utf8LengthInBytes = 0;
  5557. unsafe
  5558. {
  5559. fixed (char* sourceptr = source)
  5560. {
  5561. var error = UTF8ArrayUnsafeUtility.Copy(GetUnsafePtr(), out utf8LengthInBytes, utf8MaxLengthInBytes, sourceptr, source.Length);
  5562. if(error != CopyError.None)
  5563. return (int)error;
  5564. this.Length = utf8LengthInBytes;
  5565. }
  5566. }
  5567. return 0;
  5568. }
  5569. /// <summary>
  5570. /// Initializes and returns an instance of FixedString4096Bytes with a single character repeatedly appended some number of times.
  5571. /// </summary>
  5572. /// <param name="rune">The Unicode.Rune to repeat.</param>
  5573. /// <param name="count">The number of times to repeat the character. Default is 1.</param>
  5574. public FixedString4096Bytes(Unicode.Rune rune, int count = 1)
  5575. {
  5576. this = default;
  5577. Initialize(rune, count);
  5578. }
  5579. /// <summary>
  5580. /// Initializes an instance of FixedString4096Bytes with a single character repeatedly appended some number of times.
  5581. /// </summary>
  5582. /// <param name="rune">The Unicode.Rune to repeat.</param>
  5583. /// <param name="count">The number of times to repeat the character. Default is 1.</param>
  5584. /// <returns>zero on success, or non-zero on error.</returns>
  5585. internal int Initialize(Unicode.Rune rune, int count = 1)
  5586. {
  5587. this = default;
  5588. return (int)this.Append(rune, count);
  5589. }
  5590. /// <summary>
  5591. /// Returns the lexicographical sort order of this string relative to another.
  5592. /// </summary>
  5593. /// <param name="other">A string to compare with.</param>
  5594. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  5595. ///
  5596. /// 0 denotes that both strings have the same sort position.<br/>
  5597. /// -1 denotes that this string should be sorted to precede the other.<br/>
  5598. /// +1 denotes that this string should be sorted to follow the other.<br/>
  5599. /// </returns>
  5600. public int CompareTo(FixedString32Bytes other)
  5601. {
  5602. return FixedStringMethods.CompareTo(ref this, other);
  5603. }
  5604. /// <summary>
  5605. /// Initializes and returns an instance of FixedString4096Bytes that is a copy of another string.
  5606. /// </summary>
  5607. /// <param name="other">The string to copy.</param>
  5608. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString4096Bytes.</exception>
  5609. public FixedString4096Bytes(in FixedString32Bytes other)
  5610. {
  5611. this = default;
  5612. var error = Initialize(other);
  5613. CheckFormatError((FormatError)error);
  5614. }
  5615. /// <summary>
  5616. /// Initializes an instance of FixedString4096Bytes that is a copy of another string.
  5617. /// </summary>
  5618. /// <param name="other">The string to copy.</param>
  5619. /// <returns>zero on success, or non-zero on error.</returns>
  5620. internal int Initialize(in FixedString32Bytes other)
  5621. {
  5622. bytes = default;
  5623. utf8LengthInBytes = 0;
  5624. unsafe {
  5625. int len = 0;
  5626. byte* dstBytes = GetUnsafePtr();
  5627. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  5628. var srcLength = other.utf8LengthInBytes;
  5629. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  5630. if(error != FormatError.None)
  5631. return (int)error;
  5632. this.Length = len;
  5633. }
  5634. return 0;
  5635. }
  5636. /// <summary>
  5637. /// Returns true if a FixedString4096Bytes and another string are equal.
  5638. /// </summary>
  5639. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5640. /// <param name="a">A FixedString4096Bytes to compare for equality.</param>
  5641. /// <param name="b">A FixedString32Bytes to compare for equality.</param>
  5642. /// <returns>True if the two strings are equal.</returns>
  5643. public static bool operator ==(in FixedString4096Bytes a, in FixedString32Bytes b)
  5644. {
  5645. // this must not call any methods on 'a' or 'b'
  5646. unsafe {
  5647. int alen = a.utf8LengthInBytes;
  5648. int blen = b.utf8LengthInBytes;
  5649. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  5650. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  5651. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  5652. }
  5653. }
  5654. /// <summary>
  5655. /// Returns true if a FixedString4096Bytes and another string are unequal.
  5656. /// </summary>
  5657. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5658. /// <param name="a">A FixedString4096Bytes to compare for inequality.</param>
  5659. /// <param name="b">A FixedString32Bytes to compare for inequality.</param>
  5660. /// <returns>True if the two strings are unequal.</returns>
  5661. public static bool operator !=(in FixedString4096Bytes a, in FixedString32Bytes b)
  5662. {
  5663. return !(a == b);
  5664. }
  5665. /// <summary>
  5666. /// Returns true if this string and another string are equal.
  5667. /// </summary>
  5668. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5669. /// <param name="other">A FixedString32Bytes to compare for equality.</param>
  5670. /// <returns>True if the two strings are equal.</returns>
  5671. public bool Equals(FixedString32Bytes other)
  5672. {
  5673. return this == other;
  5674. }
  5675. /// <summary>
  5676. /// Returns the lexicographical sort order of this string relative to another.
  5677. /// </summary>
  5678. /// <param name="other">A string to compare with.</param>
  5679. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  5680. ///
  5681. /// 0 denotes that both strings have the same sort position.<br/>
  5682. /// -1 denotes that this string should be sorted to precede the other.<br/>
  5683. /// +1 denotes that this string should be sorted to follow the other.<br/>
  5684. /// </returns>
  5685. public int CompareTo(FixedString64Bytes other)
  5686. {
  5687. return FixedStringMethods.CompareTo(ref this, other);
  5688. }
  5689. /// <summary>
  5690. /// Initializes and returns an instance of FixedString4096Bytes that is a copy of another string.
  5691. /// </summary>
  5692. /// <param name="other">The string to copy.</param>
  5693. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString4096Bytes.</exception>
  5694. public FixedString4096Bytes(in FixedString64Bytes other)
  5695. {
  5696. this = default;
  5697. var error = Initialize(other);
  5698. CheckFormatError((FormatError)error);
  5699. }
  5700. /// <summary>
  5701. /// Initializes an instance of FixedString4096Bytes that is a copy of another string.
  5702. /// </summary>
  5703. /// <param name="other">The string to copy.</param>
  5704. /// <returns>zero on success, or non-zero on error.</returns>
  5705. internal int Initialize(in FixedString64Bytes other)
  5706. {
  5707. bytes = default;
  5708. utf8LengthInBytes = 0;
  5709. unsafe {
  5710. int len = 0;
  5711. byte* dstBytes = GetUnsafePtr();
  5712. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  5713. var srcLength = other.utf8LengthInBytes;
  5714. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  5715. if(error != FormatError.None)
  5716. return (int)error;
  5717. this.Length = len;
  5718. }
  5719. return 0;
  5720. }
  5721. /// <summary>
  5722. /// Returns true if a FixedString4096Bytes and another string are equal.
  5723. /// </summary>
  5724. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5725. /// <param name="a">A FixedString4096Bytes to compare for equality.</param>
  5726. /// <param name="b">A FixedString64Bytes to compare for equality.</param>
  5727. /// <returns>True if the two strings are equal.</returns>
  5728. public static bool operator ==(in FixedString4096Bytes a, in FixedString64Bytes b)
  5729. {
  5730. // this must not call any methods on 'a' or 'b'
  5731. unsafe {
  5732. int alen = a.utf8LengthInBytes;
  5733. int blen = b.utf8LengthInBytes;
  5734. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  5735. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  5736. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  5737. }
  5738. }
  5739. /// <summary>
  5740. /// Returns true if a FixedString4096Bytes and another string are unequal.
  5741. /// </summary>
  5742. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5743. /// <param name="a">A FixedString4096Bytes to compare for inequality.</param>
  5744. /// <param name="b">A FixedString64Bytes to compare for inequality.</param>
  5745. /// <returns>True if the two strings are unequal.</returns>
  5746. public static bool operator !=(in FixedString4096Bytes a, in FixedString64Bytes b)
  5747. {
  5748. return !(a == b);
  5749. }
  5750. /// <summary>
  5751. /// Returns true if this string and another string are equal.
  5752. /// </summary>
  5753. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5754. /// <param name="other">A FixedString64Bytes to compare for equality.</param>
  5755. /// <returns>True if the two strings are equal.</returns>
  5756. public bool Equals(FixedString64Bytes other)
  5757. {
  5758. return this == other;
  5759. }
  5760. /// <summary>
  5761. /// Returns the lexicographical sort order of this string relative to another.
  5762. /// </summary>
  5763. /// <param name="other">A string to compare with.</param>
  5764. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  5765. ///
  5766. /// 0 denotes that both strings have the same sort position.<br/>
  5767. /// -1 denotes that this string should be sorted to precede the other.<br/>
  5768. /// +1 denotes that this string should be sorted to follow the other.<br/>
  5769. /// </returns>
  5770. public int CompareTo(FixedString128Bytes other)
  5771. {
  5772. return FixedStringMethods.CompareTo(ref this, other);
  5773. }
  5774. /// <summary>
  5775. /// Initializes and returns an instance of FixedString4096Bytes that is a copy of another string.
  5776. /// </summary>
  5777. /// <param name="other">The string to copy.</param>
  5778. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString4096Bytes.</exception>
  5779. public FixedString4096Bytes(in FixedString128Bytes other)
  5780. {
  5781. this = default;
  5782. var error = Initialize(other);
  5783. CheckFormatError((FormatError)error);
  5784. }
  5785. /// <summary>
  5786. /// Initializes an instance of FixedString4096Bytes that is a copy of another string.
  5787. /// </summary>
  5788. /// <param name="other">The string to copy.</param>
  5789. /// <returns>zero on success, or non-zero on error.</returns>
  5790. internal int Initialize(in FixedString128Bytes other)
  5791. {
  5792. bytes = default;
  5793. utf8LengthInBytes = 0;
  5794. unsafe {
  5795. int len = 0;
  5796. byte* dstBytes = GetUnsafePtr();
  5797. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  5798. var srcLength = other.utf8LengthInBytes;
  5799. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  5800. if(error != FormatError.None)
  5801. return (int)error;
  5802. this.Length = len;
  5803. }
  5804. return 0;
  5805. }
  5806. /// <summary>
  5807. /// Returns true if a FixedString4096Bytes and another string are equal.
  5808. /// </summary>
  5809. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5810. /// <param name="a">A FixedString4096Bytes to compare for equality.</param>
  5811. /// <param name="b">A FixedString128Bytes to compare for equality.</param>
  5812. /// <returns>True if the two strings are equal.</returns>
  5813. public static bool operator ==(in FixedString4096Bytes a, in FixedString128Bytes b)
  5814. {
  5815. // this must not call any methods on 'a' or 'b'
  5816. unsafe {
  5817. int alen = a.utf8LengthInBytes;
  5818. int blen = b.utf8LengthInBytes;
  5819. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  5820. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  5821. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  5822. }
  5823. }
  5824. /// <summary>
  5825. /// Returns true if a FixedString4096Bytes and another string are unequal.
  5826. /// </summary>
  5827. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5828. /// <param name="a">A FixedString4096Bytes to compare for inequality.</param>
  5829. /// <param name="b">A FixedString128Bytes to compare for inequality.</param>
  5830. /// <returns>True if the two strings are unequal.</returns>
  5831. public static bool operator !=(in FixedString4096Bytes a, in FixedString128Bytes b)
  5832. {
  5833. return !(a == b);
  5834. }
  5835. /// <summary>
  5836. /// Returns true if this string and another string are equal.
  5837. /// </summary>
  5838. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5839. /// <param name="other">A FixedString128Bytes to compare for equality.</param>
  5840. /// <returns>True if the two strings are equal.</returns>
  5841. public bool Equals(FixedString128Bytes other)
  5842. {
  5843. return this == other;
  5844. }
  5845. /// <summary>
  5846. /// Returns the lexicographical sort order of this string relative to another.
  5847. /// </summary>
  5848. /// <param name="other">A string to compare with.</param>
  5849. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  5850. ///
  5851. /// 0 denotes that both strings have the same sort position.<br/>
  5852. /// -1 denotes that this string should be sorted to precede the other.<br/>
  5853. /// +1 denotes that this string should be sorted to follow the other.<br/>
  5854. /// </returns>
  5855. public int CompareTo(FixedString512Bytes other)
  5856. {
  5857. return FixedStringMethods.CompareTo(ref this, other);
  5858. }
  5859. /// <summary>
  5860. /// Initializes and returns an instance of FixedString4096Bytes that is a copy of another string.
  5861. /// </summary>
  5862. /// <param name="other">The string to copy.</param>
  5863. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString4096Bytes.</exception>
  5864. public FixedString4096Bytes(in FixedString512Bytes other)
  5865. {
  5866. this = default;
  5867. var error = Initialize(other);
  5868. CheckFormatError((FormatError)error);
  5869. }
  5870. /// <summary>
  5871. /// Initializes an instance of FixedString4096Bytes that is a copy of another string.
  5872. /// </summary>
  5873. /// <param name="other">The string to copy.</param>
  5874. /// <returns>zero on success, or non-zero on error.</returns>
  5875. internal int Initialize(in FixedString512Bytes other)
  5876. {
  5877. bytes = default;
  5878. utf8LengthInBytes = 0;
  5879. unsafe {
  5880. int len = 0;
  5881. byte* dstBytes = GetUnsafePtr();
  5882. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  5883. var srcLength = other.utf8LengthInBytes;
  5884. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  5885. if(error != FormatError.None)
  5886. return (int)error;
  5887. this.Length = len;
  5888. }
  5889. return 0;
  5890. }
  5891. /// <summary>
  5892. /// Returns true if a FixedString4096Bytes and another string are equal.
  5893. /// </summary>
  5894. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5895. /// <param name="a">A FixedString4096Bytes to compare for equality.</param>
  5896. /// <param name="b">A FixedString512Bytes to compare for equality.</param>
  5897. /// <returns>True if the two strings are equal.</returns>
  5898. public static bool operator ==(in FixedString4096Bytes a, in FixedString512Bytes b)
  5899. {
  5900. // this must not call any methods on 'a' or 'b'
  5901. unsafe {
  5902. int alen = a.utf8LengthInBytes;
  5903. int blen = b.utf8LengthInBytes;
  5904. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  5905. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  5906. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  5907. }
  5908. }
  5909. /// <summary>
  5910. /// Returns true if a FixedString4096Bytes and another string are unequal.
  5911. /// </summary>
  5912. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5913. /// <param name="a">A FixedString4096Bytes to compare for inequality.</param>
  5914. /// <param name="b">A FixedString512Bytes to compare for inequality.</param>
  5915. /// <returns>True if the two strings are unequal.</returns>
  5916. public static bool operator !=(in FixedString4096Bytes a, in FixedString512Bytes b)
  5917. {
  5918. return !(a == b);
  5919. }
  5920. /// <summary>
  5921. /// Returns true if this string and another string are equal.
  5922. /// </summary>
  5923. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5924. /// <param name="other">A FixedString512Bytes to compare for equality.</param>
  5925. /// <returns>True if the two strings are equal.</returns>
  5926. public bool Equals(FixedString512Bytes other)
  5927. {
  5928. return this == other;
  5929. }
  5930. /// <summary>
  5931. /// Returns the lexicographical sort order of this string relative to another.
  5932. /// </summary>
  5933. /// <param name="other">A string to compare with.</param>
  5934. /// <returns>A number denoting the lexicographical sort order of this string relative to the other:
  5935. ///
  5936. /// 0 denotes that both strings have the same sort position.<br/>
  5937. /// -1 denotes that this string should be sorted to precede the other.<br/>
  5938. /// +1 denotes that this string should be sorted to follow the other.<br/>
  5939. /// </returns>
  5940. public int CompareTo(FixedString4096Bytes other)
  5941. {
  5942. return FixedStringMethods.CompareTo(ref this, other);
  5943. }
  5944. /// <summary>
  5945. /// Initializes and returns an instance of FixedString4096Bytes that is a copy of another string.
  5946. /// </summary>
  5947. /// <param name="other">The string to copy.</param>
  5948. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString4096Bytes.</exception>
  5949. public FixedString4096Bytes(in FixedString4096Bytes other)
  5950. {
  5951. this = default;
  5952. var error = Initialize(other);
  5953. CheckFormatError((FormatError)error);
  5954. }
  5955. /// <summary>
  5956. /// Initializes an instance of FixedString4096Bytes that is a copy of another string.
  5957. /// </summary>
  5958. /// <param name="other">The string to copy.</param>
  5959. /// <returns>zero on success, or non-zero on error.</returns>
  5960. internal int Initialize(in FixedString4096Bytes other)
  5961. {
  5962. bytes = default;
  5963. utf8LengthInBytes = 0;
  5964. unsafe {
  5965. int len = 0;
  5966. byte* dstBytes = GetUnsafePtr();
  5967. byte* srcBytes = (byte*) UnsafeUtilityExtensions.AddressOf(other.bytes);
  5968. var srcLength = other.utf8LengthInBytes;
  5969. var error = UTF8ArrayUnsafeUtility.AppendUTF8Bytes(dstBytes, ref len, utf8MaxLengthInBytes, srcBytes, srcLength);
  5970. if(error != FormatError.None)
  5971. return (int)error;
  5972. this.Length = len;
  5973. }
  5974. return 0;
  5975. }
  5976. /// <summary>
  5977. /// Returns true if a FixedString4096Bytes and another string are equal.
  5978. /// </summary>
  5979. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5980. /// <param name="a">A FixedString4096Bytes to compare for equality.</param>
  5981. /// <param name="b">A FixedString4096Bytes to compare for equality.</param>
  5982. /// <returns>True if the two strings are equal.</returns>
  5983. public static bool operator ==(in FixedString4096Bytes a, in FixedString4096Bytes b)
  5984. {
  5985. // this must not call any methods on 'a' or 'b'
  5986. unsafe {
  5987. int alen = a.utf8LengthInBytes;
  5988. int blen = b.utf8LengthInBytes;
  5989. byte* aptr = (byte*) UnsafeUtilityExtensions.AddressOf(a.bytes);
  5990. byte* bptr = (byte*) UnsafeUtilityExtensions.AddressOf(b.bytes);
  5991. return UTF8ArrayUnsafeUtility.EqualsUTF8Bytes(aptr, alen, bptr, blen);
  5992. }
  5993. }
  5994. /// <summary>
  5995. /// Returns true if a FixedString4096Bytes and another string are unequal.
  5996. /// </summary>
  5997. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  5998. /// <param name="a">A FixedString4096Bytes to compare for inequality.</param>
  5999. /// <param name="b">A FixedString4096Bytes to compare for inequality.</param>
  6000. /// <returns>True if the two strings are unequal.</returns>
  6001. public static bool operator !=(in FixedString4096Bytes a, in FixedString4096Bytes b)
  6002. {
  6003. return !(a == b);
  6004. }
  6005. /// <summary>
  6006. /// Returns true if this string and another string are equal.
  6007. /// </summary>
  6008. /// <remarks>Two strings are equal if they have equal length and all their characters match.</remarks>
  6009. /// <param name="other">A FixedString4096Bytes to compare for equality.</param>
  6010. /// <returns>True if the two strings are equal.</returns>
  6011. public bool Equals(FixedString4096Bytes other)
  6012. {
  6013. return this == other;
  6014. }
  6015. /// <summary>
  6016. /// Returns a new FixedString4096Bytes that is a copy of another string.
  6017. /// </summary>
  6018. /// <param name="b">A string to copy.</param>
  6019. /// <returns>A new FixedString4096Bytes that is a copy of another string.</returns>
  6020. /// <exception cref="IndexOutOfRangeException">Thrown if the string to copy's length exceeds the capacity of FixedString4096Bytes.</exception>
  6021. [NotBurstCompatible]
  6022. public static implicit operator FixedString4096Bytes(string b) => new FixedString4096Bytes(b);
  6023. /// <summary>
  6024. /// Returns a new managed string that is a copy of this string.
  6025. /// </summary>
  6026. /// <returns>A new managed string that is a copy of this string.</returns>
  6027. [NotBurstCompatible]
  6028. public override String ToString()
  6029. {
  6030. return this.ConvertToString();
  6031. }
  6032. /// <summary>
  6033. /// Returns a hash code of this string.
  6034. /// </summary>
  6035. /// <remarks>Only the character bytes are included in the hash: any bytes beyond <see cref="Length"/> are not part of the hash.</remarks>
  6036. /// <returns>The hash code of this string.</returns>
  6037. public override int GetHashCode()
  6038. {
  6039. return this.ComputeHashCode();
  6040. }
  6041. /// <summary>
  6042. /// Returns true if this string and an object are equal.
  6043. /// </summary>
  6044. /// <remarks>
  6045. /// Returns false if the object is neither a System.String or a FixedString.
  6046. ///
  6047. /// Two strings are equal if they have equal length and all their characters match.</remarks>
  6048. /// <param name="obj">An object to compare for equality.</param>
  6049. /// <returns>True if this string and the object are equal.</returns>
  6050. [NotBurstCompatible]
  6051. public override bool Equals(object obj)
  6052. {
  6053. if(ReferenceEquals(null, obj)) return false;
  6054. if(obj is String aString) return Equals(aString);
  6055. if(obj is FixedString32Bytes aFixedString32Bytes) return Equals(aFixedString32Bytes);
  6056. if(obj is FixedString64Bytes aFixedString64Bytes) return Equals(aFixedString64Bytes);
  6057. if(obj is FixedString128Bytes aFixedString128Bytes) return Equals(aFixedString128Bytes);
  6058. if(obj is FixedString512Bytes aFixedString512Bytes) return Equals(aFixedString512Bytes);
  6059. if(obj is FixedString4096Bytes aFixedString4096Bytes) return Equals(aFixedString4096Bytes);
  6060. return false;
  6061. }
  6062. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  6063. void CheckIndexInRange(int index)
  6064. {
  6065. if (index < 0)
  6066. throw new IndexOutOfRangeException($"Index {index} must be positive.");
  6067. if (index >= utf8LengthInBytes)
  6068. throw new IndexOutOfRangeException($"Index {index} is out of range in FixedString4096Bytes of '{utf8LengthInBytes}' Length.");
  6069. }
  6070. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  6071. void CheckLengthInRange(int length)
  6072. {
  6073. if (length < 0)
  6074. throw new ArgumentOutOfRangeException($"Length {length} must be positive.");
  6075. if (length > utf8MaxLengthInBytes)
  6076. throw new ArgumentOutOfRangeException($"Length {length} is out of range in FixedString4096Bytes of '{utf8MaxLengthInBytes}' Capacity.");
  6077. }
  6078. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  6079. void CheckCapacityInRange(int capacity)
  6080. {
  6081. if (capacity > utf8MaxLengthInBytes)
  6082. throw new ArgumentOutOfRangeException($"Capacity {capacity} must be lower than {utf8MaxLengthInBytes}.");
  6083. }
  6084. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  6085. static void CheckCopyError(CopyError error, String source)
  6086. {
  6087. if (error != CopyError.None)
  6088. throw new ArgumentException($"FixedString4096Bytes: {error} while copying \"{source}\"");
  6089. }
  6090. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  6091. static void CheckFormatError(FormatError error)
  6092. {
  6093. if (error != FormatError.None)
  6094. throw new ArgumentException("Source is too long to fit into fixed string of this size");
  6095. }
  6096. }
  6097. }