Skip to content

Commit

Permalink
Revert Serialization of Everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Xilophor committed Jul 9, 2024
1 parent c11b75a commit 8dcd720
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 32 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- This allows for vanilla compatibility, though it is not recommended
- Added `LNetworkMessage`
- Added `LNetworkEvent`
- Updated Serialization
- Serializes more types and fields/properties

### Deprecated
- The `LethalClientMessage` and `LethalServerMessage` classes
Expand Down
33 changes: 4 additions & 29 deletions LethalNetworkAPI/Internal/UnnamedMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void ReceiveMessage(ulong clientId, FastBufferReader reader)
reader.ReadValueSafe(out byte[] serializedMessageData);
reader.Dispose();

var (messageID, messageType, messageData) = DeserializeMessageData(serializedMessageData);
var (messageID, messageType, messageData) = Deserialize<MessageData>(serializedMessageData);

switch (messageType)
{
Expand Down Expand Up @@ -149,36 +149,11 @@ private void ReceiveMessage(ulong clientId, FastBufferReader reader)

#region Helper Methods

private static readonly SerializationContext DefaultSerializationContext = new()
{
Config = new SerializationConfig()
{
SerializationPolicy = SerializationPolicies.Everything
}
};

private static readonly DeserializationContext DefaultDeserializationContext = new()
{
Config = new SerializationConfig()
{
SerializationPolicy = SerializationPolicies.Everything
}
};

internal static byte[] Serialize(object? data) =>
SerializationUtility.SerializeValue(data, DataFormat.Binary, DefaultSerializationContext);

internal static byte[] SerializeMessageData(MessageData messageData) =>
SerializationUtility.SerializeValue(messageData with { Data = Serialize(messageData.Data) }, DataFormat.Binary);
SerializationUtility.SerializeValue(data, DataFormat.Binary);

internal static T Deserialize<T>(byte[] serializedData) =>
SerializationUtility.DeserializeValue<T>(serializedData, DataFormat.Binary, DefaultDeserializationContext);

internal static MessageData DeserializeMessageData(byte[] serializedData)
{
var messageData = SerializationUtility.DeserializeValue<MessageData>(serializedData, DataFormat.Binary);
return messageData with { Data = Deserialize<object[]?>((byte[])messageData.Data!) };
}
SerializationUtility.DeserializeValue<T>(serializedData, DataFormat.Binary);

private static void WriteMessageData(out FastBufferWriter writer, MessageData messageData, bool deprecatedMessage = false)
{
Expand All @@ -197,7 +172,7 @@ private static void WriteMessageData(out FastBufferWriter writer, MessageData me
private static (byte[], int) SerializeDataAndGetSize(MessageData messageData)
{
var size = 0;
var serializedData = SerializeMessageData(messageData);
var serializedData = Serialize(messageData);

size += FastBufferWriter.GetWriteSize(LibIdentifier);
size += FastBufferWriter.GetWriteSize(serializedData);
Expand Down
2 changes: 1 addition & 1 deletion LethalNetworkAPI/Old/Networking/NetworkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void ReceiveMessage(ulong clientId, FastBufferReader reader)
reader.Dispose();

var (messageID, messageType, boxedMessageData) =
SerializationUtility.DeserializeValue<MessageData>(serializedMessageData, DataFormat.Binary);
UnnamedMessageHandler.Deserialize<MessageData>(serializedMessageData);

var messageData = (byte[])boxedMessageData!;

Expand Down

0 comments on commit 8dcd720

Please sign in to comment.