From 8968ec3ce04a6dd2f65ffcce6713bbe59fc92c53 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 20 Dec 2019 15:07:25 +0100 Subject: [PATCH] fixed write and read object --- MLEM.Data/NetExtensions.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MLEM.Data/NetExtensions.cs b/MLEM.Data/NetExtensions.cs index 93489e2..c56b59d 100644 --- a/MLEM.Data/NetExtensions.cs +++ b/MLEM.Data/NetExtensions.cs @@ -39,12 +39,16 @@ namespace MLEM.Data { using (var memory = new MemoryStream()) { using (var gzip = new GZipStream(memory, CompressionLevel.Fastest, true)) serializer.Serialize(new BsonDataWriter(gzip), obj, typeof(T)); - buffer.Write(memory.ToArray()); + var arr = memory.ToArray(); + buffer.Write(arr.Length); + buffer.Write(arr); } } public static T ReadObject(this NetBuffer buffer, JsonSerializer serializer) { - using (var memory = new MemoryStream(buffer.ReadBytes(buffer.LengthBytes))) { + var length = buffer.ReadInt32(); + var arr = buffer.ReadBytes(length); + using (var memory = new MemoryStream(arr)) { using (var gzip = new GZipStream(memory, CompressionMode.Decompress, true)) return serializer.Deserialize(new BsonDataReader(gzip)); }