diff --git a/TcpDotNet/Protocol/ProtocolReader.cs b/TcpDotNet/Protocol/ProtocolReader.cs
index 87a28ae..78b51da 100644
--- a/TcpDotNet/Protocol/ProtocolReader.cs
+++ b/TcpDotNet/Protocol/ProtocolReader.cs
@@ -35,6 +35,20 @@ public sealed class ProtocolReader : BinaryReader
{
}
+ ///
+ /// Reads a value from the current stream and advances the current position of the stream by sixteen
+ /// bytes.
+ ///
+ /// A value.
+ /// The end of the stream is reached.
+ public Guid ReadGuid()
+ {
+ Span buffer = stackalloc byte[16];
+ int read = Read(buffer);
+ if (read != 16) throw new EndOfStreamException();
+ return new Guid(buffer);
+ }
+
///
public override short ReadInt16()
{
@@ -75,7 +89,7 @@ public sealed class ProtocolReader : BinaryReader
}
///
- /// Reads a value from the current stream and advances the current position of the stream by
+ /// Reads a value from the current stream and advances the current position of the stream by
/// sixteen bytes.
///
/// A value read from the current stream.
diff --git a/TcpDotNet/Protocol/ProtocolWriter.cs b/TcpDotNet/Protocol/ProtocolWriter.cs
index 77b5230..ae55a0e 100644
--- a/TcpDotNet/Protocol/ProtocolWriter.cs
+++ b/TcpDotNet/Protocol/ProtocolWriter.cs
@@ -55,7 +55,7 @@ public sealed class ProtocolWriter : BinaryWriter
[CLSCompliant(false)]
public override void Write(ushort value)
{
- base.Write((ushort)IPAddress.HostToNetworkOrder((short)value));
+ base.Write((ushort) IPAddress.HostToNetworkOrder((short) value));
}
///
@@ -72,6 +72,17 @@ public sealed class ProtocolWriter : BinaryWriter
base.Write((ulong) IPAddress.HostToNetworkOrder((long) value));
}
+ ///
+ /// Writes a value to the current stream and advances the stream position by sixteen bytes.
+ ///
+ /// The value to write.
+ public void Write(Guid guid)
+ {
+ Span buffer = stackalloc byte[16];
+ guid.TryWriteBytes(buffer);
+ Write(buffer);
+ }
+
///
/// Writes a value to the current stream and advances the stream position by sixteen bytes.
///