From b11e83a167cd57778070db4df5c193b25f6f392d Mon Sep 17 00:00:00 2001 From: Forest Date: Fri, 20 Jul 2018 11:32:21 -0700 Subject: [PATCH] A couple more reader/writer things and maybe something else? --- Hazel/MessageReader.cs | 8 ++++++++ Hazel/MessageWriter.cs | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Hazel/MessageReader.cs b/Hazel/MessageReader.cs index 7e4fc03..9287023 100644 --- a/Hazel/MessageReader.cs +++ b/Hazel/MessageReader.cs @@ -76,6 +76,14 @@ namespace Hazel return output; } + public short ReadInt16() + { + short output = + (short)(this.Buffer[Position++] + | this.Buffer[Position++] << 8); + return output; + } + public int ReadInt32() { int output = this.Buffer[Position++] diff --git a/Hazel/MessageWriter.cs b/Hazel/MessageWriter.cs index 22640e6..7f38860 100644 --- a/Hazel/MessageWriter.cs +++ b/Hazel/MessageWriter.cs @@ -113,6 +113,13 @@ namespace Hazel if (this.Position > this.Length) this.Length = this.Position; } + public void Write(short value) + { + this.Buffer[this.Position++] = (byte)value; + this.Buffer[this.Position++] = (byte)(value >> 8); + if (this.Position > this.Length) this.Length = this.Position; + } + public void Write(ushort value) { this.Buffer[this.Position++] = (byte)value; @@ -152,7 +159,7 @@ namespace Hazel this.Write(bytes); } - public void WriteBytesFull(byte[] bytes) + public void WriteBytesAndSize(byte[] bytes) { this.WritePacked((uint)bytes.Length); this.Write(bytes); -- 2.39.5