(potentially) more portable implementation of double/float serialization for mono
This commit is contained in:
parent
6ad068c3eb
commit
54aef01c72
1 changed files with 13 additions and 1 deletions
|
|
@ -484,10 +484,16 @@ namespace Server
|
||||||
if( (m_Index + 8) > m_Buffer.Length )
|
if( (m_Index + 8) > m_Buffer.Length )
|
||||||
Flush();
|
Flush();
|
||||||
|
|
||||||
|
#if MONO
|
||||||
|
byte[] bytes = BitConverter.GetBytes(value);
|
||||||
|
for(int i = 0; i < bytes.Length; i++)
|
||||||
|
m_Buffer[m_Index++] = bytes[i];
|
||||||
|
#else
|
||||||
fixed( byte* pBuffer = m_Buffer )
|
fixed( byte* pBuffer = m_Buffer )
|
||||||
*((double*)(pBuffer + m_Index)) = value;
|
*((double*)(pBuffer + m_Index)) = value;
|
||||||
|
|
||||||
m_Index += 8;
|
m_Index += 8;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe override void Write( float value )
|
public unsafe override void Write( float value )
|
||||||
|
|
@ -495,10 +501,16 @@ namespace Server
|
||||||
if( (m_Index + 4) > m_Buffer.Length )
|
if( (m_Index + 4) > m_Buffer.Length )
|
||||||
Flush();
|
Flush();
|
||||||
|
|
||||||
fixed( byte* pBuffer = m_Buffer )
|
#if MONO
|
||||||
|
byte[] bytes = BitConverter.GetBytes(value);
|
||||||
|
for(int i = 0; i < bytes.Length; i++)
|
||||||
|
m_Buffer[m_Index++] = bytes[i];
|
||||||
|
#else
|
||||||
|
fixed ( byte* pBuffer = m_Buffer )
|
||||||
*((float*)(pBuffer + m_Index)) = value;
|
*((float*)(pBuffer + m_Index)) = value;
|
||||||
|
|
||||||
m_Index += 4;
|
m_Index += 4;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private char[] m_SingleCharBuffer = new char[1];
|
private char[] m_SingleCharBuffer = new char[1];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue