00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00038 #ifndef BLOCXX_BinarySerialization_HPP_
00039 #define BLOCXX_BinarySerialization_HPP_
00040 #include "blocxx/BLOCXX_config.h"
00041 #include "blocxx/Types.hpp"
00042 #include "blocxx/Bool.hpp"
00043 #include "blocxx/String.hpp"
00044 #include "blocxx/Array.hpp"
00045 #include "blocxx/ByteSwap.hpp"
00046
00047 #if defined(BLOCXX_HAVE_OSTREAM) && defined(BLOCXX_HAVE_ISTREAM)
00048 #include <ostream>
00049 #include <istream>
00050 #else
00051 #include <iostream>
00052 #endif
00053
00054
00055
00056
00057 namespace BLOCXX_NAMESPACE
00058 {
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 const UInt32 BinaryProtocolVersion = 3000008;
00080
00081
00082 const UInt32 MinBinaryProtocolVersion = 3000007;
00083
00084
00085 const UInt8 BIN_OK = 0;
00086 const UInt8 BIN_ERROR = 1;
00087 const UInt8 BIN_EXCEPTION = 2;
00088 const UInt8 IPC_AUTHENTICATE = 10;
00089 const UInt8 IPC_FUNCTIONCALL = 11;
00090 const UInt8 IPC_CLOSECONN = 12;
00091 const UInt8 BIN_DELETECLS = 20;
00092 const UInt8 BIN_DELETEINST = 21;
00093 const UInt8 BIN_DELETEQUAL = 22;
00094 const UInt8 BIN_ENUMCLSS = 23;
00095 const UInt8 BIN_ENUMCLSNAMES = 24;
00096 const UInt8 BIN_ENUMINSTS = 25;
00097 const UInt8 BIN_ENUMINSTNAMES = 26;
00098 const UInt8 BIN_ENUMQUALS = 27;
00099 const UInt8 BIN_GETCLS = 28;
00100 const UInt8 BIN_GETINST = 29;
00101 const UInt8 BIN_INVMETH = 30;
00102 const UInt8 BIN_GETQUAL = 31;
00103 const UInt8 BIN_SETQUAL = 32;
00104 const UInt8 BIN_MODIFYCLS = 33;
00105 const UInt8 BIN_CREATECLS = 34;
00106 const UInt8 BIN_MODIFYINST = 35;
00107 const UInt8 BIN_CREATEINST = 36;
00108 const UInt8 BIN_GETPROP = 37;
00109 const UInt8 BIN_SETPROP = 38;
00110 #ifndef BLOCXX_DISABLE_ASSOCIATION_TRAVERSAL
00111 const UInt8 BIN_ASSOCNAMES = 39;
00112 const UInt8 BIN_ASSOCIATORS = 40;
00113 const UInt8 BIN_REFNAMES = 41;
00114 const UInt8 BIN_REFERENCES = 42;
00115 #endif
00116 const UInt8 BIN_EXECQUERY = 43;
00117 const UInt8 BIN_GETSVRFEATURES = 44;
00118 const UInt8 BINSIG_NS = 100;
00119 const UInt8 BINSIG_OP = 101;
00120 const UInt8 BINSIG_CLS = 102;
00121 const UInt8 BINSIG_INST = 103;
00122 const UInt8 BINSIG_BOOL = 104;
00123 const UInt8 BINSIG_CLSENUM = 105;
00124 const UInt8 BINSIG_STR = 106;
00125 const UInt8 BINSIG_STRARRAY = 107;
00126 const UInt8 BINSIG_QUAL_TYPE = 108;
00127 const UInt8 BINSIG_VALUE = 109;
00128 const UInt8 BINSIG_OPENUM = 110;
00129 const UInt8 BINSIG_INSTENUM = 111;
00130 const UInt8 BINSIG_QUAL_TYPEENUM = 112;
00131 const UInt8 BINSIG_VALUEARRAY = 113;
00132 const UInt8 BINSIG_PARAMVALUEARRAY = 114;
00133 const UInt8 BINSIG_STRINGENUM = 115;
00134 const UInt8 END_CLSENUM = 150;
00135 const UInt8 END_OPENUM = 151;
00136 const UInt8 END_INSTENUM = 152;
00137 const UInt8 END_QUALENUM = 153;
00138 const UInt8 END_STRINGENUM = 154;
00140 namespace BinarySerialization
00141 {
00142 BLOCXX_COMMON_API void write(std::ostream& ostrm, const void* dataOut,
00143 int dataOutLen);
00144 BLOCXX_COMMON_API void verifySignature(std::istream& istrm, UInt8 validSig);
00145 inline void write(std::ostream& ostrm, Int32 val)
00146 {
00147 val = hton32(val);
00148 BinarySerialization::write(ostrm, &val, sizeof(val));
00149 }
00150 inline void write(std::ostream& ostrm, UInt32 val)
00151 {
00152 val = hton32(val);
00153 BinarySerialization::write(ostrm, &val, sizeof(val));
00154 }
00155 BLOCXX_COMMON_API void writeLen(std::ostream& ostrm, UInt32 len);
00156 inline void write(std::ostream& ostrm, UInt8 val)
00157 {
00158 BinarySerialization::write(ostrm, &val, sizeof(val));
00159 }
00160 inline void write(std::ostream& ostrm, UInt16 val)
00161 {
00162 val = hton16(val);
00163 BinarySerialization::write(ostrm, &val, sizeof(val));
00164 }
00165 inline void write(std::ostream& ostrm, Int16 val)
00166 {
00167 val = hton16(val);
00168 BinarySerialization::write(ostrm, &val, sizeof(val));
00169 }
00170 inline void write(std::ostream& ostrm, const String& str)
00171 {
00172 str.writeObject(ostrm);
00173 }
00174 inline void writeBool(std::ostream& ostrm,
00175 Bool arg)
00176 {
00177 BinarySerialization::write(ostrm, BINSIG_BOOL);
00178 arg.writeObject(ostrm);
00179 }
00180 inline void writeString(std::ostream& ostrm, const String& str)
00181 {
00182 BinarySerialization::write(ostrm, BINSIG_STR);
00183 str.writeObject(ostrm);
00184 }
00185 BLOCXX_COMMON_API void readLen(std::istream& istrm, UInt32& len);
00187 template <typename T>
00188 inline void
00189 readArray(std::istream& istr, T& a)
00190 {
00191 a.clear();
00192 UInt32 len;
00193 BinarySerialization::readLen(istr, len);
00194
00195 a.reserve(len);
00196 for (UInt32 i = 0; i < len; i++)
00197 {
00198 typename T::value_type x;
00199 x.readObject(istr);
00200 a.push_back(x);
00201 }
00202
00203 }
00204
00206 template <typename T>
00207 inline void
00208 writeArray(std::ostream& ostrm, const T& a)
00209 {
00210 UInt32 len = static_cast<UInt32>(a.size());
00211 BinarySerialization::writeLen(ostrm, len);
00212 for (UInt32 i = 0; i < len; i++)
00213 {
00214 a.operator[](i).writeObject(ostrm);
00215 }
00216 }
00217 inline void writeStringArray(std::ostream& ostrm,
00218 const StringArray& stra)
00219 {
00220 BinarySerialization::write(ostrm, BINSIG_STRARRAY);
00221 writeArray(ostrm, stra);
00222 }
00223 BLOCXX_COMMON_API void writeStringArray(std::ostream& ostrm,
00224 const StringArray* propertyList);
00225
00226
00227 BLOCXX_COMMON_API void read(std::istream& istrm, void* dataIn, int dataInLen);
00228 inline void read(std::istream& istrm, String& arg)
00229 {
00230 arg.readObject(istrm);
00231 }
00232 inline void read(std::istream& istrm, Int32& val)
00233 {
00234 BinarySerialization::read(istrm, &val, sizeof(val));
00235 val = ntoh32(val);
00236 }
00237 inline void read(std::istream& istrm, UInt32& val)
00238 {
00239 BinarySerialization::read(istrm, &val, sizeof(val));
00240 val = ntoh32(val);
00241 }
00242 inline void read(std::istream& istrm, UInt16& val)
00243 {
00244 BinarySerialization::read(istrm, &val, sizeof(val));
00245 val = ntoh16(val);
00246 }
00247 inline void read(std::istream& istrm, Int16& val)
00248 {
00249 BinarySerialization::read(istrm, &val, sizeof(val));
00250 val = ntoh16(val);
00251 }
00252 inline void read(std::istream& istrm, UInt8& val)
00253 {
00254 BinarySerialization::read(istrm, &val, sizeof(val));
00255 }
00256 inline Bool readBool(std::istream& istrm)
00257 {
00258 BinarySerialization::verifySignature(istrm, BINSIG_BOOL);
00259 Bool b;
00260 b.readObject(istrm);
00261 return b;
00262 }
00263 inline String readString(std::istream& istrm)
00264 {
00265 BinarySerialization::verifySignature(istrm, BINSIG_STR);
00266 String rv;
00267 rv.readObject(istrm);
00268 return rv;
00269 }
00270 inline StringArray readStringArray(std::istream& istrm)
00271 {
00272 BinarySerialization::verifySignature(istrm, BINSIG_STRARRAY);
00273 StringArray stra;
00274 readArray(istrm, stra);
00275 return stra;
00276 }
00277 }
00278
00279 }
00280
00281 #endif // BLOCXX_BinarySerialization_HPP_