Ejemplo n.º 1
0
        protected override void HandleChunks(string receivedString, Action <string> receivedStringAction)
        {
            var msgSet = ServerMsgSet.FromStringAndFraming(receivedString, framing);

            if (msgSet == null)
            {
                receivedStringAction($"Error handling string {receivedString}");
                return;
            }

            for (var i = 0; i < msgSet.FullMessages; i++)
            {
                var msg = msgSet[i];
                receivedStringAction(msgSet.IsValid(msg, framing) ? msg : $"Error handling string {receivedString}");
            }

            Buffer.SetLength(0);

            if (!msgSet.LastIsPartial)
            {
                return;
            }

            var lastMessage = msgSet.LastMessageBytes;

            Buffer.Write(lastMessage, 0, lastMessage.Length);
        }
Ejemplo n.º 2
0
        private static ServerMsgSet FromStringNonTransparent(string s, ServerMsgSet serverMsgSet)
        {
            const char lineFeed = '\n';
            serverMsgSet.messages = s.Split(lineFeed);

            var lastChar = s[s.Length - 1];
            serverMsgSet.LastIsPartial = lastChar == lineFeed;

            return serverMsgSet;
        }
Ejemplo n.º 3
0
        private static ServerMsgSet FromStringNonTransparent(string s, ServerMsgSet serverMsgSet)
        {
            const char lineFeed = '\n';

            serverMsgSet.messages = s.Split(lineFeed);

            var lastChar = s[s.Length - 1];

            serverMsgSet.LastIsPartial = lastChar == lineFeed;

            return(serverMsgSet);
        }
Ejemplo n.º 4
0
        private static ServerMsgSet FromStringOctetCounting(string s, ServerMsgSet serverMsgSet)
        {
            var matches = Regex
                .Split(s, "(\\d{1,11} <\\d{1,3}>)")
                .Where(x => !string.IsNullOrEmpty(x))
                .Select((value, index) => new { value, index })
                .ToArray();
            serverMsgSet.messages = matches
                .Where(x => x.index % 2 == 0)
                .Select(x => x.value + (matches.Length <= x.index + 1 ? string.Empty : matches[x.index + 1].value))
                .ToArray();

            serverMsgSet.LastIsPartial = !serverMsgSet.IsValid(serverMsgSet.LastMessage, FramingMethod.OctetCounting);

            return serverMsgSet;
        }
Ejemplo n.º 5
0
        private static ServerMsgSet FromStringOctetCounting(string s, ServerMsgSet serverMsgSet)
        {
            var matches = Regex
                          .Split(s, "(\\d{1,11} <\\d{1,3}>)")
                          .Where(x => !string.IsNullOrEmpty(x))
                          .Select((value, index) => new { value, index })
                          .ToArray();

            serverMsgSet.messages = matches
                                    .Where(x => x.index % 2 == 0)
                                    .Select(x => x.value + (matches.Length <= x.index + 1 ? string.Empty : matches[x.index + 1].value))
                                    .ToArray();

            serverMsgSet.LastIsPartial = !serverMsgSet.IsValid(serverMsgSet.LastMessage, FramingMethod.OctetCounting);

            return(serverMsgSet);
        }
Ejemplo n.º 6
0
 public static ServerMsgSet FromStringAndFraming(string s, FramingMethod? framing)
 {
     var msgSet = new ServerMsgSet();
     switch (framing)
     {
         case FramingMethod.NonTransparent:
         {
             return FromStringNonTransparent(s, msgSet);
         }
         case FramingMethod.OctetCounting:
         {
             return FromStringOctetCounting(s, msgSet);
         }
         default:
         {
             return null;
         }
     }
 }
Ejemplo n.º 7
0
        public static ServerMsgSet FromStringAndFraming(string s, FramingMethod?framing)
        {
            var msgSet = new ServerMsgSet();

            switch (framing)
            {
            case FramingMethod.NonTransparent:
            {
                return(FromStringNonTransparent(s, msgSet));
            }

            case FramingMethod.OctetCounting:
            {
                return(FromStringOctetCounting(s, msgSet));
            }

            default:
            {
                return(null);
            }
            }
        }