mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 15:39:27 -05:00
switched rshistoryitems to new serialization
This commit is contained in:
parent
8ae6541ceb
commit
af4fcf7679
@ -34,7 +34,31 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
void RsHistoryMsgItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
uint16_t version=0;
|
||||
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,version,"version") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,chatPeerId,"chatPeerId") ;
|
||||
RsTypeSerializer::serial_process<bool> (j,ctx,incoming,"incoming") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,peerName,"peerName") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,recvTime,"recvTime") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message,"message") ;
|
||||
}
|
||||
|
||||
RsItem *RsHistorySerialiser::create_item(uint8_t serial_class,uint8_t serial_type) const
|
||||
{
|
||||
if(serial_class != RS_PKT_CLASS_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
if(serial_type == RS_PKT_SUBTYPE_DEFAULT)
|
||||
return new RsHistoryMsgItem();
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG, RS_PKT_SUBTYPE_DEFAULT)
|
||||
{
|
||||
@ -45,6 +69,9 @@ RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONF
|
||||
saveToDisc = true;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
|
||||
/*************************************************************************/
|
||||
RsHistoryMsgItem::~RsHistoryMsgItem()
|
||||
{
|
||||
}
|
||||
@ -92,9 +119,6 @@ std::ostream& RsHistoryMsgItem::print(std::ostream &out, uint16_t indent)
|
||||
return out;
|
||||
}
|
||||
|
||||
RsHistorySerialiser::RsHistorySerialiser() : RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG)
|
||||
{
|
||||
}
|
||||
|
||||
RsHistorySerialiser::~RsHistorySerialiser()
|
||||
{
|
||||
@ -114,7 +138,6 @@ uint32_t RsHistorySerialiser::sizeHistoryMsgItem(RsHistoryMsgItem* item)
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsHistorySerialiser::serialiseHistoryMsgItem(RsHistoryMsgItem* item, void* data, uint32_t* pktsize)
|
||||
{
|
||||
@ -266,3 +289,5 @@ RsItem* RsHistorySerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
#endif
|
||||
|
@ -28,18 +28,21 @@
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsHistoryMsgItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsHistoryMsgItem();
|
||||
virtual ~RsHistoryMsgItem();
|
||||
virtual ~RsHistoryMsgItem() {}
|
||||
virtual void clear() {}
|
||||
|
||||
virtual void clear();
|
||||
std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
RsPeerId chatPeerId; // empty for global chat
|
||||
bool incoming;
|
||||
@ -54,20 +57,13 @@ public:
|
||||
bool saveToDisc;
|
||||
};
|
||||
|
||||
class RsHistorySerialiser: public RsSerialType
|
||||
class RsHistorySerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsHistorySerialiser();
|
||||
virtual ~RsHistorySerialiser();
|
||||
|
||||
virtual uint32_t size(RsItem*);
|
||||
virtual bool serialise(RsItem* item, void* data, uint32_t* size);
|
||||
virtual RsItem* deserialise(void* data, uint32_t* size);
|
||||
RsHistorySerialiser() : RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG) {}
|
||||
virtual ~RsHistorySerialiser() {}
|
||||
|
||||
private:
|
||||
virtual uint32_t sizeHistoryMsgItem(RsHistoryMsgItem*);
|
||||
virtual bool serialiseHistoryMsgItem (RsHistoryMsgItem* item, void* data, uint32_t* size);
|
||||
virtual RsHistoryMsgItem* deserialiseHistoryMsgItem(void* data, uint32_t* size);
|
||||
virtual RsItem *create_item(uint8_t service,uint8_t type) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
@ -6,7 +6,7 @@ const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_NONE ( 0x0
|
||||
const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 );
|
||||
const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE ( 0x0002 );
|
||||
|
||||
RsItem *RsGenericSerializer::deserialise(void *data, uint32_t *size)
|
||||
RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t rstype = getRsItemId(const_cast<void*>((const void*)data)) ;
|
||||
|
||||
@ -36,7 +36,36 @@ RsItem *RsGenericSerializer::deserialise(void *data, uint32_t *size)
|
||||
delete item ;
|
||||
return NULL ;
|
||||
}
|
||||
RsItem *RsConfigSerializer::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t rstype = getRsItemId(const_cast<void*>((const void*)data)) ;
|
||||
|
||||
RsItem *item = create_item(getRsItemClass(rstype),getRsItemSubType(rstype)) ;
|
||||
|
||||
if(!item)
|
||||
{
|
||||
std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl;
|
||||
std::cerr << "(EE) Data is: " << RsUtil::BinToHex(static_cast<uint8_t*>(data),std::min(50u,*size)) << ((*size>50)?"...":"") << std::endl;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
SerializeContext ctx(const_cast<uint8_t*>(static_cast<uint8_t*>(data)),*size,mFormat,mFlags);
|
||||
ctx.mOffset = 8 ;
|
||||
|
||||
item->serial_process(RsItem::DESERIALIZE, ctx) ;
|
||||
|
||||
if(ctx.mSize != ctx.mOffset)
|
||||
{
|
||||
std::cerr << "RsSerializer::deserialise(): ERROR. offset does not match expected size!" << std::endl;
|
||||
delete item ;
|
||||
return NULL ;
|
||||
}
|
||||
if(ctx.mOk)
|
||||
return item ;
|
||||
|
||||
delete item ;
|
||||
return NULL ;
|
||||
}
|
||||
bool RsGenericSerializer::serialise(RsItem *item,void *data,uint32_t *size)
|
||||
{
|
||||
SerializeContext ctx(static_cast<uint8_t*>(data),0,mFormat,mFlags);
|
||||
|
@ -25,14 +25,9 @@ public:
|
||||
static const SerializationFlags SERIALIZATION_FLAG_CONFIG ; // 0x0001
|
||||
static const SerializationFlags SERIALIZATION_FLAG_SIGNATURE ; // 0x0002
|
||||
|
||||
/*! create_item
|
||||
* should be overloaded to create the correct type of item depending on the data
|
||||
*/
|
||||
virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const=0;
|
||||
|
||||
// The following functions overload RsSerialType. They *should not* need to be further overloaded.
|
||||
|
||||
RsItem *deserialise(void *data,uint32_t *size) ;
|
||||
RsItem *deserialise(void *data,uint32_t *size) =0;
|
||||
bool serialise(RsItem *item,void *data,uint32_t *size) ;
|
||||
uint32_t size(RsItem *item) ;
|
||||
void print(RsItem *item) ;
|
||||
@ -51,7 +46,6 @@ protected:
|
||||
: RsSerialType(RS_PKT_VERSION_SERVICE,service), mFormat(format),mFlags(flags)
|
||||
{}
|
||||
|
||||
private:
|
||||
SerializeContext::SerializationFormat mFormat ;
|
||||
SerializationFlags mFlags ;
|
||||
|
||||
@ -65,6 +59,13 @@ public:
|
||||
SerializationFlags flags = SERIALIZATION_FLAG_NONE)
|
||||
|
||||
: RsGenericSerializer(service_id,format,flags) {}
|
||||
|
||||
/*! create_item
|
||||
* should be overloaded to create the correct type of item depending on the data
|
||||
*/
|
||||
virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const=0;
|
||||
|
||||
RsItem *deserialise(void *data,uint32_t *size) ;
|
||||
};
|
||||
|
||||
class RsConfigSerializer: public RsGenericSerializer
|
||||
@ -76,6 +77,13 @@ public:
|
||||
SerializationFlags flags = RsGenericSerializer::SERIALIZATION_FLAG_NONE)
|
||||
|
||||
: RsGenericSerializer(config_class,config_type,format,flags) {}
|
||||
|
||||
/*! create_item
|
||||
* should be overloaded to create the correct type of item depending on the data
|
||||
*/
|
||||
virtual RsItem *create_item(uint8_t /* class */, uint8_t /* item_type */) const=0;
|
||||
|
||||
RsItem *deserialise(void *data,uint32_t *size) ;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user