Esempio n. 1
0
        public object LoadObject()
        {
            var typeId = _reader.ReadVUInt32();

            if (typeId == 0)
            {
                return(null);
            }
            if (typeId == 1)
            {
                var backRefId = _reader.ReadVUInt32();
                return(_visited[(int)backRefId]);
            }
            if (typeId >= _id2Info.Count)
            {
                throw new BtdbMissingMetadataException();
            }
            var infoForType = _id2Info[(int)typeId];

            if (infoForType.Loader == null)
            {
                infoForType.Loader = LoaderFactory(infoForType.Descriptor);
            }
            return(infoForType.Loader(_reader, this, infoForType.Descriptor));
        }
Esempio n. 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];
            var successfulEventCount = 0;

            for (var i = 0; i < eventCount; i++)
            {
                var ev = Mapping.LoadObject(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. 3
0
        ByteBuffer WriteSecondaryKeyKey(uint secondaryKeyIndex, ByteBuffer keyBytes, ByteBuffer valueBytes)
        {
            var keyWriter = new ByteBufferWriter();

            keyWriter.WriteVUInt32(_relationInfo.Id);
            keyWriter.WriteVUInt32(secondaryKeyIndex);

            var valueReader = new ByteBufferReader(valueBytes);
            var version     = valueReader.ReadVUInt32();

            var keySaver = _relationInfo.GetPKValToSKMerger(version, secondaryKeyIndex);

            keySaver(_transaction, keyWriter, new ByteBufferReader(keyBytes), new ByteBufferReader(valueBytes), _relationInfo.DefaultClientObject);
            return(keyWriter.Data);
        }
Esempio n. 4
0
        public object CreateInstance(IInternalObjectDBTransaction tr, ByteBuffer keyBytes, ByteBuffer valueBytes,
                                     bool keyContainsRelationIndex = true)
        {
            var obj       = Creator(tr);
            var keyReader = new ByteBufferReader(keyBytes);

            if (keyContainsRelationIndex)
            {
                keyReader.SkipVUInt32(); //index Relation
            }
            GetPrimaryKeysLoader(ClientTypeVersion)(tr, keyReader, obj);
            var valueReader = new ByteBufferReader(valueBytes);
            var version     = valueReader.ReadVUInt32();

            GetValueLoader(version)(tr, valueReader, obj);
            return(obj);
        }