public static UInt64 ToUInt64(this Utf8Bytes src) { UInt64 value = 0; var p = new Utf8Iterator(src.Bytes); while (p.MoveNext()) { var b = p.Current; switch (b) { case 0x30: value = (UInt64)(value * 10); break; case 0x31: value = (UInt64)(value * 10 + 1); break; case 0x32: value = (UInt64)(value * 10 + 2); break; case 0x33: value = (UInt64)(value * 10 + 3); break; case 0x34: value = (UInt64)(value * 10 + 4); break; case 0x35: value = (UInt64)(value * 10 + 5); break; case 0x36: value = (UInt64)(value * 10 + 6); break; case 0x37: value = (UInt64)(value * 10 + 7); break; case 0x38: value = (UInt64)(value * 10 + 8); break; case 0x39: value = (UInt64)(value * 10 + 9); break; default: throw new ArgumentOutOfRangeException(); } } return(value); }
public static IEnumerable <Utf8Bytes> Split(this Utf8Bytes src, byte delemeter) { var start = 0; var p = new Utf8Iterator(src.Bytes); while (p.MoveNext()) { if (p.Current == delemeter) { if (p.BytePosition - start == 0) { yield return(default(Utf8Bytes)); } else { yield return(src.Subbytes(start, p.BytePosition - start)); } start = p.BytePosition + 1; } } if (start < p.BytePosition) { yield return(src.Subbytes(start, p.BytePosition - start)); } }
public static Int32 ToInt32(this Utf8Bytes src) { Int32 value = 0; var p = new Utf8Iterator(src.Bytes); while (p.MoveNext()) { var b = p.Current; switch (b) { case 0x30: value = value * 10; break; case 0x31: value = value * 10 + 1; break; case 0x32: value = value * 10 + 2; break; case 0x33: value = value * 10 + 3; break; case 0x34: value = value * 10 + 4; break; case 0x35: value = value * 10 + 5; break; case 0x36: value = value * 10 + 6; break; case 0x37: value = value * 10 + 7; break; case 0x38: value = value * 10 + 8; break; case 0x39: value = value * 10 + 9; break; default: throw new ArgumentOutOfRangeException(); } } return(value); }
public static Utf8Iterator GetFirst(this Utf8Bytes src) { var it = src.GetIterator(); it.MoveNext(); return(it); }
public static Utf8Bytes JsTxtFilter(Utf8Bytes src) { if (src.EndsWith(s_js) || src.EndsWith(s_css)) { src = src.Concat(s_txt); } return(src); }
public static Utf8Bytes AcceptWebSocketKey(Utf8Bytes key) { var concat = key + Utf8Bytes.From("258EAFA5-E914-47DA-95CA-C5AB0DC85B11"); using (var sha1 = SHA1.Create()) { var bs = sha1.ComputeHash(concat.Bytes.Array, concat.Bytes.Offset, concat.Bytes.Count); return(Utf8Bytes.From(Convert.ToBase64String(bs))); } }
void InternalError(Exception ex) { Logging.Error(String.Format("{0} - {1}", ID, ex)); using (var s = new NetworkStream(Socket, false)) { Http10StatusLine.InternalError.WriteTo(s); s.CRLF(); s.CRLF(); Utf8Bytes.From(ex.ToString()).WriteTo(s); } Dispose(); }
public static bool TrySearchByte(this Utf8Bytes src, Func <byte, bool> pred, out int pos) { pos = 0; for (; pos < src.ByteLength; ++pos) { if (pred(src[pos])) { return(true); } } return(false); }
public static bool TrySearchAscii(this Utf8Bytes src, Byte target, int start, out int pos) { var p = new Utf8Iterator(src.Bytes, start); while (p.MoveNext()) { var b = p.Current; if (b <= 0x7F) { // ascii if (b == target /*'\"'*/) { // closed pos = p.BytePosition; return(true); } else if (b == '\\') { // escaped switch ((char)p.Second) { case '"': // fall through case '\\': // fall through case '/': // fall through case 'b': // fall through case 'f': // fall through case 'n': // fall through case 'r': // fall through case 't': // fall through // skip next p.MoveNext(); break; case 'u': // unicode // skip next 4 p.MoveNext(); p.MoveNext(); p.MoveNext(); p.MoveNext(); break; default: // unkonw escape throw new KeyNotFoundException("unknown escape: " + p.Second); } } } } pos = -1; return(false); }
public Utf8Bytes GetHeader(Utf8Bytes key) { foreach (var message in Messages) { if (message.StartsWith(key)) { var value = message.Subbytes(key.ByteLength); if (value[0] == ':') { return(value.Subbytes(1).TrimStart()); } } } return(default(Utf8Bytes)); }
public static void WriteTo(this Utf8Bytes src, Stream dst) { dst.Write(src.Bytes.Array, src.Bytes.Offset, src.Bytes.Count); }
public static double ToDouble(this Utf8Bytes src) { return(Double.Parse(src.ToAscii(), System.Globalization.CultureInfo.InvariantCulture)); }
public void Add(Utf8Bytes str) { m_buffer.Push(str.Bytes); }
public static float ToSingle(this Utf8Bytes src) { return(Single.Parse(src.ToAscii(), System.Globalization.CultureInfo.InvariantCulture)); }
public void WebSocketTest() { var accepted = HttpSession.AcceptWebSocketKey(Utf8Bytes.From("dGhlIHNhbXBsZSBub25jZQ==")); Assert.AreEqual(Utf8Bytes.From("s3pPLMBiTxaQ9kYGzzhZRbK+xOo="), accepted); }
public FileMounter(String mountPoint, Func <Byte[]> content) { m_mountPoint = Utf8Bytes.From(mountPoint); m_content = content; }
public FolderMounter(string mountPoint, string path, PathFilter pathFilter) { m_mountPoint = Utf8Bytes.From(mountPoint); m_path = path; m_filter = pathFilter; }
public HttpRequest(Utf8Bytes line) { RequestLine = line; }