mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-20 15:00:36 -04:00
Major improvements to the serialiser to make it work with retroshare.
This is still a first draft - the message types will surely change. -corrected ids and added service classes. -Added disc/msg/chat/cache/file messages -Extended serialiser to handle service extensions. -corrected IpAddrPort code. -More debugging code. -Added some tests. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@270 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9f76b1a313
commit
e8ccb0b427
22 changed files with 3101 additions and 333 deletions
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
|
||||
#include <map>
|
||||
#include <iosfwd>
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
|
@ -51,12 +52,13 @@
|
|||
* 8 bits: SubType
|
||||
******************************************************************/
|
||||
|
||||
const uint8_t RS_PKT_VERSION1 = 0x01;
|
||||
const uint8_t RS_PKT_VERSION1 = 0x01;
|
||||
const uint8_t RS_PKT_VERSION_SERVICE = 0x02;
|
||||
|
||||
const uint8_t RS_PKT_CLASS_BASE = 0x01;
|
||||
const uint8_t RS_PKT_CLASS_SERVICE = 0x02;
|
||||
const uint8_t RS_PKT_CLASS_SERV_INIT = 0x03;
|
||||
const uint8_t RS_PKT_CLASS_CONFIG = 0x11;
|
||||
const uint8_t RS_PKT_CLASS_CONFIG = 0x02;
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_DEFAULT = 0x01; /* if only one subtype */
|
||||
|
||||
|
||||
class RsItem
|
||||
|
@ -67,6 +69,11 @@ class RsItem
|
|||
|
||||
virtual ~RsItem();
|
||||
virtual void clear() = 0;
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
|
||||
|
||||
/* source / destination id */
|
||||
std::string PeerId() { return peerId; }
|
||||
void PeerId(std::string id) { peerId = id; }
|
||||
|
||||
/* complete id */
|
||||
uint32_t PacketId();
|
||||
|
@ -77,8 +84,13 @@ uint8_t PacketClass();
|
|||
uint8_t PacketType();
|
||||
uint8_t PacketSubType();
|
||||
|
||||
/* For Service Packets */
|
||||
RsItem(uint8_t ver, uint16_t service, uint8_t subtype);
|
||||
uint16_t PacketService(); /* combined Packet class/type (mid 16bits) */
|
||||
|
||||
private:
|
||||
uint32_t type;
|
||||
std::string peerId;
|
||||
};
|
||||
|
||||
|
||||
|
@ -87,6 +99,7 @@ class RsSerialType
|
|||
public:
|
||||
RsSerialType(uint32_t t); /* only uses top 24bits */
|
||||
RsSerialType(uint8_t ver, uint8_t cls, uint8_t t);
|
||||
RsSerialType(uint8_t ver, uint16_t service);
|
||||
|
||||
virtual ~RsSerialType();
|
||||
|
||||
|
@ -127,6 +140,46 @@ uint8_t getRsItemClass(uint32_t type);
|
|||
uint8_t getRsItemType(uint32_t type);
|
||||
uint8_t getRsItemSubType(uint32_t type);
|
||||
|
||||
uint16_t getRsItemService(uint32_t type);
|
||||
|
||||
/* size constants */
|
||||
uint32_t getRsPktBaseSize();
|
||||
uint32_t getRsPktMaxSize();
|
||||
|
||||
|
||||
|
||||
/* helper fns for printing */
|
||||
std::ostream &printRsItemBase(std::ostream &o, std::string n, uint16_t i);
|
||||
std::ostream &printRsItemEnd(std::ostream &o, std::string n, uint16_t i);
|
||||
|
||||
/* defined in rstlvtypes.cc - redeclared here for ease */
|
||||
std::ostream &printIndent(std::ostream &out, uint16_t indent);
|
||||
/* Wrapper class for data that is serialised somewhere else */
|
||||
|
||||
class RsRawItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsRawItem(uint32_t t, uint32_t size)
|
||||
:RsItem(t), len(size) { data = malloc(len); }
|
||||
|
||||
virtual ~RsRawItem()
|
||||
{
|
||||
if (data)
|
||||
free(data);
|
||||
data = NULL;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
uint32_t getRawLength() { return len; }
|
||||
void * getRawData() { return data; }
|
||||
|
||||
virtual void clear() { return; } /* what can it do? */
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
private:
|
||||
void *data;
|
||||
uint32_t len;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue