You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-16 15:16:33 +09:00
PeekString fixed not to advance read position
This commit is contained in:
@@ -306,22 +306,10 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public string PeekString()
|
||||
{
|
||||
int byteLen = (int)ReadVariableUInt32();
|
||||
|
||||
if (byteLen == 0)
|
||||
return String.Empty;
|
||||
|
||||
NetException.Assert(m_bitLength - m_readPosition >= (byteLen * 8), c_readOverflowError);
|
||||
|
||||
if ((m_readPosition & 7) == 0)
|
||||
{
|
||||
// read directly
|
||||
string retval = System.Text.Encoding.UTF8.GetString(m_data, m_readPosition >> 3, byteLen);
|
||||
return retval;
|
||||
}
|
||||
|
||||
byte[] bytes = PeekBytes(byteLen);
|
||||
return System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||
int wasReadPosition = m_readPosition;
|
||||
string retval = ReadString();
|
||||
m_readPosition = wasReadPosition;
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user