From 33ce82b717ad8778ce67f2c166703ba95a80cba3 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 17 Jun 2020 18:29:36 -0400 Subject: [PATCH] add sbyte[] support to Reader and Writer --- Libraries/UniversalEditor.Core/IO/Reader.cs | 7 +++++++ Libraries/UniversalEditor.Core/IO/Writer.cs | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Libraries/UniversalEditor.Core/IO/Reader.cs b/Libraries/UniversalEditor.Core/IO/Reader.cs index 71b8533c..3a259fc5 100644 --- a/Libraries/UniversalEditor.Core/IO/Reader.cs +++ b/Libraries/UniversalEditor.Core/IO/Reader.cs @@ -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; diff --git a/Libraries/UniversalEditor.Core/IO/Writer.cs b/Libraries/UniversalEditor.Core/IO/Writer.cs index 1936f853..a912f886 100644 --- a/Libraries/UniversalEditor.Core/IO/Writer.cs +++ b/Libraries/UniversalEditor.Core/IO/Writer.cs @@ -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];