15 #include "networkmod.h" 18 #define mRequestPacketHeaderSize 10 42 RequestPacket(
od_int32 payloadsize=0);
48 bool isError()
const {
return subID()==cErrorSubID(); }
50 const void* payload()
const;
55 int setIsNewRequest();
61 void setPayload(
void*,
od_int32 size);
62 void setStringPayload(
const char*);
68 static void setSystemSizeLimit(
od_int32);
99 static od_int32 getPayloadSize(
const void*);
101 void* payload(
bool takeover=
false);
120 , curpos_(startpos) {}
122 # define mNPFSizeFor(v) Network::PacketFiller::sizeFor(v) 123 # define mNPFSizeForArr(a,s) Network::PacketFiller::sizeFor(a,s) 125 static int sizeFor(
const T&);
127 static int sizeFor(
const T*,
int nrelems,
bool rawmode=
false);
128 static int sizeFor(
bool);
129 static int sizeFor(
const char*);
133 template <
class T>
const PacketFiller&
135 template <
class T>
const PacketFiller&
136 put(
const T*,
int nrelems,
bool rawmode=
false)
const;
137 const PacketFiller& put(
const char*)
const;
138 const PacketFiller& put(
bool)
const;
139 const PacketFiller& put(
const OD::String&)
const;
142 const PacketFiller& putBytes(
const void*,
int nrbytes)
const;
165 , curpos_(startpos) {}
167 template <
class T>
void get(T&)
const;
168 inline bool getBool()
const;
169 inline int getInt()
const;
170 inline float getFloat()
const;
171 inline double getDouble()
const;
174 template <
class T>
void getArr(T*,
int maxsz,
bool rawmode=
false)
const;
175 template <
class T>
void getSet(
TypeSet<T>&,
int maxsz=-1,
176 bool rawmode=
false)
const;
179 inline void move(
int nrb )
const { curpos_ += nrb; }
180 inline void moveTo(
int pos )
const { curpos_ = pos; }
181 template <
class T>
void peek(T&)
const;
182 inline int peekInt()
const;
183 void getBytes(
void*,
int nrbytes)
const;
185 inline bool atEndOfPkt()
const;
202 return sizeFor( ((
int)var) );
208 return (rawmode ? 0 :
sizeof(
int)) + nrelems *
sizeof(T);
218 return sizeof(int) + str.
size();
223 int ret =
sizeof(int);
224 for (
int idx=0; idx<bss.
size(); idx++ )
225 ret += sizeFor( bss.
get(idx) );
232 const int toput = var ? 1 : 0;
240 return putBytes( &var,
sizeof(T) );
249 return putBytes( arr, nrelems *
sizeof(T) );
259 const int sz = str.
size();
261 return putBytes( str.
str(), sz );
266 const int sz = bss.
size();
268 for (
int idx=0; idx<sz; idx++ )
278 OD::memCopy( pkt_.payload_+curpos_, ptr, sz );
290 OD::memCopy( &var, pkt_.payload_+curpos_,
sizeof(T) );
296 getBytes( &var,
sizeof(T) );
306 {
pErrMsg(
"Invalid string size"); }
312 getBytes( cstr, sz );
317 {
int ret = 0; peek(ret);
return ret; }
319 {
int ret = 0;
get(ret);
return ret != 0; }
321 {
int ret = 0;
get(ret);
return ret; }
323 {
float ret = 0.f;
get(ret);
return ret; }
325 {
double ret = 0.;
get(ret);
return ret; }
341 getBytes( arr, sz*
sizeof(T) );
352 if ( maxsz >= 0 && sz > maxsz )
358 getBytes( ts.
arr(), sz*
sizeof(T) );
364 int setsz;
get( setsz );
366 if ( maxsz >= 0 && sz > maxsz )
372 for (
int idx=0; idx<sz; idx++ )
379 for (
int idx=sz; idx<setsz; idx++ )
387 OD::memCopy( ptr, pkt_.payload_+curpos_, nrbytes );
393 {
return curpos_ >= pkt_.payloadSize(); }
static od_int32 headerSize()
Definition: netreqpacket.h:98
#define mExpClass(module)
Definition: commondefs.h:160
Header header_
Definition: netreqpacket.h:79
BufferString getString() const
Definition: netreqpacket.h:326
static od_int16 cMoreSubID()
Definition: netreqpacket.h:83
RequestPacket & pkt_
Definition: netreqpacket.h:146
void move(int nrb) const
Definition: netreqpacket.h:179
static int sizeFor(const T &)
Definition: netreqpacket.h:196
void peek(T &) const
Definition: netreqpacket.h:288
PacketFiller(RequestPacket &p, int startpos=0)
Definition: netreqpacket.h:118
const char * str() const
Definition: odstring.h:48
Definition: jobcommunic.h:24
int curpos_
Definition: netreqpacket.h:147
OD::String that holds an existing text string.
Definition: fixedstring.h:29
void setIsLast()
Definition: netreqpacket.h:58
const PacketFiller & putBytes(const void *, int nrbytes) const
Definition: netreqpacket.h:273
BufferString & setEmpty()
int curpos_
Definition: netreqpacket.h:190
#define mRequestPacketHeaderSize
Definition: netreqpacket.h:18
Set of BufferString objects.
Definition: bufstringset.h:28
void getArr(T *, int maxsz, bool rawmode=false) const
Definition: netreqpacket.h:330
unsigned int size() const
Definition: netreqpacket.h:39
char * payload_
Definition: netreqpacket.h:80
bool atEndOfPkt() const
Definition: netreqpacket.h:392
virtual T * arr()
3rd party access
Definition: typeset.h:92
size_type size() const
Definition: objectset.h:50
const void * getRawHeader() const
Definition: netreqpacket.h:105
bool setBufSize(unsigned int)
Set of (small) copyable elements.
Definition: commontypes.h:30
static od_int16 cBeginSubID()
Definition: netreqpacket.h:82
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:31
bool isError() const
Definition: netreqpacket.h:48
void setEmpty()
Definition: odset.h:46
bool isNewRequest() const
Definition: netreqpacket.h:46
void * getRawHeader()
Definition: netreqpacket.h:104
void getBytes(void *, int nrbytes) const
Definition: netreqpacket.h:383
int peekInt() const
Definition: netreqpacket.h:316
void setIsError()
Definition: netreqpacket.h:57
#define od_int16
Definition: plftypes.h:27
const PacketFiller & put(const T &) const
Definition: netreqpacket.h:238
int getInt() const
Definition: netreqpacket.h:320
float getFloat() const
Definition: netreqpacket.h:322
Definition: netreqpacket.h:115
#define od_int32
Definition: plftypes.h:31
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
const RequestPacket & pkt_
Definition: netreqpacket.h:189
void get(T &) const
Definition: netreqpacket.h:294
bool getBool() const
Definition: netreqpacket.h:318
void moveTo(int pos) const
Definition: netreqpacket.h:180
bool isRequestEnd() const
Definition: netreqpacket.h:47
virtual bool setSize(size_type, T val=T())
void getSet(TypeSet< T > &, int maxsz=-1, bool rawmode=false) const
Definition: netreqpacket.h:345
BufferString & get(int idx)
Definition: bufstringset.h:36
static od_int16 cEndSubID()
Definition: netreqpacket.h:84
#define pErrMsg(msg)
Definition: errmsg.h:60
double getDouble() const
Definition: netreqpacket.h:324
static od_int16 cErrorSubID()
Definition: netreqpacket.h:85
char * getCStr()
Definition: bufstring.h:75
od_int32 totalSize() const
Definition: netreqpacket.h:52
PacketInterpreter(const RequestPacket &p, int startpos=0)
Definition: netreqpacket.h:162
Definition: netreqpacket.h:159