csharp.ProtocolRegistrationTemplate.cs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of protocol Show documentation
Show all versions of protocol Show documentation
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;
}
}