golang.ProtocolRegistrationTemplate.go 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!
func (protocol ${protocol_name}) ProtocolId() int16 {
return ${protocol_id}
}
func (protocol ${protocol_name}) write(buffer *ByteBuffer, packet any) {
if packet == nil {
buffer.WriteInt(0)
return
}
var message = packet.(*${protocol_name})
${protocol_write_serialization}
}
func (protocol ${protocol_name}) read(buffer *ByteBuffer) any {
var packet = new(${protocol_name})
var length = buffer.ReadInt()
if length == 0 {
return packet
}
var beforeReadIndex = buffer.GetReadOffset()
${protocol_read_deserialization}
if length > 0 {
buffer.SetReadOffset(beforeReadIndex + length)
}
return packet
}