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(); }
public void ProcessMetadataLog(ByteBuffer buffer) { var reader = new ByteBufferReader(buffer); var typeId = reader.ReadVInt32(); while (typeId != 0) { var typeCategory = (TypeCategory)reader.ReadUInt8(); ITypeDescriptor descriptor; switch (typeCategory) { case TypeCategory.BuildIn: throw new ArgumentOutOfRangeException(); case TypeCategory.Class: descriptor = new ObjectTypeDescriptor(this, reader, NestedDescriptorReader); break; case TypeCategory.List: descriptor = new ListTypeDescriptor(this, reader, NestedDescriptorReader); break; case TypeCategory.Dictionary: descriptor = new DictionaryTypeDescriptor(this, reader, NestedDescriptorReader); break; case TypeCategory.Enum: descriptor = new EnumTypeDescriptor(this, reader); break; default: throw new ArgumentOutOfRangeException(); } while (-typeId - 1 >= _id2InfoNew.Count) _id2InfoNew.Add(null); if (_id2InfoNew[-typeId - 1] == null) _id2InfoNew[-typeId - 1] = new SerializerTypeInfo { Id = typeId, Descriptor = descriptor }; typeId = reader.ReadVInt32(); } for (var i = 0; i < _id2InfoNew.Count; i++) { _id2InfoNew[i].Descriptor.MapNestedTypes(d => { var placeHolderDescriptor = d as PlaceHolderDescriptor; return placeHolderDescriptor != null ? _id2InfoNew[-placeHolderDescriptor.TypeId - 1].Descriptor : d; }); } // This additional cycle is needed to fill names of recursive structures for (var i = 0; i < _id2InfoNew.Count; i++) { _id2InfoNew[i].Descriptor.MapNestedTypes(d => d); } for (var i = 0; i < _id2InfoNew.Count; i++) { var infoForType = _id2InfoNew[i]; for (var j = ReservedBuildinTypes; j < _id2Info.Count; j++) { if (infoForType.Descriptor.Equals(_id2Info[j].Descriptor)) { _remapToOld[infoForType.Descriptor] = _id2Info[j].Descriptor; _id2InfoNew[i] = _id2Info[j]; infoForType = _id2InfoNew[i]; break; } } if (infoForType.Id < 0) { infoForType.Id = _id2Info.Count; _id2Info.Add(infoForType); _typeOrDescriptor2Info[infoForType.Descriptor] = infoForType; } } for (var i = 0; i < _id2InfoNew.Count; i++) { _id2InfoNew[i].Descriptor.MapNestedTypes(d => { ITypeDescriptor res; return _remapToOld.TryGetValue(d, out res) ? res : d; }); } _id2InfoNew.Clear(); _remapToOld.Clear(); }
internal MemorizedPosition(ByteBufferReader owner, int pos, int end) { _owner = owner; _pos = pos; _end = end; }