event.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "event.h"
  2. #include "event_pb.h"
  3. namespace NActors {
  4. const TScopeId TScopeId::LocallyGenerated{
  5. Max<ui64>(), Max<ui64>()
  6. };
  7. TString IEventHandle::GetTypeName() const {
  8. return HasEvent() ? TypeName(*(const_cast<IEventHandle*>(this)->GetBase())) : TypeName(*this);
  9. }
  10. TString IEventHandle::ToString() const {
  11. return HasEvent() ? const_cast<IEventHandle*>(this)->GetBase()->ToString().data() : "serialized?";
  12. }
  13. std::unique_ptr<IEventHandle> IEventHandle::Forward(std::unique_ptr<IEventHandle>&& ev, TActorId recipient) {
  14. return std::unique_ptr<IEventHandle>(ev->Forward(recipient).Release());
  15. }
  16. TIntrusivePtr<TEventSerializedData> IEventHandle::ReleaseChainBuffer() {
  17. if (Buffer) {
  18. TIntrusivePtr<TEventSerializedData> result;
  19. DoSwap(result, Buffer);
  20. Event.Reset();
  21. return result;
  22. }
  23. if (Event) {
  24. TAllocChunkSerializer serializer;
  25. Event->SerializeToArcadiaStream(&serializer);
  26. auto chainBuf = serializer.Release(Event->CreateSerializationInfo());
  27. Event.Reset();
  28. return chainBuf;
  29. }
  30. return new TEventSerializedData;
  31. }
  32. TIntrusivePtr<TEventSerializedData> IEventHandle::GetChainBuffer() {
  33. if (Buffer) {
  34. return Buffer;
  35. }
  36. if (Event) {
  37. TAllocChunkSerializer serializer;
  38. Event->SerializeToArcadiaStream(&serializer);
  39. Buffer = serializer.Release(Event->CreateSerializationInfo());
  40. return Buffer;
  41. }
  42. return new TEventSerializedData;
  43. }
  44. }