diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 08d29ab..47931a4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,8 +21,8 @@ jobs: run: | VERSION_FILE=${{ github.workspace }}/.version VERSION=$(<"$VERSION_FILE") - echo ::set-env name=VERSION::$VERSION - echo ::set-env name=VERSION_E::$(echo ${GITHUB_SHA} | cut -c1-8) + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "VERSION_E=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_ENV mkdir ./release for RUNTIME in win-x86 win-x64 linux-x64 osx-x64; do # Server diff --git a/.version b/.version index afaf360..7f20734 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.0.0 \ No newline at end of file +1.0.1 \ No newline at end of file diff --git a/Arrowgene.Buffers/Buffer.cs b/Arrowgene.Buffers/Buffer.cs index 1ab9880..c11b92b 100644 --- a/Arrowgene.Buffers/Buffer.cs +++ b/Arrowgene.Buffers/Buffer.cs @@ -52,11 +52,13 @@ public Buffer(IEndiannessSwapper endiannessSwapper) public abstract IBuffer Provide(byte[] buffer); public abstract byte[] GetAllBytes(); public abstract byte[] GetAllBytes(int offset); + public abstract void WriteBool(bool value); public abstract void WriteByte(byte value); public abstract void WriteBytes(byte[] bytes); public abstract void WriteBytes(byte[] source, int srcOffset, int length); public abstract void WriteBytes(byte[] source, int srcOffset, int dstOffset, int count); public abstract void WriteDecimal(decimal value); + public abstract bool ReadBool(); public abstract byte ReadByte(); public abstract byte GetByte(int offset); public abstract byte[] ReadBytes(int length); @@ -352,16 +354,6 @@ public virtual void WriteCString(string value, Func converter) WriteByte(0); } - public virtual string ToHexString(string separator = null) - { - return Service.ToHexString(GetAllBytes(), separator); - } - - public virtual string ToAsciiString(string separator = " ") - { - return Service.ToAsciiString(GetAllBytes(), separator); - } - public virtual string GetString(int offset, int length) { return GetString(offset, length, NoEncoding); @@ -556,13 +548,6 @@ public virtual void WriteDouble(double value, Endianness endianness) _endiannessSwapper.WriteSwap(value, WriteDouble, _endiannessSwapper.SwapBytes, endianness); } - public string Dump() - { - return ToAsciiString() + - Environment.NewLine + - ToHexString(); - } - public override string ToString() { return $"Size:{Size} Position:{Position}"; diff --git a/Arrowgene.Buffers/BufferManager.cs b/Arrowgene.Buffers/BufferManager.cs deleted file mode 100644 index a47191b..0000000 --- a/Arrowgene.Buffers/BufferManager.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Collections.Generic; -using System.Net.Sockets; - -namespace Arrowgene.Buffers -{ - - // TODO rework this one - public class BufferManager - { - private readonly int _numBytes; - private readonly int _bufferSize; - private readonly Stack _freeIndexPool; - - private int _currentIndex; - private byte[] _buffer; - - public BufferManager(int totalBytes, int bufferSize) - { - _numBytes = totalBytes; - _currentIndex = 0; - _bufferSize = bufferSize; - _freeIndexPool = new Stack(); - } - - public void InitBuffer() - { - _buffer = new byte[_numBytes]; - } - - public bool SetBuffer(SocketAsyncEventArgs args) - { - if (_freeIndexPool.Count > 0) - { - args.SetBuffer(_buffer, _freeIndexPool.Pop(), _bufferSize); - } - else - { - if (_numBytes - _bufferSize < _currentIndex) - { - return false; - } - - args.SetBuffer(_buffer, _currentIndex, _bufferSize); - _currentIndex += _bufferSize; - } - - return true; - } - - public void FreeBuffer(SocketAsyncEventArgs args) - { - _freeIndexPool.Push(args.Offset); - args.SetBuffer(null, 0, 0); - } - } -} \ No newline at end of file diff --git a/Arrowgene.Buffers/IBuffer.cs b/Arrowgene.Buffers/IBuffer.cs index e0010a3..69df02b 100644 --- a/Arrowgene.Buffers/IBuffer.cs +++ b/Arrowgene.Buffers/IBuffer.cs @@ -64,6 +64,11 @@ public interface IBuffer /// Returns all written bytes from a specific offset, without affecting the position. /// byte[] GetAllBytes(int offset); + + /// + /// Writes a 0x00 byte if false or 0x01 byte if true + /// + void WriteBool(bool value); void WriteByte(byte value); @@ -111,6 +116,11 @@ public interface IBuffer void WriteBuffer(IBuffer value, int offset, int length); + /// + /// Reads 0x00 byte as false, everything else as true + /// + bool ReadBool(); + /// /// Read byte. /// Advances the cursor. @@ -356,12 +366,12 @@ public interface IBuffer string ReadFixedString(int length); /// - /// Reads a till a 0byte, but advances the position for the length. + /// Reads a string till a 0byte, but advances the position for the length. /// string ReadFixedString(int length, Encoding encoding); /// - /// Reads a till a 0byte, but advances the position for the length. + /// Reads a string till a 0byte, but advances the position for the length. /// string ReadFixedString(int length, Func converter); @@ -433,15 +443,5 @@ public interface IBuffer /// Advances the cursor. /// void WriteCString(string value, Func converter); - - /// - /// Hex representation of the buffer. - /// - string ToHexString(string? separator = null); - - /// - /// Ascii representation of the buffer. - /// - string ToAsciiString(string? separator = null); } } \ No newline at end of file diff --git a/Arrowgene.Buffers/Service.cs b/Arrowgene.Buffers/Service.cs deleted file mode 100644 index 6457984..0000000 --- a/Arrowgene.Buffers/Service.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Text; - -namespace Arrowgene.Buffers -{ - internal static class Service - { - public static string ToHexString(byte[] data, string separator = null) - { - StringBuilder sb = new StringBuilder(); - int len = data.Length; - for (int i = 0; i < len; i++) - { - sb.Append(data[i].ToString("X2")); - if (separator != null && i < len - 1) - { - sb.Append(separator); - } - } - - return sb.ToString(); - } - - public static string ToAsciiString(byte[] data, string separator = " ") - { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < data.Length; i++) - { - char c = '.'; - if (data[i] >= 'A' && data[i] <= 'Z') c = (char) data[i]; - if (data[i] >= 'a' && data[i] <= 'z') c = (char) data[i]; - if (data[i] >= '0' && data[i] <= '9') c = (char) data[i]; - if (separator != null && i != 0) - { - sb.Append(separator); - } - - sb.Append(c); - } - - return sb.ToString(); - } - } -} \ No newline at end of file diff --git a/Arrowgene.Buffers/StreamBuffer.cs b/Arrowgene.Buffers/StreamBuffer.cs index 588f138..83d9f19 100644 --- a/Arrowgene.Buffers/StreamBuffer.cs +++ b/Arrowgene.Buffers/StreamBuffer.cs @@ -85,6 +85,11 @@ public override byte[] GetAllBytes(int offset) return GetBytes(offset, Size - offset); } + public override void WriteBool(bool value) + { + _binaryWriter.Write(value); + } + public override void WriteBytes(byte[] bytes) { _binaryWriter.Write(bytes); @@ -151,6 +156,11 @@ public override void WriteDecimal(decimal value) _binaryWriter.Write(value); } + public override bool ReadBool() + { + return _binaryReader.ReadBoolean(); + } + public override byte ReadByte() { return _binaryReader.ReadByte();