How to use the spade.typesystem.types.int32.Int32 function in spade

To help you get started, we’ve selected a few spade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nyxxxie / serenity / tests / typesystem / test_int32.py View on Github external
def test_convert_zero_bytes():
    int32 = Int32(bytes([0x00, 0x00, 0x00, 0x00]))
    assert int32.string() == "0"
    assert int32.bytes() == bytes([0x00, 0x00, 0x00, 0x00])
github nyxxxie / serenity / tests / typesystem / test_int32.py View on Github external
def test_convert_zero_string():
    int32 = Int32("0")
    assert int32.string() == "0"
    assert int32.bytes() == bytes([0x00, 0x00, 0x00, 0x00])
github nyxxxie / serenity / tests / typesystem / test_int32.py View on Github external
def test_too_many_bytes():
    int32 = Int32(bytes([0x00, 0x00, 0x00, 0x01, 0x00]))
    assert int32.size() == 4
    assert int32.string() is None
    assert int32.bytes() is None
    #assert int32.size() == 4
github nyxxxie / serenity / tests / typesystem / test_int32.py View on Github external
def test_convert_min_string():
    int32 = Int32("-2147483648")
    assert int32.string() == "-2147483648"
    assert int32.bytes() == bytes([0x80, 0x00, 0x00, 0x00])
github nyxxxie / serenity / tests / typesystem / test_int32.py View on Github external
def test_convert_max_bytes():
    int32 = Int32(bytes([0x7F, 0xFF, 0xFF, 0xFF]))
    assert int32.string() == "2147483647"
    assert int32.bytes() == bytes([0x7F, 0xFF, 0xFF, 0xFF])
github nyxxxie / serenity / tests / typesystem / test_int32.py View on Github external
def test_none():
    int32 = Int32()
    assert int32.size() == 4
    assert int32.string() is None
    assert int32.bytes() is None
github nyxxxie / serenity / tests / typesystem / test_int32.py View on Github external
def test_convert_positive_bytes():
    int32 = Int32(bytes([0x00, 0x00, 0x00, 0x01]))
    assert int32.string() == "1"
    assert int32.bytes() == bytes([0x00, 0x00, 0x00, 0x01])
github nyxxxie / serenity / tests / typesystem / test_int32.py View on Github external
def test_convert_positive_string():
    int32 = Int32("1")
    assert int32.string() == "1"
    assert int32.bytes() == bytes([0x00, 0x00, 0x00, 0x01])
github nyxxxie / serenity / tests / typesystem / test_int32.py View on Github external
def test_convert_min_bytes():
    int32 = Int32(bytes([0x80, 0x00, 0x00, 0x00])) #TODO: get binary value for this
    assert int32.string() == "-2147483648"
    assert int32.bytes() == bytes([0x80, 0x00, 0x00, 0x00])
github nyxxxie / serenity / spade / typesystem / types / int32.py View on Github external
def to_bytes(self, data) -> bytes:
        if not data:
            return None

        if isinstance(data, bytes):
            if len(data) == 4:
                return data
        elif isinstance(data, str):
            return struct.pack(">i", int(data))
        else:
            raise SpadeTypeException("Can't convert {}.".format(type(data)))

        return None

typemanager.add_type(Int32)