Created
June 8, 2011 19:02
-
-
Save Kronos11/1015097 to your computer and use it in GitHub Desktop.
BaseANHPacket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> | |
struct BaseANHPacket { | |
// header | |
uint16_t priority; | |
uint32_t time_stamp; | |
uint32_t process_id; | |
void serialize(anh::ByteBuffer& buffer) const { | |
buffer.write(priority); | |
buffer.write(time_stamp); | |
buffer.write(T::type()); | |
buffer.write(process_id); | |
onSerialize(buffer); | |
} | |
void deserialize(anh::ByteBuffer buffer) { | |
priority = buffer.read<uint16_t>(); | |
time_stamp = buffer.read<uint32_t>(); | |
anh::HashString type = buffer.read<anh::HashString>(); | |
process_id = buffer.read<uint32_t>(); | |
if (type != T::type()) | |
{ | |
return; | |
} | |
onDeserialize(std::move(buffer)); | |
} | |
virtual void onSerialize(anh::ByteBuffer& buffer) const = 0; | |
virtual void onDeserialize(anh::ByteBuffer buffer) = 0; | |
}; | |
struct NetworkEventMessage : public BaseANHPacket<NetworkEventMessage> { | |
static anh::HashString type() { return anh::HashString("NetworkEventMessage"); } | |
void onDeserialize(anh::ByteBuffer buffer) { | |
} | |
void onSerialize(anh::ByteBuffer& buffer) const { | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment