private IEnumerable <object> GetArgs(DaemonMsgCreateData proto) { var args = new object[proto.Props.ArgsCount]; for (int i = 0; i < args.Length; i++) { var typeName = proto.Props.GetClasses(i); var arg = proto.Props.GetArgs(i); if (typeName == "" && ByteString.Empty.Equals(arg)) { //HACK: no typename and empty arg gives null args[i] = null; } else { Type t = null; if (typeName != null) { t = Type.GetType(typeName); } args[i] = Deserialize(arg, t); } } return(args); }
/// <summary> /// Deserializes a byte array into an object of type <paramref name="type"/>. /// </summary> /// <param name="bytes">The array containing the serialized object</param> /// <param name="type">The type of object contained in the array</param> /// <returns>The object contained in the array</returns> /// <exception cref="TypeLoadException"> /// Could not find type on the remote system. /// Ensure that the remote system has an assembly that contains the type in its assembly search path. /// </exception> public override object FromBinary(byte[] bytes, Type type) { var proto = DaemonMsgCreateData.ParseFrom(bytes); Type clazz; try { clazz = Type.GetType(proto.Props.Clazz, true); } catch (TypeLoadException ex) { var msg = string.Format( "Could not find type '{0}' on the remote system. " + "Ensure that the remote system has an assembly that contains the type {0} in its assembly search path", proto.Props.Clazz); throw new TypeLoadException(msg, ex); } var args = GetArgs(proto); var props = new Props(GetDeploy(proto.Props.Deploy), clazz, args); return(new DaemonMsgCreate( props, GetDeploy(proto.Deploy), proto.Path, DeserializeActorRef(proto.Supervisor))); }
public override object FromBinary(byte[] bytes, Type type) { var proto = DaemonMsgCreateData.ParseFrom(bytes); var clazz = Type.GetType(proto.Props.Clazz); var args = GetArgs(proto); var props = new Props(GetDeploy(proto.Props.Deploy), clazz, args); return(new DaemonMsgCreate( props, GetDeploy(proto.Deploy), proto.Path, DeserializeActorRef(proto.Supervisor))); }
/// <summary> /// Serializes the given object into a byte array /// </summary> /// <param name="obj">The object to serialize </param> /// <returns>A byte array containing the serialized object</returns> /// <exception cref="ArgumentException"> /// This exception is thrown when the specified <paramref name="obj" /> is not of type <see cref="DaemonMsgCreate"/>. /// </exception> public override byte[] ToBinary(object obj) { var msg = obj as DaemonMsgCreate; if (msg == null) { throw new ArgumentException("Can't serialize a non-DaemonMsgCreate message using DaemonMsgCreateSerializer"); } DaemonMsgCreateData daemonBuilder = DaemonMsgCreateData.CreateBuilder() .SetProps(GetPropsData(msg.Props)) .SetDeploy(GetDeployData(msg.Deploy)) .SetPath(msg.Path) .SetSupervisor(SerializeActorRef(msg.Supervisor)) .Build(); return(daemonBuilder.ToByteArray()); }
private IEnumerable<object> GetArgs(DaemonMsgCreateData proto) { var args = new object[proto.Props.ArgsCount]; for (int i = 0; i < args.Length; i++) { var typeName = proto.Props.GetClasses(i); var arg = proto.Props.GetArgs(i); if (typeName == "" && ByteString.Empty.Equals(arg)) { //HACK: no typename and empty arg gives null args[i] = null; } else { Type t = null; if (typeName != null) t = Type.GetType(typeName); args[i] = Deserialize(arg, t); } } return args; }