From: Forest Date: Wed, 30 Jun 2021 03:11:45 +0000 (-0700) Subject: Add long/ulong support X-Git-Tag: 1.0.0~2^2 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=2a4a13eeb77b969743d656e114cd2de6479499e6;p=rhonda%2Fimpostor.hazel.git Add long/ulong support --- diff --git a/Hazel/MessageReader.cs b/Hazel/MessageReader.cs index 190be12..4e0cd2a 100644 --- a/Hazel/MessageReader.cs +++ b/Hazel/MessageReader.cs @@ -309,6 +309,34 @@ namespace Hazel return output; } + public ulong ReadUInt64() + { + ulong output = (ulong)this.FastByte() + | (ulong)this.FastByte() << 8 + | (ulong)this.FastByte() << 16 + | (ulong)this.FastByte() << 24 + | (ulong)this.FastByte() << 32 + | (ulong)this.FastByte() << 40 + | (ulong)this.FastByte() << 48 + | (ulong)this.FastByte() << 56; + + return output; + } + + public long ReadInt64() + { + long output = (long)this.FastByte() + | (long)this.FastByte() << 8 + | (long)this.FastByte() << 16 + | (long)this.FastByte() << 24 + | (long)this.FastByte() << 32 + | (long)this.FastByte() << 40 + | (long)this.FastByte() << 48 + | (long)this.FastByte() << 56; + + return output; + } + public unsafe float ReadSingle() { float output = 0; diff --git a/Hazel/MessageWriter.cs b/Hazel/MessageWriter.cs index 0cabb66..7d4e050 100644 --- a/Hazel/MessageWriter.cs +++ b/Hazel/MessageWriter.cs @@ -204,6 +204,32 @@ namespace Hazel if (this.Position > this.Length) this.Length = this.Position; } + public void Write(ulong value) + { + this.Buffer[this.Position++] = (byte)value; + this.Buffer[this.Position++] = (byte)(value >> 8); + this.Buffer[this.Position++] = (byte)(value >> 16); + this.Buffer[this.Position++] = (byte)(value >> 24); + this.Buffer[this.Position++] = (byte)(value >> 32); + this.Buffer[this.Position++] = (byte)(value >> 40); + this.Buffer[this.Position++] = (byte)(value >> 48); + this.Buffer[this.Position++] = (byte)(value >> 56); + if (this.Position > this.Length) this.Length = this.Position; + } + + public void Write(long value) + { + this.Buffer[this.Position++] = (byte)value; + this.Buffer[this.Position++] = (byte)(value >> 8); + this.Buffer[this.Position++] = (byte)(value >> 16); + this.Buffer[this.Position++] = (byte)(value >> 24); + this.Buffer[this.Position++] = (byte)(value >> 32); + this.Buffer[this.Position++] = (byte)(value >> 40); + this.Buffer[this.Position++] = (byte)(value >> 48); + this.Buffer[this.Position++] = (byte)(value >> 56); + if (this.Position > this.Length) this.Length = this.Position; + } + public unsafe void Write(float value) { fixed (byte* ptr = &this.Buffer[this.Position])