コード例 #1
0
 public void TestEncode_Max96()
 {
     Assert.That(
         new Timestamp(9223372036854775807L, 999999999).Encode(),
         Is.EqualTo(MessagePackExtendedTypeObject.Unpack(0xFF, new byte[] { 0x3B, 0x9A, 0xC9, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }))
         );
 }
コード例 #2
0
 public void TestEncode_Min96()
 {
     Assert.That(
         new Timestamp(-9223372036854775808L, 0).Encode(),
         Is.EqualTo(MessagePackExtendedTypeObject.Unpack(0xFF, new byte[] { 0, 0, 0, 0, 0x80, 0, 0, 0, 0, 0, 0, 0 }))
         );
 }
コード例 #3
0
 public void TestEncode_Max64()
 {
     Assert.That(
         new Timestamp(17179869183L, 999999999).Encode(),
         Is.EqualTo(MessagePackExtendedTypeObject.Unpack(0xFF, new byte[] { 0xEE, 0x6B, 0x27, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }))
         );
 }
コード例 #4
0
 public void TestEncode_Min64()
 {
     Assert.That(
         new Timestamp(0L, 1).Encode(),
         Is.EqualTo(MessagePackExtendedTypeObject.Unpack(0xFF, new byte[] { 0, 0, 0, 0x4, 0, 0, 0, 0 }))
         );
 }
コード例 #5
0
 public void TestEncode_Max32()
 {
     Assert.That(
         new Timestamp(4294967295L, 0).Encode(),
         Is.EqualTo(MessagePackExtendedTypeObject.Unpack(0xFF, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }))
         );
 }
コード例 #6
0
        /// <summary>
        ///		Encodes this instance to a <see cref="MessagePackExtendedTypeObject"/>.
        /// </summary>
        /// <returns>A <see cref="MessagePackExtendedTypeObject"/> which equivalant to this instance.</returns>
        public MessagePackExtendedTypeObject Encode()
        {
            if ((this.unixEpochSeconds >> 34) != 0)
            {
                // timestamp 96
                var value = this;
                var body  = new byte[12];
                body[0]  = unchecked (( byte )((this.nanoseconds >> 24) & 0xFF));
                body[1]  = unchecked (( byte )((this.nanoseconds >> 16) & 0xFF));
                body[2]  = unchecked (( byte )((this.nanoseconds >> 8) & 0xFF));
                body[3]  = unchecked (( byte )((this.nanoseconds) & 0xFF));
                body[4]  = unchecked (( byte )((this.unixEpochSeconds >> 56) & 0xFF));
                body[5]  = unchecked (( byte )((this.unixEpochSeconds >> 48) & 0xFF));
                body[6]  = unchecked (( byte )((this.unixEpochSeconds >> 40) & 0xFF));
                body[7]  = unchecked (( byte )((this.unixEpochSeconds >> 32) & 0xFF));
                body[8]  = unchecked (( byte )((this.unixEpochSeconds >> 24) & 0xFF));
                body[9]  = unchecked (( byte )((this.unixEpochSeconds >> 16) & 0xFF));
                body[10] = unchecked (( byte )((this.unixEpochSeconds >> 8) & 0xFF));
                body[11] = unchecked (( byte )(this.unixEpochSeconds & 0xFF));

                return(MessagePackExtendedTypeObject.Unpack(TypeCode, body));
            }
            else
            {
                var encoded = ((( ulong )this.nanoseconds) << 34) | unchecked (( ulong )this.unixEpochSeconds);
                if ((encoded & 0xFFFFFFFF00000000L) == 0)
                {
                    // timestamp 32
                    var value = unchecked (( uint )encoded);
                    var body  = new byte[4];
                    body[0] = unchecked (( byte )((encoded >> 24) & 0xFF));
                    body[1] = unchecked (( byte )((encoded >> 16) & 0xFF));
                    body[2] = unchecked (( byte )((encoded >> 8) & 0xFF));
                    body[3] = unchecked (( byte )(encoded & 0xFF));

                    return(MessagePackExtendedTypeObject.Unpack(TypeCode, body));
                }
                else
                {
                    // timestamp 64
                    var body = new byte[8];
                    body[0] = unchecked (( byte )((encoded >> 56) & 0xFF));
                    body[1] = unchecked (( byte )((encoded >> 48) & 0xFF));
                    body[2] = unchecked (( byte )((encoded >> 40) & 0xFF));
                    body[3] = unchecked (( byte )((encoded >> 32) & 0xFF));
                    body[4] = unchecked (( byte )((encoded >> 24) & 0xFF));
                    body[5] = unchecked (( byte )((encoded >> 16) & 0xFF));
                    body[6] = unchecked (( byte )((encoded >> 8) & 0xFF));
                    body[7] = unchecked (( byte )(encoded & 0xFF));

                    return(MessagePackExtendedTypeObject.Unpack(TypeCode, body));
                }
            }
        }
コード例 #7
0
 public void TestDecode_InvalidLength_13()
 {
     Assert.Throws <ArgumentException>(() => Timestamp.Decode(MessagePackExtendedTypeObject.Unpack(0xFF, new byte [13])));
 }