Beispiel #1
0
        bool Process(BlockType blockType, ReadOnlySpan <byte> block, IEventStoreObserver observer)
        {
            if ((blockType & BlockType.Compressed) != 0)
            {
                CompressionStrategy.Decompress(ref block);
            }
            var reader = new SpanReader(block);

            if ((blockType & BlockType.HasTypeDeclaration) != 0)
            {
                Mapping.LoadTypeDescriptors(ref reader);
            }
            var  metadata = (blockType & BlockType.HasMetadata) != 0 ? Mapping.LoadObject(ref reader) : null;
            uint eventCount;

            if ((blockType & BlockType.HasOneEvent) != 0)
            {
                eventCount = 1;
            }
            else if ((blockType & BlockType.HasMoreEvents) != 0)
            {
                eventCount = reader.ReadVUInt32();
            }
            else
            {
                eventCount = 0;
            }
            var readEvents = observer.ObservedMetadata(metadata, eventCount);

            if (!readEvents)
            {
                return(observer.ShouldStopReadingNextEvents());
            }
            var events = new object[eventCount];
            var successfulEventCount = 0;

            for (var i = 0; i < eventCount; i++)
            {
                var ev = Mapping.LoadObject(ref reader);
                if (ev == null)
                {
                    continue;
                }
                events[successfulEventCount] = ev;
                successfulEventCount++;
            }

            if (eventCount != successfulEventCount)
            {
                Array.Resize(ref events, successfulEventCount);
            }

            observer.ObservedEvents(events);
            return(observer.ShouldStopReadingNextEvents());
        }
Beispiel #2
0
        bool Process(BlockType blockType, ByteBuffer block, IEventStoreObserver observer)
        {
            if ((blockType & BlockType.Compressed) != 0)
            {
                CompressionStrategy.Decompress(ref block);
            }
            var reader = new ByteBufferReader(block);

            if ((blockType & BlockType.HasTypeDeclaration) != 0)
            {
                Mapping.LoadTypeDescriptors(reader);
            }
            var  metadata = (blockType & BlockType.HasMetadata) != 0 ? Mapping.LoadObject(reader) : null;
            uint eventCount;

            if ((blockType & BlockType.HasOneEvent) != 0)
            {
                eventCount = 1;
            }
            else if ((blockType & BlockType.HasMoreEvents) != 0)
            {
                eventCount = reader.ReadVUInt32();
            }
            else
            {
                eventCount = 0;
            }
            var readEvents = observer.ObservedMetadata(metadata, eventCount);

            if (!readEvents)
            {
                return(observer.ShouldStopReadingNextEvents());
            }
            var events = new object[eventCount];

            for (var i = 0; i < eventCount; i++)
            {
                events[i] = Mapping.LoadObject(reader);
            }
            observer.ObservedEvents(events);
            return(observer.ShouldStopReadingNextEvents());
        }
Beispiel #3
0
 bool Process(BlockType blockType, ByteBuffer block, IEventStoreObserver observer)
 {
     if ((blockType & BlockType.Compressed) != 0)
     {
         CompressionStrategy.Decompress(ref block);
     }
     var reader = new ByteBufferReader(block);
     if ((blockType & BlockType.HasTypeDeclaration) != 0)
     {
         Mapping.LoadTypeDescriptors(reader);
     }
     var metadata = (blockType & BlockType.HasMetadata) != 0 ? Mapping.LoadObject(reader) : null;
     uint eventCount;
     if ((blockType & BlockType.HasOneEvent) != 0)
     {
         eventCount = 1;
     }
     else if ((blockType & BlockType.HasMoreEvents) != 0)
     {
         eventCount = reader.ReadVUInt32();
     }
     else
     {
         eventCount = 0;
     }
     var readEvents = observer.ObservedMetadata(metadata, eventCount);
     if (!readEvents) return observer.ShouldStopReadingNextEvents();
     var events = new object[eventCount];
     for (var i = 0; i < eventCount; i++)
     {
         events[i] = Mapping.LoadObject(reader);
     }
     observer.ObservedEvents(events);
     return observer.ShouldStopReadingNextEvents();
 }