예제 #1
0
    def test_string_decode_encode(self):
        from klvdata.common import bytes_to_hexstr
        from klvdata.common import hexstr_to_bytes

        self.assertEqual(
            hexstr_to_bytes(
                bytes_to_hexstr(b'\x50\x72\x65\x64\x61\x74\x6F\x72')),
            b'\x50\x72\x65\x64\x61\x74\x6F\x72')

        self.assertEqual(
            bytes_to_hexstr(
                hexstr_to_bytes(
                    '06 0E 2B 34 - 02 0B 01 01 – 0E 01 03 01 - 01 00 00 00')),
            '06 0E 2B 34 02 0B 01 01 0E 01 03 01 01 00 00 00')
예제 #2
0
    def test_st0601_timestamp(self):
        key = b'\x02'
        length = b'\x08'
        value = b'\x00\x04\x60\x50\x58\x4E\x01\x80'
        klv = key + length + value

        from klvdata.misb0601 import PrecisionTimeStamp

        # Basic Properties
        self.assertEqual(PrecisionTimeStamp(value).key, key)
        self.assertEqual(PrecisionTimeStamp(value).length, length)
        self.assertEqual(bytes_to_hexstr(bytes(PrecisionTimeStamp(value).value)), bytes_to_hexstr(value))
        self.assertEqual(bytes(PrecisionTimeStamp(value)), klv)

        # Check __str__
        self.assertEqual(str(PrecisionTimeStamp(value)), "PrecisionTimeStamp: (b'\\x02', 8, 2009-01-12 22:08:22+00:00)")
예제 #3
0
 def __str__(self):
     return bytes_to_hexstr(self.value, start='0x', sep='')