aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/test/perftest/simple_proto.cpp
blob: 601aa50a79c885e28e2c5f8aad7026725ef274f2 (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_VERIFY(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();
}