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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 class SerializeBuffer {
32 //constructor for send buffers
33 SerializeBuffer(ULONG size,bool isMalloc=false,bool autoincrease=false);
34 //constructor for SerializeBuffers with external buffers
35 SerializeBuffer(UCHAR *buffer,ULONG size,bool owning=false,bool isMalloc=true,bool autoincrease=false);
37 //access to bufferpointer
38 UCHAR * getStart(){ return start;}
39 UCHAR * getCurrent(){ return current;}
40 UCHAR * getEnd(){ return end;}
41 //get the buffer and take it away from this object
42 UCHAR * steelBuffer();
43 //seek relative to current
47 //encode/decode functions
48 //always return != 0 on error
49 int encodeLong(ULONG data);
50 int encodeLongLong(ULLONG data);
51 int encodeShort(USHORT data);
52 int encodeString(const char *data);
53 int encodeByte(UCHAR data);
55 int decodeLong(ULONG & data);
56 int decodeLong(int & data);
57 int decodeLongLong(ULLONG & data);
58 int decodeShort(USHORT & data);
59 int decodeString(ULONG &len,char * &data);
60 int decodeByte(UCHAR &data);
71 //check buffer space and enlarge if allowed
72 int checkSpace(int size);
79 virtual ~Serializable();
81 //get the #of bytes needed to serialize
82 int getSerializedLen();
84 //advance buffer, check if >= end
86 int serialize(SerializeBuffer *b);
88 //advance buffer, check if >= end
90 int deserialize(SerializeBuffer *b);
91 //or the received version after deserialize
92 //can be queried with deserializeImpl
95 static int getSerializedStringLen(const char *str);
97 //methods to be overwritten by impl
98 //those methods can use the version info
99 //the length and version is automatically encoded and decoded by the base class
100 virtual int getSerializedLenImpl()=0;
101 virtual int serializeImpl(SerializeBuffer *b)=0;
102 virtual int deserializeImpl(SerializeBuffer *b)=0;
107 * a class for creating a list of serializable parameters
108 * by including a version handling this automatically maintains compatibility
114 * SerializableList myList();
115 * myList.addParam(&myP1);
116 * myList.addParam(&myP2);
117 * //now serialize/deserialize...
118 * //later - second version:
121 * char *myString=NULL;
122 * SerializableList myList();
123 * myList.addParam(&myP1);
124 * myList.addParam(&myP2);
125 * myList.addParam(&myString,2); //this parameter is new in version 2
126 * myList.deserialize(buffer);
127 * if (!myList.isDeserialized(&myString)) {
128 * //we got a version 1 message
129 * myString=strcpy(new char[22],"default-for-myString");
133 class SerializableList : public Serializable{
136 virtual ~SerializableList();
139 * add a parameter to the list
140 * no life cycle handling included
141 * params should be initialized before!
142 * when adding new params after having released a version
143 * add them to the end with a new version - this will automatically maintain
145 * will return !=0 if adding is not possible (e.g. adding with a smaller version)
147 int addParam(Serializable *p,USHORT version=1);
148 int addParam(USHORT *p,USHORT version=1);
149 int addParam(ULONG *p,USHORT version=1);
150 int addParam(ULLONG *p,USHORT version=1);
151 int addParam(char **p,USHORT version=1);
154 * for lists only intended for encoding also
155 * const members will be added
156 * this is fully compatible to non const addParams on the other side
157 * so on the sender side you can use the addParam(const ... ) methods, on the receiver
159 * After having called one of this methods deserialize will always fail!
161 int addParam(const Serializable *p,USHORT vs=1){
163 return addParam((Serializable *)p,vs);
165 int addParam(const USHORT *p,USHORT vs=1){
167 return addParam((USHORT *)p,vs);
169 int addParam(const ULONG *p,USHORT vs=1){
171 return addParam((ULONG *)p,vs);
173 int addParam(const int *p,USHORT vs=1){
175 return addParam((ULONG *)p,vs);
177 int addParam(const ULLONG *p,USHORT vs=1){
179 return addParam((ULLONG *)p,vs);
181 int addParam(const char **p,USHORT vs=1){
183 return addParam((char **)p,vs);
188 * check functions to test if a certain parameter has been filled
191 bool isDeserialized(Serializable *p);
192 bool isDeserialized(USHORT *p);
193 bool isDeserialized(ULONG *p);
194 bool isDeserialized(ULLONG *p);
195 bool isDeserialized(char **p);
197 //return the highest version after adding params
201 virtual int getSerializedLenImpl();
202 virtual int serializeImpl(SerializeBuffer *b);
203 virtual int deserializeImpl(SerializeBuffer *b);
204 bool encodeOnly; //if any addParam(const ...) is called this will be set
228 isDeserialized=false;
231 bool isEqual(void *p,Ptypes t);
233 std::vector<struct Pentry>list;
234 Pentry *findEntry(void *p,Ptypes t);