void TestRoundTrip(byte[] values, int?expectedEncodeLength = null) { var stream = new MemoryStream(); var writer = new ByteRunLengthEncodingWriter(stream); writer.Write(values); //If we know the encode length, make sure it's correct if (expectedEncodeLength.HasValue) { Assert.Equal(expectedEncodeLength.Value, stream.Length); } stream.Seek(0, SeekOrigin.Begin); var reader = new ByteRunLengthEncodingReader(stream); var result = reader.Read().ToArray(); //Make sure all bytes in the written stream were consumed Assert.Equal(stream.Length, stream.Position); //Check the actual values Assert.Equal(values.Length, result.Length); for (int i = 0; i < values.Length; i++) { Assert.Equal(values[i], result[i]); } }
void TestRead(byte[] expected, byte[] input) { var stream = new MemoryStream(input); var reader = new ByteRunLengthEncodingReader(stream); var actual = reader.Read().ToArray(); Assert.Equal(expected.Length, actual.Length); for (int i = 0; i < expected.Length; i++) { Assert.Equal(expected[i], actual[i]); } }
protected byte[] ReadByteStream(Protocol.StreamKind streamKind) { var stripeStream = GetStripeStream(streamKind); if (stripeStream == null) { return(null); } var stream = stripeStream.GetDecompressedStream(); var reader = new ByteRunLengthEncodingReader(stream); return(reader.Read().ToArray()); }