/// <inheritdoc /> public object Deserialize(Type expectedType, IDeserializationContext context) { if (expectedType == null) { throw new ArgumentNullException(nameof(expectedType)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } var typeHandle = expectedType.TypeHandle; var deserializer = GetDeserializer(typeHandle); if (deserializer == null) { LogWarning(3, "no deserializer found for type {0}", expectedType.FullName); throw new ArgumentOutOfRangeException("no deserializer provided for the selected type", "expectedType"); } var inputStream = InputStream.Create(context.StreamReader); var bondReader = new BondBinaryReader(inputStream); return(deserializer.Deserialize(bondReader)); }
protected internal static object DeserializeGrainReference(Type t, IDeserializationContext context) { var reader = context.StreamReader; GrainId id = reader.ReadGrainId(); SiloAddress silo = null; GuidId observerId = null; byte siloAddressPresent = reader.ReadByte(); if (siloAddressPresent != 0) { silo = reader.ReadSiloAddress(); } bool expectObserverId = id.IsClient; if (expectObserverId) { observerId = GuidId.DeserializeFromStream(reader); } // store as null, serialize as empty. var genericArg = reader.ReadString(); if (string.IsNullOrEmpty(genericArg)) { genericArg = null; } var runtimeClient = context.AdditionalContext as IRuntimeClient; if (expectObserverId) { return(NewObserverGrainReference(id, observerId, runtimeClient)); } return(FromGrainId(id, runtimeClient, genericArg, silo)); }
/// <summary> /// Returns a new nested context which begins at the specified position. /// </summary> /// <param name="context"></param> /// <param name="position"></param> /// <param name="reader"></param> /// <returns></returns> public static IDeserializationContext CreateNestedContext( this IDeserializationContext context, int position, BinaryTokenStreamReader reader) { return new DeserializationContext.NestedDeserializationContext(context, position, reader); }
/// <inheritdoc /> public object Deserialize(Type expectedType, IDeserializationContext context) { if (expectedType == null) { throw new ArgumentNullException(nameof(expectedType)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } var typeHandle = expectedType.TypeHandle; MessageParser parser = null; if (!Parsers.TryGetValue(typeHandle, out parser)) { throw new ArgumentException("No parser found for the expected type " + expectedType, nameof(expectedType)); } var reader = context.StreamReader; int length = reader.ReadInt(); byte[] data = reader.ReadBytes(length); object message = parser.ParseFrom(data); return(message); }
public object Deserialize(Type expectedType, IDeserializationContext context) { DeserializeCalled = true; return(new FakeSerialized { SomeData = "fake deserialization" }); }
public object Deserialize(Type expectedType, IDeserializationContext context) { var reader = context.StreamReader; if (reader == null) { throw new ArgumentNullException(nameof(reader)); } var n = reader.ReadInt(); var bytes = reader.ReadBytes(n); var formatter = new BinaryFormatter { Context = new StreamingContext(StreamingContextStates.All, context) }; object retVal = null; using (var memoryStream = new MemoryStream(bytes)) { retVal = formatter.Deserialize(memoryStream); } return(retVal); }
public static object Deserializer(Type expected, IDeserializationContext context) { var pattern = context.StreamReader.ReadString(); var options = (RegexOptions)context.StreamReader.ReadInt(); return(new RegexStreamNamespacePredicate(new Regex(pattern, options))); }
public PropertyValueDeserializerNode(IDeserializerNode parent, PropertySpec property) { this.parent = parent; this.property = property; this.valueType = property.PropertyType; this.context = parent.Context; }
/// <summary> /// Initializes a new <see cref="NestedDeserializationContext"/> instance. /// </summary> /// <param name="parent"></param> /// <param name="position">The position, relative to the outer-most context, at which this context begins.</param> /// <param name="reader"></param> public NestedDeserializationContext(IDeserializationContext parent, int position, BinaryTokenStreamReader reader) { this.position = position; this.parent = parent; this.StreamReader = reader; this.CurrentObjectOffset = this.parent.CurrentObjectOffset; }
public object DeserializeGrainReference(Type t, IDeserializationContext context) { var reader = context.StreamReader; GrainId id = reader.ReadGrainId(); GrainInterfaceType interfaceType = reader.ReadGrainInterfaceType(); return(_activator.CreateReference(id, interfaceType)); }
public static object Deserializer(Type expected, IDeserializationContext context) { TestTypeA result = new TestTypeA(); context.RecordObject(result); result.Collection = (ICollection <TestTypeA>)SerializationManager.DeserializeInner(typeof(ICollection <TestTypeA>), context); return(result); }
static object Deserialize(Type t, IDeserializationContext context) { var reader = context.StreamReader; var path = ActorPath.Parse(reader.ReadString()); var system = context.ServiceProvider.GetRequiredService <IActorSystem>(); return(system.ActorOf(path)); }
static object Deserialize(Type t, IDeserializationContext context) { var reader = context.StreamReader; var path = StreamPath.Parse(reader.ReadString()); var manager = context.ServiceProvider.GetRequiredService <IStreamProviderManager>(); return(new StreamRef(path, manager.GetStreamProvider(path.Provider))); }
static object Deserialize(Type t, IDeserializationContext context) { var reader = context.StreamReader; var path = StreamPath.Parse(reader.ReadString()); var provider = context.ServiceProvider.GetServiceByName <IStreamProvider>(path.Provider); return(new StreamRef(path, provider)); }
/// <summary> /// Deserializes an event sequence token /// </summary> /// <param name="expected">The expected type.</param> /// <param name="context">The deserialization context.</param> /// <returns></returns> public static object Deserialize(Type expected, IDeserializationContext context) { var reader = context.StreamReader; var deserialized = new EventHubSequenceTokenV2(reader.ReadString(), reader.ReadLong(), reader.ReadInt()); context.RecordObject(deserialized); return(deserialized); }
public override Expression Deserialize(IDeserializationContext context, BinaryExpressionNode node) { return(Expression.MakeBinary( node.NodeType, serializer.Deserialize(context, node.Left), serializer.Deserialize(context, node.Right) )); }
internal static object DeserializeGrainCancellationToken(Type expected, IDeserializationContext context) { var reader = context.StreamReader; var cancellationRequested = reader.ReadToken() == SerializationTokenType.True; var tokenId = reader.ReadGuid(); return(new GrainCancellationToken(tokenId, cancellationRequested)); }
/// <summary> /// Reads a version header from the IDeserializationContext. /// </summary> /// <param name="context"> /// The context under which the deserialization process takes place. /// Provides access to required objects. /// </param> /// <param name="maximumVersion"> /// The maximum expected version. /// </param> /// <param name="type"> /// The type the header relates to. /// </param> /// <returns> /// The version that has been read. /// </returns> public static int ReadHeader(this IDeserializationContext context, int maximumVersion, Type type) { int version = context.ReadInt32(); ThrowHelper.InvalidVersion(version, 1, maximumVersion, type); return(version); }
public object Deserialize(Type expectedType, IDeserializationContext outerContext) { var outerReader = outerContext.StreamReader; var typeKey = TypeSerializer.ReadTypeKey(outerReader); // Read the length of the serialized payload. var length = outerReader.ReadInt(); // The nested data was serialized beginning at the current offset (after the length property). // Record the current offset for use when creating the nested deserialization context. var position = outerContext.CurrentPosition; // Read the nested payload. var innerBytes = outerReader.ReadBytes(length); var innerContext = outerContext.CreateNestedContext(position: position, reader: new BinaryTokenStreamReader(innerBytes)); object result; // If the concrete type is available and the exception is valid for reconstruction, // reconstruct the original exception type. var actualType = this.typeSerializer.GetTypeFromTypeKey(typeKey, throwOnError: false); if (actualType != null) { // Deserialize into the concrete type. var methods = this.GetSerializerMethods(actualType); result = methods.Deserialize(null, innerContext); } else { // Since the concrete type is unavailable, deserialize into the fallback type. // Read the Exception fields. var exception = (RemoteNonDeserializableException)this.fallbackBaseExceptionSerializer.Deserialize(null, innerContext); exception.OriginalTypeName = typeKey.GetTypeName(); // If there is additional data, store it for later serialization. var additionalDataLength = length - innerContext.StreamReader.CurrentPosition; if (additionalDataLength > 0) { exception.AdditionalData = innerContext.StreamReader.ReadBytes(additionalDataLength); } // If a particular type is expected, but the actual type is not available, throw an exception to avoid if (expectedType != null && !expectedType.IsAssignableFrom(typeof(RemoteNonDeserializableException))) { throw new SerializationException( $"Unable to deserialize exception of unavailable type {exception.OriginalTypeName} into expected type {expectedType}. " + $" See {nameof(Exception.InnerException)} for recovered information.", exception); } result = exception; } return(result); }
public override void Deserialize(IDeserializationContext context) { context.ReadDefaultHeader(this.GetType()); this.IsStatic = context.ReadBoolean(); this.Density = context.ReadSingle(); this.Width = context.ReadSingle(); this.Height = context.ReadSingle(); }
internal static object DeserializeGrainCancellationToken(Type expected, IDeserializationContext context) { var runtime = context.ServiceProvider.GetService(typeof(IGrainCancellationTokenRuntime)) as IGrainCancellationTokenRuntime; var reader = context.StreamReader; var cancellationRequested = reader.ReadBoolean(); var tokenId = reader.ReadGuid(); return(new GrainCancellationToken(tokenId, cancellationRequested, runtime)); }
internal static object Deserialize(Type expected, IDeserializationContext context) { string etag = SerializationManager.DeserializeInner <string>(context); TView state = SerializationManager.DeserializeInner <TView>(context); int globalVersion = SerializationManager.DeserializeInner <int>(context); string writeVector = SerializationManager.DeserializeInner <string>(context); return(new GrainStateWithMetaDataAndETag <TView>(etag, state, globalVersion, writeVector)); }
public ItemValueDeserializerNode(TypeSpec expectedBaseType, IDeserializationContext context, string expandPath = "", IDeserializerNode parent = null) { this.parent = parent; this.expectedBaseType = expectedBaseType; this.context = context; this.expandPath = expandPath; valueType = expectedBaseType; }
internal static object Deserialize(Type expected, IDeserializationContext context) { int a = (int)SerializationManager.DeserializeInner <int>(context); int b = (int)SerializationManager.DeserializeInner <int>(context); return(new AdvancedPOCO { A = a, B = b }); }
public override void Deserialize(IDeserializationContext context) { context.ReadDefaultHeader(typeof(Wall)); this.Position = context.ReadVector2(); this.Rotation = context.ReadSingle(); this.Physics.FixtureDescription = context.ReadObject <IPhysicsBodyDescription>(); this.DrawStrategy = context.ReadObject <IEntityDrawStrategy>(); }
public object Deserialize(Type expectedType, IDeserializationContext context) { var reader = context.StreamReader; var length = reader.ReadInt(); var inBytes = reader.ReadBytes(length); using (var stream = new MemoryStream(inBytes)) return(serializer.Deserialize(stream)); }
private static object Deserialize(Type expected, IDeserializationContext context) { DeserializeCounter++; var result = new ClassWithCustomSerializer(); var stream = context.StreamReader; result.IntProperty = stream.ReadInt(); result.StringProperty = stream.ReadString(); return(result); }
private Type ReadNamedType(IDeserializationContext context) { var reader = context.StreamReader; var hashCode = reader.ReadInt(); var count = reader.ReadUShort(); var typeName = reader.ReadBytes(count); return(this.typeKeyCache.GetOrAdd( new TypeKey(hashCode, typeName), k => Type.GetType(Encoding.UTF8.GetString(k.TypeName), throwOnError: true))); }
/// <inheritdoc /> public object Deserialize(Type expectedType, IDeserializationContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var reader = context.StreamReader; var str = reader.ReadString(); return JsonConvert.DeserializeObject(str, expectedType, this.settings.Value); }
public object Deserialize(Type expected, IDeserializationContext context) { AssertConstructorHasBeenCalled(); CallCounter++; var a = (int)context.GetSerializationManager().Deserialize(typeof(int), context.StreamReader); return(new SimplePocoClass { A = a }); }
public override Expression Deserialize(IDeserializationContext context, LambdaExpressionNode node) { var parameters = node.Parameters .Select(parameter => serializer.Deserialize(context, parameter) as ParameterExpression); return(Expression.Lambda( serializer.Deserialize(context, node.Body), false, parameters )); }
public static object?Deserialize(Type expected, IDeserializationContext context) { using (Profiler.TraceMethod(nameof(J))) { var jsonSerializer = GetSerializer(context); var stream = new StreamReaderWrapper(context.StreamReader); return(jsonSerializer.Deserialize <object>(stream, expected)); } }