/**
  * @param EventMessageInterface $event
  * @return mixed
  */
 public function writeEventMessage(EventMessageInterface $event)
 {
     if ($event instanceof DomainEventMessageInterface) {
         $type = 3;
     } else {
         $type = 1;
     }
     $serializedPayload = $this->serializer->serializePayload($event);
     $serializedMetaData = $this->serializer->serializeMetaData($event);
     $data = pack("na36N", $type, $event->getIdentifier(), $event->getTimestamp()->format('U'));
     if ($event instanceof DomainEventMessageInterface) {
         $data .= pack("a36N", $event->getAggregateIdentifier(), $event->getScn());
     }
     $packFormat = sprintf("Na%sNa%sNa%s", strlen($serializedPayload->getType()->getName()), strlen($serializedPayload->getData()), strlen($serializedMetaData->getData()));
     $data .= pack($packFormat, strlen($serializedPayload->getType()->getName()), $serializedPayload->getType()->getName(), strlen($serializedPayload->getData()), $serializedPayload->getData(), strlen($serializedMetaData->getData()), $serializedMetaData->getData());
     return $data;
 }
 public function appendSnapshotEvent($type, DomainEventMessageInterface $snapshotEvent)
 {
     // Persist snapshot before pruning redundant archived ones, in order to prevent snapshot misses when reloading
     // an aggregate, which may occur when a READ_UNCOMMITTED transaction isolation level is used.
     $serializedPayload = $this->serializer->serializePayload($snapshotEvent);
     $serializedMetaData = $this->serializer->serializeMetaData($snapshotEvent);
     $this->entryStore->persistSnapshot($type, $snapshotEvent, $serializedPayload, $serializedMetaData, $this->entityManager);
     if ($this->maxSnapshotsArchived > 0) {
         $this->entryStore->pruneSnapshots($type, $snapshotEvent, $this->maxSnapshotsArchived, $this->entityManager);
     }
 }
 /**
  * @param CommandMessageInterface $commandMessage
  * @param SerializerInterface $serializer
  * @param bool $expectReply
  */
 public function __construct(CommandMessageInterface $commandMessage, SerializerInterface $serializer, $expectReply)
 {
     $this->commandMessage = $commandMessage;
     $this->commandIdentifier = $commandMessage->getIdentifier();
     $this->expectReply = $expectReply;
     $messageSerializer = new MessageSerializer($serializer);
     $payload = $messageSerializer->serializePayload($commandMessage);
     $metaData = $messageSerializer->serializeMetaData($commandMessage);
     $this->payloadType = $payload->getType()->getName();
     $this->payloadRevision = $payload->getType()->getRevision();
     $this->serializedPayload = $payload->getData();
     $this->serializedMetaData = $metaData->getData();
     $this->commandName = $commandMessage->getCommandName();
 }
 /**
  * Creates a new event entry to store in Mongo.
  *
  * @param string $aggregateType String containing the aggregate type of the event
  * @param DomainEventMessageInterface $event The actual DomainEvent to store
  * @param SerializerInterface $serializer Serializer to use for the event to store
  * @return EventEntry
  */
 public static function fromDomainEvent($aggregateType, DomainEventMessageInterface $event, SerializerInterface $serializer)
 {
     /**serializationTarget = String.class;
      * if (serializer.canSerializeTo(DBObject.class)) {
      * serializationTarget = DBObject.class;
      * }*/
     $messageSerializer = new MessageSerializer($serializer);
     $serializedPayloadObject = $messageSerializer->serializePayload($event);
     $serializedMetaDataObject = $messageSerializer->serializeMetaData($event);
     return new self($event->getAggregateIdentifier(), $event->getScn(), $event->getTimestamp()->getTimestamp(), $aggregateType, $serializedPayloadObject->getData(), $serializedPayloadObject->getType()->getName(), $serializedPayloadObject->getType()->getRevision(), $serializedMetaDataObject->getData(), $event->getIdentifier());
 }