blob: 3e28413325cb3554429537b9f4c64f51eb1bac71 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include "simple_proto.h"
#include <util/generic/cast.h>
#include <typeinfo>
using namespace NBus;
void TSimpleProtocol::Serialize(const TBusMessage* mess, TBuffer& data) {
Y_ABORT_UNLESS(typeid(TSimpleMessage) == typeid(*mess));
const TSimpleMessage* typed = static_cast<const TSimpleMessage*>(mess);
data.Append((const char*)&typed->Payload, 4);
}
TAutoPtr<TBusMessage> TSimpleProtocol::Deserialize(ui16, TArrayRef<const char> payload) {
if (payload.size() != 4) {
return nullptr;
}
TAutoPtr<TSimpleMessage> r(new TSimpleMessage);
memcpy(&r->Payload, payload.data(), 4);
return r.Release();
}
|