What's a fast serializer that works cross platform that can be used for saving/loading custom levels?

I’m looking for a serializer that works across multiple platforms including those that don’t support JIT compilation(eg. IOS). I would also prefer if the serialized object is non-human readable(eg. no xml/json).

Binaryformatter is a good choice but relatively slow.

Protobuf is a lot faster but requires pre-compilation in order to work on platforms which don’t support JIT compilation, which i can’t do since it breaks some of my code.

Is there any other serializer that i can use which has a similar speed to protobuf? (I mainly care about the deserialization speed and not too much on the serialization speed)

You may have a look [at this post][1]. Reflection doesn’t require JIT support. Only dynamic code generation is not supported. I haven’t used any Protobuf implementations yet, but i’m sure there are implementations which work on AOT platforms.

edit
Here’s a quick example how you can manually serialize objects using the BinaryReader / Writer:

using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;


public class LevelObject
{
    public string name;
    public Vector3 position;
    public Quaternion rotation;
    public void Serialize(BinaryWriter aWriter)
    {
        aWriter.Write(name);
        position.WriteTo(aWriter);
        rotation.WriteTo(aWriter);
    }
    public void Deserialize(BinaryReader aReader)
    {
        name = aReader.ReadString();
        position = aReader.ReadVector3();
        rotation = aReader.ReadQuaternion();
    }
}

public class Level
{
    public string name;
    public List<LevelObject> objects = new List<LevelObject>();
    public void Serialize(BinaryWriter aWriter)
    {
        aWriter.Write(name);
        aWriter.Write(objects.Count);
        for (int i = 0; i < objects.Count; i++)
            objects*.Serialize(aWriter);*

}
public void Deserialize(BinaryReader aReader)
{
name = aReader.ReadString();
int count = aReader.ReadInt32();
objects.Clear();
for(int i = 0; i < count; i++)
{
var obj = new LevelObject();
obj.Deserialize(aReader);
objects.Add(obj);
}
}
}

public static class Extensions
{
public static void WriteTo(this Vector3 aVec, BinaryWriter aWriter)
{
aWriter.Write(aVec.x);
aWriter.Write(aVec.y);
aWriter.Write(aVec.z);
}
public static Vector3 ReadVector3(this BinaryReader aReader)
{
return new Vector3(aReader.ReadSingle(), aReader.ReadSingle(), aReader.ReadSingle());
}
public static void WriteTo(this Quaternion aRot, BinaryWriter aWriter)
{
aWriter.Write(aRot.x);
aWriter.Write(aRot.y);
aWriter.Write(aRot.z);
aWriter.Write(aRot.w);
}
public static Quaternion ReadQuaternion(this BinaryReader aReader)
{
return new Quaternion(aReader.ReadSingle(), aReader.ReadSingle(), aReader.ReadSingle(), aReader.ReadSingle());
}
}

public class Loader : MonoBehaviour
{
public Level level;
public void SaveToStream(FileStream aStream)
{
using (var writer = new BinaryWriter(aStream))
level.Serialize(writer);
}
public void SaveToFile(string aFileName)
{
using (var fs = File.OpenWrite(aFileName))
SaveToStream(fs);
}
public void LoadFromStream(FileStream aStream)
{
using (var reader = new BinaryReader(aStream))
{
level = new Level();
level.Deserialize(reader);
}
}
public void LoadFromFile(string aFileName)
{
using (var fs = File.OpenRead(aFileName))
LoadFromStream(fs);
}
}
Of course this is just an example. Of course if you use polymorphism in your object tree you have to handle that yourself. However most serialization solutions do not directly support polymorphism as the actual runtime type would need to be encoded in some way so the deserializer can recreate the correct type. The BinaryFormatter does this by serializing the full class name as string which makes the result quite large.
[1]: dot.NET - Advanced .NET Knowledge: ProtoBuf in Unity3D