All Downloads are FREE. Search and download functionalities are using the official Maven repository.

csharp.ProtocolRegistrationTemplate.cs Maven / Gradle / Ivy

Go to download

zfoo protocol is binary serialization framework for Java/C++/js/ts/C#/Go/Lua/GDScript/Python

The newest version!
public class ${protocol_name}Registration : IProtocolRegistration
{
    public short ProtocolId()
    {
        return ${protocol_id};
    }

    public void Write(ByteBuffer buffer, object packet)
    {
        if (packet == null)
        {
            buffer.WriteInt(0);
            return;
        }
        ${protocol_name} message = (${protocol_name}) packet;
        ${protocol_write_serialization}
    }

    public object Read(ByteBuffer buffer)
    {
        int length = buffer.ReadInt();
        if (length == 0)
        {
            return null;
        }
        int beforeReadIndex = buffer.GetReadOffset();
        ${protocol_name} packet = new ${protocol_name}();
        ${protocol_read_deserialization}
        if (length > 0)
        {
            buffer.SetReadOffset(beforeReadIndex + length);
        }
        return packet;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy