public void WriteDuration(AvroDuration value) { var bytes = new byte[12]; bytes[0] = (byte)((value.Months >> 24) & 0xFF); bytes[1] = (byte)((value.Months >> 16) & 0xFF); bytes[2] = (byte)((value.Months >> 8) & 0xFF); bytes[3] = (byte)((value.Months) & 0xFF); bytes[4] = (byte)((value.Days >> 24) & 0xFF); bytes[5] = (byte)((value.Days >> 16) & 0xFF); bytes[6] = (byte)((value.Days >> 8) & 0xFF); bytes[7] = (byte)((value.Days) & 0xFF); bytes[8] = (byte)((value.MilliSeconds >> 24) & 0xFF); bytes[9] = (byte)((value.MilliSeconds >> 16) & 0xFF); bytes[10] = (byte)((value.MilliSeconds >> 8) & 0xFF); bytes[11] = (byte)((value.MilliSeconds) & 0xFF); var sb = new StringBuilder(); foreach (var b in bytes) { sb.Append("\\u00"); sb.Append(b.ToString("x2")); } Advance(true, sb.ToString()); }
public void EncodeDuration(uint[] value, int expectedLength, byte[] expectedValue) { var duration = new AvroDuration(value[0], value[1], value[2]); using (var stream = new MemoryStream()) using (var encoder = new BinaryEncoder(stream)) { encoder.WriteDuration(duration); Assert.AreEqual(expectedLength, stream.Position, "Encode offset error"); Assert.AreEqual(expectedValue, stream.GetBuffer().AsSpan(0, expectedLength).ToArray()); } }
public void TestDuration(uint[] expected) { using (var stream = new MemoryStream()) using (var encoder = new BinaryEncoder(stream)) using (var decoder = new BinaryDecoder(stream)) { var expectedDuration = new AvroDuration(expected[0], expected[1], expected[2]); encoder.WriteDuration(expectedDuration); stream.Seek(0, SeekOrigin.Begin); var actual = decoder.ReadDuration(); Assert.AreEqual(expectedDuration, actual); } }
public void DecodeDuration(uint[] expectedValue, int expectedLength, byte[] value) { var duration = new AvroDuration(expectedValue[0], expectedValue[1], expectedValue[2]); using (var stream = new MemoryStream(value)) using (var decoder = new BinaryDecoder(stream)) { var decode = decoder.ReadDuration(); Assert.AreEqual(expectedLength, stream.Position, "Decode offset error"); Assert.AreEqual(duration, decode); stream.Seek(0, SeekOrigin.Begin); decoder.SkipDuration(); Assert.AreEqual(expectedLength, stream.Position, "Skip offset error"); } }
public void WriteDuration(AvroDuration value) { _stream.WriteByte((byte)((value.Months >> 24) & 0xFF)); _stream.WriteByte((byte)((value.Months >> 16) & 0xFF)); _stream.WriteByte((byte)((value.Months >> 8) & 0xFF)); _stream.WriteByte((byte)((value.Months) & 0xFF)); _stream.WriteByte((byte)((value.Days >> 24) & 0xFF)); _stream.WriteByte((byte)((value.Days >> 16) & 0xFF)); _stream.WriteByte((byte)((value.Days >> 8) & 0xFF)); _stream.WriteByte((byte)((value.Days) & 0xFF)); _stream.WriteByte((byte)((value.MilliSeconds >> 24) & 0xFF)); _stream.WriteByte((byte)((value.MilliSeconds >> 16) & 0xFF)); _stream.WriteByte((byte)((value.MilliSeconds >> 8) & 0xFF)); _stream.WriteByte((byte)((value.MilliSeconds) & 0xFF)); }