1
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-12-11 17:21:19 +04:00

Implement scr parsing

This commit is contained in:
bird_egop
2025-02-25 01:51:28 +03:00
parent ba7c2afe2a
commit b47a9aff5d
2 changed files with 92 additions and 33 deletions

View File

@@ -0,0 +1,39 @@
using System.Buffers.Binary;
using System.Text;
namespace ParkanPlayground;
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);
}
}