From: Forest Date: Fri, 20 Jul 2018 18:32:21 +0000 (-0700) Subject: A couple more reader/writer things and maybe something else? X-Git-Tag: 1.0.0~84 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=b11e83a167cd57778070db4df5c193b25f6f392d;p=rhonda%2Fimpostor.hazel.git A couple more reader/writer things and maybe something else? --- 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);