From 51b230f520eca7dad401eb8a0eef27ac1bb46e65 Mon Sep 17 00:00:00 2001 From: Michal Gregorczyk Date: Mon, 4 Dec 2023 12:27:15 +0100 Subject: [PATCH 1/3] remove unnecessary white spaces --- projects/jdwp/runtime/BUCK | 2 -- projects/jdwp/tests/BUCK | 2 -- 2 files changed, 4 deletions(-) diff --git a/projects/jdwp/runtime/BUCK b/projects/jdwp/runtime/BUCK index 48f578c..165d50f 100644 --- a/projects/jdwp/runtime/BUCK +++ b/projects/jdwp/runtime/BUCK @@ -12,7 +12,5 @@ python_library( ":type-aliases", ], visibility = ["PUBLIC", ], - - deps = [], ) diff --git a/projects/jdwp/tests/BUCK b/projects/jdwp/tests/BUCK index 3769477..23ce85d 100644 --- a/projects/jdwp/tests/BUCK +++ b/projects/jdwp/tests/BUCK @@ -5,8 +5,6 @@ python_test( deps = [ "//projects/jdwp/defs:defs", "//projects/jdwp/codegen:codegen", - - ], srcs = glob(["**/*.py"]), ) From c8e161933f9e3a899de9fa2ad4316c1cccb4da08 Mon Sep 17 00:00:00 2001 From: Michal Gregorczyk Date: Mon, 4 Dec 2023 12:45:13 +0100 Subject: [PATCH 2/3] fix async_streams.py --- projects/jdwp/defs/schema.py | 2 +- projects/jdwp/runtime/BUCK | 1 + projects/jdwp/runtime/async_streams.py | 58 +++++++++++++------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/projects/jdwp/defs/schema.py b/projects/jdwp/defs/schema.py index 3dda5dc..483e6be 100644 --- a/projects/jdwp/defs/schema.py +++ b/projects/jdwp/defs/schema.py @@ -41,7 +41,7 @@ class IdType(Enum): OBJECT_ID = "objectID" THREAD_ID = "threadID" THREAD_GROUP_ID = "threadGroupID" - STRING_ID = "stringId" + STRING_ID = "stringID" CLASS_LOADER_ID = "classLoaderID" CLASS_OBJECT_ID = "classObjectID" ARRAY_ID = "arrayID" diff --git a/projects/jdwp/runtime/BUCK b/projects/jdwp/runtime/BUCK index 165d50f..bb80a57 100644 --- a/projects/jdwp/runtime/BUCK +++ b/projects/jdwp/runtime/BUCK @@ -10,6 +10,7 @@ python_library( name = "runtime", srcs = [ ":type-aliases", + "async_streams.py", ], visibility = ["PUBLIC", ], deps = [], diff --git a/projects/jdwp/runtime/async_streams.py b/projects/jdwp/runtime/async_streams.py index 98a5598..f1f9ae8 100644 --- a/projects/jdwp/runtime/async_streams.py +++ b/projects/jdwp/runtime/async_streams.py @@ -3,7 +3,7 @@ import abc import typing -from projects.jdwp.defs.schema import IdType +from projects.jdwp.runtime.type_aliases import * class JDWPInputStreamBase(abc.ABC): @@ -22,59 +22,59 @@ async def read_string(self) -> str: # Methods for IdType @abc.abstractmethod - async def read_object_id(self) -> IdType.OBJECT_ID: + async def read_object_id(self) -> ObjectIDType: pass @abc.abstractmethod - async def read_thread_id(self) -> IdType.THREAD_ID: + async def read_thread_id(self) -> ThreadIDType: pass @abc.abstractmethod - async def read_thread_group_id(self) -> IdType.THREAD_GROUP_ID: + async def read_thread_group_id(self) -> ThreadGroupIDType: pass @abc.abstractmethod - async def read_string_id(self) -> IdType.STRING_ID: + async def read_string_id(self) -> StringIDType: pass @abc.abstractmethod - async def read_class_loader_id(self) -> IdType.CLASS_LOADER_ID: + async def read_class_loader_id(self) -> ClassLoaderIDType: pass @abc.abstractmethod - async def read_class_object_id(self) -> IdType.CLASS_OBJECT_ID: + async def read_class_object_id(self) -> ClassObjectIDType: pass @abc.abstractmethod - async def read_array_id(self) -> IdType.ARRAY_ID: + async def read_array_id(self) -> ArrayIDType: pass @abc.abstractmethod - async def read_reference_type_id(self) -> IdType.REFERENCE_TYPE_ID: + async def read_reference_type_id(self) -> ReferenceTypeIDType: pass @abc.abstractmethod - async def read_class_id(self) -> IdType.CLASS_ID: + async def read_class_id(self) -> ClassIDType: pass @abc.abstractmethod - async def read_interface_id(self) -> IdType.INTERFACE_ID: + async def read_interface_id(self) -> InterfaceIDType: pass @abc.abstractmethod - async def read_array_type_id(self) -> IdType.ARRAY_TYPE_ID: + async def read_array_type_id(self) -> ArrayTypeIDType: pass @abc.abstractmethod - async def read_method_id(self) -> IdType.METHOD_ID: + async def read_method_id(self) -> MethodIDType: pass @abc.abstractmethod - async def read_field_id(self) -> IdType.FIELD_ID: + async def read_field_id(self) -> FieldIDType: pass @abc.abstractmethod - async def read_frame_id(self) -> IdType.FRAME_ID: + async def read_frame_id(self) -> FrameIDType: pass # Methods for IntegralType @@ -109,59 +109,59 @@ def write_string(self, value: str) -> None: # Methods for IdType @abc.abstractmethod - def write_object_id(self, value: IdType.OBJECT_ID) -> None: + def write_object_id(self, value: ObjectIDType) -> None: pass @abc.abstractmethod - def write_thread_id(self, value: IdType.THREAD_ID) -> None: + def write_thread_id(self, value: ThreadIDType) -> None: pass @abc.abstractmethod - def write_thread_group_id(self, value: IdType.THREAD_GROUP_ID) -> None: + def write_thread_group_id(self, value: ThreadGroupIDType) -> None: pass @abc.abstractmethod - def write_string_id(self, value: IdType.STRING_ID) -> None: + def write_string_id(self, value: StringIDType) -> None: pass @abc.abstractmethod - def write_class_loader_id(self, value: IdType.CLASS_LOADER_ID) -> None: + def write_class_loader_id(self, value: ClassLoaderIDType) -> None: pass @abc.abstractmethod - def write_class_object_id(self, value: IdType.CLASS_OBJECT_ID) -> None: + def write_class_object_id(self, value: ClassObjectIDType) -> None: pass @abc.abstractmethod - def write_array_id(self, value: IdType.ARRAY_ID) -> None: + def write_array_id(self, value: ArrayIDType) -> None: pass @abc.abstractmethod - def write_reference_type_id(self, value: IdType.REFERENCE_TYPE_ID) -> None: + def write_reference_type_id(self, value: ReferenceTypeIDType) -> None: pass @abc.abstractmethod - def write_class_id(self, value: IdType.CLASS_ID) -> None: + def write_class_id(self, value: ClassIDType) -> None: pass @abc.abstractmethod - def write_interface_id(self, value: IdType.INTERFACE_ID) -> None: + def write_interface_id(self, value: InterfaceIDType) -> None: pass @abc.abstractmethod - def write_array_type_id(self, value: IdType.ARRAY_TYPE_ID) -> None: + def write_array_type_id(self, value: ArrayTypeIDType) -> None: pass @abc.abstractmethod - def write_method_id(self, value: IdType.METHOD_ID) -> None: + def write_method_id(self, value: MethodIDType) -> None: pass @abc.abstractmethod - def write_field_id(self, value: IdType.FIELD_ID) -> None: + def write_field_id(self, value: FieldIDType) -> None: pass @abc.abstractmethod - def write_frame_id(self, value: IdType.FRAME_ID) -> None: + def write_frame_id(self, value: FrameIDType) -> None: pass # Methods for IntegralType From e05355f8bbd43ed4986edbc0ba01ee7a13e691e4 Mon Sep 17 00:00:00 2001 From: Michal Gregorczyk Date: Mon, 4 Dec 2023 12:38:16 +0100 Subject: [PATCH 3/3] 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