git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@730 b45a01b8-16f6-495d-af2f-9b41ad6348cc

This commit is contained in:
chrisparker126 2008-09-21 11:08:08 +00:00
parent 50f956a148
commit a52c34a551
2 changed files with 13 additions and 237 deletions

View File

@ -26,9 +26,9 @@
#include <iostream>
#include "serialiser/rsbaseserial.h"
#include "serialiser/rsqblogitems.h"
#include "serialiser/rstlvbase.h"
#include "../serialiser/rsbaseserial.h"
#include "../serialiser/rsqblogitems.h"
#include "../serialiser/rstlvbase.h"
/************************************************************/
@ -43,7 +43,7 @@ std::ostream &RsQblogMsg::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsQblogMsg", indent);
uint16_t int_Indent = indent + 2;
/* print out the content of the item */
printIndent(out, int_Indent);
out << "blogMsg(send time): " << sendTime << std::endl;
@ -51,165 +51,9 @@ std::ostream &RsQblogMsg::print(std::ostream &out, uint16_t indent)
out << "blogMsg(recvd time): " << recvTime << std::endl;
printIndent(out, int_Indent);
std::string cnv_blog(message.begin(), message.end());
out << "blogMsg(message): " << cnv_blog << std::endl;
printIndent(out, int_Indent);
out << "blogMsg(message): " << cnv_blog << std::endl;
printIndent(out, int_Indent);
attachment.print(out, int_Indent);
printIndent(out, int_Indent);
printIndent(out, int_Indent);
return out;
}
/********************************************* RsQblogProfile section ***********************************/
/********************************************* RsQblogProfile section ***********************************/
/********************************************* RsQblogProfile section ***********************************/
RsQblogProfile::~RsQblogProfile(void)
{
return;
}
void RsQblogProfile::clear()
{
timeStamp = 0;
openProfile.TlvClear();
}
std::ostream &RsQblogProfile::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsQblogProfile", indent);
uint16_t int_Indent = indent + 2;
out << "RsQblogProfile::print() : timeStamp" << timeStamp;
out << std::endl;
openProfile.print(out, int_Indent);
printRsItemEnd(out, "RsQblogProfile", indent);
return out;
}
uint32_t RsQblogProfileSerialiser::sizeItem(RsQblogProfile *item)
{
uint32_t s = 8; // for header size
s += 4; // time stamp
s += item->openProfile.TlvSize();
return s;
}
/*******************************************************************************/
bool RsQblogProfileSerialiser::serialiseItem(RsQblogProfile* item, void* data, uint32_t *size)
{
uint32_t tlvsize = sizeItem(item);
uint32_t offset = 0;
if (*size < tlvsize)
return false; /* not enough space */
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsQblogSerialiser::serialiseItem() Header: " << ok << std::endl;
std::cerr << "RsQblogSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory part */
ok &= setRawUInt32(data, tlvsize, &offset, item->timeStamp);
ok &= item->openProfile.SetTlv(data, *size, &offset);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsQblogSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
}
return ok;
}
/**************************************************************************/
RsQblogProfile* RsQblogProfileSerialiser::deserialiseItem(void * data, uint32_t *size)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_QBLOG != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_QBLOG_PROFILE != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*size = rssize;
bool ok = true;
/* ready to load */
RsQblogProfile *item = new RsQblogProfile();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
RsTlvKeyValueWideSet* kvSetOpen;
ok &= getRawUInt32(data, rssize, &offset, &(item->timeStamp));
ok &= kvSetOpen->GetTlv(data, *size, &offset);
/* copy over deserialised files */
item->openProfile = *kvSetOpen;
if (offset != rssize)
{
/* error, improper item */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*********************************************************************/
bool RsQblogProfileSerialiser::serialise(RsItem *item, void* data, uint32_t* size)
{
return serialiseItem((RsQblogProfile *) item, data, size);
}
RsItem* RsQblogProfileSerialiser::deserialise(void* data, uint32_t* size)
{
return deserialiseItem(data, size);
}
uint32_t RsQblogProfileSerialiser::size(RsItem *item)
{
return sizeItem((RsQblogProfile *) item);
}

View File

@ -29,14 +29,11 @@
#include <map>
#include <list>
#include <string>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rsmsgitems.h"
#include "serialiser/rstlvkvwide.h"
const uint8_t RS_PKT_SUBTYPE_QBLOG_PROFILE = 0x01;
#include "../serialiser/rsserviceids.h"
#include "../serialiser/rsserial.h"
#include "../serialiser/rsmsgitems.h"
#include "../serialiser/rstlvkvwide.h"
/*!
@ -45,7 +42,7 @@ const uint8_t RS_PKT_SUBTYPE_QBLOG_PROFILE = 0x01;
class RsQblogMsg: public RsMsgItem
{
public:
RsQblogMsg()
RsQblogMsg()
:RsMsgItem(RS_SERVICE_TYPE_QBLOG)
{ return; }
@ -56,29 +53,6 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
};
/*!
* retroshare qblog profile item for storing received and sent profile info
* designed in an open ended way to accomodate multiple fields
*/
class RsQblogProfile: public RsItem
{
public:
RsQblogProfile()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_QBLOG, // add profile id type
RS_PKT_SUBTYPE_QBLOG_PROFILE)
{ return; }
virtual ~RsQblogProfile();
virtual void clear();
/// inherited method from RsItem
std::ostream &print(std::ostream &out, uint16_t indent = 0);
uint32_t timeStamp;
/// contains various profile information set by user, this and below use an open ended format
RsTlvKeyValueWideSet openProfile;
};
/*!
* to serialise rsQblogItems: method names are self explanatory
@ -92,50 +66,8 @@ class RsQblogMsgSerialiser : public RsMsgSerialiser
{ return; }
virtual ~RsQblogMsgSerialiser()
{ return; }
};
/*!
* to serialise rsQblogProfile items, method names are self explanatory
*/
class RsQblogProfileSerialiser : public RsSerialType
{
public:
RsQblogProfileSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_QBLOG)
{ return; }
virtual ~RsQblogProfileSerialiser()
{ return; }
/**
* check size of RsItem to be serialised
* @param RsItem RsItem which is going to be serilised
* @return size of the RsItem
*/
virtual uint32_t size(RsItem *);
/**
* serialise contents of item to data
* @param item RsItem which is going to be serilised
* @param data where contents will be serialised into
* @return size of the RsItem in bytes
*/
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
/**
* serialise contents of item to data
* @param data where contents will be deserialisedout of
* @return size of the RsItem in bytes
*/
virtual RsItem * deserialise(void *data, uint32_t *size);
private:
virtual uint32_t sizeItem(RsQblogProfile *);
virtual bool serialiseItem (RsQblogProfile *item, void *data, uint32_t *size);
virtual RsQblogProfile *deserialiseItem(void *data, uint32_t *size);
};
#endif /*RSQBLOGITEM_H_*/