After seeing the GetBytes and GetString methods of Encoding class, I was confused why always byte stream is converted as a base64 string and saved to Player prefs in many implementations.
I see those methods are considering the entire length while making the conversion and more over String in C# seems NOT considered as null terminated by default.
I do see the advantage of base64 conversion over Network but to disk I’m not understanding the requirement.
Can anyone please clarify on this?
Yes, in general a string in C# / Mono can contain any data including nulls (‘\0’). However Since PlayerPrefs are stored in different ways depending on the platform there could possibly be some problems with pure binary data. On Windows standalone it’s stored in the windows registry (personally i would prefer a seperate file like the webplayer uses).
Since Base64 encoding ist just slightly larger (+1/3) it usually doesn’t hurt but it’s ensured it only contains human readable characters. This simplyfies cross compatibility with other systems or if you switch to a database / webserver backend.