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
00033
00034
00035
00036
00037
00038 #ifndef _OASYS_MARSHAL_SERIALIZE_H_
00039 #define _OASYS_MARSHAL_SERIALIZE_H_
00040
00041 #include "Serialize.h"
00042 #include "BufferedSerializeAction.h"
00043 #include "../util/ExpandableBuffer.h"
00044 #include "../util/CRC32.h"
00045
00046 namespace oasys {
00047
00049
00053 class Marshal : public BufferedSerializeAction {
00054 public:
00058 Marshal(context_t context, u_char* buf, size_t length, int options = 0);
00059
00063 Marshal(context_t context, ExpandableBuffer* buf, int options = 0);
00064
00071 int action(const SerializableObject* const_object)
00072 {
00073 SerializableObject* object = (SerializableObject*)const_object;
00074 return SerializeAction::action(object);
00075 }
00076
00077 void process(const char* name, SerializableObject* const_object)
00078 {
00079 SerializableObject* object = (SerializableObject*)const_object;
00080 return SerializeAction::process(name, object);
00081 }
00082
00083
00084 void end_action();
00085
00086 void process(const char* name, u_int32_t* i);
00087 void process(const char* name, u_int16_t* i);
00088 void process(const char* name, u_int8_t* i);
00089 void process(const char* name, bool* b);
00090 void process(const char* name, u_char* bp, size_t len);
00091 void process(const char* name, u_char** bp, size_t* lenp, int flags);
00092 void process(const char* name, std::string* s);
00093
00094 private:
00095 bool add_crc_;
00096 };
00097
00099
00106 class Unmarshal : public BufferedSerializeAction {
00107 public:
00111 Unmarshal(context_t context, const u_char* buf, size_t length,
00112 int options = 0);
00113
00114
00115 void begin_action();
00116
00117 void process(const char* name, u_int32_t* i);
00118 void process(const char* name, u_int16_t* i);
00119 void process(const char* name, u_int8_t* i);
00120 void process(const char* name, bool* b);
00121 void process(const char* name, u_char* bp, size_t len);
00122 void process(const char* name, u_char** bp, size_t* lenp, int flags);
00123 void process(const char* name, std::string* s);
00124
00125 private:
00126 bool has_crc_;
00127 };
00128
00130
00134 class MarshalSize : public SerializeAction {
00135 public:
00139 MarshalSize(context_t context, int options = 0)
00140 : SerializeAction(Serialize::INFO, context, options), size_(0)
00141 {
00142 }
00143
00147 int action(const SerializableObject* const_object)
00148 {
00149 SerializableObject* object = (SerializableObject*)const_object;
00150 return SerializeAction::action(object);
00151 }
00152
00153 void process(const char* name, SerializableObject* const_object)
00154 {
00155 SerializableObject* object = (SerializableObject*)const_object;
00156 return SerializeAction::process(name, object);
00157 }
00158
00160 size_t size() { return size_; }
00161
00165 static size_t get_size(u_int32_t*) { return 4; }
00166 static size_t get_size(u_int16_t*) { return 2; }
00167 static size_t get_size(u_int8_t*) { return 1; }
00168 static size_t get_size(bool*) { return 1; }
00169 static size_t get_size(u_char*, size_t len) { return len; }
00170 static size_t get_size(std::string* s) { return s->length() + 4; }
00172
00175 void begin_action();
00176 void process(const char* name, u_int32_t* i);
00177 void process(const char* name, u_int16_t* i);
00178 void process(const char* name, u_int8_t* i);
00179 void process(const char* name, bool* b);
00180 void process(const char* name, u_char* bp, size_t len);
00181 void process(const char* name, u_char** bp, size_t* lenp, int flags);
00182 void process(const char* name, std::string* s);
00184
00185 private:
00186 size_t size_;
00187 };
00188
00190
00193 class MarshalCRC : public SerializeAction {
00194 public:
00195 MarshalCRC(context_t context)
00196 : SerializeAction(Serialize::INFO, context) {}
00197
00198 u_int32_t crc() { return crc_.value(); }
00199
00201 int action(const SerializableObject* const_object)
00202 {
00203 SerializableObject* object = (SerializableObject*)const_object;
00204 return SerializeAction::action(object);
00205 }
00206 void process(const char* name, SerializableObject* const_object)
00207 {
00208 SerializableObject* object = (SerializableObject*)const_object;
00209 return SerializeAction::process(name, object);
00210 }
00213
00214 void process(const char* name, u_int32_t* i);
00215 void process(const char* name, u_int16_t* i);
00216 void process(const char* name, u_int8_t* i);
00217 void process(const char* name, bool* b);
00218 void process(const char* name, u_char* bp, size_t len);
00219 void process(const char* name, u_char** bp, size_t* lenp, int flags);
00220 void process(const char* name, std::string* s);
00221
00222 private:
00223 CRC32 crc_;
00224 };
00225
00226
00228
00231 class MarshalCopy {
00232 public:
00234 static size_t copy(ExpandableBuffer* buf,
00235 const SerializableObject* src,
00236 SerializableObject* dst);
00237 };
00238
00239 }
00240
00241 #endif