diff --git a/Convention/[RScript] b/Convention/[RScript] index d3e21ca..dde9e6b 160000 --- a/Convention/[RScript] +++ b/Convention/[RScript] @@ -1 +1 @@ -Subproject commit d3e21cad156f61ba46a61ec2008231de49ef946b +Subproject commit dde9e6b82da6479ba928c5ecf0ac3c6cacf8ee71 diff --git a/Convention/[Runtime]/File.cs b/Convention/[Runtime]/File.cs index c027103..2f1020c 100644 --- a/Convention/[Runtime]/File.cs +++ b/Convention/[Runtime]/File.cs @@ -161,18 +161,7 @@ namespace Convention { if (IsFile() == false) throw new InvalidOperationException("Target is not a file"); - var file = this.OriginInfo as FileInfo; - const int BlockSize = 1024; - long FileSize = file.Length; - byte[] result = new byte[FileSize]; - long offset = 0; - using (var fs = file.OpenRead()) - { - fs.ReadAsync(result[(int)(offset)..(int)(offset + BlockSize)], 0, (int)(offset + BlockSize) - (int)(offset)); - offset += BlockSize; - offset = System.Math.Min(offset, FileSize); - } - return result; + return File.ReadAllBytes(FullPath); } public List LoadAsCsv() @@ -245,7 +234,7 @@ namespace Convention public void SaveAsBinary(byte[] data) { - SaveDataAsBinary(FullPath, data, (OriginInfo as FileInfo).OpenWrite()); + File.WriteAllBytes(FullPath, data); } public void SaveAsCsv(List csvData) @@ -1113,4 +1102,32 @@ namespace Convention #endregion } + +#if ENABLE_UNSAFE + + public static class UnsafeBinarySerializer + { + public static unsafe byte[] StructToBytes(T structure) where T : unmanaged + { + int size = sizeof(T); + byte[] bytes = new byte[size]; + + fixed (byte* ptr = bytes) + { + *(T*)ptr = structure; + } + + return bytes; + } + + public static unsafe T BytesToStruct(byte[] bytes) where T : unmanaged + { + fixed (byte* ptr = bytes) + { + return *(T*)ptr; + } + } + } + +#endif }