public static OperationalMessage MessageFrom(string content)
        {
            if (content.StartsWith(APP))
            {
                return(ApplicationSays.From(content));
            }

            if (content.StartsWith(DIR))
            {
                return(Directory.From(content));
            }

            if (content.StartsWith(ELECT))
            {
                return(Elect.From(content));
            }

            if (content.StartsWith(JOIN))
            {
                return(Join.From(content));
            }

            if (content.StartsWith(LEADER))
            {
                return(Leader.From(content));
            }

            if (content.StartsWith(LEAVE))
            {
                return(Leave.From(content));
            }

            if (content.StartsWith(PING))
            {
                return(Ping.From(content));
            }

            if (content.StartsWith(PULSE))
            {
                return(Pulse.From(content));
            }

            if (content.StartsWith(SPLIT))
            {
                return(Split.From(content));
            }

            if (content.StartsWith(VOTE))
            {
                return(Vote.From(content));
            }

            return(null);
        }
Beispiel #2
0
        public static void MessageToBytes(ApplicationSays app, Stream buffer)
        {
            var builder = new StringBuilder(OperationalMessage.APP).Append("\n");

            builder
            .Append("id=").Append(app.Id.Value)
            .Append(" nm=").Append(app.Name.Value)
            .Append(" si=").Append(app.SaysId)
            .Append("\n").Append(app.Payload);

            var bytes = Converters.TextToBytes(builder.ToString());

            buffer.Write(bytes, 0, bytes.Length);
        }