def test_with_header_binary(self) -> None: control = easy(val=6, val_list=[5, 4, 3, 2, 1]) iobuf = serialize_with_header( control, protocol=Protocol.BINARY, transform=Transform.ZLIB_TRANSFORM ) decoded = deserialize_from_header(easy, iobuf) self.assertEqual(control, decoded)
def test_bad_deserialize(self) -> None: with self.assertRaises(Error): deserialize(easy, b"", protocol=Protocol.JSON) with self.assertRaises(Error): deserialize(easy, b"\x05AAAAAAAA") with self.assertRaises(Error): deserialize(easy, b"\x02\xDE\xAD\xBE\xEF", protocol=Protocol.BINARY) with self.assertRaises(BufferError): deserialize_from_header(easy, b"\x02\xDE\xAD\xBE\xEF") with self.assertRaises(Error): control = easy(val=5, val_list=[4, 3, 2, 1]) buf = serialize_with_header(control, transform=Transform.ZSTD_TRANSFORM) newBytes = bytearray(buf) newBytes[4] += 1 deserialize_from_header(easy, bytes(newBytes))
def test_with_header_bytes(self) -> None: control = easy(val=5, val_list=[4, 3, 2, 1]) buf = serialize_with_header(control, transform=Transform.ZSTD_TRANSFORM) decoded = deserialize_from_header(easy, buf) self.assertEqual(control, decoded)
def test_with_header_json(self) -> None: control = easy(val=4, val_list=[3, 2, 1]) iobuf = serialize_with_header(control, protocol=Protocol.JSON) decoded = deserialize_from_header(easy, iobuf) self.assertEqual(control, decoded)
def test_with_header(self) -> None: control = easy(val=5, val_list=[4, 3, 2, 1]) iobuf = serialize_with_header(control, transform=Transform.ZSTD_TRANSFORM) decoded = deserialize_from_header(easy, iobuf) self.assertEqual(control, decoded)