Add support for reading/writing System.Guid
This commit is contained in:
parent
96ca5d778b
commit
a87e186c58
|
@ -35,6 +35,20 @@ public sealed class ProtocolReader : BinaryReader
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a <see cref="Guid" /> value from the current stream and advances the current position of the stream by sixteen
|
||||||
|
/// bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="Guid" /> value.</returns>
|
||||||
|
/// <exception cref="EndOfStreamException">The end of the stream is reached.</exception>
|
||||||
|
public Guid ReadGuid()
|
||||||
|
{
|
||||||
|
Span<byte> buffer = stackalloc byte[16];
|
||||||
|
int read = Read(buffer);
|
||||||
|
if (read != 16) throw new EndOfStreamException();
|
||||||
|
return new Guid(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override short ReadInt16()
|
public override short ReadInt16()
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,6 +72,17 @@ public sealed class ProtocolWriter : BinaryWriter
|
||||||
base.Write((ulong) IPAddress.HostToNetworkOrder((long) value));
|
base.Write((ulong) IPAddress.HostToNetworkOrder((long) value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a <see cref="Guid" /> value to the current stream and advances the stream position by sixteen bytes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="guid">The <see cref="Guid" /> value to write.</param>
|
||||||
|
public void Write(Guid guid)
|
||||||
|
{
|
||||||
|
Span<byte> buffer = stackalloc byte[16];
|
||||||
|
guid.TryWriteBytes(buffer);
|
||||||
|
Write(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a <see cref="Quaternion" /> value to the current stream and advances the stream position by sixteen bytes.
|
/// Writes a <see cref="Quaternion" /> value to the current stream and advances the stream position by sixteen bytes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue