private void ProduceBytes(byte[] bytes) { int i = 0; while (bytes.Length > i + 4) { byte type = bytes[i]; var builder = new StringBuilder(); i++; while (bytes[i] != byte.MaxValue) { builder.Append(bytes[i]); i++; } i++; int length = int.Parse(builder.ToString()); if (type == 0) { var buffer = new byte[length]; Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length); TextSubject.OnNext(Encoding.UTF8.GetString(buffer)); } else if (type == 1) { var buffer = new byte[length - 1]; Buffer.BlockCopy(bytes, i + 1, buffer, 0, buffer.Length); BytesSubject.OnNext(buffer); } i += length; } }
public void Dispose() { //TextSubject.Clear(); //BytesSubject.Clear(); TextSubject.Dispose(); BytesSubject.Dispose(); }
protected override void ProduceText(string text) { string[] items = text.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in items) { if (item[0] == 'b') { byte[] bytes = Convert.FromBase64String(item.Substring(1)); BytesSubject.OnNext(bytes); } else { TextSubject.OnNext(item); } } }
public void Dispose() { TextSubject.Dispose(); BytesSubject.Dispose(); }