internal static Dictionary<RuntimeTypeHandle, object> InitializeDefaultTable( PackerCompatibilityOptions packerCompatibilityOptions ) { var dictionary = new Dictionary<RuntimeTypeHandle, object>( 428 ); dictionary.Add( typeof( MessagePackObject ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.MsgPack_MessagePackObjectMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( MessagePackExtendedTypeObject ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.MsgPack_MessagePackExtendedTypeObjectMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( Object ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_ObjectMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( String ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_StringMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( StringBuilder ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Text_StringBuilderMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( Char[] ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_CharArrayMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( Byte[] ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_ByteArrayMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.DateTime ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_DateTimeMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.DateTimeOffset ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_DateTimeOffsetMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Boolean ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_BooleanMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Byte ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_ByteMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Char ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_CharMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Decimal ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_DecimalMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Double ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_DoubleMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Guid ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_GuidMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Int16 ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Int16MessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Int32 ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Int32MessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Int64 ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Int64MessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.SByte ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_SByteMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Single ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_SingleMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.TimeSpan ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_TimeSpanMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.UInt16 ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_UInt16MessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.UInt32 ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_UInt32MessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.UInt64 ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_UInt64MessagePackSerializer( packerCompatibilityOptions ) ); #if !SILVERLIGHT && !NETFX_CORE #if !SILVERLIGHT dictionary.Add( typeof( System.Runtime.InteropServices.ComTypes.FILETIME ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Runtime_InteropServices_ComTypes_FILETIMEMessagePackSerializer( packerCompatibilityOptions ) ); #endif // !SILVERLIGHT && !NETFX_CORE #endif // !SILVERLIGHT #if !SILVERLIGHT && !NETFX_CORE #if !SILVERLIGHT dictionary.Add( typeof( System.Collections.Specialized.BitVector32 ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Collections_Specialized_BitVector32MessagePackSerializer( packerCompatibilityOptions ) ); #endif // !SILVERLIGHT && !NETFX_CORE #endif // !SILVERLIGHT #if !WINDOWS_PHONE #if !NETFX_35 dictionary.Add( typeof( System.Numerics.BigInteger ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Numerics_BigIntegerMessagePackSerializer( packerCompatibilityOptions ) ); #endif // !WINDOWS_PHONE #endif // !NETFX_35 dictionary.Add( typeof( System.ArraySegment<> ).TypeHandle, typeof( System_ArraySegment_1MessagePackSerializer<> ) ); dictionary.Add( typeof( System.Collections.DictionaryEntry ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Collections_DictionaryEntryMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Collections.Generic.KeyValuePair<,> ).TypeHandle, typeof( System_Collections_Generic_KeyValuePair_2MessagePackSerializer<, > ) ); #if !WINDOWS_PHONE #if !NETFX_35 dictionary.Add( typeof( System.Numerics.Complex ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Numerics_ComplexMessagePackSerializer( packerCompatibilityOptions ) ); #endif // !WINDOWS_PHONE #endif // !NETFX_35 dictionary.Add( typeof( System.Uri ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_UriMessagePackSerializer( packerCompatibilityOptions ) ); dictionary.Add( typeof( System.Version ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_VersionMessagePackSerializer( packerCompatibilityOptions ) ); #if !SILVERLIGHT && !NETFX_CORE #if !SILVERLIGHT dictionary.Add( typeof( System.Collections.Specialized.NameValueCollection ).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Collections_Specialized_NameValueCollectionMessagePackSerializer( packerCompatibilityOptions ) ); #endif // !SILVERLIGHT && !NETFX_CORE #endif // !SILVERLIGHT return dictionary; }
public EnumMessagePackSerializer(Type type, PackerCompatibilityOptions packerCompatibilityOptions) : base(type, packerCompatibilityOptions) { if (!type.GetIsEnum()) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Type '{0}' is not enum.", type)); } }
/// <summary> /// Gets the system default repository. /// </summary> /// <param name="packerCompatibilityOptions"><see cref="PackerCompatibilityOptions"/> for default serializers must use.</param> /// <returns> /// The system default repository. /// This value will not be <c>null</c>. /// Note that the repository is frozen. /// </returns> public static SerializerRepository GetDefault(PackerCompatibilityOptions packerCompatibilityOptions) { SerializerRepository repository; if (!_defaults.TryGetValue(packerCompatibilityOptions, out repository)) { throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, "'{0}' is not valid combination.", packerCompatibilityOptions)); } return(repository); }
private NonGenericMessagePackSerializer( SerializationContext ownerContext, Type targetType, PackerCompatibilityOptions? packerCompatibilityOptions ) { if ( ownerContext == null ) { throw new ArgumentNullException( "ownerContext" ); } this._packerCompatibilityOptionsForCompatibility = packerCompatibilityOptions; this._ownerContext = ownerContext; this._targetType = targetType; this._isNullable = JudgeNullable( targetType ); }
/// <summary> /// Serializes specified object to the <see cref="T:System.IO.Stream" /> asynchronously. /// </summary> /// <param name="type"></param> /// <param name="value"></param> /// <param name="stream"></param> /// <param name="packerCompatibilityOptions"></param> /// <param name="cancellationToken"></param> /// <returns></returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="stream" /> is <c>null</c>. /// </exception> /// <exception cref="T:System.Runtime.Serialization.SerializationException"> /// Failed to serialize object. /// </exception> /// <seealso cref="P:Capabilities" /> public static async Task PackAsync(Type type, object?value, Stream?stream, PackerCompatibilityOptions packerCompatibilityOptions = PackerCompatibilityOptions.None, CancellationToken cancellationToken = default) { if (stream is null) { return; } var packer = Packer.Create(stream, packerCompatibilityOptions); await MessagePackSerializer.Get(type).PackToAsync(packer, value, cancellationToken); stream.TrySeek(0, SeekOrigin.Begin); }
public StreamPacker(Stream stream, PackerCompatibilityOptions compatibilityOptions, PackerUnpackerStreamOptions streamOptions) : base(compatibilityOptions) { if (stream == null) { throw new ArgumentNullException("stream"); } var options = streamOptions ?? PackerUnpackerStreamOptions.None; this._stream = options.WrapStream(stream); this._ownsStream = options.OwnsStream; }
public StreamPacker( Stream stream, PackerCompatibilityOptions compatibilityOptions, PackerUnpackerStreamOptions streamOptions ) : base( compatibilityOptions ) { if ( stream == null ) { throw new ArgumentNullException( "stream" ); } var options = streamOptions ?? PackerUnpackerStreamOptions.None; this._stream = options.WrapStream( stream ); this._ownsStream = options.OwnsStream; }
internal SerializationContext( SerializerRepository serializers, PackerCompatibilityOptions packerCompatibilityOptions) { Contract.Requires(serializers != null); this._compatibilityOptions = new SerializationCompatibilityOptions() { PackerCompatibilityOptions = packerCompatibilityOptions }; this._serializers = serializers; this._typeLock = new HashSet <Type>(); this._defaultCollectionTypes = new DefaultConcreteTypeRepository(); }
public static void Pack( this IMessagePackSerializer source, Stream stream, object objectTree, PackerCompatibilityOptions packerCompatibilityOptions ) { if ( source == null ) { throw new ArgumentNullException("source"); } if ( stream == null ) { throw new ArgumentNullException( "stream" ); } // Packer does not have finalizer, so just avoiding packer disposing prevents stream closing. source.PackTo( Packer.Create( stream, packerCompatibilityOptions ), objectTree ); }
/// <summary> /// Creates new <see cref="SerializationContext"/> for generation based testing. /// </summary> /// <param name="method"><see cref="SerializationMethod"/>.</param> /// <param name="compatibilityOptions"><see cref="PackerCompatibilityOptions"/> for built-in serializers.</param> /// <returns>A new <see cref="SerializationContext"/> for generation based testing.</returns> public static SerializationContext CreateContext(SerializationMethod method, PackerCompatibilityOptions compatibilityOptions) { var context = new SerializationContext(compatibilityOptions) { SerializationMethod = method }; foreach (var entry in _serializers) { context.Serializers.Register(entry.Key, entry.Value, null, null, SerializerRegistrationOptions.None); } #if !AOT context.SerializerOptions.DisableRuntimeCodeGeneration = true; #endif // !AOT return(context); }
private static void TestOnWorkerAppDomain(string geneartedAssemblyFilePath, PackerCompatibilityOptions packerCompatibilityOptions, byte[] bytesValue, byte[] expectedPackedValue, TestType testType) { var appDomainSetUp = new AppDomainSetup() { ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase }; var workerDomain = AppDomain.CreateDomain("Worker", null, appDomainSetUp); try { var testerProxy = workerDomain.CreateInstanceAndUnwrap(typeof(Tester).Assembly.FullName, typeof(Tester).FullName) as Tester; testerProxy.DoTest(geneartedAssemblyFilePath, ( int )packerCompatibilityOptions, bytesValue, expectedPackedValue, 1, testType); } finally { AppDomain.Unload(workerDomain); } }
internal SerializationContext( SerializerRepository serializers, PackerCompatibilityOptions packerCompatibilityOptions) { this._compatibilityOptions = new SerializationCompatibilityOptions { PackerCompatibilityOptions = packerCompatibilityOptions }; this._serializers = serializers; #if !XAMIOS && !XAMDROID && !UNITY #if SILVERLIGHT || NETFX_35 this._typeLock = new Dictionary <Type, object>(); #else this._typeLock = new ConcurrentDictionary <Type, object>(); #endif // SILVERLIGHT || NETFX_35 #endif // !XAMIOS && !XAMDROID && !UNITY this._defaultCollectionTypes = new DefaultConcreteTypeRepository(); }
internal SerializationContext( SerializerRepository serializers, PackerCompatibilityOptions packerCompatibilityOptions) { Contract.Requires(serializers != null); this._compatibilityOptions = new SerializationCompatibilityOptions() { PackerCompatibilityOptions = packerCompatibilityOptions }; this._serializers = serializers; #if SILVERLIGHT || NETFX_35 this._typeLock = new HashSet <Type>(); #else this._typeLock = new ConcurrentDictionary <Type, object>(); #endif this._defaultCollectionTypes = new DefaultConcreteTypeRepository(); }
/// <summary> /// Initializes a new instance of the <see cref="SerializationContext"/> class with copy of <see cref="SerializerRepository.GetDefault()"/> for specified <see cref="PackerCompatibilityOptions"/>. /// </summary> /// <param name="packerCompatibilityOptions"><see cref="PackerCompatibilityOptions"/> which will be used on built-in serializers.</param> public SerializationContext( PackerCompatibilityOptions packerCompatibilityOptions ) { this._compatibilityOptions = new SerializationCompatibilityOptions { PackerCompatibilityOptions = packerCompatibilityOptions }; this._serializers = new SerializerRepository( SerializerRepository.GetDefault( this ) ); #if SILVERLIGHT || NETFX_35 || UNITY this._typeLock = new Dictionary<Type, object>(); #else this._typeLock = new ConcurrentDictionary<Type, object>(); #endif // SILVERLIGHT || NETFX_35 || UNITY this._generationLock = new object(); this._defaultCollectionTypes = new DefaultConcreteTypeRepository(); this._serializerGeneratorOptions = new SerializerOptions(); }
/// <summary> /// Creates new <see cref="SerializationContext"/> for generation based testing. /// </summary> /// <param name="method"><see cref="SerializationMethod"/>.</param> /// <param name="compatibilityOptions"><see cref="PackerCompatibilityOptions"/> for built-in serializers.</param> /// <returns>A new <see cref="SerializationContext"/> for generation based testing.</returns> public static SerializationContext CreateContext(SerializationMethod method, PackerCompatibilityOptions compatibilityOptions) { var context = new SerializationContext(compatibilityOptions) { SerializationMethod = method }; var serializers = method == SerializationMethod.Array ? _arrayBasedSerializers : _mapBasedSerializers; foreach (var entry in serializers) { context.Serializers.Register(entry.Key, entry.Value); } #if !XAMIOS && !UNITY_IPHONE context.IsRuntimeGenerationDisabled = true; #endif return(context); }
/// <summary> /// Initializes a new instance of the <see cref="SerializationContext"/> class with copy of <see cref="SerializerRepository.GetDefault()"/> for specified <see cref="PackerCompatibilityOptions"/>. /// </summary> /// <param name="packerCompatibilityOptions"><see cref="PackerCompatibilityOptions"/> which will be used on built-in serializers.</param> public SerializationContext( PackerCompatibilityOptions packerCompatibilityOptions ) { this._compatibilityOptions = new SerializationCompatibilityOptions { PackerCompatibilityOptions = packerCompatibilityOptions }; this._serializers = new SerializerRepository( SerializerRepository.GetDefault( this ) ); #if !FEATURE_CONCURRENT this._typeLock = new Dictionary<Type, object>(); #else this._typeLock = new ConcurrentDictionary<Type, object>(); #endif // !FEATURE_CONCURRENT this._generationLock = new object(); this._defaultCollectionTypes = new DefaultConcreteTypeRepository(); this._serializerGeneratorOptions = new SerializerOptions(); this._dictionarySerializationOptions = new DictionarySerlaizationOptions(); this._enumSerializationOptions = new EnumSerializationOptions(); }
private static void TestOnWorkerAppDomainForMultiple( string geneartedAssemblyFilePath, PackerCompatibilityOptions packerCompatibilityOptions, byte[] bytesValue1, byte[] expectedPackedValue1, byte[] bytesValue2, byte[] expectedPackedValue2 ) { var appDomainSetUp = new AppDomainSetup() { ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase }; var workerDomain = AppDomain.CreateDomain( "Worker", null, appDomainSetUp ); try { var testerProxy = workerDomain.CreateInstanceAndUnwrap( typeof( Tester ).Assembly.FullName, typeof( Tester ).FullName ) as Tester; testerProxy.DoTest( geneartedAssemblyFilePath, ( int )packerCompatibilityOptions, bytesValue1, expectedPackedValue1, 2, TestType.GeneratorTestObject ); testerProxy.DoTest( geneartedAssemblyFilePath, ( int )packerCompatibilityOptions, bytesValue2, expectedPackedValue2, 2, TestType.AnotherGeneratorTestObject ); } finally { AppDomain.Unload( workerDomain ); } }
/// <summary> /// Create standard Safe <see cref="Packer"/> instancde wrapping specified <see cref="Stream"/> with specified <see cref="PackerCompatibilityOptions"/>. /// </summary> /// <param name="stream"><see cref="Stream"/> object.</param> /// <param name="compatibilityOptions">A <see cref="PackerCompatibilityOptions"/> which specifies compatibility options.</param> /// <param name="ownsStream"> /// <c>true</c> to close <paramref name="stream"/> when this instance is disposed; /// <c>false</c>, otherwise. /// </param> /// <returns>Safe <see cref="Packer"/>. This will not be null.</returns> /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null.</exception> /// <remarks> /// You can specify any derived <see cref="Stream"/> class like FileStream, <see cref="MemoryStream"/>, /// NetworkStream, UnmanagedMemoryStream, or so. /// </remarks> public static Packer Create(Stream stream, PackerCompatibilityOptions compatibilityOptions, bool ownsStream) { return(new StreamPacker(stream, compatibilityOptions, ownsStream ? PackerUnpackerStreamOptions.SingletonOwnsStream : PackerUnpackerStreamOptions.None)); }
/// <summary> /// Initializes a new instance of the <see cref="Packer"/> class with specified <see cref="PackerCompatibilityOptions"/>. /// </summary> /// <param name="compatibilityOptions">A <see cref="PackerCompatibilityOptions"/> which specifies compatibility options.</param> protected Packer(PackerCompatibilityOptions compatibilityOptions) { this._compatibilityOptions = compatibilityOptions; }
public MessagePackByteArrayPacker(byte[] buffer, ByteBufferAllocator allocator, PackerCompatibilityOptions compatibilityOptions) : this(buffer, 0, allocator, compatibilityOptions) { }
/// <summary> /// Creates new <see cref="SerializationContext"/> for generation based testing. /// </summary> /// <param name="method"><see cref="SerializationMethod"/>.</param> /// <param name="compatibilityOptions"><see cref="PackerCompatibilityOptions"/> for built-in serializers.</param> /// <returns>A new <see cref="SerializationContext"/> for generation based testing.</returns> public static SerializationContext CreateContext( SerializationMethod method, PackerCompatibilityOptions compatibilityOptions ) { var context = new SerializationContext( compatibilityOptions ) { SerializationMethod = method }; foreach ( var entry in _serializers ) { context.Serializers.Register( entry.Key, entry.Value, null, null, SerializerRegistrationOptions.None ); } #if !AOT context.SerializerOptions.DisableRuntimeCodeGeneration = true; #endif // !AOT return context; }
public System_ByteArrayMessagePackSerializer(PackerCompatibilityOptions packerCompatibilityOptions) : base(packerCompatibilityOptions) { }
private static void TestOnWorkerAppDomainWithCompile( string geneartedSourceFilePath, PackerCompatibilityOptions packerCompatibilityOptions, EnumSerializationMethod enumSerializationMethod, TestEnumType enumValue, byte[] expectedPackedValue ) { var parameters = new CompilerParameters(); parameters.ReferencedAssemblies.Add( typeof( GeneratedCodeAttribute ).Assembly.Location ); parameters.ReferencedAssemblies.Add( typeof( MessagePackObject ).Assembly.Location ); parameters.ReferencedAssemblies.Add( Assembly.GetExecutingAssembly().Location ); var result = CodeDomProvider.CreateProvider( "C#" ).CompileAssemblyFromFile( parameters, geneartedSourceFilePath ); Assert.That( result.Errors.Count, Is.EqualTo( 0 ), String.Join( Environment.NewLine, result.Output.OfType<string>().ToArray() ) ); try { var appDomainSetUp = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase }; var workerDomain = AppDomain.CreateDomain( "Worker", null, appDomainSetUp ); try { var testerProxy = workerDomain.CreateInstanceAndUnwrap( typeof( Tester ).Assembly.FullName, typeof( Tester ).FullName ) as Tester; testerProxy.DoTest( result.PathToAssembly, ( int ) packerCompatibilityOptions, ( int ) enumSerializationMethod, enumValue, expectedPackedValue, 1 ); } finally { AppDomain.Unload( workerDomain ); } } finally { File.Delete( result.PathToAssembly ); } }
private static void TestOnWorkerAppDomain( string geneartedAssemblyFilePath, PackerCompatibilityOptions packerCompatibilityOptions, EnumSerializationMethod enumSerializationMethod, TestEnumType enumValue, byte[] expectedPackedValue ) { var appDomainSetUp = new AppDomainSetup() { ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase }; var workerDomain = AppDomain.CreateDomain( "Worker", null, appDomainSetUp ); try { var testerProxy = workerDomain.CreateInstanceAndUnwrap( typeof( Tester ).Assembly.FullName, typeof( Tester ).FullName ) as Tester; testerProxy.DoTest( geneartedAssemblyFilePath, ( int )packerCompatibilityOptions, ( int )enumSerializationMethod, enumValue, expectedPackedValue, 1 ); } finally { AppDomain.Unload( workerDomain ); } }
/// <summary> /// Create standard Safe <see cref="Packer"/> instancde wrapping specified <see cref="Stream"/> with specified <see cref="PackerCompatibilityOptions"/>. /// </summary> /// <param name="stream"><see cref="Stream"/> object.</param> /// <param name="compatibilityOptions">A <see cref="PackerCompatibilityOptions"/> which specifies compatibility options.</param> /// <param name="streamOptions"><see cref="PackerUnpackerStreamOptions"/> which specifies stream handling options.</param> /// <returns>Safe <see cref="Packer"/>. This will not be null.</returns> /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null.</exception> /// <remarks> /// You can specify any derived <see cref="Stream"/> class like FileStream, <see cref="MemoryStream"/>, /// NetworkStream, UnmanagedMemoryStream, or so. /// </remarks> public static Packer Create( Stream stream, PackerCompatibilityOptions compatibilityOptions, PackerUnpackerStreamOptions streamOptions ) { return new StreamPacker( stream, compatibilityOptions, streamOptions ); }
/// <summary> /// Initializes a new instance of the <see cref="NonGenericMessagePackSerializer"/> class with explicitly specified compatibility option. /// </summary> /// <param name="ownerContext">A <see cref="SerializationContext"/> which owns this serializer.</param> /// <param name="targetType">The type to be serialized.</param> /// <param name="packerCompatibilityOptions">The <see cref="PackerCompatibilityOptions"/> for new packer creation.</param> /// <param name="capabilities">The capability flags for this instance.</param> /// <exception cref="ArgumentNullException"><paramref name="ownerContext"/> is <c>null</c>.</exception> /// <remarks> /// This method also supports backword compatibility with 0.4. /// </remarks> protected NonGenericMessagePackSerializer( SerializationContext ownerContext, Type targetType, PackerCompatibilityOptions packerCompatibilityOptions, SerializerCapabilities capabilities ) : this( ownerContext, targetType, new PackerCompatibilityOptions?( packerCompatibilityOptions ), capabilities ) { }
private NonGenericMessagePackSerializer( SerializationContext ownerContext, Type targetType, PackerCompatibilityOptions? packerCompatibilityOptions, SerializerCapabilities capabilities ) : base( ownerContext, packerCompatibilityOptions, capabilities ) { this._targetType = targetType; this._isNullable = JudgeNullable( targetType ); }
internal SerializationCompatibilityOptions() { this._packerCompatibilityOptions = PackerCompatibilityOptions.Classic; }
private static void TestPackToMessageCoreWithOption( MessagePackObject target, byte[] expected, PackerCompatibilityOptions compatibilityOptions ) { using ( var buffer = new MemoryStream() ) using ( var packer = Packer.Create( buffer, compatibilityOptions ) ) { target.PackToMessage( packer, new PackingOptions() ); var actual = buffer.ToArray(); Assert.AreEqual( expected, actual ); } }
public MsgPack_MessagePackObjectMessagePackSerializer(PackerCompatibilityOptions packerCompatibilityOptions) : base(packerCompatibilityOptions) { }
private static void TestExtraFieldCore(SerializationMethod method, EmitterFlavor flavor, PackerCompatibilityOptions compat) { var serializer = CreateSerializer <VersioningTestTarget>(flavor); using (var stream = new MemoryStream()) { if (method == SerializationMethod.Array) { stream.Write(new byte[] { 0x94, 0x1, 0xFF, 0xA1, ( byte )'a', 0xC0 }); } else { const string String10 = "1234567890"; // packed as MinimumFixedRaw or Bin8 const string String40 = "1234567890123456789012345678901234567890"; // packed as Bin8 or Str8 var packer = Packer.Create(stream, compat, false); packer.PackMapHeader(7); packer.PackString("Field1"); packer.Pack(1); packer.PackString("Extra1"); packer.PackString(String40); packer.PackString("Extra2"); packer.PackBinary(System.Text.Encoding.UTF8.GetBytes(String40)); packer.PackString("Field2"); packer.Pack(-1); packer.PackString("Extra3"); packer.PackString(String10); packer.PackString("Field3"); packer.PackString("a"); packer.PackString("Extra4"); packer.PackNull(); } stream.Position = 0; var result = serializer.Unpack(stream); Assert.That(result.Field1, Is.EqualTo(1)); Assert.That(result.Field2, Is.EqualTo(-1)); Assert.That(result.Field3, Is.EqualTo("a")); } }
/// <summary> /// Create standard Safe <see cref="Packer"/> instancde wrapping specified <see cref="Stream"/> with specified <see cref="PackerCompatibilityOptions"/>. /// </summary> /// <param name="stream"><see cref="Stream"/> object.</param> /// <param name="compatibilityOptions">A <see cref="PackerCompatibilityOptions"/> which specifies compatibility options.</param> /// <param name="ownsStream"> /// <c>true</c> to close <paramref name="stream"/> when this instance is disposed; /// <c>false</c>, otherwise. /// </param> /// <returns>Safe <see cref="Packer"/>. This will not be null.</returns> /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null.</exception> /// <remarks> /// You can specify any derived <see cref="Stream"/> class like FileStream, <see cref="MemoryStream"/>, /// NetworkStream, UnmanagedMemoryStream, or so. /// </remarks> public static Packer Create( Stream stream, PackerCompatibilityOptions compatibilityOptions, bool ownsStream ) { return new StreamPacker( stream, compatibilityOptions, ownsStream ? PackerUnpackerStreamOptions.SingletonOwnsStream : PackerUnpackerStreamOptions.None ); }
/// <summary> /// Initializes a new instance of the <see cref="MessagePackSerializer{T}"/> class. /// </summary> /// <param name="packerCompatibilityOptions">The <see cref="PackerCompatibilityOptions"/> for new packer creation.</param> protected MessagePackSerializer(PackerCompatibilityOptions packerCompatibilityOptions) { this._packerCompatibilityOptions = packerCompatibilityOptions; }
/// <summary> /// Creates new <see cref="SerializationContext"/> for generation based testing. /// </summary> /// <param name="method"><see cref="SerializationMethod"/>.</param> /// <param name="compatibilityOptions"><see cref="PackerCompatibilityOptions"/> for built-in serializers.</param> /// <returns>A new <see cref="SerializationContext"/> for generation based testing.</returns> public static SerializationContext CreateContext( SerializationMethod method, PackerCompatibilityOptions compatibilityOptions ) { var context = new SerializationContext( compatibilityOptions ) { SerializationMethod = method }; var serializers = method == SerializationMethod.Array ? _arrayBasedSerializers : _mapBasedSerializers; foreach ( var entry in serializers ) { context.Serializers.Register( entry.Key, entry.Value ); } #if !XAMIOS && !UNITY_IPHONE context.IsRuntimeGenerationDisabled = true; #endif return context; }
public StreamPacker( Stream output, PackerCompatibilityOptions compatibilityOptions, bool ownsStream ) : base( compatibilityOptions ) { this._stream = output; this._ownsStream = ownsStream; }
/// <summary> /// Create standard Safe <see cref="Packer"/> instancde wrapping specified <see cref="Stream"/> with specified <see cref="PackerCompatibilityOptions"/>. /// </summary> /// <param name="stream"><see cref="Stream"/> object. This stream will be closed when <see cref="Packer.Dispose(Boolean)"/> is called.</param> /// <param name="compatibilityOptions">A <see cref="PackerCompatibilityOptions"/> which specifies compatibility options.</param> /// <returns>Safe <see cref="Packer"/>. This will not be null.</returns> /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null.</exception> /// <remarks> /// You can specify any derived <see cref="Stream"/> class like FileStream, <see cref="MemoryStream"/>, /// NetworkStream, UnmanagedMemoryStream, or so. /// </remarks> public static Packer Create( Stream stream, PackerCompatibilityOptions compatibilityOptions ) { return Create( stream, compatibilityOptions, true ); }
/// <summary> /// Gets the system default repository bound to default context. /// </summary> /// <param name="packerCompatibilityOptions"><see cref="PackerCompatibilityOptions"/> for default serializers must use.</param> /// <returns> /// The system default repository. /// This value will not be <c>null</c>. /// Note that the repository is frozen. /// </returns> /// <exception cref="ArgumentOutOfRangeException"><paramref name="packerCompatibilityOptions"/> is invalid.</exception> public static SerializerRepository GetDefault(PackerCompatibilityOptions packerCompatibilityOptions) { var newContext = new SerializationContext(SerializationContext.Default.Serializers, packerCompatibilityOptions); return(GetDefault(newContext)); }
/// <summary> /// Initializes a new instance of the <see cref="Packer"/> class with specified <see cref="PackerCompatibilityOptions"/>. /// </summary> /// <param name="compatibilityOptions">A <see cref="PackerCompatibilityOptions"/> which specifies compatibility options.</param> protected Packer( PackerCompatibilityOptions compatibilityOptions ) { this._compatibilityOptions = compatibilityOptions; }
public MessagePackByteArrayPacker(byte[] buffer, int startOffset, ByteBufferAllocator allocator, PackerCompatibilityOptions compatibilityOptions) : base(compatibilityOptions) { this._buffer = buffer ?? Binary.Empty; if (startOffset < 0) { throw new ArgumentOutOfRangeException("startOffset"); } if (startOffset > this._buffer.Length) { throw new ArgumentException("The startOffset is too large or the length of buffer is too small."); } this._initialOffset = startOffset; this._offset = startOffset; this._allocator = allocator; }
public System_DateTimeOffsetMessagePackSerializer(PackerCompatibilityOptions packerCompatibilityOptions) : base(typeof(System.DateTimeOffset), packerCompatibilityOptions) { }
/// <summary> /// Create standard Safe <see cref="Packer"/> instancde wrapping specified <see cref="Stream"/> with specified <see cref="PackerCompatibilityOptions"/>. /// </summary> /// <param name="stream"><see cref="Stream"/> object. This stream will be closed when <see cref="Packer.Dispose(Boolean)"/> is called.</param> /// <param name="compatibilityOptions">A <see cref="PackerCompatibilityOptions"/> which specifies compatibility options.</param> /// <returns>Safe <see cref="Packer"/>. This will not be null.</returns> /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null.</exception> /// <remarks> /// You can specify any derived <see cref="Stream"/> class like FileStream, <see cref="MemoryStream"/>, /// NetworkStream, UnmanagedMemoryStream, or so. /// </remarks> public static Packer Create(Stream stream, PackerCompatibilityOptions compatibilityOptions) { return(Create(stream, compatibilityOptions, true)); }
public System_BooleanMessagePackSerializer(PackerCompatibilityOptions packerCompatibilityOptions) : base(typeof(bool), packerCompatibilityOptions) { }
/// <summary> /// Create standard Safe <see cref="Packer"/> instancde wrapping specified <see cref="Stream"/> with specified <see cref="PackerCompatibilityOptions"/>. /// </summary> /// <param name="stream"><see cref="Stream"/> object.</param> /// <param name="compatibilityOptions">A <see cref="PackerCompatibilityOptions"/> which specifies compatibility options.</param> /// <param name="streamOptions"><see cref="PackerUnpackerStreamOptions"/> which specifies stream handling options.</param> /// <returns>Safe <see cref="Packer"/>. This will not be null.</returns> /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null.</exception> /// <remarks> /// You can specify any derived <see cref="Stream"/> class like FileStream, <see cref="MemoryStream"/>, /// NetworkStream, UnmanagedMemoryStream, or so. /// </remarks> public static Packer Create(Stream stream, PackerCompatibilityOptions compatibilityOptions, PackerUnpackerStreamOptions streamOptions) { return(new StreamPacker(stream, compatibilityOptions, streamOptions)); }
public TestSerializer(SerializationContext ownerContext, PackerCompatibilityOptions packerCompatibilityOptions) : base(ownerContext, packerCompatibilityOptions) { }
public MessagePackStreamPacker(Stream stream, PackerUnpackerStreamOptions streamOptions, PackerCompatibilityOptions compatibilityOptions) : base(compatibilityOptions) { if (stream == null) { throw new ArgumentNullException("stream"); } var options = streamOptions ?? PackerUnpackerStreamOptions.None; this._destination = options.WrapStream(stream); this._ownsStream = options.OwnsStream; this._scalarBuffer = new byte[sizeof(ulong) + 1]; }
public System_UriMessagePackSerializer(PackerCompatibilityOptions packerCompatibilityOptions) : base(typeof(Uri), packerCompatibilityOptions) { }
/// <summary> /// Initializes a new instance of the <see cref="NonGenericMessagePackSerializer"/> class with explicitly specified compatibility option. /// </summary> /// <param name="ownerContext">A <see cref="SerializationContext"/> which owns this serializer.</param> /// <param name="targetType">The type to be serialized.</param> /// <param name="packerCompatibilityOptions">The <see cref="PackerCompatibilityOptions"/> for new packer creation.</param> /// <exception cref="ArgumentNullException"><paramref name="ownerContext"/> is <c>null</c>.</exception> /// <remarks> /// This method also supports backword compatibility with 0.4. /// </remarks> protected NonGenericMessagePackSerializer(SerializationContext ownerContext, Type targetType, PackerCompatibilityOptions packerCompatibilityOptions) : this(ownerContext, targetType, new PackerCompatibilityOptions?(packerCompatibilityOptions)) { }
internal SerializationCompatibilityOptions() { this._packerCompatibilityOptions = PackerCompatibilityOptions.Classic; }
internal static Dictionary <RuntimeTypeHandle, object> InitializeDefaultTable(PackerCompatibilityOptions packerCompatibilityOptions) { var dictionary = new Dictionary <RuntimeTypeHandle, object>(428); dictionary.Add(typeof(MessagePackObject).TypeHandle, new MsgPack.Serialization.DefaultSerializers.MsgPack_MessagePackObjectMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(MessagePackExtendedTypeObject).TypeHandle, new MsgPack.Serialization.DefaultSerializers.MsgPack_MessagePackExtendedTypeObjectMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(Object).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_ObjectMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(String).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_StringMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(StringBuilder).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Text_StringBuilderMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(Char[]).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_CharArrayMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(Byte[]).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_ByteArrayMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.DateTime).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_DateTimeMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.DateTimeOffset).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_DateTimeOffsetMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Boolean).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_BooleanMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Byte).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_ByteMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Char).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_CharMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Decimal).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_DecimalMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Double).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_DoubleMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Guid).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_GuidMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Int16).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Int16MessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Int32).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Int32MessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Int64).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Int64MessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.SByte).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_SByteMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Single).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_SingleMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.TimeSpan).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_TimeSpanMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.UInt16).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_UInt16MessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.UInt32).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_UInt32MessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.UInt64).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_UInt64MessagePackSerializer(packerCompatibilityOptions)); #if !SILVERLIGHT && !NETFX_CORE #if !SILVERLIGHT dictionary.Add(typeof(System.Collections.Specialized.BitVector32).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Collections_Specialized_BitVector32MessagePackSerializer(packerCompatibilityOptions)); #endif // !SILVERLIGHT && !NETFX_CORE #endif // !SILVERLIGHT #if !WINDOWS_PHONE #endif // !NETFX_35 //dictionary.Add( typeof( System.ArraySegment<> ).TypeHandle, typeof( System_ArraySegment_1MessagePackSerializer<> ) ); dictionary.Add(typeof(System.Collections.DictionaryEntry).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Collections_DictionaryEntryMessagePackSerializer(packerCompatibilityOptions)); //dictionary.Add( typeof( System.Collections.Generic.KeyValuePair<,> ).TypeHandle, typeof( System_Collections_Generic_KeyValuePair_2MessagePackSerializer<, > ) ); dictionary.Add(typeof(System.Uri).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_UriMessagePackSerializer(packerCompatibilityOptions)); dictionary.Add(typeof(System.Version).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_VersionMessagePackSerializer(packerCompatibilityOptions)); #if !SILVERLIGHT && !NETFX_CORE #if !SILVERLIGHT dictionary.Add(typeof(System.Collections.Specialized.NameValueCollection).TypeHandle, new MsgPack.Serialization.DefaultSerializers.System_Collections_Specialized_NameValueCollectionMessagePackSerializer(packerCompatibilityOptions)); #endif // !SILVERLIGHT && !NETFX_CORE #endif // !SILVERLIGHT return(dictionary); }
/// <summary> /// Initializes a new instance of the <see cref="MessagePackSerializer"/> class. /// </summary> /// <param name="ownerContext">A <see cref="SerializationContext"/> which owns this serializer.</param> /// <param name="packerCompatibilityOptions">The <see cref="PackerCompatibilityOptions"/> for new packer creation.</param> /// <param name="capabilities">The capability flags for this instance.</param> internal MessagePackSerializer( SerializationContext ownerContext, PackerCompatibilityOptions? packerCompatibilityOptions, SerializerCapabilities capabilities ) { if ( ownerContext == null ) { ThrowArgumentNullException( "ownerContext" ); } this._ownerContext = ownerContext; this._packerCompatibilityOptionsForCompatibility = packerCompatibilityOptions; this._capabilities = capabilities; }