public static IByteDevice Wrap(IByteInDevice inDevice, IByteOutDevice outDevice) { return(inDevice.NotNull() || outDevice.NotNull() ? new ByteDeviceCombiner(inDevice, outDevice) { Wrapped = true } : null); }
public virtual bool Close() { bool result; if (result = this.backend.NotNull()) { this.backend.Close(); this.backend = null; } return result; }
public virtual async Tasks.Task <bool> Close() { bool result; if (result = this.inDevice.NotNull() && !this.Wrapped) { result = await this.inDevice.Close(); this.inDevice = null; } if (this.outDevice.NotNull() && !this.Wrapped) { result = await this.outDevice.Close(); this.outDevice = null; } return(result); }
byte? Next() { byte? result; if (this.nextPosition < this.matchingLength) result = this.endMark[this.nextPosition++]; else if (this.backend.IsNull()) result = null; else { byte? next = result = this.backend.Read(); if (next.HasValue && next.Value == this.endMark[0]) { this.nextPosition = 1; this.matchingLength = 1; while (true) { if (this.matchingLength < this.endMark.Length) { while (!(next = this.backend.Peek()).HasValue) ; if (next.Value != this.endMark[this.matchingLength]) break; this.matchingLength++; next = this.backend.Read(); } else { this.matchingLength = 0; this.backend = null; result = null; break; } } } } return result; }
public static IByteDevice Open(IByteInDevice inDevice, IByteOutDevice outDevice) { return(inDevice.NotNull() || outDevice.NotNull() ? new ByteDeviceCombiner(inDevice, outDevice) : null); }
public virtual bool Close() { bool result; if (result = this.inDevice.NotNull() && !this.Wrapped) { this.inDevice.Close(); this.inDevice = null; } if (this.outDevice.NotNull() && !this.Wrapped) { result |= this.outDevice.NotNull(); this.outDevice.Close(); this.outDevice = null; } return result; }
protected ByteDeviceCombiner(IByteInDevice inDevice) : this(inDevice, null) { }
public static IByteDevice Wrap(IByteInDevice inDevice) { return ByteDeviceCombiner.Wrap(inDevice, null); }
public static IByteDevice Open(IByteInDevice inDevice) { return ByteDeviceCombiner.Open(inDevice, null); }
public static Request Parse(IByteInDevice device) { Request result = new Request(); string[] firstLine = Request.ReadLine(device).Decode().Join().Split(' '); if (firstLine.Length == 3) { result.Method = firstLine[0].Parse<Method>(); result.Path = firstLine[1]; result.Protocol = firstLine[2]; string line; while ((line = Request.ReadLine(device).Decode().Join()).NotEmpty()) { string[] parts = line.Split(new char[] { ':' }, 2); result[parts[0].Trim()] = parts[1].Trim(); } } return result; }
protected FixedLengthByteInDevice(IByteInDevice backend, int length) { this.backend = backend; this.length = length; }
protected ByteDeviceCombiner(IByteInDevice inDevice, IByteOutDevice outDevice) { this.inDevice = inDevice; this.outDevice = outDevice; }
public static IByteDevice Wrap(IByteInDevice inDevice) { return(ByteDeviceCombiner.Wrap(inDevice, null)); }
public static bool Write (this IByteOutDevice me, IByteInDevice device) { return me.Write(device.AsEnumerable()); }
public static IByteInDevice Open(IByteInDevice device, int length) { return (device.NotNull() && length > 0) ? new FixedLengthByteInDevice(device, length) : null; }
static Generic.IEnumerable<byte> ReadLine(IByteInDevice device) { foreach (byte b in device.Read(13, 10)) if (b != 13 && b != 10) yield return b; }
public Decoder(IByteInDevice backend, System.Text.Encoding encoding) { this.backend = backend; this.encoding = encoding; this.queue = this.backend.AsEnumerable().Decode(this.encoding).Cast(c => (char?)c).GetEnumerator(); }
public static Generic.IEnumerator <Tasks.Task <byte?> > GetEnumerator(this IByteInDevice device) { yield return(device.Read()); }
public bool Close() { bool result; if (result = this.backend.NotNull() && this.backend.Close()) { this.backend = null; this.queue = null; } return result; }
public static IByteDevice Open(IByteInDevice inDevice, IByteOutDevice outDevice) { return inDevice.NotNull() || outDevice.NotNull() ? new ByteDeviceCombiner(inDevice, outDevice) : null; }
public bool Close() { bool result; this.backend = null; if (result = this.Closed.NotNull()) { this.Closed(); this.Closed = null; } return result; }
public static IByteDevice Wrap(IByteInDevice inDevice, IByteOutDevice outDevice) { return inDevice.NotNull() || outDevice.NotNull() ? new ByteDeviceCombiner(inDevice, outDevice) { Wrapped = true } : null; }
public static IByteInDevice Open(IByteInDevice backend, byte[] endMark) { return backend.NotNull() ? endMark.NotEmpty() ? new PartialByteInDevice(backend, endMark) : backend : null; }
PartialByteInDevice(IByteInDevice backend, byte[] endMark) { this.backend = backend; this.endMark = endMark; }
public static ByteStream Open(IByteInDevice device) { return ByteStream.Open(ByteDeviceCombiner.Open(device)); }
public static IByteDevice Open(IByteInDevice inDevice) { return(ByteDeviceCombiner.Open(inDevice, null)); }