コード例 #1
0
        public static JsonElement?ReadJson(this PeekableBinaryStream stream)
        {
            var sb = new StringBuilder();

            // ReSharper disable once IteratorMethodResultIsIgnored
            stream.ReadAllAsciiLines(l => sb.Append(l).ToString().Parse() != null);
            return(sb.ToString().Parse());
        }
コード例 #2
0
        private bool ProcessHeaders()
        {
            var headers = _stream.ReadAllAsciiLines(l => !l.IsNullOrWhiteSpace()).Select(l =>
            {
                var parts = l !.Split(":", 2).Select(p => p.Trim()).ToArray();
                return(Key: parts[0], Value: parts[1]);
            }).ToDictionary(h => h.Key, h => h.Value);

            // After the headers are read, the next byte should be the content block.
            if (_stream.CurrentByte.IsJsonBlock() && headers.TryGetValue("Content-Length", out var value) && Int32.TryParse(value, out var contentLength))
            {
                ProcessMessage(_stream.ReadJson(contentLength));
                return(true);
            }
            return(false);
        }