add sbyte[] support to Reader and Writer

This commit is contained in:
Michael Becker 2020-06-17 18:29:36 -04:00
parent 2d5bbeadba
commit 33ce82b717
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
2 changed files with 22 additions and 0 deletions

View File

@ -141,6 +141,13 @@ namespace UniversalEditor.IO
return buffer;
}
[CLSCompliant(false)]
public sbyte[] ReadSBytes(long length)
{
byte[] buffer = ReadBytes(length);
return (sbyte[])(Array)buffer;
}
public int ReadCompactInt32()
{
int multiplier = 1;

View File

@ -62,6 +62,21 @@ namespace UniversalEditor.IO
Write(data, 0, data.Length);
}
[CLSCompliant(false)]
public void WriteSBytes(sbyte[] data)
{
if (data == null) return;
// thanks https://stackoverflow.com/questions/829983/how-to-convert-a-sbyte-to-byte-in-c
byte[] realdata = (byte[])(Array)data;
for (int i = 0; i < Transformations.Count; i++)
{
realdata = Transformations[i].Transform(realdata);
}
Write(realdata, 0, realdata.Length);
}
public void WriteFixedLengthBytes(byte[] data, int count)
{
if (data == null) data = new byte[0];