mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-25 06:40:28 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
41 lines
894 B
C#
41 lines
894 B
C#
namespace Sandbox;
|
|
|
|
internal partial class BytePack
|
|
{
|
|
/// <summary>
|
|
/// A value array is useful because we only have to write the header once, and it's a single
|
|
/// block of memory to read. Useful.
|
|
/// </summary>
|
|
class ValueArrayPacker : Packer
|
|
{
|
|
internal override Identifier Header => Identifier.ArrayValue;
|
|
|
|
public override void Write( ref ByteStream bs, object obj )
|
|
{
|
|
if ( obj is not Array array ) throw new NotSupportedException();
|
|
|
|
bs.Write( array.Length );
|
|
|
|
var et = array.GetType().GetElementType();
|
|
var w = GetHandlerFor( et );
|
|
|
|
|
|
w.WriteTypeIdentifier( ref bs, et );
|
|
bs.WriteValueArray( array );
|
|
}
|
|
|
|
public override object Read( ref ByteStream bs )
|
|
{
|
|
var len = bs.Read<int>();
|
|
|
|
var handler = GetHandlerFor( ref bs );
|
|
|
|
var array = Array.CreateInstance( handler.TargetType, len );
|
|
bs.ReadValueArray( array );
|
|
|
|
return array;
|
|
}
|
|
}
|
|
|
|
}
|