Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Mewiof committed Jan 18, 2022
1 parent 0109868 commit 3479bc6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
16 changes: 7 additions & 9 deletions LiteNetLib/Utils/NetDataReader.cs
Expand Up @@ -217,9 +217,7 @@ public bool GetBool()

public char GetChar()
{
char result = BitConverter.ToChar(_data, _position);
_position += 2;
return result;
return (char)GetUShort();
}

public ushort GetUShort()
Expand Down Expand Up @@ -401,7 +399,7 @@ public bool PeekBool()

public char PeekChar()
{
return BitConverter.ToChar(_data, _position);
return (char)PeekUShort();
}

public ushort PeekUShort()
Expand Down Expand Up @@ -517,13 +515,13 @@ public bool TryGetBool(out bool result)

public bool TryGetChar(out char result)
{
if (AvailableBytes >= 2)
if (!TryGetUShort(out ushort uShortValue))
{
result = GetChar();
return true;
result = '\0';
return false;
}
result = '\0';
return false;
result = (char)uShortValue;
return true;
}

public bool TryGetShort(out short result)
Expand Down
5 changes: 1 addition & 4 deletions LiteNetLib/Utils/NetDataWriter.cs
Expand Up @@ -162,10 +162,7 @@ public void Put(uint value)

public void Put(char value)
{
if (_autoResize)
ResizeIfNeed(_position + 2);
FastBitConverter.GetBytes(_data, _position, value);
_position += 2;
Put((ushort)value);
}

public void Put(ushort value)
Expand Down

0 comments on commit 3479bc6

Please sign in to comment.