An Overlay-based
Virtual Network Substrate
SpoVNet

source: source/ariba/DataMessage.h @ 7497

Last change on this file since 7497 was 7497, checked in by Christoph Mayer, 14 years ago
File size: 1.9 KB
Line 
1#ifndef DATAMESSAGE_H_
2#define DATAMESSAGE_H_
3
4#define USE_MESSAGE_UTILITY
5
6#include <memory>
7#include <inttypes.h>
8
9// use message utility
10#ifdef USE_MESSAGE_UTILITY
11  #include "ariba/utility/messages.h"
12  namespace ariba {
13    typedef utility::Message Message;
14  }
15#endif
16
17namespace ariba {
18
19// define sequence number type
20typedef uint16_t seqnum_t;
21
22/**
23 * This class wraps different representations of a message. In its current
24 * version is allows to specify binary data (as void*) with a size specifying
25 * the number of bytes of data or an message object that can be
26 * serialized if necessary. The main idea is, that simulation environments
27 * do not necessarily need to serialize messages.
28 *
29 * For performance reasons methods of this class are inlined where possible!
30 *
31 * @author Sebastian Mies <mies@tm.uka.de>
32 */
33class DataMessage {
34private:
35        void* data;
36        size_t size;
37public:
38        static const DataMessage UNSPECIFIED;
39
40        inline DataMessage() {
41                this->data = NULL;
42                this->size = 0;
43        }
44
45        inline DataMessage( const void* data, const size_t size ) {
46                this->data = const_cast<void*>(data);
47                this->size = size;
48        }
49
50        inline DataMessage(const DataMessage& message){
51                this->data = message.data;
52                this->size = message.size;
53        }
54
55#ifdef USE_MESSAGE_UTILITY
56        inline DataMessage( const Message* message ) {
57                this->data = (void*)const_cast<Message*>(message);
58                this->size = ~0;
59        }
60
61        inline DataMessage( const Message& message ) {
62                this->data = (void*)const_cast<Message*>(&message);
63                this->size = ~0;
64        }
65
66        inline Message* getMessage() const {
67                return (Message*)data;
68        }
69
70        inline operator Message* () const {
71                return (Message*)data;
72        }
73#endif
74
75        inline bool isMessage() const {
76                return size >= 0;
77        }
78
79        inline bool isData() const {
80                return size == ~(size_t)0;
81        }
82
83        inline void* getData() const {
84                return data;
85        }
86
87        inline size_t getSize() const {
88                return size;
89        }
90
91        inline bool isUnspecified() const {
92                return data == NULL;
93        }
94};
95
96} // namespace ariba
97
98#endif /* DATAMESSAGE_H_ */
Note: See TracBrowser for help on using the repository browser.