Skip to content

Commit

Permalink
Fix the remaining code based errors
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Jan 19, 2024
1 parent c575c82 commit e6253e4
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/NexusMods.EventSourcing.RocksDB/RocksDBEventStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

namespace NexusMods.EventSourcing.RocksDB;

/// <summary>
/// RocksDB event store
/// </summary>
/// <typeparam name="TSerializer"></typeparam>
public sealed class RocksDBEventStore<TSerializer> : AEventStore, IDisposable
where TSerializer : IEventSerializer
{
Expand All @@ -23,6 +27,12 @@ public sealed class RocksDBEventStore<TSerializer> : AEventStore, IDisposable
private readonly ColumnFamilyHandle _snapshotColumn;
private readonly Dictionary<IIndexableAttribute,ColumnFamilyHandle> _indexColumns;

/// <summary>
/// DI constructor
/// </summary>
/// <param name="serializer"></param>
/// <param name="settings"></param>
/// <param name="serializationRegistry"></param>
public RocksDBEventStore(TSerializer serializer, Settings settings, ISerializationRegistry serializationRegistry) : base(serializationRegistry)
{
_serializer = serializer;
Expand Down Expand Up @@ -118,6 +128,7 @@ private void PutIndex(IIndexableAttribute attr, IAccumulator accumulator, Transa
_db.Put(keySpan, ReadOnlySpan<byte>.Empty, _indexColumns[attr]);
}

/// <inheritdoc />
public override void EventsForIndex<TIngester, TVal>(IIndexableAttribute<TVal> attr, TVal value, TIngester ingester, TransactionId fromTx,
TransactionId toTx)
{
Expand Down Expand Up @@ -167,6 +178,7 @@ public override void EventsForIndex<TIngester, TVal>(IIndexableAttribute<TVal> a

}

/// <inheritdoc />
public override TransactionId GetSnapshot(TransactionId asOf, EntityId entityId, out IAccumulator loadedDefinition,
out (IAttribute Attribute, IAccumulator Accumulator)[] loadedAttributes)
{
Expand Down Expand Up @@ -224,6 +236,7 @@ public override TransactionId GetSnapshot(TransactionId asOf, EntityId entityId,
return TransactionId.Min;
}

/// <inheritdoc />
public override void SetSnapshot(TransactionId txId, EntityId id, IDictionary<IAttribute, IAccumulator> attributes)
{
var span = SerializeSnapshot(id, attributes);
Expand Down
6 changes: 6 additions & 0 deletions src/NexusMods.EventSourcing.RocksDB/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

namespace NexusMods.EventSourcing.RocksDB;

/// <summary>
/// Settings for the RocksDB event store.
/// </summary>
public class Settings
{
/// <summary>
/// The storage location for the RocksDB database
/// </summary>
public AbsolutePath StorageLocation { get; set; } = default!;
}
6 changes: 6 additions & 0 deletions src/NexusMods.EventSourcing.RocksDB/SpanDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

namespace NexusMods.EventSourcing.RocksDB;

/// <summary>
/// A deserializer for RocksDB events, used so we can deserializer during read events
/// </summary>
/// <param name="serializer"></param>
/// <typeparam name="TSerializer"></typeparam>
public class SpanDeserializer<TSerializer>(TSerializer serializer) : ISpanDeserializer<IEvent>
where TSerializer : IEventSerializer
{
/// <inheritdoc />
public IEvent Deserialize(ReadOnlySpan<byte> buffer)
{
return serializer.Deserialize(buffer);
Expand Down
6 changes: 6 additions & 0 deletions src/NexusMods.EventSourcing/IndexerIngester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ namespace NexusMods.EventSourcing;
/// </summary>
public class IndexerIngester : IEventIngester, IEventContext
{
/// <summary>
/// The attributes that were indexed.
/// </summary>
public readonly Dictionary<IIndexableAttribute, List<IAccumulator>> IndexedAttributes = new();

/// <summary>
/// The entity ids that were indexed.
/// </summary>
public readonly HashSet<EntityId> Ids = new();


Expand Down
7 changes: 7 additions & 0 deletions src/NexusMods.EventSourcing/Serialization/StringSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@

namespace NexusMods.EventSourcing.Serialization;

/// <summary>
/// Serializer for writing strings.
/// </summary>
public class StringSerializer : IVariableSizeSerializer<string>
{
/// <inheritdoc />
public bool CanSerialize(Type valueType)
{
return valueType == typeof(string);
}

/// <inheritdoc />
public bool TryGetFixedSize(Type valueType, out int size)
{
size = 0;
return false;
}

/// <inheritdoc />
public void Serialize<TWriter>(string value, TWriter output) where TWriter : IBufferWriter<byte>
{
var size = System.Text.Encoding.UTF8.GetByteCount(value);
Expand All @@ -28,6 +34,7 @@ public void Serialize<TWriter>(string value, TWriter output) where TWriter : IBu
output.Advance(size + 2);
}

/// <inheritdoc />
public int Deserialize(ReadOnlySpan<byte> from, out string value)
{
var size = BinaryPrimitives.ReadUInt16LittleEndian(from);
Expand Down
7 changes: 7 additions & 0 deletions src/NexusMods.EventSourcing/Serialization/UInt32Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@

namespace NexusMods.EventSourcing.Serialization;

/// <summary>
/// Serializer for writing UInt32.
/// </summary>
public sealed class UInt32Serializer : IFixedSizeSerializer<uint>
{
/// <inheritdoc />
public bool CanSerialize(Type valueType) => valueType == typeof(uint);

/// <inheritdoc />
public bool TryGetFixedSize(Type valueType, out int size)
{
size = sizeof(uint);
return valueType == typeof(uint);
}

/// <inheritdoc />
public void Serialize(uint value, Span<byte> output)
{
BinaryPrimitives.WriteUInt32BigEndian(output, value);
}

/// <inheritdoc />
public uint Deserialize(ReadOnlySpan<byte> from)
{
return BinaryPrimitives.ReadUInt32BigEndian(from);
Expand Down
7 changes: 7 additions & 0 deletions src/NexusMods.EventSourcing/Serialization/UInt64Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@

namespace NexusMods.EventSourcing.Serialization;

/// <summary>
/// Serializer for writing UInt64.
/// </summary>
public sealed class UInt64Serializer : IFixedSizeSerializer<ulong>
{
/// <inheritdoc />
public bool CanSerialize(Type valueType) => valueType == typeof(ulong);

/// <inheritdoc />
public bool TryGetFixedSize(Type valueType, out int size)
{
size = sizeof(ulong);
return valueType == typeof(ulong);
}

/// <inheritdoc />
public void Serialize(ulong value, Span<byte> output)
{
BinaryPrimitives.WriteUInt64BigEndian(output, value);
}

/// <inheritdoc />
public ulong Deserialize(ReadOnlySpan<byte> from)
{
return BinaryPrimitives.ReadUInt64BigEndian(from);
Expand Down
7 changes: 7 additions & 0 deletions src/NexusMods.EventSourcing/Serialization/UInt8Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@

namespace NexusMods.EventSourcing.Serialization;

/// <summary>
/// Serializer for writing UInt8.
/// </summary>
public sealed class UInt8Serializer : IFixedSizeSerializer<byte>
{
/// <inheritdoc />
public bool CanSerialize(Type valueType) => valueType == typeof(byte);

/// <inheritdoc />
public bool TryGetFixedSize(Type valueType, out int size)
{
size = sizeof(byte);
return valueType == typeof(byte);
}

/// <inheritdoc />
public void Serialize(byte value, Span<byte> output)
{
output[0] = value;
}

/// <inheritdoc />
public byte Deserialize(ReadOnlySpan<byte> from)
{
return from[0];
Expand Down
8 changes: 8 additions & 0 deletions src/NexusMods.EventSourcing/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@

namespace NexusMods.EventSourcing;

/// <summary>
/// The services for the Event Sourcing library.
/// </summary>
public static class Services
{
/// <summary>
/// Adds the Event Sourcing services to the service collection.
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddEventSourcing(this IServiceCollection services)
{
return services
Expand Down

0 comments on commit e6253e4

Please sign in to comment.