From 2a4a13eeb77b969743d656e114cd2de6479499e6 Mon Sep 17 00:00:00 2001 From: Forest Date: Tue, 29 Jun 2021 20:11:45 -0700 Subject: [PATCH] Add long/ulong support --- Hazel/MessageReader.cs | 28 ++++++++++++++++++++++++++++ Hazel/MessageWriter.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) 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]) -- 2.39.5