Skip to content

Commit

Permalink
refactor 'EnumComponent' & custom serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
akopetsch committed May 31, 2024
1 parent 01ec7b5 commit 22df036
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
10 changes: 0 additions & 10 deletions ByteSerialization/Components/Values/Customs/ICustomSerializable.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ByteSerialization.Components.Values.Primitives
{
public class EnumComponent : PrimitiveComponent
public class EnumPrimitiveComponent : PrimitiveComponent
{
private Type UnderlyingType { get; set; }

Expand Down
6 changes: 3 additions & 3 deletions ByteSerialization/Components/Values/ValueComponentFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions ByteSerialization/ICustomSerializable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT

using ByteSerialization.IO;

namespace ByteSerialization
{
public interface ICustomSerializable
{
void Serialize(EndianBinaryWriter writer);
void Deserialize(EndianBinaryReader reader);
}
}

0 comments on commit 22df036

Please sign in to comment.