File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
Source/Mocha.Common/Serialization Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -9,14 +9,28 @@ public static class Serializer
99 {
1010 var serialized = BinaryConverter . Serialize ( obj ) ;
1111
12- return Compress ( serialized ) ;
12+ if ( serialized . Length < 512 )
13+ {
14+ return serialized ;
15+ }
16+
17+ var header = "BILZ"u8 . ToArray ( ) ;
18+ return header . Concat ( Compress ( serialized ) ) . ToArray ( ) ;
1319 }
1420
1521 public static T ? Deserialize < T > ( byte [ ] data ) where T : new ( )
1622 {
17- var serialized = Decompress ( data ) ;
23+ byte [ ] decompressedData = data ;
24+
25+ if ( data . Length > 4 )
26+ {
27+ var header = data [ 0 ..4 ] ;
28+
29+ if ( Enumerable . SequenceEqual ( header , "BILZ"u8 . ToArray ( ) ) )
30+ decompressedData = Decompress ( data [ 4 ..] ) ;
31+ }
1832
19- return BinaryConverter . Deserialize < T > ( serialized ) ;
33+ return BinaryConverter . Deserialize < T > ( decompressedData ) ;
2034 }
2135
2236 public static byte [ ] Compress ( byte [ ] uncompressedData )
You can’t perform that action at this time.
0 commit comments