generated from Nexus-Mods/NexusMods.App.Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/NexusMods.EventSourcing.Abstractions/EntityIdDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters