mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-24 23:37:07 +00:00
29 lines
839 B
C++
29 lines
839 B
C++
class ${protocol_name}Registration : public IProtocolRegistration {
|
|
public:
|
|
int16_t protocolId() override {
|
|
return ${protocol_id};
|
|
}
|
|
|
|
void write(ByteBuffer &buffer, IProtocol *packet) override {
|
|
if (packet == nullptr) {
|
|
buffer.writeInt(0);
|
|
return;
|
|
}
|
|
auto *message = (${protocol_name} *) packet;
|
|
${protocol_write_serialization}
|
|
}
|
|
|
|
IProtocol *read(ByteBuffer &buffer) override {
|
|
auto *packet = new ${protocol_name}();
|
|
auto length = buffer.readInt();
|
|
if (length == 0) {
|
|
return packet;
|
|
}
|
|
auto beforeReadIndex = buffer.getReaderOffset();
|
|
${protocol_read_deserialization}
|
|
if (length > 0) {
|
|
buffer.setReaderOffset(beforeReadIndex + length);
|
|
}
|
|
return packet;
|
|
}
|
|
}; |