Esempio n. 1
0
        /// <inheritdoc />
        public override byte[] ToBinary(object obj)
        {
            if (obj is ActorSelectionMessage sel)
            {
                var envelope = new Proto.Msg.SelectionEnvelope();
                envelope.Payload = _payloadSupport.PayloadToProto(sel.Message);

                foreach (var element in sel.Elements)
                {
                    Proto.Msg.Selection selection = null;
                    if (element is SelectChildName m1)
                    {
                        selection = BuildPattern(m1.Name, Proto.Msg.Selection.Types.PatternType.ChildName);
                    }
                    else if (element is SelectChildPattern m)
                    {
                        selection = BuildPattern(m.PatternStr, Proto.Msg.Selection.Types.PatternType.ChildPattern);
                    }
                    else if (element is SelectParent)
                    {
                        selection = BuildPattern(null, Proto.Msg.Selection.Types.PatternType.Parent);
                    }

                    envelope.Pattern.Add(selection);
                }


                return(envelope.ToByteArray());
            }

            throw new ArgumentException($"Cannot serialize object of type [{obj.GetType().TypeQualifiedName()}]");
        }
Esempio n. 2
0
        private Proto.Msg.Selection BuildPattern(string matcher, Proto.Msg.Selection.Types.PatternType tpe)
        {
            var selection = new Proto.Msg.Selection { Type = tpe };
            if (matcher != null)
                selection.Matcher = matcher;

            return selection;
        }