Exemple #1
0
        protected bool TryGetStringFromFieldDelimiter(IByteBuffer input, string packetSignature, out string value)
        {
            value = null;
            int startIndex = input.ReaderIndex;

            for (int i = 0; input.ReadableBytes > 0; i++)
            {
                switch (input.ReadByte())
                {
                case ProtocolConstants.FIELD_DELIMITER_SPACES:
                case ProtocolConstants.FIELD_DELIMITER_TAB:
                    value = input.GetString(startIndex, i, Encoding.UTF8);
                    return(true);

                case ProtocolConstants.NEW_LINES_CR:
                case ProtocolConstants.NEW_LINES_LF:
#if DEBUG
                    _logger.LogWarning($"[130]NATS protocol name of `{packetSignature}` is invalid. Text = ", input.ReadString(input.ReadableBytes, Encoding.UTF8));
#endif
                    return(false);

                default:
                    break;
                }
            }
            return(false);
        }
Exemple #2
0
        protected string GetStringFromFieldDelimiter(IByteBuffer input, string packetSignature)
        {
            int startIndex = input.ReaderIndex;

            for (int i = 0; input.ReadableBytes > 0; i++)
            {
                switch (input.ReadByte())
                {
                case ProtocolConstants.FIELD_DELIMITER_SPACES:
                case ProtocolConstants.FIELD_DELIMITER_TAB:
                    return(input.GetString(startIndex, i, Encoding.UTF8));

                case ProtocolConstants.NEW_LINES_CR:
                    if (ProtocolConstants.NEW_LINES_LF == input.SafeReadByte())
                    {
                        input.SetReaderIndex(startIndex);
                        return(string.Empty);
                    }
#if DEBUG
                    _logger.LogWarning($"[157]NATS protocol name of `{packetSignature}` is invalid. Text = ", input.ReadString(input.ReadableBytes, Encoding.UTF8));
#endif
                    break;

                default:
                    break;
                }
            }
            return(string.Empty);
        }
Exemple #3
0
 protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output)
 {
     if (input.GetString(0, 3, Encoding.UTF8).StartsWith("GET"))
     {
         // this is a websocket upgrade request, so add the appropriate decoders/encoders
         context.Channel.Pipeline.AddAfter("messageInterceptor", "websocketCodec", new WebSocketFrameCodec());
         context.Channel.Pipeline.AddAfter("messageInterceptor", "protocolHandler", new WebSocketServerProtocolHandler("/", true));
         context.Channel.Pipeline.AddAfter("messageInterceptor", "objectAggregator", new HttpObjectAggregator(65536));
         context.Channel.Pipeline.AddAfter("messageInterceptor", "httpCodec", new HttpServerCodec());
     }
     // Remove ourselves
     context.Channel.Pipeline.Remove(this);
 }
Exemple #4
0
        protected bool TryGetStringFromNewlineDelimiter(IByteBuffer input, string packetSignature, out string value)
        {
            value = null;
            int startIndex = input.ReaderIndex;

            for (int i = 0; input.ReadableBytes > 0; i++)
            {
                if (ProtocolConstants.NEW_LINES_CR == input.ReadByte())
                {
                    if (ProtocolConstants.NEW_LINES_LF == input.SafeReadByte())
                    {
                        value = input.GetString(startIndex, i, Encoding.UTF8);
                        return(true);
                    }
#if DEBUG
                    _logger.LogWarning($"[181]NATS protocol name of `{packetSignature}` is invalid. Text = ", input.ReadString(input.ReadableBytes, Encoding.UTF8));
#endif
                    break;
                }
            }
            return(false);
        }