switched wiki and wire items to new serialization

This commit is contained in:
csoler 2017-04-29 21:46:54 +02:00
parent 5cba0059c8
commit d58c638af8
4 changed files with 120 additions and 74 deletions

View File

@ -31,7 +31,22 @@
#define GXSID_DEBUG 1 #define GXSID_DEBUG 1
RsItem *RsGxsWikiSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
{
if(service != RS_SERVICE_GXS_TYPE_WIKI)
return NULL ;
switch(item_sub_id)
{
case RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM: return new RsGxsWikiCollectionItem();
case RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM: return new RsGxsWikiCommentItem();
case RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM: return new RsGxsWikiSnapshotItem();
default:
return NULL ;
}
}
#ifdef TO_REMOVE
uint32_t RsGxsWikiSerialiser::size(RsItem *item) uint32_t RsGxsWikiSerialiser::size(RsItem *item)
{ {
RsGxsWikiCollectionItem* grp_item = NULL; RsGxsWikiCollectionItem* grp_item = NULL;
@ -117,6 +132,7 @@ RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size)
/*****************************************************************************************/ /*****************************************************************************************/
/*****************************************************************************************/ /*****************************************************************************************/
#endif
void RsGxsWikiCollectionItem::clear() void RsGxsWikiCollectionItem::clear()
{ {
@ -125,6 +141,7 @@ void RsGxsWikiCollectionItem::clear()
collection.mHashTags.clear(); collection.mHashTags.clear();
} }
#ifdef TO_REMOVE
std::ostream& RsGxsWikiCollectionItem::print(std::ostream& out, uint16_t indent) std::ostream& RsGxsWikiCollectionItem::print(std::ostream& out, uint16_t indent)
{ {
printRsItemBase(out, "RsGxsWikiCollectionItem", indent); printRsItemBase(out, "RsGxsWikiCollectionItem", indent);
@ -154,7 +171,16 @@ uint32_t RsGxsWikiSerialiser::sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem
return s; return s;
} }
#endif
void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,collection.mDescription,"collection.mDescription") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_CATEGORY,collection.mCategory ,"collection.mCategory") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,collection.mHashTags ,"collection.mHashTags") ;
}
#ifdef TO_REMOVE
bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem *item, void *data, uint32_t *size) bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem *item, void *data, uint32_t *size)
{ {
@ -277,6 +303,7 @@ RsGxsWikiCollectionItem* RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem(v
/*****************************************************************************************/ /*****************************************************************************************/
/*****************************************************************************************/ /*****************************************************************************************/
#endif
void RsGxsWikiSnapshotItem::clear() void RsGxsWikiSnapshotItem::clear()
{ {
@ -284,6 +311,7 @@ void RsGxsWikiSnapshotItem::clear()
snapshot.mHashTags.clear(); snapshot.mHashTags.clear();
} }
#ifdef TO_REMOVE
std::ostream& RsGxsWikiSnapshotItem::print(std::ostream& out, uint16_t indent) std::ostream& RsGxsWikiSnapshotItem::print(std::ostream& out, uint16_t indent)
{ {
printRsItemBase(out, "RsGxsWikiSnapshotItem", indent); printRsItemBase(out, "RsGxsWikiSnapshotItem", indent);
@ -311,7 +339,15 @@ uint32_t RsGxsWikiSerialiser::sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *ite
return s; return s;
} }
#endif
void RsGxsWikiSnapshotItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_WIKI_PAGE,snapshot.mPage,"snapshot.mPage") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG ,snapshot.mPage,"snapshot.mHashTags") ;
}
#ifdef TO_REMOVE
bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item, void *data, uint32_t *size) bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item, void *data, uint32_t *size)
{ {
@ -431,12 +467,14 @@ RsGxsWikiSnapshotItem* RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem(void
/*****************************************************************************************/ /*****************************************************************************************/
/*****************************************************************************************/ /*****************************************************************************************/
#endif
void RsGxsWikiCommentItem::clear() void RsGxsWikiCommentItem::clear()
{ {
comment.mComment.clear(); comment.mComment.clear();
} }
#ifdef TO_REMOVE
std::ostream& RsGxsWikiCommentItem::print(std::ostream& out, uint16_t indent) std::ostream& RsGxsWikiCommentItem::print(std::ostream& out, uint16_t indent)
{ {
printRsItemBase(out, "RsGxsWikiCommentItem", indent); printRsItemBase(out, "RsGxsWikiCommentItem", indent);
@ -460,7 +498,14 @@ uint32_t RsGxsWikiSerialiser::sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item)
return s; return s;
} }
#endif
void RsGxsWikiCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"comment.mComment") ;
}
#ifdef TO_REMOVE
bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item, void *data, uint32_t *size) bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item, void *data, uint32_t *size)
{ {
@ -578,3 +623,5 @@ RsGxsWikiCommentItem* RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem(void *d
/*****************************************************************************************/ /*****************************************************************************************/
/*****************************************************************************************/ /*****************************************************************************************/
#endif

View File

@ -29,28 +29,24 @@
#include <map> #include <map>
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "serialiser/rsserial.h" #include "rsitems/rsitem.h"
//#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h" #include "serialiser/rsgxsitems.h"
#include "retroshare/rswiki.h" #include "retroshare/rswiki.h"
const uint8_t RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM = 0x02; const uint8_t RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM = 0x03; const uint8_t RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM = 0x03;
const uint8_t RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM = 0x04; const uint8_t RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM = 0x04;
class RsGxsWikiCollectionItem : public RsGxsGrpItem class RsGxsWikiCollectionItem : public RsGxsGrpItem
{ {
public: public:
RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIKI, RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM) {}
virtual ~RsGxsWikiCollectionItem() {}
RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIKI, void clear();
RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM) { return;}
virtual ~RsGxsWikiCollectionItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsWikiCollection collection; RsWikiCollection collection;
}; };
@ -59,11 +55,12 @@ class RsGxsWikiSnapshotItem : public RsGxsMsgItem
{ {
public: public:
RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI, RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI, RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM) {}
RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM) {return; } virtual ~RsGxsWikiSnapshotItem() {}
virtual ~RsGxsWikiSnapshotItem() { return;} void clear();
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsWikiSnapshot snapshot; RsWikiSnapshot snapshot;
}; };
@ -71,42 +68,23 @@ class RsGxsWikiCommentItem : public RsGxsMsgItem
{ {
public: public:
RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI, RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI, RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM) {}
RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM) { return; } virtual ~RsGxsWikiCommentItem() {}
virtual ~RsGxsWikiCommentItem() { return; }
void clear(); void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsWikiComment comment; RsWikiComment comment;
}; };
class RsGxsWikiSerialiser : public RsSerialType class RsGxsWikiSerialiser : public RsServiceSerializer
{ {
public: public:
RsGxsWikiSerialiser() RsGxsWikiSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_WIKI) {}
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_WIKI) virtual ~RsGxsWikiSerialiser() {}
{ return; }
virtual ~RsGxsWikiSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item);
bool serialiseGxsWikiCollectionItem (RsGxsWikiCollectionItem *item, void *data, uint32_t *size);
RsGxsWikiCollectionItem * deserialiseGxsWikiCollectionItem(void *data, uint32_t *size);
uint32_t sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item);
bool serialiseGxsWikiSnapshotItem (RsGxsWikiSnapshotItem *item, void *data, uint32_t *size);
RsGxsWikiSnapshotItem * deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size);
uint32_t sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item);
bool serialiseGxsWikiCommentItem (RsGxsWikiCommentItem *item, void *data, uint32_t *size);
RsGxsWikiCommentItem * deserialiseGxsWikiCommentItem(void *data, uint32_t *size);
virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const;
}; };
#endif /* RS_WIKI_ITEMS_H */ #endif /* RS_WIKI_ITEMS_H */

