コード例 #1
0
        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());
        }
コード例 #2
0
        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());
                }
        }
コード例 #3
0
 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);
             }
 }
コード例 #4
0
        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");
                }
        }
コード例 #5
0
        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));
        }