Esempio n. 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());
        }
Esempio n. 2
0
        public void CanSerializeString()
        {
            var writer = new ByteBufferWriter();
            var storedDescriptorCtx = _mapping.StoreNewDescriptors(writer, "Hello");

            storedDescriptorCtx.FinishNewDescriptors(writer);
            storedDescriptorCtx.StoreObject(writer, "Hello");
            storedDescriptorCtx.CommitNewDescriptors();
            var reader = new ByteBufferReader(writer.Data);
            var obj    = _mapping.LoadObject(reader);

            Assert.Equal("Hello", obj);
        }
Esempio n. 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());
        }
Esempio n. 4
0
        public void CanSerializeString()
        {
            var writer = new SpanWriter();
            var storedDescriptorCtx = _mapping.StoreNewDescriptors("Hello");

            storedDescriptorCtx.FinishNewDescriptors(ref writer);
            storedDescriptorCtx.StoreObject(ref writer, "Hello");
            storedDescriptorCtx.CommitNewDescriptors();
            var reader = new SpanReader(writer.GetSpan());
            var obj    = _mapping.LoadObject(ref reader);

            Assert.Equal("Hello", obj);
        }
Esempio n. 5
0
        void TestSerialization(object value)
        {
            var writer = new SpanWriter();
            var storedDescriptorCtx = _mapping.StoreNewDescriptors(value);

            storedDescriptorCtx.FinishNewDescriptors(ref writer);
            storedDescriptorCtx.StoreObject(ref writer, value);
            storedDescriptorCtx.CommitNewDescriptors();
            var reader = new SpanReader(writer.GetSpan());

            _mapping.LoadTypeDescriptors(ref reader);
            Assert.Equal(value, _mapping.LoadObject(ref reader));
            Assert.True(reader.Eof);
            _mapping = _ts.CreateMapping();
            reader   = new SpanReader(writer.GetSpan());
            _mapping.LoadTypeDescriptors(ref reader);
            Assert.Equal(value, _mapping.LoadObject(ref reader));
            Assert.True(reader.Eof);
        }