private Identify IdentifyFromProto(byte[] bytes)
        {
            var protoMessage = Proto.Msg.Identify.Parser.ParseFrom(bytes);

            if (protoMessage.MessageId == null)
            {
                return(new Identify(null));
            }
            return(new Identify(_payloadSupport.PayloadFrom(protoMessage.MessageId)));
        }
Exemple #2
0
        /// <inheritdoc />
        public override object FromBinary(byte[] bytes, Type type)
        {
            var selectionEnvelope = Proto.Msg.SelectionEnvelope.Parser.ParseFrom(bytes);
            var message           = _payloadSupport.PayloadFrom(selectionEnvelope.Payload);

            var elements = new SelectionPathElement[selectionEnvelope.Pattern.Count];

            for (var i = 0; i < selectionEnvelope.Pattern.Count; i++)
            {
                var p = selectionEnvelope.Pattern[i];
                if (p.Type == Proto.Msg.Selection.Types.PatternType.ChildName)
                {
                    elements[i] = new SelectChildName(p.Matcher);
                }
                if (p.Type == Proto.Msg.Selection.Types.PatternType.ChildPattern)
                {
                    elements[i] = new SelectChildPattern(p.Matcher);
                }
                if (p.Type == Proto.Msg.Selection.Types.PatternType.Parent)
                {
                    elements[i] = new SelectParent();
                }
            }

            return(new ActorSelectionMessage(message, elements));
        }
Exemple #3
0
        public Exception ExceptionFromProtoNet(Proto.Msg.ExceptionData proto)
        {
            if (string.IsNullOrEmpty(proto.TypeName))
            {
                return(null);
            }

            Type exceptionType = Type.GetType(proto.TypeName);

            var serializationInfo = new SerializationInfo(exceptionType, DefaultFormatterConverter);

            serializationInfo.AddValue("ClassName", proto.TypeName);
            serializationInfo.AddValue("Message", proto.Message);
            serializationInfo.AddValue("StackTraceString", proto.StackTrace);
            serializationInfo.AddValue("Source", proto.Source);
            serializationInfo.AddValue("InnerException", ExceptionFromProto(proto.InnerException));
            serializationInfo.AddValue("HelpURL", string.Empty);
            serializationInfo.AddValue("RemoteStackTraceString", string.Empty);
            serializationInfo.AddValue("RemoteStackIndex", 0);
            serializationInfo.AddValue("ExceptionMethod", string.Empty);
            serializationInfo.AddValue("HResult", int.MinValue);

            foreach (var field in proto.CustomFields)
            {
                serializationInfo.AddValue(field.Key, _wrappedPayloadSupport.PayloadFrom(field.Value));
            }

            Exception       obj             = null;
            ConstructorInfo constructorInfo = exceptionType.GetConstructor(
                All,
                null,
                new[] { typeof(SerializationInfo), typeof(StreamingContext) },
                null);

            if (constructorInfo != null)
            {
                object[] args = { serializationInfo, new StreamingContext() };
                obj = constructorInfo.Invoke(args).AsInstanceOf <Exception>();
            }

            return(obj);
        }
        /// <inheritdoc />
        public override object FromBinary(byte[] bytes, Type type)
        {
            var selectionEnvelope = Proto.Msg.SelectionEnvelope.Parser.ParseFrom(bytes);

            var elements = new SelectionPathElement[selectionEnvelope.Pattern.Count];

            for (var i = 0; i < selectionEnvelope.Pattern.Count; i++)
            {
                var p = selectionEnvelope.Pattern[i];
                if (p.Type == Proto.Msg.Selection.Types.PatternType.ChildName)
                {
                    elements[i] = new SelectChildName(p.Matcher);
                }
                if (p.Type == Proto.Msg.Selection.Types.PatternType.ChildPattern)
                {
                    elements[i] = new SelectChildPattern(p.Matcher);
                }
                if (p.Type == Proto.Msg.Selection.Types.PatternType.Parent)
                {
                    elements[i] = new SelectParent();
                }
            }

            object message;

            try
            {
                message = _payloadSupport.PayloadFrom(selectionEnvelope.Payload);
            }
            catch (Exception ex)
            {
                var payload = selectionEnvelope.Payload;

                var manifest = !payload.MessageManifest.IsEmpty
                    ? payload.MessageManifest.ToStringUtf8()
                    : string.Empty;

                throw new SerializationException(
                          $"Failed to deserialize payload object when deserializing {nameof(ActorSelectionMessage)} with " +
                          $"payload [SerializerId={payload.SerializerId}, Manifest={manifest}] addressed to [" +
                          $"{string.Join(",", elements.Select(e => e.ToString()))}]. {GetErrorForSerializerId(payload.SerializerId)}", ex);
            }

            return(new ActorSelectionMessage(message, elements));
        }