View File

@ -26,12 +26,27 @@
#include <iostream> #include <iostream>
#include "rswireitems.h" #include "rswireitems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h" #include "serialization/rstypeserializer.h"
#define WIRE_DEBUG 1 #define WIRE_DEBUG 1
RsItem *RsGxsWireSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
{
if(service != RS_SERVICE_GXS_TYPE_WIRE)
return NULL ;
switch(item_subtype)
{
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM: return new RsGxsWireGroupItem();
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM: return new RsGxsWirePulseItem();
default:
return NULL ;
}
}
#ifdef TO_REMOVE
uint32_t RsGxsWireSerialiser::size(RsItem *item) uint32_t RsGxsWireSerialiser::size(RsItem *item)
{ {
RsGxsWireGroupItem* grp_item = NULL; RsGxsWireGroupItem* grp_item = NULL;
@ -104,12 +119,14 @@ RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size)
/*****************************************************************************************/ /*****************************************************************************************/
/*****************************************************************************************/ /*****************************************************************************************/
#endif
void RsGxsWireGroupItem::clear() void RsGxsWireGroupItem::clear()
{ {
group.mDescription.clear(); group.mDescription.clear();
} }
#ifdef TO_REMOVE
std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent) std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent)
{ {
printRsItemBase(out, "RsGxsWireGroupItem", indent); printRsItemBase(out, "RsGxsWireGroupItem", indent);
@ -134,6 +151,14 @@ uint32_t RsGxsWireSerialiser::sizeGxsWireGroupItem(RsGxsWireGroupItem *item)
return s; return s;
} }
#endif
void RsGxsWireGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ;
}
#ifdef TO_REMOVE
bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size) bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size)
{ {
@ -287,6 +312,15 @@ uint32_t RsGxsWireSerialiser::sizeGxsWirePulseItem(RsGxsWirePulseItem *item)
return s; return s;
} }
#endif
void RsGxsWirePulseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,pulse.mHashTags,"pulse.mHashTags") ;
}
#ifdef TO_REMOVE
bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size) bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size)
{ {
@ -406,3 +440,4 @@ RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data,
/*****************************************************************************************/ /*****************************************************************************************/
/*****************************************************************************************/ /*****************************************************************************************/
#endif

View File

@ -43,13 +43,12 @@ class RsGxsWireGroupItem : public RsGxsGrpItem
public: public:
RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIRE, RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIRE, RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) {}
RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) { return;} virtual ~RsGxsWireGroupItem() {}
virtual ~RsGxsWireGroupItem() { return;}
void clear(); void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsWireGroup group; RsWireGroup group;
}; };
@ -58,36 +57,23 @@ class RsGxsWirePulseItem : public RsGxsMsgItem
{ {
public: public:
RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIRE, RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIRE, RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {}
RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {return; } virtual ~RsGxsWirePulseItem() {}
virtual ~RsGxsWirePulseItem() { return;} void clear();
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsWirePulse pulse; RsWirePulse pulse;
}; };
class RsGxsWireSerialiser : public RsSerialType class RsGxsWireSerialiser : public RsServiceSerializer
{ {
public: public:
RsGxsWireSerialiser() RsGxsWireSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_WIRE) {}
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_WIRE) virtual ~RsGxsWireSerialiser() {}
{ return; }
virtual ~RsGxsWireSerialiser() { return; }
uint32_t size(RsItem *item); virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const ;
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsWireGroupItem(RsGxsWireGroupItem *item);
bool serialiseGxsWireGroupItem (RsGxsWireGroupItem *item, void *data, uint32_t *size);
RsGxsWireGroupItem * deserialiseGxsWireGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsWirePulseItem(RsGxsWirePulseItem *item);
bool serialiseGxsWirePulseItem (RsGxsWirePulseItem *item, void *data, uint32_t *size);
RsGxsWirePulseItem * deserialiseGxsWirePulseItem(void *data, uint32_t *size);
}; };
#endif /* RS_WIKI_ITEMS_H */ #endif /* RS_WIKI_ITEMS_H */