00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef OTCODEC_H
00013 #define OTCODEC_H
00014
00015
00016 #include "ot_lib.h"
00017
00018
00019
00020
00021 #define MAX_CODEC_NAME_LEN 20
00022
00023
00024
00025 #define OT_MAGIC_STRING "OT_BYNARY_STREAM"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00084
00085
00086
00087 class ot_messageCodec
00088 {
00089 private:
00090
00091 string m_codecName;
00092
00093
00094 protected:
00095
00098 ot_messageCodec(const string &codecName);
00099
00100
00101 public:
00102
00104 virtual ~ot_messageCodec(void) {}
00105
00109 virtual void encodeDataStream(ostream &s,const ot_map &msg) const = 0;
00110
00114 virtual auto_ptr<ot_map> decodeDataStream(istream &s) const = 0;
00115
00116
00120 void buildDataStream(ostream &s,const ot_map &msg) const;
00121
00122
00123 static auto_ptr<ot_messageBase> decodeDataFromNet(ost::TCPStream *s,string &requesCodec);
00124
00125 static void encodeDataToNet(ost::TCPStream *s,
00126 const ot_messageCodec *codec,
00127 const ot_messageBase &message);
00128
00129
00132 string getCodecName(void) const;
00133
00134
00136 void encode(ostream &s,const ot_messageBase &message) const;
00137
00139 auto_ptr<ot_messageBase> decode(istream &s) const;
00140
00141 };
00142
00143
00144 #endif