예제 #1
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));
        }
예제 #2
0
        /// <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));
        }