aboutsummaryrefslogtreecommitdiff
path: root/cvs/cvsweb.cgi/code/nel/src/net/message.cpp?rev=1.21&content-type=text/x-cvsweb-markup&sortby=date/index.html
blob: 0f2922b28cbe10805b5395f10beb834a95ce8005 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
<HEAD><style>		A { color:black }</style>
<!-- hennerik CVSweb $Revision: 1.93 $ -->
<TITLE>code/nel/src/net/message.cpp - view - 1.21</TITLE></HEAD>
<BODY BGCOLOR="#eeeeee">
<table width="100%" border=0 cellspacing=0 cellpadding=1 bgcolor="#aaaaaa"><tr valign=bottom><td><a href="message.cpp?sortby=date"><IMG SRC="http://www.nevrax.org/inc/img/picto-up.gif" ALT="[BACK]" BORDER="0" WIDTH="14" HEIGHT="13"></a> <b>Return to <A HREF="message.cpp?sortby=date">message.cpp</A>
 CVS log</b> <IMG SRC="http://www.nevrax.org/inc/img/picto-news.gif" ALT="[TXT]" BORDER="0" WIDTH="13" HEIGHT="15"></td><td align=right><IMG SRC="http://www.nevrax.org/inc/img/picto-dir.gif" ALT="[DIR]" BORDER="0" WIDTH="15" HEIGHT="13"> <b>Up to  <a href="/cvs/cvsweb.cgi/?sortby=date">Nevrax</a> / <a href="/cvs/cvsweb.cgi/code/?sortby=date">code</a> / <a href="/cvs/cvsweb.cgi/code/nel/?sortby=date">nel</a> / <a href="/cvs/cvsweb.cgi/code/nel/src/?sortby=date">src</a> / <a href="/cvs/cvsweb.cgi/code/nel/src/net/?sortby=date">net</a></b></td></tr></table><HR noshade><table width="100%"><tr><td bgcolor="#ffffff">File:  <a href="/cvs/cvsweb.cgi/?sortby=date">Nevrax</a> / <a href="/cvs/cvsweb.cgi/code/?sortby=date">code</a> / <a href="/cvs/cvsweb.cgi/code/nel/?sortby=date">nel</a> / <a href="/cvs/cvsweb.cgi/code/nel/src/?sortby=date">src</a> / <a href="/cvs/cvsweb.cgi/code/nel/src/net/?sortby=date">net</a> / <a href="/cvs/cvsweb.cgi/code/nel/src/net/message.cpp?sortby=date">message.cpp</a>&nbsp;(<A HREF="/cvs/cvsweb.cgi/~checkout~/code/nel/src/net/message.cpp?rev=1.21&amp;sortby=date" target="cvs_checkout" onClick="window.open('/cvs/cvsweb.cgi/~checkout~/code/nel/src/net/message.cpp?rev=1.21','cvs_checkout','resizeable,scrollbars');"><b>download</b></A>)<BR>
Revision <B>1.21</B>, <i>Wed Jul 10 17:08:24 2002 UTC</i> (2 weeks, 4 days ago) by <i>lecroart</i>
<BR>Branch: <b>MAIN</b>
<BR>CVS Tags: <b>HEAD</b><BR>Changes since <b>1.20: +2 -2
 lines</b><PRE>
REMOVE: a warning
</PRE>
</td></tr></table><HR noshade><PRE>/** \file message.cpp
 * CMessage class
 *
 * $Id: message.cpp,v 1.21 2002/07/10 17:08:24 lecroart Exp $
 */

/* Copyright, 2000 Nevrax Ltd.
 *
 * This file is part of NEVRAX NEL.
 * NEVRAX NEL is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.

 * NEVRAX NEL is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with NEVRAX NEL; see the file COPYING. If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 */

#include &quot;stdnet.h&quot;

#include &quot;nel/net/message.h&quot;

/*#ifdef MESSAGES_PLAIN_TEXT
#pragma message( &quot;CMessage: compiling messages as plain text&quot; )
#else
#pragma message( &quot;CMessage: compiling messages as binary&quot; )
#endif*/

