LibUv Networking (#65)

This commit is contained in:
Kamron Batman 2019-12-26 18:08:50 -08:00 committed by GitHub
parent ec6629fbe9
commit 5e2be2d7b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
69 changed files with 5612 additions and 586 deletions

View file

@ -175,13 +175,13 @@ namespace Server.Network
return sb.ToString();
}
public bool IsSafeChar(int c) => c >= 0x20 && c < 0xFFFE;
private static bool IsSafeChar(int c) => c >= 0x20 && c < 0xFFFE;
public string ReadUTF8StringSafe(int fixedLength)
{
string s;
if (m_Reader.TryReadTo(out ReadOnlySpan<byte> span, (byte)'\0', true))
if (m_Reader.TryReadTo(out ReadOnlySpan<byte> span, (byte)'\0'))
s = Utility.UTF8.GetString(span.Length > fixedLength ? span.Slice(0, fixedLength) : span);
else
{
@ -203,7 +203,7 @@ namespace Server.Network
{
string s;
if (m_Reader.TryReadTo(out ReadOnlySpan<byte> span, (byte)'\0', true))
if (m_Reader.TryReadTo(out ReadOnlySpan<byte> span, (byte)'\0'))
s = Utility.UTF8.GetString(span);
else
{
@ -222,7 +222,7 @@ namespace Server.Network
public string ReadUTF8String() =>
Utility.UTF8.GetString(
m_Reader.TryReadTo(out ReadOnlySpan<byte> span, (byte)'\0', true) ? span :
m_Reader.TryReadTo(out ReadOnlySpan<byte> span, (byte)'\0') ? span :
m_Reader.Sequence.Slice(m_Reader.Position, m_Reader.Remaining).ToArray()
);