kotlin.ProtocolRegistrationTemplate.kt 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!
class ${protocol_name}Registration : IProtocolRegistration {
override fun protocolId(): Short {
return ${protocol_id}
}
override fun write(buffer: ByteBuffer, packet: Any?) {
if (packet == null) {
buffer.writeInt(0)
return
}
val message = packet as ${protocol_name}
${protocol_write_serialization}
}
override fun read(buffer: ByteBuffer): Any {
val length = buffer.readInt()
val packet = ${protocol_name}()
if (length == 0) {
return packet
}
val beforeReadIndex = buffer.getReadOffset()
${protocol_read_deserialization}
if (length > 0) {
buffer.setReadOffset(beforeReadIndex + length)
}
return packet
}
}