namespace NLNET
{

bool CMessage::_DefaultStringMode = false;


#define FormatLong 1
#define FormatShort 0


CMessage::CMessage (NLMISC::CStringIdArray &amp;sida, const std::string &amp;name, bool inputStream, TStreamFormat streamformat, uint32 defaultCapacity) :
 &nbsp; &nbsp; &nbsp; &nbsp;NLMISC::CMemStream (inputStream, false, defaultCapacity),
 &nbsp; &nbsp; &nbsp; &nbsp;_TypeSet (false), _SIDA (&amp;sida), _HeaderSize(0xFFFFFFFF)
{
 &nbsp; &nbsp; &nbsp; &nbsp;init( name, streamformat );
}

CMessage::CMessage (const std::string &amp;name, bool inputStream, TStreamFormat streamformat, uint32 defaultCapacity) :
 &nbsp; &nbsp; &nbsp; &nbsp;NLMISC::CMemStream (inputStream, false, defaultCapacity),
 &nbsp; &nbsp; &nbsp; &nbsp;_TypeSet (false), _SIDA (NULL), _HeaderSize(0xFFFFFFFF)
{
 &nbsp; &nbsp; &nbsp; &nbsp;init( name, streamformat );
}


/*
 * Utility method
 */
void CMessage::init( const std::string &amp;name, TStreamFormat streamformat )
{
 &nbsp; &nbsp; &nbsp; &nbsp;if ( streamformat == UseDefault )
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setStringMode( _DefaultStringMode );
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;else
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setStringMode( streamformat == String );
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;if (!name.empty())
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setType (name);
}


CMessage::CMessage (NLMISC::CMemStream &amp;memstr) :
 &nbsp; &nbsp; &nbsp; &nbsp;_HeaderSize(0xFFFFFFFF)
{
 &nbsp; &nbsp; &nbsp; &nbsp;fill (memstr.buffer (), memstr.length ());
 &nbsp; &nbsp; &nbsp; &nbsp;uint8 LongFormat=2;
 &nbsp; &nbsp; &nbsp; &nbsp;serial (LongFormat);

 &nbsp; &nbsp; &nbsp; &nbsp;if (LongFormat)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::string name;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (name);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setType (name);
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;else
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NLMISC::CStringIdArray::TStringId id;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (id);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setType (id);
 &nbsp; &nbsp; &nbsp; &nbsp;}
}


/// Copy constructor
CMessage::CMessage (const CMessage &amp;other)
{
 &nbsp; &nbsp; &nbsp; &nbsp;operator= (other);
}

/// Assignment operator
CMessage &amp;CMessage::operator= (const CMessage &amp;other)
{
 &nbsp; &nbsp; &nbsp; &nbsp;CMemStream::operator= (other);
 &nbsp; &nbsp; &nbsp; &nbsp;_TypeSet = other._TypeSet;
 &nbsp; &nbsp; &nbsp; &nbsp;_SIDA = other._SIDA;
 &nbsp; &nbsp; &nbsp; &nbsp;TypeHasAnId = other.TypeHasAnId;
 &nbsp; &nbsp; &nbsp; &nbsp;TypeHasAName = other.TypeHasAName;
 &nbsp; &nbsp; &nbsp; &nbsp;_Name = other._Name;
 &nbsp; &nbsp; &nbsp; &nbsp;_Id = other._Id;
 &nbsp; &nbsp; &nbsp; &nbsp;_HeaderSize = other._HeaderSize;
 &nbsp; &nbsp; &nbsp; &nbsp;return *this;

}

