IBinarySerializer interface


IBinarySerializer is used to serialize custom data.

Every data type which is broadcasted by a room or by an actor, or used as actor state must have it's own serializer.

IBinarySerializer needs to implement Serialize and Deserialize methods, and need to provide a unique TypeKey.

Examples

public class CarState
{
    public string Color { get; set; }
    public float Acceleration { get; set; }
    public float MaxSpeed { get; set; }

    public class Serializer : IBinarySerializer<CarState>
    {
        public int TypeKey => 0;
        public void Write(IBinaryWriter writer, CarState data)
        {
            writer.WriteString(data.Color);
            writer.WriteFloat(data.Acceleration);
            writer.WriteFloat(data.MaxSpeed);
        }

        public CarState Read(IBinaryReader reader)
        {
            return new CarState
            {
                Color = reader.ReadString(),
                Acceleration = reader.ReadFloat(),
                MaxSpeed = reader.ReadFloat()
            };
        }
    }
}

results matching ""

    No results matching ""