]> git.stg.codes - stg.git/blob - stglibs/sgcp.lib/packet.h
f5a4374e9f22ba62c0855f3d79739ed1d9e82e61
[stg.git] / stglibs / sgcp.lib / packet.h
1 #ifndef __STG_SGCP_PACKET_H__
2 #define __STG_SGCP_PACKET_H__
3
4 /*
5  *    This program is free software; you can redistribute it and/or modify
6  *    it under the terms of the GNU General Public License as published by
7  *    the Free Software Foundation; either version 2 of the License, or
8  *    (at your option) any later version.
9  *
10  *    This program is distributed in the hope that it will be useful,
11  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *    GNU General Public License for more details.
14  *
15  *    You should have received a copy of the GNU General Public License
16  *    along with this program; if not, write to the Free Software
17  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 /*
21  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
22  */
23
24 #include <boost/stdint.hpp>
25
26 namespace STG
27 {
28 namespace SGCP
29 {
30
31 struct __attribute__ ((__packed__)) Packet
32 {
33     Packet(uint16_t type, uint16_t size);
34
35     bool valid() const { return magic == MAGIC; }
36
37     static uint64_t MAGIC;
38     static uint16_t VERSION;
39
40     enum Types { PING, PONG, DATA };
41
42     uint64_t magic;
43     uint64_t senderTime;
44     uint16_t version;
45     uint16_t type;
46     uint32_t size;
47 };
48
49 Packet hton(Packet value);
50
51 } // namespace SGCP
52 } // namespace STG
53
54 #endif