Start moving protocol-specific code to protocol.[ch]pp
[novacoin.git] / src / protocol.h
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2011 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
5
6 #ifndef __cplusplus
7 # error This header can only be compiled as C++.
8 #endif
9
10 #ifndef __INCLUDED_PROTOCOL_H__
11 #define __INCLUDED_PROTOCOL_H__
12
13 #include "serialize.h"
14 #include <string>
15
16 //
17 // Message header
18 //  (4) message start
19 //  (12) command
20 //  (4) size
21 //  (4) checksum
22
23 extern unsigned char pchMessageStart[4];
24
25 class CMessageHeader
26 {
27     public:
28         CMessageHeader();
29         CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
30
31         std::string GetCommand() const;
32         bool IsValid() const;
33
34         IMPLEMENT_SERIALIZE
35             (
36              READWRITE(FLATDATA(pchMessageStart));
37              READWRITE(FLATDATA(pchCommand));
38              READWRITE(nMessageSize);
39              if (nVersion >= 209)
40              READWRITE(nChecksum);
41             )
42
43     // TODO: make private (improves encapsulation)
44     public:
45         enum { COMMAND_SIZE=12 };
46         char pchMessageStart[sizeof(::pchMessageStart)];
47         char pchCommand[COMMAND_SIZE];
48         unsigned int nMessageSize;
49         unsigned int nChecksum;
50 };
51
52 #endif // __INCLUDED_PROTOCOL_H__