protected override int GetBodyLengthFromHeader(ref ReadOnlySequence <byte> buffer) { // skip the switch flag var strLen = buffer.GetString(Utf8Encoding); return(int.Parse(strLen.TrimStart('0'))); }
protected override TextPackageInfo DecodePackage(ref ReadOnlySequence <byte> buffer) { NextFilter = SwitchFilter; // skip the switch flag return(new TextPackageInfo { Text = buffer.GetString(Encoding.UTF8) }); }
protected override StringPackageInfo DecodePackage(ref ReadOnlySequence <byte> buffer) { var text = buffer.GetString(Encoding.UTF8); var parts = text.Split(' '); return(new StringPackageInfo { Key = parts[0], Parameters = parts.Skip(1).ToArray() }); }
public StringPackageInfo Decode(ref ReadOnlySequence <byte> buffer, object context) { var text = buffer.GetString(Encoding); var parts = text.Split(' '); return(new StringPackageInfo { Key = parts[0], Body = text, Parameters = parts.Skip(1).ToArray() }); }
public StringPackageInfo Decode(ref ReadOnlySequence <byte> buffer, object context) { var text = buffer.GetString(Encoding); var parts = text.Split(' ', 2); var key = parts[0]; if (parts.Length <= 1) { return(new StringPackageInfo { Key = key }); } return(new StringPackageInfo { Key = key, Body = parts[1], Parameters = parts[1].Split(' ') }); }
public PackageInfo Decode(ref ReadOnlySequence <byte> buffer, object context) { var text = buffer.GetString(new UTF8Encoding(false)); var index = text.IndexOf(' '); var package = new PackageInfo { Raw = text }; if (index == -1) { package.Key = text; } else { package.Key = text.Substring(0, index); package.Content = text.Substring(index + 1, text.Length - index - 1); } return(package); }
protected override TextPackageInfo DecodePackage(ReadOnlySequence<byte> buffer) { return new TextPackageInfo { Text = buffer.GetString(Encoding.UTF8) }; }
/// <summary> /// 对包进行解码 /// </summary> /// <param name="buffer"></param> /// <returns></returns> protected override TextPackageInfo DecodePackage(ref ReadOnlySequence <byte> buffer) { return(new TextPackageInfo { Text = buffer.GetString(Encoding) }); }
private HttpHeader ParseHttpHeaderItems(ReadOnlySequence <byte> header) { var headerText = header.GetString(Encoding.UTF8); var reader = new StringReader(headerText); var firstLine = reader.ReadLine(); if (string.IsNullOrEmpty(firstLine)) { return(null); } var items = new NameValueCollection(); var prevKey = string.Empty; var line = string.Empty; while (!string.IsNullOrEmpty(line = reader.ReadLine())) { if (line.StartsWith(_TAB) && !string.IsNullOrEmpty(prevKey)) { var currentValue = items.Get(prevKey); items[prevKey] = currentValue + line.Trim(); continue; } int pos = line.IndexOf(_COLON); if (pos <= 0) { continue; } string key = line.Substring(0, pos); if (!string.IsNullOrEmpty(key)) { key = key.Trim(); } if (string.IsNullOrEmpty(key)) { continue; } var valueOffset = pos + 1; if (line.Length <= valueOffset) //No value in this line { continue; } var value = line.Substring(valueOffset); if (!string.IsNullOrEmpty(value) && value.StartsWith(' ') && value.Length > 1) { value = value.Substring(1); } var existingValue = items.Get(key); if (string.IsNullOrEmpty(existingValue)) { items.Add(key, value); } else { items[key] = existingValue + ", " + value; } prevKey = key; } var metaInfo = firstLine.Split(' '); if (metaInfo.Length != 3) { // invalid first line return(null); } return(new HttpHeader(metaInfo[0], metaInfo[1], metaInfo[2], items)); }
public TextPackageInfo Decode(ref ReadOnlySequence <byte> buffer, object context) { return(new TextPackageInfo { Text = buffer.GetString(Encoding.UTF8) }); }
public HttpHeader(ReadOnlySequence <byte> data) { Data = data; _items = new NameValueCollection(); var stringReader = new StringReader(Data.GetString(Encoding.UTF8)); var line = string.Empty; var prevKey = string.Empty; while (!string.IsNullOrEmpty(line = stringReader.ReadLine())) { if (line.StartsWith(_TAB) && !string.IsNullOrEmpty(prevKey)) { var currentValue = _items.Get(prevKey); _items[prevKey] = currentValue + line.Trim(); continue; } int pos = line.IndexOf(_COLON); if (pos <= 0) { continue; } string key = line.Substring(0, pos); if (!string.IsNullOrEmpty(key)) { key = key.Trim(); } if (string.IsNullOrEmpty(key)) { continue; } var valueOffset = pos + 1; if (line.Length <= valueOffset) //No value in this line { continue; } var value = line.Substring(valueOffset); if (!string.IsNullOrEmpty(value) && value.StartsWith(' ') && value.Length > 1) { value = value.Substring(1); } var existingValue = _items.Get(key); if (string.IsNullOrEmpty(existingValue)) { _items.Add(key, value); } else { _items[key] = existingValue + ", " + value; } prevKey = key; } }
protected override int GetBodyLengthFromHeader(ReadOnlySequence <byte> buffer) { var strLen = buffer.GetString(Encoding.ASCII); return(int.Parse(strLen.TrimStart('0'))); }
public string DecodePieceByPiece() { var dataSequence = new ReadOnlySequence <byte>(_head, 0, _tail, _tail.Memory.Length); return(dataSequence.GetString(_encoding)); }
private bool TryParseHttpHeaderItems(ref ReadOnlySequence <byte> header, out string firstLine, out NameValueCollection items) { var headerText = header.GetString(Encoding.UTF8); var reader = new StringReader(headerText); firstLine = reader.ReadLine(); if (string.IsNullOrEmpty(firstLine)) { items = null; return(false); } items = new NameValueCollection(); var prevKey = string.Empty; var line = string.Empty; while (!string.IsNullOrEmpty(line = reader.ReadLine())) { if (line.StartsWith(_TAB) && !string.IsNullOrEmpty(prevKey)) { var currentValue = items.Get(prevKey); items[prevKey] = currentValue + line.Trim(); continue; } int pos = line.IndexOf(_COLON); if (pos <= 0) { continue; } string key = line.Substring(0, pos); if (!string.IsNullOrEmpty(key)) { key = key.Trim(); } if (string.IsNullOrEmpty(key)) { continue; } var valueOffset = pos + 1; if (line.Length <= valueOffset) //No value in this line { continue; } var value = line.Substring(valueOffset); if (!string.IsNullOrEmpty(value) && value.StartsWith(' ') && value.Length > 1) { value = value.Substring(1); } var existingValue = items.Get(key); if (string.IsNullOrEmpty(existingValue)) { items.Add(key, value); } else { items[key] = existingValue + ", " + value; } prevKey = key; } return(true); }