mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
fixed a few bugs in new serialization
This commit is contained in:
parent
5b3e488b42
commit
a941136c04
@ -92,7 +92,7 @@ bool DistantChatService::handleOutgoingItem(RsChatItem *item)
|
||||
uint32_t size = RsChatSerialiser().size(item) ;
|
||||
RsTemporaryMemory mem(size) ;
|
||||
|
||||
if(!RsChatSerialiser().serialise(item,mem,size))
|
||||
if(!RsChatSerialiser().serialise(item,mem,&size))
|
||||
{
|
||||
std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl;
|
||||
return false;
|
||||
@ -152,7 +152,7 @@ bool DistantChatService::acceptDataFromPeer(const RsGxsId& gxs_id,const RsGxsTun
|
||||
uint32_t size = RsChatSerialiser().size(item) ;
|
||||
RsTemporaryMemory mem(size) ;
|
||||
|
||||
if(!RsChatSerialiser().serialise(item,mem,size))
|
||||
if(!RsChatSerialiser().serialise(item,mem,&size))
|
||||
{
|
||||
std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl;
|
||||
return false;
|
||||
@ -218,7 +218,7 @@ void DistantChatService::receiveData(const RsGxsTunnelService::RsGxsTunnelId &tu
|
||||
contact.from_id = tinfo.source_gxs_id ;
|
||||
}
|
||||
|
||||
RsItem *item = RsChatSerialiser().deserialise(data,data_size) ;
|
||||
RsItem *item = RsChatSerialiser().deserialise(data,&data_size) ;
|
||||
|
||||
if(item != NULL)
|
||||
{
|
||||
|
@ -219,6 +219,7 @@ uint32_t RsSerialType::size(RsItem *)
|
||||
|
||||
bool RsSerialType::serialise(RsItem */*item*/, void */*data*/, uint32_t */*size*/)
|
||||
{
|
||||
std::cerr << "(EE) Empty method called for missing serialize() method in serializer class " << typeid(this).name() << std::endl;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsSerialType::serialise()" << std::endl;
|
||||
#endif
|
||||
|
@ -1,10 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/rsprint.h"
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
|
||||
RsItem *RsSerializer::deserialise(const uint8_t *data,uint32_t size)
|
||||
RsItem *RsSerializer::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t rstype = getRsItemId(const_cast<void*>((const void*)data)) ;
|
||||
|
||||
@ -13,11 +11,11 @@ RsItem *RsSerializer::deserialise(const uint8_t *data,uint32_t size)
|
||||
if(!item)
|
||||
{
|
||||
std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl;
|
||||
std::cerr << "(EE) Data is: " << RsUtil::BinToHex(data,std::min(50u,size)) << ((size>50)?"...":"") << 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*>(data),size);
|
||||
SerializeContext ctx(const_cast<uint8_t*>(static_cast<uint8_t*>(data)),*size);
|
||||
ctx.mOffset = 8 ;
|
||||
|
||||
item->serial_process(RsItem::DESERIALIZE, ctx) ;
|
||||
@ -29,13 +27,13 @@ RsItem *RsSerializer::deserialise(const uint8_t *data,uint32_t size)
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
bool RsSerializer::serialise(RsItem *item,uint8_t *const data,uint32_t size)
|
||||
bool RsSerializer::serialise(RsItem *item,void *data,uint32_t *size)
|
||||
{
|
||||
SerializeContext ctx(data,0);
|
||||
SerializeContext ctx(static_cast<uint8_t*>(data),0);
|
||||
|
||||
uint32_t tlvsize = this->size(item) ;
|
||||
|
||||
if(tlvsize > size)
|
||||
if(tlvsize > *size)
|
||||
throw std::runtime_error("Cannot serialise: not enough room.") ;
|
||||
|
||||
if(!setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize))
|
||||
|
@ -12,7 +12,7 @@
|
||||
class RsSerializer: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsSerializer(uint16_t service_id) : RsSerialType(service_id) {}
|
||||
RsSerializer(uint16_t service_id) : RsSerialType(RS_PKT_VERSION_SERVICE,service_id) {}
|
||||
|
||||
/*! create_item
|
||||
* should be overloaded to create the correct type of item depending on the data
|
||||
@ -22,11 +22,10 @@ class RsSerializer: public RsSerialType
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
// The following functions *should not* be overloaded.
|
||||
// They are kept public in order to allow them to be called if needed.
|
||||
// The following functions overload RsSerialType. They *should not* need to be further overloaded.
|
||||
|
||||
RsItem *deserialise(const uint8_t *data,uint32_t size) ;
|
||||
bool serialise(RsItem *item,uint8_t *const data,uint32_t size) ;
|
||||
RsItem *deserialise(void *data,uint32_t *size) ;
|
||||
bool serialise(RsItem *item,void *data,uint32_t *size) ;
|
||||
uint32_t size(RsItem *item) ;
|
||||
void print(RsItem *item) ;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user