mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
add serialization API
This commit is contained in:
parent
c9388d4837
commit
09ea40e37f
|
@ -38,7 +38,6 @@ void FairMQExample8Sampler::Run()
|
|||
Ex8Header* header = new Ex8Header;
|
||||
// Set stopFlag to 1 for the first 4 messages, and to 0 for the 5th.
|
||||
counter < 5 ? header->stopFlag = 0 : header->stopFlag = 1;
|
||||
|
||||
LOG(INFO) << "Sending header with stopFlag: " << header->stopFlag;
|
||||
|
||||
FairMQParts parts;
|
||||
|
|
|
@ -19,6 +19,48 @@
|
|||
|
||||
#include "FairMQDevice.h"
|
||||
|
||||
|
||||
struct MyPoint
|
||||
{
|
||||
/* data */
|
||||
double x=6;
|
||||
double y=6;
|
||||
double z=6;
|
||||
};
|
||||
|
||||
struct Ex8Header {
|
||||
int32_t stopFlag;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct MyPointSerializer
|
||||
{
|
||||
void Serialize(std::unique_ptr<FairMQMessage>& msg, MyPoint* input)
|
||||
{
|
||||
int DataSize = sizeof(MyPoint);
|
||||
msg->Rebuild(DataSize);
|
||||
MyPoint* digiptr = reinterpret_cast<MyPoint*>(msg->GetData());
|
||||
digiptr->x=input->x;
|
||||
digiptr->y=input->y;
|
||||
digiptr->z=input->z;
|
||||
}
|
||||
|
||||
void Deserialize(std::unique_ptr<FairMQMessage>& msg, MyPoint* input)
|
||||
{
|
||||
MyPoint* digiptr = static_cast<MyPoint*>(msg->GetData());
|
||||
input->x=digiptr->x;
|
||||
input->y=digiptr->y;
|
||||
input->z=digiptr->z;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class FairMQExample8Sampler : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -17,6 +17,51 @@
|
|||
|
||||
#include "FairMQDevice.h"
|
||||
|
||||
|
||||
struct Ex8Header {
|
||||
int32_t stopFlag;
|
||||
};
|
||||
|
||||
|
||||
struct MyPoint
|
||||
{
|
||||
/* data */
|
||||
double x=1;
|
||||
double y=1;
|
||||
double z=1;
|
||||
};
|
||||
|
||||
|
||||
struct MyPointSerializer
|
||||
{
|
||||
void Serialize(std::unique_ptr<FairMQMessage>& msg, MyPoint* input)
|
||||
{
|
||||
int DataSize = sizeof(MyPoint);
|
||||
msg->Rebuild(DataSize);
|
||||
MyPoint* digiptr = reinterpret_cast<MyPoint*>(msg->GetData());
|
||||
digiptr->x=input->x;
|
||||
digiptr->y=input->y;
|
||||
digiptr->z=input->z;
|
||||
}
|
||||
|
||||
void Deserialize(std::unique_ptr<FairMQMessage>& msg, MyPoint* input)
|
||||
{
|
||||
MyPoint* digiptr = static_cast<MyPoint*>(msg->GetData());
|
||||
input->x=digiptr->x;
|
||||
input->y=digiptr->y;
|
||||
input->z=digiptr->z;
|
||||
}
|
||||
|
||||
void Deserialize(FairMQMessage& msg, MyPoint* input)
|
||||
{
|
||||
MyPoint* digiptr = static_cast<MyPoint*>(msg.GetData());
|
||||
input->x=digiptr->x;
|
||||
input->y=digiptr->y;
|
||||
input->z=digiptr->z;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class FairMQExample8Sink : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue
Block a user