using System.IO;
using System.Text;
using TBL.CSharp.Serialization.Utilities;
namespace TBL.CSharp.Serialization.Marshal.Serializer
{
///
/// Marshal 风格的二进制序列化器
///
public unsafe partial class BinarySerializer
{
///
/// 是否需要端序转换
///
private readonly bool _isNeedEndianConversion;
///
/// 构造序列化器
///
/// 是否需要字节序转换
public BinarySerializer(bool isNeedEndianConversion)
{
_isNeedEndianConversion = isNeedEndianConversion;
}
///
/// 创建和此序列化器字节序适配的
///
public BinaryReader CreateBinaryReader(Stream stream) => _isNeedEndianConversion
? new BinaryReaderWithEndianConversion(stream, Encoding.UTF8, true)
: new BinaryReader(stream, Encoding.UTF8, true);
///
/// 创建和此序列化器字节序适配的
///
public BinaryWriter CreateBinaryWriter(Stream stream) => _isNeedEndianConversion
? new BinaryWriterWithEndianConversion(stream, Encoding.UTF8, true)
: new BinaryWriter(stream, Encoding.UTF8, true);
}
}