This repository has been archived by the owner on Sep 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialize content to/from binary using BinaryPack
- Loading branch information
Showing
40 changed files
with
68 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using BinaryPack; | ||
using System.IO.Compression; | ||
|
||
namespace Apparatus.Core.Common; | ||
|
||
public static class Serializer | ||
{ | ||
public static byte[] Serialize<T>(T obj) where T : new() | ||
{ | ||
var serialized = BinaryConverter.Serialize(obj); | ||
|
||
return Compress(serialized); | ||
} | ||
|
||
public static T? Deserialize<T>(byte[] data) where T : new() | ||
{ | ||
var serialized = Decompress(data); | ||
|
||
return BinaryConverter.Deserialize<T>(serialized); | ||
} | ||
|
||
public static byte[] Compress(byte[] uncompressedData) | ||
{ | ||
using var stream = new MemoryStream(); | ||
using var deflate = new DeflateStream(stream, CompressionLevel.Fastest); | ||
|
||
deflate.Write(uncompressedData); | ||
deflate.Close(); | ||
|
||
return stream.ToArray(); | ||
} | ||
|
||
public static byte[] Decompress(byte[] compressedData) | ||
{ | ||
using var outputStream = new MemoryStream(); | ||
|
||
using (var compressStream = new MemoryStream(compressedData)) | ||
{ | ||
using var deflateStream = new DeflateStream(compressStream, CompressionMode.Decompress); | ||
deflateStream.CopyTo(outputStream); | ||
} | ||
|
||
return outputStream.ToArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
-2.92 MB
(18%)
Source/Mocha.Example/fs/content/materials/Floor_base.texture
Binary file not shown.
Binary file modified
BIN
-2.95 MB
(17%)
Source/Mocha.Example/fs/content/materials/Floor_normal.texture
Binary file not shown.
Binary file modified
BIN
-3.05 MB
(14%)
Source/Mocha.Example/fs/content/materials/Floor_packed.texture
Binary file not shown.
Binary file modified
BIN
-3.09 MB
(13%)
Source/Mocha.Example/fs/content/materials/PBR/Floor_ao.texture
Binary file not shown.
Binary file modified
BIN
-2.92 MB
(18%)
Source/Mocha.Example/fs/content/materials/PBR/Floor_color.texture
Binary file not shown.
Binary file modified
BIN
-3.21 MB
(9.6%)
Source/Mocha.Example/fs/content/materials/PBR/Floor_metal.texture
Binary file not shown.
Binary file modified
BIN
-2.95 MB
(17%)
Source/Mocha.Example/fs/content/materials/PBR/Floor_normal.texture
Binary file not shown.
Binary file modified
BIN
-3.03 MB
(15%)
Source/Mocha.Example/fs/content/materials/PBR/Floor_smooth.texture
Binary file not shown.
Binary file modified
BIN
-3.01 MB
(15%)
Source/Mocha.Example/fs/content/materials/PBR/ice_color.texture
Binary file not shown.
Binary file modified
BIN
-3.09 MB
(13%)
Source/Mocha.Example/fs/content/materials/PBR/ice_height.texture
Binary file not shown.
Binary file modified
BIN
-3.24 MB
(8.9%)
Source/Mocha.Example/fs/content/materials/PBR/ice_normal.texture
Binary file not shown.
Binary file modified
BIN
-3.03 MB
(15%)
Source/Mocha.Example/fs/content/materials/PBR/ice_rough.texture
Binary file not shown.
Binary file modified
BIN
-2.89 MB
(19%)
Source/Mocha.Example/fs/content/materials/PBR/tiles_color.texture
Binary file not shown.
Binary file modified
BIN
-2.99 MB
(16%)
Source/Mocha.Example/fs/content/materials/PBR/tiles_height.texture
Binary file not shown.
Binary file modified
BIN
-2.86 MB
(20%)
Source/Mocha.Example/fs/content/materials/PBR/tiles_normal.texture
Binary file not shown.
Binary file modified
BIN
-2.97 MB
(17%)
Source/Mocha.Example/fs/content/materials/PBR/tiles_rough.texture
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-3.24 MB
(8.9%)
Source/Mocha.Example/fs/content/materials/ice_normal.texture
Binary file not shown.
Binary file modified
BIN
-3.08 MB
(13%)
Source/Mocha.Example/fs/content/materials/ice_packed.texture
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-2.89 MB
(19%)
Source/Mocha.Example/fs/content/materials/tiles_base.texture
Binary file not shown.
Binary file modified
BIN
-2.86 MB
(20%)
Source/Mocha.Example/fs/content/materials/tiles_normal.texture
Binary file not shown.
Binary file modified
BIN
-2.93 MB
(18%)
Source/Mocha.Example/fs/content/materials/tiles_packed.texture
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters