Skip to content

Commit

Permalink
Latest updates (won't build yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Jan 17, 2024
1 parent 0f503f4 commit f23183b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/NexusMods.EventSourcing.Abstractions/EntityIdDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Buffers;
using System.Buffers.Binary;
using NexusMods.EventSourcing.Abstractions.Serialization;

namespace NexusMods.EventSourcing.Abstractions;

public class EntityIdDefinition : IAttribute<EntityDefinitionAccumulator>, IIndexableAttribute<EntityId>
{
/// <inheritdoc />
public Type Owner => typeof(IEntity);

/// <inheritdoc />
public string Name => "Id";
public EntityDefinitionAccumulator CreateAccumulator()
{
return new EntityDefinitionAccumulator();
}

IAccumulator IAttribute.CreateAccumulator()
{
return new EntityDefinitionAccumulator();
}

public void WriteTo(Span<byte> span, EntityId value)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public UInt128 IndexedAttributeId { get; set; }

/// <inheritdoc />
public int SpanSize()
{
return 16;
}

/// <inheritdoc />
public void WriteTo(Span<byte> span, IAccumulator accumulator)
{

}
}

internal class EntityDefinitionAccumulator : IAccumulator
{
internal EntityId Id;

public void WriteTo(IBufferWriter<byte> writer, ISerializationRegistry registry)
{
var span = writer.GetSpan(16);
BinaryPrimitives.WriteUInt128BigEndian(span, Id.Value);
writer.Advance(16);
}

public int ReadFrom(ref ReadOnlySpan<byte> data, ISerializationRegistry registry)
{
Id = EntityId.From(data);
return 16;
}
}
3 changes: 3 additions & 0 deletions src/NexusMods.EventSourcing.Abstractions/IEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public interface IEntity : INotifyPropertyChanged
/// </summary>
public static readonly TypeAttributeDefinition TypeAttribute = new();


public static readonly ScalarAttribute<IEntity, EntityId> EntityIdAttribute = new("Id");

/// <summary>
/// Called when a property of the entity has changed.
/// </summary>
Expand Down

0 comments on commit f23183b

Please sign in to comment.