Commit 5812bdc5 authored by Ray Koopa's avatar Ray Koopa

Split packages into Syroot.BinaryData and Syroot.BinaryData.Serialization

parent b5b2262c
res/Logo.png

901 Bytes | W: | H:

res/Logo.png

910 Bytes | W: | H:

res/Logo.png
res/Logo.png
res/Logo.png
res/Logo.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -33,6 +33,8 @@
<DocumentationSources>
<DocumentationSource sourceFile="..\Syroot.BinaryData\bin\Release\net45\Syroot.BinaryData.dll" />
<DocumentationSource sourceFile="..\Syroot.BinaryData\bin\Release\net45\Syroot.BinaryData.xml" />
<DocumentationSource sourceFile="..\Syroot.BinaryData.Serialization\bin\Release\net45\Syroot.BinaryData.Serialization.dll" />
<DocumentationSource sourceFile="..\Syroot.BinaryData.Serialization\bin\Release\net45\Syroot.BinaryData.Serialization.xml" />
</DocumentationSources>
<SaveComponentCacheCapacity>100</SaveComponentCacheCapacity>
<BuildAssemblerVerbosity>OnlyWarningsAndErrors</BuildAssemblerVerbosity>
......@@ -58,7 +60,8 @@
<MissingTags>AutoDocumentCtors, AutoDocumentDispose</MissingTags>
<NamespaceSummaries>
<NamespaceSummaryItem name="Syroot.BinaryData" isDocumented="True">This namespace provides classes providing advanced binary data reading and writing functionality.</NamespaceSummaryItem>
<NamespaceSummaryItem name="Syroot.BinaryData.Extensions" isDocumented="True">This namespace provides extension methods for the Stream class to add new reading and writing functionality.</NamespaceSummaryItem></NamespaceSummaries>
<NamespaceSummaryItem name="Syroot.BinaryData.Extensions" isDocumented="True">This namespace provides extension methods for the Stream class to add new reading and writing functionality.</NamespaceSummaryItem>
</NamespaceSummaries>
<WebsiteSdkLinkType>Msdn</WebsiteSdkLinkType>
<HtmlSdkLinkType>Msdn</HtmlSdkLinkType>
<IncludeFavorites>False</IncludeFavorites>
......
namespace Syroot.BinaryData
{
/// <summary>
/// Represents formats of array length encodings.
/// </summary>
public enum ArrayLengthCoding
{
/// <summary>
/// The array has a prefix of a 7-bit encoded integer of variable size determining the number of elements out
/// of which the array consists.
/// </summary>
DynamicCount,
/// <summary>
/// The array has a prefix of 1 byte determining the number of elements out of which the array consists.
/// </summary>
ByteCount,
/// <summary>
/// The array has a prefix of 2 bytes determining the number of elements out of which the array consists.
/// </summary>
Int16Count,
/// <summary>
/// The array has a prefix of 4 bytes determining number of elements out of which the array consists.
/// </summary>
Int32Count,
/// <summary>
/// The array has a prefix of 2 bytes determining the number of elements out of which the array consists.
/// </summary>
UInt16Count
}
}
using System;
using System.Collections;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures how many elements in an <see cref="IEnumerable"/> member are read through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataArrayAttribute : Attribute
public class ArrayAttribute : Attribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataArrayAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="ArrayAttribute"/> class with the given configuration.
/// </summary>
/// <param name="count">The number of elements to read.</param>
public DataArrayAttribute(int count)
public ArrayAttribute(int count)
{
Count = count;
}
/// <summary>
/// Initializes a new instance of the <see cref="DataArrayAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="ArrayAttribute"/> class with the given configuration.
/// </summary>
/// <param name="countProvider">The name of the member or method to use for retrieving the number of elements to
/// read.</param>
public DataArrayAttribute(string countProvider)
public ArrayAttribute(string countProvider)
{
CountProvider = countProvider;
}
/// <summary>
/// Initializes a new instance of the <see cref="DataArrayAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="ArrayAttribute"/> class with the given configuration.
/// </summary>
/// <param name="coding">The <see cref="ArrayLengthCoding"/> to read or write the value in.</param>
/// <param name="endian">The <see cref="Endian"/> of this value.</param>
public DataArrayAttribute(ArrayLengthCoding coding, Endian endian = Endian.None)
public ArrayAttribute(ArrayLengthCoding coding, Endian endian = Endian.None)
{
Coding = coding;
CodingEndian = endian;
......
using System;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures how a <see cref="Boolean"/> member is read or written through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataBooleanAttribute : Attribute
public class BooleanAttribute : Attribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataBooleanAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="BooleanAttribute"/> class with the given configuration.
/// </summary>
/// <param name="coding">The <see cref="BooleanCoding"/> to read or write the value in.</param>
public DataBooleanAttribute(BooleanCoding coding)
public BooleanAttribute(BooleanCoding coding)
{
Coding = coding;
}
......
using System;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures a class or struct for reading and writing it through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class DataClassAttribute : Attribute
public class ClassAttribute : Attribute
{
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
......
using System;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures an <see cref="IDataConverter"/> to read or write the member with through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataConverterAttribute : Attribute
public class ConverterAttribute : Attribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataConverterAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="ConverterAttribute"/> class with the given configuration.
/// </summary>
/// <param name="converterType">The type of the <see cref="IDataConverter"/> to use.</param>
public DataConverterAttribute(Type converterType)
public ConverterAttribute(Type converterType)
{
ConverterType = converterType;
}
......
using System;
using System.Collections.Generic;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Represents a cache for <see cref="IDataConverter"/> instances.
/// </summary>
internal static class DataConverterCache
internal static class ConverterCache
{
// ---- FIELDS -------------------------------------------------------------------------------------------------
......
using System;
using System.IO;
using Syroot.BinaryData.Extensions;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures how a <see cref="DateTime"/> member is read or written through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataDateTimeAttribute : Attribute
public class DateTimeAttribute : Attribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataDateTimeAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="DateTimeAttribute"/> class with the given configuration.
/// </summary>
/// <param name="coding">The <see cref="DateTimeCoding"/> to read or write the value in.</param>
public DataDateTimeAttribute(DateTimeCoding coding)
public DateTimeAttribute(DateTimeCoding coding)
{
Coding = coding;
}
......
using System;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures in which endianness a value is read or written through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataEndianAttribute : Attribute
public class EndianAttribute : Attribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataEndianAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="EndianAttribute"/> class with the given configuration.
/// </summary>
/// <param name="endian">The endianness in which to read or write the value.</param>
public DataEndianAttribute(Endian endian)
public EndianAttribute(Endian endian)
{
Endian = endian;
}
......
using System;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures how an <see cref="Enum"/> member is read or written through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataEnumAttribute : Attribute
public class EnumAttribute : Attribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataEnumAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="EnumAttribute"/> class with the given configuration.
/// </summary>
/// <param name="strict"><c>true</c> to validate the value when it is read or written.</param>
public DataEnumAttribute(bool strict)
public EnumAttribute(bool strict)
{
Strict = strict;
}
......
using System;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures that a member is explicitly read or written through binary serialization. Use this attribute if the
/// owning instance is marked as <see cref="DataClassAttribute.Explicit"/> and no other attributes are meaningful
/// owning instance is marked as <see cref="ClassAttribute.Explicit"/> and no other attributes are meaningful
/// for the member.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataMemberAttribute : Attribute { }
public class MemberAttribute : Attribute { }
}
using System;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures an offset at which the value is read or written through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataOffsetAttribute : Attribute
public class OffsetAttribute : Attribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataOffsetAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="OffsetAttribute"/> class with the given configuration.
/// </summary>
/// <param name="origin">The anchor from which to manipulate the stream position by the given delta.</param>
/// <param name="delta">The number of bytes to manipulate the stream position with.</param>
public DataOffsetAttribute(Origin origin, long delta)
public OffsetAttribute(Origin origin, long delta)
{
Origin = origin;
Delta = delta;
......
using System;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures an offset which is seeked to after reading the instance through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class DataOffsetEndAttribute : DataOffsetAttribute
public class OffsetEndAttribute : OffsetAttribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataOffsetEndAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="OffsetEndAttribute"/> class with the given configuration.
/// </summary>
/// <param name="origin">The anchor from which to manipulate the stream position by the given delta.</param>
/// <param name="delta">The number of bytes to manipulate the stream position with.</param>
public DataOffsetEndAttribute(Origin origin, long delta) : base(origin, delta) { }
public OffsetEndAttribute(Origin origin, long delta) : base(origin, delta) { }
}
}
using System;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures an offset which is seeked to before reading the instance through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class DataOffsetStartAttribute : DataOffsetAttribute
public class OffsetStartAttribute : OffsetAttribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataOffsetStartAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="OffsetStartAttribute"/> class with the given configuration.
/// </summary>
/// <param name="origin">The anchor from which to manipulate the stream position by the given delta.</param>
/// <param name="delta">The number of bytes to manipulate the stream position with.</param>
public DataOffsetStartAttribute(Origin origin, long delta) : base(origin, delta) { }
public OffsetStartAttribute(Origin origin, long delta) : base(origin, delta) { }
}
}
using System;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures the index determining the order in which members of an instance are read or written through binary
/// serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataOrderAttribute : Attribute
public class OrderAttribute : Attribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataOrderAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="OrderAttribute"/> class with the given configuration.
/// </summary>
/// <param name="index">The index determining the order when the value is read or written.</param>
public DataOrderAttribute(int index)
public OrderAttribute(int index)
{
Index = index;
}
......
using System;
using System.Text;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Configures how a <see cref="String"/> member is read or written through binary serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataStringAttribute : Attribute
public class StringAttribute : Attribute
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="DataStringAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="StringAttribute"/> class with the given configuration.
/// </summary>
/// <param name="coding">The <see cref="StringCoding"/> to read or write the value in.</param>
/// <param name="codePage">The code page of the <see cref="Encoding"/> to use.</param>
public DataStringAttribute(StringCoding coding, int codePage = 0)
public StringAttribute(StringCoding coding, int codePage = 0)
{
Coding = coding;
CodePage = codePage;
}
/// <summary>
/// Initializes a new instance of the <see cref="DataStringAttribute"/> class with the given configuration.
/// Initializes a new instance of the <see cref="StringAttribute"/> class with the given configuration.
/// </summary>
/// <param name="length">The length of the string to read. Handles the string with
/// <see cref="StringCoding.Raw"/>.</param>
/// <param name="codePage">The code page of the <see cref="Encoding"/> to use.</param>
public DataStringAttribute(int length, int codePage = 0)
public StringAttribute(int length, int codePage = 0)
{
Length = length;
CodePage = codePage;
......
......@@ -3,10 +3,8 @@ using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using Syroot.BinaryData.Core;
using Syroot.BinaryData.Extensions;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Represents logic to serialize and deserialize objects of any type.
......@@ -113,7 +111,7 @@ namespace Syroot.BinaryData.Serialization
// Let a converter handle all the data after adjusting to the offset.
TypeData typeData = TypeData.Get(type);
ApplyOffset(stream, parentOffset, typeData.StartOrigin, typeData.StartDelta);
value = memberData.ConverterAttrib.Read(stream, memberData);
value = null;// TODO: memberData.ConverterAttrib.Read(stream, memberData);
ApplyOffset(stream, parentOffset, typeData.EndOrigin, typeData.EndDelta);
}
else if (_typeReaders.TryGetValue(type.TypeHandle, out var reader))
......
......@@ -2,7 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
namespace Syroot.BinaryData.Core
namespace Syroot.BinaryData
{
/// <summary>
/// Represents a collection of extension methods for the <see cref="Type"/> class.
......
using System.IO;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Represents a converter for reading and writing custom values.
......
......@@ -3,10 +3,8 @@ using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using Syroot.BinaryData.Core;
using Syroot.BinaryData.Extensions;
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Represents information on a member of a type read and written through binary serialiazion.
......@@ -30,7 +28,7 @@ namespace Syroot.BinaryData.Serialization
MemberInfo = memberInfo;
// Get any possible attribute.
DataArrayAttribute arrayAttrib = MemberInfo.GetCustomAttribute<DataArrayAttribute>();
ArrayAttribute arrayAttrib = MemberInfo.GetCustomAttribute<ArrayAttribute>();
if (arrayAttrib != null)
{
IsExported = true;
......@@ -39,55 +37,55 @@ namespace Syroot.BinaryData.Serialization
ArrayCountCoding = arrayAttrib.Coding;
ArrayCountCodingEndian = arrayAttrib.CodingEndian;
}
DataBooleanAttribute booleanAttrib = MemberInfo.GetCustomAttribute<DataBooleanAttribute>();
BooleanAttribute booleanAttrib = MemberInfo.GetCustomAttribute<BooleanAttribute>();
if (booleanAttrib != null)
{
IsExported = true;
BooleanCoding = booleanAttrib.Coding;
}
DataConverterAttribute converterAttrib = MemberInfo.GetCustomAttribute<DataConverterAttribute>();
ConverterAttribute converterAttrib = MemberInfo.GetCustomAttribute<ConverterAttribute>();
if (converterAttrib != null)
{
IsExported = true;
ConverterType = converterAttrib.ConverterType;
}
DataDateTimeAttribute dateTimeAttrib = MemberInfo.GetCustomAttribute<DataDateTimeAttribute>();
DateTimeAttribute dateTimeAttrib = MemberInfo.GetCustomAttribute<DateTimeAttribute>();
if (dateTimeAttrib != null)
{
IsExported = true;
DateTimeCoding = dateTimeAttrib.Coding;
}
DataEndianAttribute endianAttrib = MemberInfo.GetCustomAttribute<DataEndianAttribute>();
EndianAttribute endianAttrib = MemberInfo.GetCustomAttribute<EndianAttribute>();
if (endianAttrib != null)
{
IsExported = true;
Endian = endianAttrib.Endian;
}
DataEnumAttribute enumAttrib = MemberInfo.GetCustomAttribute<DataEnumAttribute>();
EnumAttribute enumAttrib = MemberInfo.GetCustomAttribute<EnumAttribute>();
if (enumAttrib != null)
{
IsExported = true;
EnumStrict = enumAttrib.Strict;
}
DataMemberAttribute memberAttrib = MemberInfo.GetCustomAttribute<DataMemberAttribute>();
MemberAttribute memberAttrib = MemberInfo.GetCustomAttribute<MemberAttribute>();
if (memberAttrib != null)
{
IsExported = true;
}
DataOffsetAttribute offsetAttrib = MemberInfo.GetCustomAttribute<DataOffsetAttribute>();
OffsetAttribute offsetAttrib = MemberInfo.GetCustomAttribute<OffsetAttribute>();
if (offsetAttrib != null)
{
IsExported = true;
OffsetDelta = offsetAttrib.Delta;
OffsetOrigin = offsetAttrib.Origin;
}
DataOrderAttribute orderAttrib = MemberInfo.GetCustomAttribute<DataOrderAttribute>();
OrderAttribute orderAttrib = MemberInfo.GetCustomAttribute<OrderAttribute>();
if (orderAttrib != null)
{
IsExported = true;
Index = orderAttrib.Index;
}
DataStringAttribute stringAttrib = MemberInfo.GetCustomAttribute<DataStringAttribute>();
StringAttribute stringAttrib = MemberInfo.GetCustomAttribute<StringAttribute>();
if (stringAttrib != null)
{
IsExported = true;
......@@ -100,7 +98,7 @@ namespace Syroot.BinaryData.Serialization
if (Type.IsEnumerable() && arrayAttrib == null)
{
throw new InvalidOperationException(
$"Enumerable member \"{MemberInfo}\" must be decorated with a {nameof(DataArrayAttribute)}.");
$"Enumerable member \"{MemberInfo}\" must be decorated with a {nameof(ArrayAttribute)}.");
}
}
......@@ -219,7 +217,7 @@ namespace Syroot.BinaryData.Serialization
switch (ArrayCountCoding)
{
case ArrayLengthCoding.DynamicCount:
return stream.Read7BitEncodedInt32();
return stream.ReadDynamicInt32();
case ArrayLengthCoding.ByteCount:
return stream.ReadByte();
case ArrayLengthCoding.Int16Count:
......
namespace Syroot.BinaryData.Serialization
namespace Syroot.BinaryData
{
/// <summary>
/// Represents the origins of offsets of a class, structure, or member.
......
using System.IO;
namespace Syroot.BinaryData
{
public static partial class StreamExtensions
{
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
/// <summary>
/// Returns an object of type <typeparamref name="T"/> read from the <paramref name="stream"/>.
/// </summary>
/// <typeparam name="T">The type of the object to read.</typeparam>
/// <param name="stream">The extended <see cref="Stream"/> instance.</param>
/// <param name="converter">The <see cref="ByteConverter"/> to use for converting multibyte data.</param>
/// <returns>The value read from the current stream.</returns>
public static T ReadObject<T>(this Stream stream, ByteConverter converter = null)
=> (T)BinarySerialization.ReadClass(stream, TypeData.Get(typeof(T)), null,
converter ?? ByteConverter.System);
/// <summary>
/// Returns an array of objects of type <typeparamref name="T"/> read from the <paramref name="stream"/>.
/// </summary>
/// <typeparam name="T">The type of the object to load.</typeparam>
/// <param name="stream">The extended <see cref="Stream"/> instance.</param>
/// <param name="count">The number of values to read.</param>
/// <param name="converter">The <see cref="ByteConverter"/> to use for converting multibyte data.</param>
/// <returns>The array of values read from the current stream.</returns>
public static T[] ReadObjects<T>(this Stream stream, int count, ByteConverter converter = null)
{
converter = converter ?? ByteConverter.System;
var values = new T[count];
lock (stream)
{
for (int i = 0; i < count; i++)
{
values[i] = stream.ReadObject<T>(converter);
}
}
return values;
}
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
private static void FillBuffer(Stream stream, int length)
{
if (stream.Read(Buffer, 0, length) < length)
throw new EndOfStreamException($"Could not read {length} bytes.");
}
}
}
using System.IO;
namespace Syroot.BinaryData
{
public static partial class StreamExtensions
{
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
// ---- Object ----
/// <summary>
/// Writes an object or enumerable of objects to the <paramref name="stream"/>.
/// </summary>
/// <param name="stream">The extended <see cref="Stream"/> instance.</param>
/// <param name="value">The object or enumerable of objects to write.</param>
/// <param name="converter">The <see cref="ByteConverter"/> to use for converting multibyte data.</param>
public static void WriteObject(this Stream stream, object value, ByteConverter converter = null)
=> WriteObject(value.GetType(), stream, null, BinaryMemberAttribute.Default, value, converter);
}
}
using System;
using System.IO;
namespace Syroot.BinaryData
{
/// <summary>
/// Represents static extension methods for read and write operations on <see cref="Stream"/> instances.
/// </summary>
public static partial class StreamExtensions
{
// ---- FIELDS -------------------------------------------------------------------------------------------------
[ThreadStatic] private static byte[] _buffer;
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
private static byte[] Buffer
{
get
{
if (_buffer == null)
_buffer = new byte[16];
return _buffer;
}
}
}
}