public int ComputeSize(int n) { var ms = new MemoryStream(); var writer = new ReusableStreamToForwardDataWriterAdapter(); writer.SetTarget(ms); writer.WriteVariableInt(n); return((int)ms.Length); }
public void Serialized_Zero_Is_Zero_Byte() { var ms = new MemoryStream(); var writer = new ReusableStreamToForwardDataWriterAdapter(); writer.SetTarget(ms); writer.WriteVariableInt(0); AssertEquals(1, ms.Length); AssertEquals(0, ms.GetBuffer()[0]); }
private void RunRoundTripTest(int[] numbers) { var ms = new MemoryStream(); var writer = new ReusableStreamToForwardDataWriterAdapter(); writer.SetTarget(ms); foreach (var number in numbers) { writer.WriteVariableInt(number); } ms.Position = 0; var reader = new ReusableLengthLimitedStreamToForwardDataReaderAdapter(); reader.SetTarget(ms); reader.SetBytesRemaining(ms.Length); foreach (var number in numbers) { AssertEquals(number, reader.ReadVariableInt()); } }