/// Sets the message type as a number (in range 0..32767) and put it in the buffer if we are in writing mode
void CMessage::setType (NLMISC::CStringIdArray::TStringId id)
{
 &nbsp; &nbsp; &nbsp; &nbsp;// PATCH: the id system is not available
 &nbsp; &nbsp; &nbsp; &nbsp;nlstop;

 &nbsp; &nbsp; &nbsp; &nbsp;// check if we already do a setType ()
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (!_TypeSet);
 &nbsp; &nbsp; &nbsp; &nbsp;// don't accept negative value
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (id &gt;= 0 &amp;&amp; id &lt; pow(2, sizeof (NLMISC::CStringIdArray::TStringId)*8));

 &nbsp; &nbsp; &nbsp; &nbsp;_Id = id;
 &nbsp; &nbsp; &nbsp; &nbsp;TypeHasAnId = true;
 &nbsp; &nbsp; &nbsp; &nbsp;TypeHasAName = false;

 &nbsp; &nbsp; &nbsp; &nbsp;if (!isReading ())
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// check if they don't already serial some stuffs
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlassert (length () == 0);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uint8 format = FormatLong | (_StringMode &lt;&lt; 1);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlinfo( &quot;OUT format = %hu&quot;, (uint16)format );

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Force binary mode for header
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bool msgmode = _StringMode;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_StringMode = false;

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// debug features, we number all packet to be sure that they are all sent and received
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// \todo remove this debug feature when ok
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// this value will be fill after in the callback function
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uint32 zeroValue = 123;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (zeroValue);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (format);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// End of binary header
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_StringMode = msgmode;

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (id);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_HeaderSize = getPos ();
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;else
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// we set the id, now, we try to set the name if available in the sida
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (_SIDA != NULL)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_Name = _SIDA-&gt;getString (id);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TypeHasAName = true;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;_TypeSet = true;
}

/// Sets the message type as a string and put it in the buffer if we are in writing mode
void CMessage::setType (const std::string &amp;name)
{
 &nbsp; &nbsp; &nbsp; &nbsp;// check if we already do a setType ()
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (!_TypeSet);
 &nbsp; &nbsp; &nbsp; &nbsp;// don't accept empty string
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (!name.empty ());

 &nbsp; &nbsp; &nbsp; &nbsp;_Name = name;
 &nbsp; &nbsp; &nbsp; &nbsp;TypeHasAnId = false;
 &nbsp; &nbsp; &nbsp; &nbsp;TypeHasAName = true;

 &nbsp; &nbsp; &nbsp; &nbsp;if (!isReading ())
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// check if they don't already serial some stuffs
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nlassert (length () == 0);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// if we can send the id instead of the string, &quot;just do it&quot; (c)nike!
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//NLMISC::CStringIdArray::TStringId id = _SIDA-&gt;getId (name);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// PATCH: always send in full text
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NLMISC::CStringIdArray::TStringId id = -1;

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Force binary mode for header
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bool msgmode = _StringMode;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_StringMode = false;

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// debug features, we number all packet to be sure that they are all sent and received
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// \todo remove this debug feature when ok
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// this value will be fill after in the callback function
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uint32 zeroValue = 123;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (zeroValue);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (id == -1)
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uint8 format = FormatLong | (msgmode &lt;&lt; 1);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//nldebug( &quot;OUT format = %hu&quot;, (uint16)format );
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (format);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// End of binary header
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_StringMode = msgmode;

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial ((std::string&amp;)name);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uint8 format = FormatShort | (msgmode &lt;&lt; 1);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//nldebug( &quot;OUT format = %hu&quot;, (uint16)format );
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (format);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// End of binary header
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_StringMode = msgmode;

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (id);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_Id = id;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TypeHasAnId = true;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_HeaderSize = getPos ();
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;_TypeSet = true;
}

/// Returns the size, in byte of the header that contains the type name of the message or the type number
uint32 CMessage::getHeaderSize ()
{
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (!isReading ());
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (_HeaderSize != 0xFFFFFFFF);
 &nbsp; &nbsp; &nbsp; &nbsp;return _HeaderSize;
}

