Skip to content

Commit 7ca8911

Browse files
committed
Added IBitWritable interface for structs
1 parent 67af7b2 commit 7ca8911

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

MLAPI/NetworkingManagerComponents/Binary/BitReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ public object ReadObjectPacked(Type type)
174174
return null;
175175
}
176176
}
177-
if (typeof(BitWritable).IsAssignableFrom(type))
177+
if (typeof(IBitWritable).IsAssignableFrom(type))
178178
{
179179
object instance = Activator.CreateInstance(type);
180-
((BitWritable)instance).Read(this.source);
180+
((IBitWritable)instance).Read(this.source);
181181
return instance;
182182
}
183183

MLAPI/NetworkingManagerComponents/Binary/BitWritable.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,27 @@
44

55
namespace MLAPI.Serialization
66
{
7-
[Obsolete("The IBitWritable interface has been replaced with the abstract BitWritable class", true)]
7+
/// <summary>
8+
/// Interface for serializable classes and structs
9+
/// </summary>
810
public interface IBitWritable
911
{
10-
[Obsolete("The IBitWritable interface has been replaced with the abstract BitWritable class", true)]
12+
/// <summary>
13+
/// Reads the contents from the stream and applies it to the type instance
14+
/// </summary>
15+
/// <param name="stream">The stream to read from</param>
1116
void Read(Stream stream);
12-
[Obsolete("The IBitWritable interface has been replaced with the abstract BitWritable class", true)]
17+
/// <summary>
18+
/// Writes the contents of the type instance to the stream
19+
/// </summary>
20+
/// <param name="stream">The stream to write to</param>
1321
void Write(Stream stream);
1422
}
1523

1624
/// <summary>
1725
/// BitWritable is the base class for writable types
1826
/// </summary>
19-
public abstract class BitWritable
27+
public abstract class AutoBitWritable : IBitWritable
2028
{
2129
/// <summary>
2230
/// Writes the contents of the type instance to the stream

MLAPI/NetworkingManagerComponents/Binary/BitWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ public void WriteObjectPacked(object value)
190190
WriteUInt16Packed(((NetworkedBehaviour)value).GetBehaviourId());
191191
return;
192192
}
193-
else if (value is BitWritable)
193+
else if (value is IBitWritable)
194194
{
195195
if (value == null)
196196
{
197197
throw new ArgumentException("BitWriter cannot write IBitWritable types with a null value");
198198
}
199-
((BitWritable)value).Write(this.sink);
199+
((IBitWritable)value).Write(this.sink);
200200
return;
201201
}
202202

MLAPI/NetworkingManagerComponents/Binary/SerializationHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;
5+
using MLAPI.Internal;
56
using UnityEngine;
67

78
namespace MLAPI.Serialization
@@ -65,7 +66,7 @@ internal static FieldInfo[] GetFieldsForType(Type type)
6566
/// <returns>Whether or not the type is supported</returns>
6667
public static bool IsTypeSupported(Type type)
6768
{
68-
return type.IsEnum || SupportedTypes.Contains(type) || (typeof(BitWritable).IsAssignableFrom(type));
69+
return type.IsEnum || SupportedTypes.Contains(type) || type.HasInterface(typeof(IBitWritable));
6970
}
7071
}
7172
}

0 commit comments

Comments
 (0)