From 22df0368b3bbac1f43daa57272cc99b2da7b0590 Mon Sep 17 00:00:00 2001 From: Alexander Kopetsch Date: Sat, 1 Jun 2024 01:36:52 +0200 Subject: [PATCH] refactor 'EnumComponent' & custom serialization --- .../CustomSerializableComponent.cs} | 8 ++++---- .../Components/Values/Customs/ICustomSerializable.cs | 10 ---------- .../{EnumComponent.cs => EnumPrimitiveComponent.cs} | 2 +- .../Components/Values/ValueComponentFactory.cs | 6 +++--- ByteSerialization/ICustomSerializable.cs | 12 ++++++++++++ 5 files changed, 20 insertions(+), 18 deletions(-) rename ByteSerialization/Components/Values/{Customs/CustomComponent.cs => CustomSerializables/CustomSerializableComponent.cs} (64%) delete mode 100644 ByteSerialization/Components/Values/Customs/ICustomSerializable.cs rename ByteSerialization/Components/Values/Primitives/{EnumComponent.cs => EnumPrimitiveComponent.cs} (88%) create mode 100644 ByteSerialization/ICustomSerializable.cs diff --git a/ByteSerialization/Components/Values/Customs/CustomComponent.cs b/ByteSerialization/Components/Values/CustomSerializables/CustomSerializableComponent.cs similarity index 64% rename from ByteSerialization/Components/Values/Customs/CustomComponent.cs rename to ByteSerialization/Components/Values/CustomSerializables/CustomSerializableComponent.cs index 59f347d..c2d1bd5 100644 --- a/ByteSerialization/Components/Values/Customs/CustomComponent.cs +++ b/ByteSerialization/Components/Values/CustomSerializables/CustomSerializableComponent.cs @@ -2,23 +2,23 @@ using System; -namespace ByteSerialization.Components.Values.Customs +namespace ByteSerialization.Components.Values.CustomSerializables { - public class CustomComponent : ValueComponent + public class CustomSerializableComponent : ValueComponent { private ICustomSerializable CustomSerializable { get; set; } public override void Serialize() { CustomSerializable = Node.Value as ICustomSerializable; - CustomSerializable.Serialize(this); + CustomSerializable.Serialize(Writer); } public override void Deserialize() { Node.Value = Activator.CreateInstance(Node.Type); CustomSerializable = Node.Value as ICustomSerializable; - CustomSerializable.Deserialize(this); + CustomSerializable.Deserialize(Reader); } } } diff --git a/ByteSerialization/Components/Values/Customs/ICustomSerializable.cs b/ByteSerialization/Components/Values/Customs/ICustomSerializable.cs deleted file mode 100644 index 1684105..0000000 --- a/ByteSerialization/Components/Values/Customs/ICustomSerializable.cs +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: MIT - -namespace ByteSerialization.Components.Values.Customs -{ - public interface ICustomSerializable - { - void Serialize(CustomComponent customComponent); - void Deserialize(CustomComponent customComponent); - } -} diff --git a/ByteSerialization/Components/Values/Primitives/EnumComponent.cs b/ByteSerialization/Components/Values/Primitives/EnumPrimitiveComponent.cs similarity index 88% rename from ByteSerialization/Components/Values/Primitives/EnumComponent.cs rename to ByteSerialization/Components/Values/Primitives/EnumPrimitiveComponent.cs index f019909..f8a7f56 100644 --- a/ByteSerialization/Components/Values/Primitives/EnumComponent.cs +++ b/ByteSerialization/Components/Values/Primitives/EnumPrimitiveComponent.cs @@ -4,7 +4,7 @@ namespace ByteSerialization.Components.Values.Primitives { - public class EnumComponent : PrimitiveComponent + public class EnumPrimitiveComponent : PrimitiveComponent { private Type UnderlyingType { get; set; } diff --git a/ByteSerialization/Components/Values/ValueComponentFactory.cs b/ByteSerialization/Components/Values/ValueComponentFactory.cs index 7075812..ec5434b 100644 --- a/ByteSerialization/Components/Values/ValueComponentFactory.cs +++ b/ByteSerialization/Components/Values/ValueComponentFactory.cs @@ -2,7 +2,7 @@ using ByteSerialization.Components.Values.Composites.Collections; using ByteSerialization.Components.Values.Composites.Records; -using ByteSerialization.Components.Values.Customs; +using ByteSerialization.Components.Values.CustomSerializables; using ByteSerialization.Components.Values.CustomSerializers; using ByteSerialization.Components.Values.Primitives; using ByteSerialization.Extensions; @@ -29,11 +29,11 @@ public Type GetComponentType(Type type) if (type.IsPrimitive) return typeof(PrimitiveComponent); if (type.IsEnum) - return typeof(EnumComponent); + return typeof(EnumPrimitiveComponent); } if (typeof(ICustomSerializable).IsAssignableFrom(type)) - return typeof(CustomComponent); + return typeof(CustomSerializableComponent); if (type.IsArray) return typeof(ArrayComponent); diff --git a/ByteSerialization/ICustomSerializable.cs b/ByteSerialization/ICustomSerializable.cs new file mode 100644 index 0000000..f1d89e1 --- /dev/null +++ b/ByteSerialization/ICustomSerializable.cs @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT + +using ByteSerialization.IO; + +namespace ByteSerialization +{ + public interface ICustomSerializable + { + void Serialize(EndianBinaryWriter writer); + void Deserialize(EndianBinaryReader reader); + } +}