00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _SERIALIZE_H
00021 #define _SERIALIZE_H
00022
00023 #include <vector>
00024 #include <string>
00025 #include "secstwomsg.h"
00026
00027 #ifndef _LIBXML_ALREADY_INCLUDED
00028 class xmlTextWriter;
00029 class xmlSaveCtxt;
00030 #endif
00031
00032 namespace freesecs
00033 {
00034 namespace secstwo
00035 {
00043 class binary_deserializer_t
00044 {
00045 public:
00049 typedef uint8_t data_t;
00059 binary_deserializer_t(data_t *begin, data_t *end);
00060
00080 pdata_item_t operator()(data_t **next_item);
00081
00082 private:
00086 data_t *_begin;
00090 data_t *_end;
00094 data_t *_sod;
00098 data_t *_eod;
00102 size_t _data_len;
00106 data_type_t _type;
00107 };
00108
00115 class binary_serializer_t
00116 {
00117 public:
00121 typedef std::vector<uint8_t> data_container_t;
00122
00129 binary_serializer_t(pdata_item_t pitem);
00134 data_container_t::const_iterator begin() const;
00139 data_container_t::const_iterator end() const;
00140
00144 operator const data_container_t&();
00145
00146 private:
00150 data_container_t _raw_data;
00154 pdata_item_t _pitem;
00155
00156 private:
00160 binary_serializer_t();
00161 };
00162
00169 class xml_deserializer_t
00170 {
00171 public:
00175 typedef std::vector<pmsg_t> msg_container_t;
00176 public:
00189 xml_deserializer_t(xmlNode* pnode);
00195 operator const pdata_item_t&();
00201 operator const pmsg_t&();
00202 public:
00220 static int from_file(int fd, int schema_fd, msg_container_t &msg_container);
00225 static int from_mem(void *buf, size_t buflen, void *schema_buf, size_t schema_buflen, msg_container_t &msg_container);
00226
00227 private:
00231 static int read_from(xmlDoc *pdoc, xmlDoc *pschema_doc, msg_container_t &msg_container);
00235 pdata_item_t _pitem;
00239 pmsg_t _pmsg;
00240 };
00241
00247 class xml_serializer_t
00248 {
00249 public:
00253 typedef std::vector<pmsg_t> msg_container_t;
00257 typedef std::string data_container_t;
00263 xml_serializer_t(pdata_item_t pitem);
00269 xml_serializer_t(pmsg_t pmsg);
00273 ~xml_serializer_t();
00278 const char *get();
00279
00280 public:
00289 static int to_file(int fd, const msg_container_t &msg_container);
00298 static int to_mem(data_container_t& container, const msg_container_t &msg_container);
00299
00300 protected:
00304 xml_serializer_t(pdata_item_t, xmlTextWriter*);
00308 xml_serializer_t(pmsg_t, xmlTextWriter*);
00309
00310 private:
00314 static int save_to(xmlSaveCtxt *psave_ctx, const msg_container_t &msg_container);
00318 void serialize(pdata_item_t, xmlTextWriter*);
00322 void serialize(pmsg_t, xmlTextWriter*);
00326 data_container_t _raw_data;
00327 };
00328 };
00329 };
00330 #endif