2 Copyright 2004-2005 Chris Tallon, Andreas Vogel
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 class SerializeBuffer {
31 //constructor for send buffers
32 SerializeBuffer(ULONG size,bool isMalloc=false,bool autoincrease=false);
33 //constructor for SerializeBuffers with external buffers
34 SerializeBuffer(UCHAR *buffer,ULONG size,bool owning=false,bool isMalloc=true,bool autoincrease=false);
36 //access to bufferpointer
37 UCHAR * getStart(){ return start;}
38 UCHAR * getCurrent(){ return current;}
39 UCHAR * getEnd(){ return end;}
40 //get the buffer and take it away from this object
41 UCHAR * steelBuffer();
42 //seek relative to current
46 //encode/decode functions
47 //always return != 0 on error
48 int encodeLong(ULONG data);
49 int encodeLongLong(ULLONG data);
50 int encodeShort(USHORT data);
51 int encodeString(const char *data);
52 int encodeByte(UCHAR data);
54 int decodeLong(ULONG & data);
55 int decodeLong(int & data);
56 int decodeLongLong(ULLONG & data);
57 int decodeShort(USHORT & data);
58 int decodeString(ULONG &len,char * &data);
59 int decodeByte(UCHAR &data);
70 //check buffer space and enlarge if allowed
71 int checkSpace(int size);
78 virtual ~Serializable();
80 //get the #of bytes needed to serialize
81 int getSerializedLen();
83 //advance buffer, check if >= end
85 int serialize(SerializeBuffer *b);
87 //advance buffer, check if >= end
89 int deserialize(SerializeBuffer *b);
90 //or the received version after deserialize
91 //can be queried with deserializeImpl
94 static int getSerializedStringLen(const char *str);
96 //methods to be overwritten by impl
97 //those methods can use the version info
98 //the length and version is automatically encoded and decoded by the base class
99 virtual int getSerializedLenImpl()=0;
100 virtual int serializeImpl(SerializeBuffer *b)=0;
101 virtual int deserializeImpl(SerializeBuffer *b)=0;
106 * a class for creating a list of serializable parameters
107 * by including a version handling this automatically maintains compatibility
113 * SerializableList myList();
114 * myList.addParam(&myP1);
115 * myList.addParam(&myP2);
116 * //now serialize/deserialize...
117 * //later - second version:
120 * char *myString=NULL;
121 * SerializableList myList();
122 * myList.addParam(&myP1);
123 * myList.addParam(&myP2);
124 * myList.addParam(&myString,2); //this parameter is new in version 2
125 * myList.deserialize(buffer);
126 * if (!myList.isDeserialized(&myString)) {
127 * //we got a version 1 message
128 * myString=strcpy(new char[22],"default-for-myString");
132 class SerializableList : public Serializable{
135 virtual ~SerializableList();
138 * add a parameter to the list
139 * no life cycle handling included
140 * params should be initialized before!
141 * when adding new params after having released a version
142 * add them to the end with a new version - this will automatically maintain
144 * will return !=0 if adding is not possible (e.g. adding with a smaller version)
146 int addParam(Serializable *p,USHORT version=1);
147 int addParam(USHORT *p,USHORT version=1);
148 int addParam(ULONG *p,USHORT version=1);
149 int addParam(ULLONG *p,USHORT version=1);
150 int addParam(char **p,USHORT version=1);
153 * for lists only intended for encoding also
154 * const members will be added
155 * this is fully compatible to non const addParams on the other side
156 * so on the sender side you can use the addParam(const ... ) methods, on the receiver
158 * After having called one of this methods deserialize will always fail!
160 int addParam(const Serializable *p,USHORT vs=1){
162 return addParam((Serializable *)p,vs);
164 int addParam(const USHORT *p,USHORT vs=1){
166 return addParam((USHORT *)p,vs);
168 int addParam(const ULONG *p,USHORT vs=1){
170 return addParam((ULONG *)p,vs);
172 int addParam(const int *p,USHORT vs=1){
174 return addParam((ULONG *)p,vs);
176 int addParam(const ULLONG *p,USHORT vs=1){
178 return addParam((ULLONG *)p,vs);
180 int addParam(const char **p,USHORT vs=1){
182 return addParam((char **)p,vs);
187 * check functions to test if a certain parameter has been filled
190 bool isDeserialized(Serializable *p);
191 bool isDeserialized(USHORT *p);
192 bool isDeserialized(ULONG *p);
193 bool isDeserialized(ULLONG *p);
194 bool isDeserialized(char **p);
196 //return the highest version after adding params
200 virtual int getSerializedLenImpl();
201 virtual int serializeImpl(SerializeBuffer *b);
202 virtual int deserializeImpl(SerializeBuffer *b);
203 bool encodeOnly; //if any addParam(const ...) is called this will be set
227 isDeserialized=false;
230 bool isEqual(void *p,Ptypes t);
232 vector<struct Pentry>list;
233 Pentry *findEntry(void *p,Ptypes t);