Example #1
0
def test_unpack_tsresol():
    assert unpack_timestamp_resolution(int2byte(0)) == 1
    assert unpack_timestamp_resolution(int2byte(1)) == 1e-1
    assert unpack_timestamp_resolution(int2byte(6)) == 1e-6
    assert unpack_timestamp_resolution(int2byte(100)) == 1e-100

    assert unpack_timestamp_resolution(int2byte(0 | 0b10000000)) == 1
    assert unpack_timestamp_resolution(int2byte(1 | 0b10000000)) == 2**-1
    assert unpack_timestamp_resolution(int2byte(6 | 0b10000000)) == 2**-6
    assert unpack_timestamp_resolution(int2byte(100 | 0b10000000)) == 2**-100
Example #2
0
def test_unpack_tsresol():
    assert unpack_timestamp_resolution(bytes((0, ))) == 1
    assert unpack_timestamp_resolution(bytes((1, ))) == 1e-1
    assert unpack_timestamp_resolution(bytes((6, ))) == 1e-6
    assert unpack_timestamp_resolution(bytes((100, ))) == 1e-100

    assert unpack_timestamp_resolution(bytes((0 | 0b10000000, ))) == 1
    assert unpack_timestamp_resolution(bytes((1 | 0b10000000, ))) == 2**-1
    assert unpack_timestamp_resolution(bytes((6 | 0b10000000, ))) == 2**-6
    assert unpack_timestamp_resolution(bytes((100 | 0b10000000, ))) == 2**-100
Example #3
0
def test_unpack_tsresol():
    assert unpack_timestamp_resolution(int2byte(0)) == 1
    assert unpack_timestamp_resolution(int2byte(1)) == 1e-1
    assert unpack_timestamp_resolution(int2byte(6)) == 1e-6
    assert unpack_timestamp_resolution(int2byte(100)) == 1e-100

    assert unpack_timestamp_resolution(int2byte(0 | 0b10000000)) == 1
    assert unpack_timestamp_resolution(int2byte(1 | 0b10000000)) == 2 ** -1
    assert unpack_timestamp_resolution(int2byte(6 | 0b10000000)) == 2 ** -6
    assert unpack_timestamp_resolution(int2byte(100 | 0b10000000)) == 2 ** -100
Example #4
0
    def timestamp_resolution(self):
        # ------------------------------------------------------------
        # Resolution of timestamps. If the Most Significant Bit is
        # equal to zero, the remaining bits indicates the resolution
        # of the timestamp as as a negative power of 10 (e.g. 6 means
        # microsecond resolution, timestamps are the number of
        # microseconds since 1/1/1970). If the Most Significant Bit is
        # equal to one, the remaining bits indicates the resolution as
        # as negative power of 2 (e.g. 10 means 1/1024 of second). If
        # this option is not present, a resolution of 10^-6 is assumed
        # (i.e. timestamps have the same resolution of the standard
        # 'libpcap' timestamps).
        # ------------------------------------------------------------

        if 'if_tsresol' in self.options:
            return unpack_timestamp_resolution(self.options['if_tsresol'])

        return 1e-6
Example #5
0
    def timestamp_resolution(self):
        # ------------------------------------------------------------
        # Resolution of timestamps. If the Most Significant Bit is
        # equal to zero, the remaining bits indicates the resolution
        # of the timestamp as as a negative power of 10 (e.g. 6 means
        # microsecond resolution, timestamps are the number of
        # microseconds since 1/1/1970). If the Most Significant Bit is
        # equal to one, the remaining bits indicates the resolution as
        # as negative power of 2 (e.g. 10 means 1/1024 of second). If
        # this option is not present, a resolution of 10^-6 is assumed
        # (i.e. timestamps have the same resolution of the standard
        # 'libpcap' timestamps).
        # ------------------------------------------------------------

        if 'if_tsresol' in self.options:
            return unpack_timestamp_resolution(self.options['if_tsresol'])

        return 1e-6