From e05355f8bbd43ed4986edbc0ba01ee7a13e691e4 Mon Sep 17 00:00:00 2001 From: Michal Gregorczyk Date: Mon, 4 Dec 2023 12:38:16 +0100 Subject: [PATCH] add a base class for jdwp structs --- projects/jdwp/runtime/BUCK | 1 + projects/jdwp/runtime/jdwpstruct.py | 20 ++++++++++++++++++++ projects/jdwp/tests/BUCK | 1 + projects/jdwp/tests/runtime/jdwpstruct.py | 8 ++++++++ 4 files changed, 30 insertions(+) create mode 100644 projects/jdwp/runtime/jdwpstruct.py create mode 100644 projects/jdwp/tests/runtime/jdwpstruct.py diff --git a/projects/jdwp/runtime/BUCK b/projects/jdwp/runtime/BUCK index bb80a57..2c75ba2 100644 --- a/projects/jdwp/runtime/BUCK +++ b/projects/jdwp/runtime/BUCK @@ -11,6 +11,7 @@ python_library( srcs = [ ":type-aliases", "async_streams.py", + "jdwpstruct.py", ], visibility = ["PUBLIC", ], deps = [], diff --git a/projects/jdwp/runtime/jdwpstruct.py b/projects/jdwp/runtime/jdwpstruct.py new file mode 100644 index 0000000..b6f9b58 --- /dev/null +++ b/projects/jdwp/runtime/jdwpstruct.py @@ -0,0 +1,20 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. + +from __future__ import annotations + +import abc +from projects.jdwp.runtime.async_streams import ( + JDWPInputStreamBase, + JDWPOutputStreamBase, +) + + +class JDWPStruct(abc.ABC): + @abc.abstractmethod + async def serialize(self, output: JDWPOutputStreamBase): + pass + + @staticmethod + @abc.abstractmethod + async def parse(input: JDWPInputStreamBase) -> JDWPStruct: + pass diff --git a/projects/jdwp/tests/BUCK b/projects/jdwp/tests/BUCK index 23ce85d..1483495 100644 --- a/projects/jdwp/tests/BUCK +++ b/projects/jdwp/tests/BUCK @@ -5,6 +5,7 @@ python_test( deps = [ "//projects/jdwp/defs:defs", "//projects/jdwp/codegen:codegen", + "//projects/jdwp/runtime:runtime", ], srcs = glob(["**/*.py"]), ) diff --git a/projects/jdwp/tests/runtime/jdwpstruct.py b/projects/jdwp/tests/runtime/jdwpstruct.py new file mode 100644 index 0000000..f0ccdd4 --- /dev/null +++ b/projects/jdwp/tests/runtime/jdwpstruct.py @@ -0,0 +1,8 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. + +import unittest + + +class JDWPStructTest(unittest.TestCase): + def test_jdwpstruct_can_be_imported(self): + from projects.jdwp.runtime.jdwpstruct import JDWPStruct