0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-18 23:59:46 +03:00

добавил tma в просмотр и отрефакторил код

This commit is contained in:
bird_egop
2024-11-26 04:05:25 +03:00
parent b336f44b72
commit e16b219854
28 changed files with 878 additions and 537 deletions

View File

@ -0,0 +1,39 @@
using System.Buffers.Binary;
using System.Text;
namespace MissionTmaLib.Parsing;
public static class Extensions
{
public static int ReadInt32LittleEndian(this FileStream fs)
{
Span<byte> buf = stackalloc byte[4];
fs.ReadExactly(buf);
return BinaryPrimitives.ReadInt32LittleEndian(buf);
}
public static float ReadFloatLittleEndian(this FileStream fs)
{
Span<byte> buf = stackalloc byte[4];
fs.ReadExactly(buf);
return BinaryPrimitives.ReadSingleLittleEndian(buf);
}
public static string ReadLengthPrefixedString(this FileStream fs)
{
var len = fs.ReadInt32LittleEndian();
if (len == 0)
{
return "";
}
var buffer = new byte[len];
fs.ReadExactly(buffer, 0, len);
return Encoding.ASCII.GetString(buffer, 0, len);
}
}