This commit is contained in:
Garry Newman 2016-10-05 09:44:35 +01:00
parent 1b2463cc0b
commit e6126a0e40
3 changed files with 15 additions and 18 deletions

View File

@ -9,7 +9,7 @@ namespace Facepunch.Steamworks.Test
public partial class Server
{
[TestMethod]
public void Invetory()
public void InventoryDeserialize()
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{

View File

@ -79,20 +79,18 @@ internal void Fill()
} ).ToArray();
}
internal byte[] Serialize()
internal unsafe byte[] Serialize()
{
uint size = 0;
inventory.inventory.SerializeResult( Handle, IntPtr.Zero, out size );
IntPtr ptr = Marshal.AllocHGlobal((int) size);
if ( !inventory.inventory.SerializeResult( Handle, ptr, out size ) )
return null;
var data = new byte[size];
Marshal.Copy( ptr, data, 0, (int)size );
Marshal.FreeHGlobal( ptr );
fixed ( byte* ptr = data )
{
if ( !inventory.inventory.SerializeResult( Handle, (IntPtr) ptr, out size ) )
return null;
}
return data;
}

View File

@ -206,23 +206,22 @@ private Definition FindDefinition( int def )
return Definitions.FirstOrDefault( x => x.Id == def );
}
public Result Deserialize( byte[] data, int dataLength = -1 )
public unsafe Result Deserialize( byte[] data, int dataLength = -1 )
{
if ( dataLength == -1 )
dataLength = data.Length;
int resultHandle = -1;
IntPtr ptr = Marshal.AllocHGlobal( dataLength);
Marshal.Copy( data, 0, ptr, dataLength );
var result = inventory.DeserializeResult( out resultHandle, ptr, (uint)dataLength, false );
Marshal.FreeHGlobal( ptr );
fixed ( byte* ptr = data )
{
var result = inventory.DeserializeResult( out resultHandle, (IntPtr) ptr, (uint)dataLength, false );
if ( !result || resultHandle == -1 )
return null;
return new Result( this, resultHandle );
}
}
}
}