Пример #1
0
        bool OnParseContextLength()
        {
            lock (bufferStreamUTF8_)
            {
                /*bufferStreamUTF8=Content-Length: 52\r\nContent-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n{"method":"initialized",...
                 *                                   ^
                 *                                   |
                 *                                   tail
                 */
                var tail = ByteListUtil.StrStr(bufferStreamUTF8_, "\r\n");
                if (tail == -1)
                {
                    return(false);
                }

                {
                    int numericalLen = tail - HeaderContentLengthLength_;
                    var byteArray    = bufferStreamUTF8_.GetRange(HeaderContentLengthLength_, numericalLen);
                    var unicodeLen   = Encoding.UTF8.GetString(byteArray.ToArray());
                    var value        = string.Join("", unicodeLen);
                    contentLength = int.Parse(value);
                }

                /*(Ex)
                 * (Before) bufferStreamUTF8=Content-Length: 52\nContent-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n{"method":"initialized",...
                 * (After)  bufferStreamUTF8=Content-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n{"method":"initialized",...
                 */
                bufferStreamUTF8_.RemoveRange(0, tail + 2);//2="\r\n"
            }
            return(true);
        }
Пример #2
0
        bool OnFindContextLength()
        {
            /*Memo
             * 以下2通りの記述方法あり。
             * "Content-Length:123"
             * "Content-Length: 123"
             */
            lock (bufferStreamUTF8_)
            {
                //var jsonDataUnicode = Encoding.UTF8.GetString(bufferStreamUTF8.ToArray());

                /* "Content-Length:"を見付ける。
                 */
                if (bufferStreamUTF8_.Count < HeaderContentLengthLength_)
                {
                    return(false);
                }
                if (ByteListUtil.StartsWith(bufferStreamUTF8_, HeaderContentLength_))
                {
                    return(true);
                }
#if false
                /*Content-Length:以外が渡されたため、Content-Length:まで読み飛ばす。
                 */
                var headerIndex = ByteListUtil.StrStr(bufferStreamUTF8, HeaderContentLength_);
                if (headerIndex == -1)
                {
                    return(false);
                }
                bufferStreamUTF8.RemoveRange(0, headerIndex);
                var uni = Encoding.UTF8.GetString(bufferStreamUTF8.ToArray());
#endif
            }
            return(false);
        }
Пример #3
0
        bool OnSkipContextHeader()
        {
            lock (bufferStreamUTF8_)
            {
                /*
                 * (Before) bufferStreamUTF8=Content-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n{"method":"initialized",...
                 *              or
                 *          bufferStreamUTF8=\r\n\r\n{"method":"initialized",...
                 */


                /* bufferStreamUTF8=Content-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n{"method":"initialized",...
                 *                                                                        ^       ^
                 *                                                                        |       |
                 *                                                                        |       separatorEndIndex;
                 *                                                                        separatorFirstIndex;
                 *              or
                 *
                 * bufferStreamUTF8=\r\n\r\n{"method":"initialized",...
                 *                 ^       ^
                 *                 |       |
                 *                 |       separatorEndIndex;
                 *                 separatorFirstIndex;
                 */
                var separatorFirstIndex = ByteListUtil.StrStr(bufferStreamUTF8_, "\r\n");
                if (separatorFirstIndex == -1)
                {
                    return(false);
                }
                var separatorEndIndex = ByteListUtil.StrSpn(bufferStreamUTF8_, separatorFirstIndex, "\r\n");
                if (separatorEndIndex == -1)
                {
                    return(false);
                }
                bufferStreamUTF8_.RemoveRange(0, separatorEndIndex);
                Debug.Assert(bufferStreamUTF8_[0] == Convert.ToByte('{'));

                /*(After) bufferStreamUTF8={"method":"initialized",...
                 */
            }
            return(true);
        }