/**
  * Writes the given snapshotEvent to the {@link #snapshotEventFile}.
  * Prepends a long value to the event in the file indicating the bytes to skip when reading the {@link #eventFile}.
  *
  * @param DomainEventMessageInterface $snapshotEvent The snapshot to write to the {@link #snapshotEventFile}
  * @throws EventStoreException
  */
 public function writeSnapshotEvent(DomainEventMessageInterface $snapshotEvent)
 {
     try {
         $offset = $this->calculateOffset($snapshotEvent);
         $this->snapshotEventFile->fwrite(pack("N", $offset));
         $eventMessageWriter = new FilesystemEventMessageWriter($this->snapshotEventFile, $this->eventSerializer);
         $eventMessageWriter->writeEventMessage($snapshotEvent);
     } catch (\Exception $ex) {
         throw new EventStoreException("Error writing a snapshot event", 0, $ex);
     }
 }
 public function appendEvents($type, DomainEventStreamInterface $events)
 {
     if (!$events->hasNext()) {
         return;
     }
     $next = $events->peek();
     if (0 === $next->getScn() && $this->fileResolver->eventFileExists($type, $next->getAggregateIdentifier())) {
         throw new ConflictingModificationException(sprintf("Could not create event stream for aggregate, such stream " . "already exists, type=%s, id=%s", $type, $next->getAggregateIdentifier()));
     }
     $file = $this->fileResolver->openEventFileForWriting($type, $next->getAggregateIdentifier());
     $eventMessageWriter = new FilesystemEventMessageWriter($file, $this->serializer);
     while ($events->hasNext()) {
         $eventMessageWriter->writeEventMessage($events->next());
     }
 }