mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-01-15 00:08:02 +03:00
Delete old packet data stream.
This commit is contained in:
parent
7852ef9d5a
commit
519a01b6f6
@ -1,54 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
using Syroot.BinaryData;
|
|
||||||
|
|
||||||
namespace Syroot.Worms.Mgame.GameServer
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an in-memory stream formatting data for being sent or received from <see cref="Packet"/> instances.
|
|
||||||
/// </summary>
|
|
||||||
internal class PacketDataStream : BinaryStream
|
|
||||||
{
|
|
||||||
// ---- FIELDS -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
private readonly MemoryStream _baseStream;
|
|
||||||
|
|
||||||
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
static PacketDataStream()
|
|
||||||
{
|
|
||||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal PacketDataStream(MemoryStream baseStream)
|
|
||||||
: base(baseStream, encoding: Encoding.GetEncoding(949), stringCoding: StringCoding.Int16CharCount)
|
|
||||||
{
|
|
||||||
_baseStream = baseStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal PacketDataStream(MemoryStream baseStream, int offset)
|
|
||||||
: this(new MemoryStream(baseStream.GetBuffer(), offset, (int)baseStream.Length - offset)) { }
|
|
||||||
|
|
||||||
internal PacketDataStream() : this(new MemoryStream()) { }
|
|
||||||
|
|
||||||
internal PacketDataStream(byte[] buffer) : this(new MemoryStream(buffer)) { }
|
|
||||||
|
|
||||||
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a <see cref="Span{Byte}"/> containing the actually used memory buffer bytes.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>The span containing the used buffer bytes.</returns>
|
|
||||||
internal Span<byte> GetSpan() => _baseStream.GetBuffer().AsSpan(0, (int)Position);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reads the remaining bytes in the buffer.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>The remaining bytes.</returns>
|
|
||||||
internal byte[] ReadToEnd()
|
|
||||||
{
|
|
||||||
return ReadBytes((int)(Length - Position));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user