/// <inheritdoc /> public void CopyTo(IWriteBytes destination, int bufferSize = 81920) { var buffer = new byte[bufferSize]; var bytesRead = Stream.Read(buffer, 0, bufferSize); while (bytesRead > 0) { destination.WriteBytes(buffer, 0, bytesRead); bytesRead = Stream.Read(buffer, 0, bufferSize); } }
public void ReadBytes(long index, int count, IWriteBytes destination) { while (count > 0) { var readBuffer = _buffers[(int)(index / BufferSizeAsLong)]; var readIndex = (int)(index % BufferSizeAsLong); var numBytes = Min(count, BufferSize - readIndex); destination.WriteBytes(readBuffer, readIndex, numBytes); index += numBytes; count -= numBytes; } }
public static void WriteCompressedByteArray(this IWriteBytes stream, byte[] bytes) { if (bytes is null) { stream.WriteCompressedBool(false); } else { stream.WriteCompressedBool(true); stream.WriteCompressedUInt((uint)bytes.Length); stream.WriteBytes(bytes); } }
public static void WriteCompressedString(this IWriteBytes stream, string value) { if (null == value) { stream.WriteCompressedBool(false); } else { stream.WriteCompressedBool(true); var bytes = Encoding.GetBytes(value); UIntCompressor.WriteCompressedUInt(stream, (uint)bytes.Length); stream.WriteBytes(bytes, 0, bytes.Length); } }
public static void WriteFullDouble(this IWriteBytes stream, double value) { stream.WriteBytes(BitConverter.GetBytes(value), 0, 8); }