/// <summary> /// Asyncronously reads <paramref name="count"/> bytes. /// </summary> /// <param name="count">The number of bytes to read.</param> /// <returns>A <see cref="Task"/> that completes when the entire read operation has completed. The result of the task contains the array of bytes that was read.</returns> /// <exception cref="EndOfStreamException">Thrown when the end of the stream is reached before the read is completed.</exception> public static async Task <byte[]> ReadBytesAsync(this IReadBytes reader, int count) { var bytes = new byte[count]; await reader.ReadBytesAsync(bytes, 0, count).ConfigureAwait(false); return(bytes); }
public static double ReadFullDouble(this IReadBytes stream) { var bytes = new byte[8]; stream.ReadBytes(bytes, 0, 8); return(BitConverter.ToDouble(bytes, 0)); }
/// <summary> /// Reads <paramref name="count"/> bytes. /// </summary> /// <param name="count">The number of bytes to read.</param> /// <returns>The array of bytes that was read.</returns> /// <exception cref="EndOfStreamException">Thrown when the end of the stream is reached before the read is completed.</exception> public static byte[] ReadBytes(this IReadBytes reader, int count) { var bytes = new byte[count]; reader.ReadBytes(bytes, 0, count); return(bytes); }
public static byte[] ReadRemaining(this IReadBytes reader) { using (var ms = new MemoryStream()) { reader.CopyTo(ms.AsIWriteBytes()); return(ms.ToArray()); } }
public static async Task <byte[]> ReadRemainingAsync(this IReadBytes reader) { using (var ms = new MemoryStream()) { await reader.CopyToAsync(ms.AsIWriteBytes()).ConfigureAwait(false); return(ms.ToArray()); } }
public static double?ReadNullableFullDouble(this IReadBytes stream) { if (!stream.ReadCompressedBool()) { return(null); } return(stream.ReadFullDouble()); }
public static T?ReadCompressedNullableEnum <T>(this IReadBytes stream) where T : struct, Enum { if (!stream.ReadCompressedBool()) { return(null); } return(stream.ReadCompressedEnum <T>()); }
public static long?ReadCompressedNullableLong(this IReadBytes stream) { if (!stream.ReadCompressedBool()) { return(null); } return(stream.ReadCompressedLong()); }
public static MonthStamp?ReadCompressedNullableMonthStamp(this IReadBytes stream) { if (!stream.ReadCompressedBool()) { return(null); } return(stream.ReadCompressedMonthStamp()); }
public static decimal?ReadCompressedNullableDecimal(this IReadBytes stream) { if (!stream.ReadCompressedBool()) { return(null); } return(stream.ReadCompressedDecimal()); }
public static DateTime?ReadCompressedNullableDateTime(this IReadBytes stream) { if (!stream.ReadCompressedBool()) { return(null); } return(stream.ReadCompressedDateTime()); }
public static uint?ReadCompressedNullableUInt(this IReadBytes stream) { if (!stream.ReadCompressedBool()) { return(null); } return(stream.ReadCompressedUInt()); }
public static byte[] ReadCompressedByteArray(this IReadBytes stream) { if (!stream.ReadCompressedBool()) { return(null); } var length = (int)stream.ReadCompressedUInt(); return(stream.ReadBytes(length)); }
public static bool?ReadCompressedNullableBool(this IReadBytes stream) { var byteValue = stream.ReadByte(); if (byteValue == 2) { return(null); } return(byteValue == 1); }
public static decimal ReadCompressedDecimal(this IReadBytes stream) { var bits = new int[4]; bits[0] = stream.ReadCompressedInt(); bits[1] = stream.ReadCompressedInt(); bits[2] = stream.ReadCompressedInt(); bits[3] = stream.ReadCompressedInt(); return(new decimal(bits)); }
public static double ReadDoubleOffset(this IReadBytes stream, double seed, double tickSize) { var numTicks = stream.ReadCompressedInt(); /// Since this is true 80% of the time in a trading platform, we use this optimization for significant performance gains. if (numTicks == 0) { return(seed); } return(ToValue(tickSize, ToTicks(seed, tickSize) + numTicks)); }
public static string ReadCompressedString(this IReadBytes stream) { if (!stream.ReadCompressedBool()) { return(null); } var length = (int)UIntCompressor.ReadCompressedUInt(stream); var bytes = new byte[length]; stream.ReadBytes(bytes, 0, length); return(Encoding.GetString(bytes)); }
public static ulong ReadCompressedULong(this IReadBytes stream) { ulong result = 0; int shiftBits = 0; ulong inputByte = (ulong)stream.ReadByte(); while ((inputByte < MORE_MASK)) { result |= (inputByte) << shiftBits; inputByte = (ulong)stream.ReadByte(); shiftBits += 7; } return(result | ((inputByte & DATA_MASK) << shiftBits)); }
public static uint ReadCompressedUInt(this IReadBytes stream) { uint result = 0; int shiftBits = 0; int inputByte = stream.ReadByte(); while ((inputByte < MORE_MASK)) { result |= (uint)((inputByte) << shiftBits); inputByte = stream.ReadByte(); shiftBits += 7; } return(result | (uint)((inputByte & DATA_MASK) << shiftBits)); }
public static MonthStamp ReadCompressedMonthStamp(this IReadBytes stream) { var value = (int)stream.ReadCompressedUInt(); return(new MonthStamp(value / 12, (value % 12) + 1)); }
public static TimeStamp ReadCompressedTimeStamp(this IReadBytes stream) { return(new TimeStamp(stream.ReadCompressedLong())); }
public static DateTime ReadCompressedDateTime(this IReadBytes stream) { return(new DateTime(stream.ReadCompressedLong(), stream.ReadCompressedEnum <DateTimeKind>())); }
public abstract T Decompress(IReadBytes stream);
object IDecompressor.Decompress(IReadBytes stream) => Decompress(stream);
public static T ReadCompressedEnum <T>(this IReadBytes stream) where T : Enum { return((T)(object)stream.ReadCompressedInt()); }
public static bool ReadCompressedBool(this IReadBytes stream) { return(stream.ReadByte() == 1); }
public static DateStamp ReadCompressedDateStamp(this IReadBytes stream) { var value = (int)stream.ReadCompressedUInt(); return(new DateStamp(value / 100 / 12, (value / 100 % 12) + 1, value % 100)); }
public static long ReadCompressedLong(this IReadBytes input) { var value = input.ReadCompressedULong(); return((long)((value >> 1) ^ (~(value & 1) + 1))); }
public override T Decompress(IReadBytes stream) => Read(stream);
public static int ReadCompressedInt(this IReadBytes input) { var value = input.ReadCompressedUInt(); return((int)((value >> 1) ^ (~(value & 1) + 1))); }