simple_proto.cpp 640 B

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