Initial commit
This commit is contained in:
46
Include/ZNet/ZNetPacket.hpp
Normal file
46
Include/ZNet/ZNetPacket.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
ZNetPacket.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 6/4/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
ZNet packet class, represents a packet
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETPACKET_HPP
|
||||
#define _ZNETPACKET_HPP
|
||||
|
||||
#include <pstdint.h>
|
||||
|
||||
/*
|
||||
ZNetPacket defines a logical packet that is to be sent or has been received. The data is appended
|
||||
at the end of the structure, so getting the address requires pointer manipulation. It does
|
||||
not represent the wire format of what is sent, since packets may be merged.
|
||||
*/
|
||||
|
||||
struct ZNetPacket
|
||||
{
|
||||
uint32_t dataSize; //< Size of the packet (logically)
|
||||
uint32_t flags; //< The flags. ZNET_TRANSIENT, ZNET_RELIABLE, etc.
|
||||
int32_t refCount; //< Reference count
|
||||
|
||||
uint8_t* GetData() { return (uint8_t*) ((uintptr_t)this + sizeof(ZNetPacket)); }
|
||||
void AddReference() { refCount++; }
|
||||
void ReleaseReference()
|
||||
{
|
||||
refCount--;
|
||||
if(refCount == 0)
|
||||
free(this);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user