// The message was filled with an CMemStream, Now, we'll get the message type on this buffer
void CMessage::readType ()
{
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (isReading ());

 &nbsp; &nbsp; &nbsp; &nbsp;// debug features, we number all packet to be sure that they are all sent and received
 &nbsp; &nbsp; &nbsp; &nbsp;// \todo remove this debug feature when ok

 &nbsp; &nbsp; &nbsp; &nbsp;// we remove the message from the message
 &nbsp; &nbsp; &nbsp; &nbsp;const uint HeaderSize = 4;
 &nbsp; &nbsp; &nbsp; &nbsp;seek (HeaderSize, begin);
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uint32 zeroValue;
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (zeroValue);

 &nbsp; &nbsp; &nbsp; &nbsp;// Force binary mode for header
 &nbsp; &nbsp; &nbsp; &nbsp;_StringMode = false;

 &nbsp; &nbsp; &nbsp; &nbsp;uint8 format;
 &nbsp; &nbsp; &nbsp; &nbsp;serial (format);
 &nbsp; &nbsp; &nbsp; &nbsp;//nldebug( &quot;IN format = %hu&quot;, (uint16)format );
 &nbsp; &nbsp; &nbsp; &nbsp;bool LongFormat = (format &amp; 1);

 &nbsp; &nbsp; &nbsp; &nbsp;// Set mode for the following of the buffer
 &nbsp; &nbsp; &nbsp; &nbsp;_StringMode = (format &gt;&gt; 1) &amp; 1;
 &nbsp; &nbsp; &nbsp; &nbsp;if (LongFormat)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::string name;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (name);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setType (name);
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;else
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NLMISC::CStringIdArray::TStringId id;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;serial (id);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setType (id);
 &nbsp; &nbsp; &nbsp; &nbsp;}
}

// Returns true if the message type was already set
bool CMessage::typeIsSet () const
{
 &nbsp; &nbsp; &nbsp; &nbsp;return _TypeSet;
}

// Clear the message. With this function, you can reuse a message to create another message
void CMessage::clear ()
{
 &nbsp; &nbsp; &nbsp; &nbsp;CMemStream::clear ();
 &nbsp; &nbsp; &nbsp; &nbsp;_TypeSet = false;
}

/// Returns the type name in string if available. Be sure that the message have the name of the message type
std::string CMessage::getName () const
{
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (_TypeSet &amp;&amp; TypeHasAName);
 &nbsp; &nbsp; &nbsp; &nbsp;return _Name;
}

/// Returns the type id of this message is available.
NLMISC::CStringIdArray::TStringId CMessage::getId () const
{
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (_TypeSet &amp;&amp; TypeHasAnId);
 &nbsp; &nbsp; &nbsp; &nbsp;return _Id;
}

/** Returns a readable string to display it to the screen. It's only for debugging purpose!
 * Don't use it for anything else than to debugging, the string format could change in the futur
 */
std::string CMessage::toString () const
{
 &nbsp; &nbsp; &nbsp; &nbsp;nlassert (_TypeSet);
 &nbsp; &nbsp; &nbsp; &nbsp;std::stringstream s;
 &nbsp; &nbsp; &nbsp; &nbsp;if (TypeHasAName &amp;&amp; TypeHasAnId) s &lt;&lt; &quot;('&quot; &lt;&lt; _Name &lt;&lt; &quot;',&quot; &lt;&lt; _Id &lt;&lt; &quot;)&quot;;
 &nbsp; &nbsp; &nbsp; &nbsp;else if (TypeHasAName) s &lt;&lt; &quot;('&quot; &lt;&lt; _Name &lt;&lt; &quot;',&quot; &lt;&lt; _SIDA-&gt;getId (_Name, true) &lt;&lt; &quot;)&quot;;
 &nbsp; &nbsp; &nbsp; &nbsp;else if (TypeHasAnId) s &lt;&lt; &quot;('&quot; &lt;&lt; _SIDA-&gt;getString (_Id) &lt;&lt; &quot;',&quot; &lt;&lt; _Id &lt;&lt; &quot;')&quot;;
 &nbsp; &nbsp; &nbsp; &nbsp;return s.str();
}



}
</PRE>