Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Ros2-v1.1 branch #48

Open
wants to merge 10 commits into
base: ros2
Choose a base branch
from
2 changes: 0 additions & 2 deletions vda5050_serializer/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<maintainer email="[email protected]">Jannik Abbenseth</maintainer>
<license>Apache2.0</license>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

Expand Down
4 changes: 2 additions & 2 deletions vda5050_serializer/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[develop]
script-dir=$base/lib/vda5050_serializer
script_dir=$base/lib/vda5050_serializer
[install]
install-scripts=$base/lib/vda5050_serializer
install_scripts=$base/lib/vda5050_serializer
23 changes: 0 additions & 23 deletions vda5050_serializer/test/test_copyright.py

This file was deleted.

23 changes: 0 additions & 23 deletions vda5050_serializer/test/test_flake8.py

This file was deleted.

29 changes: 26 additions & 3 deletions vda5050_serializer/vda5050_serializer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#! /usr/bin/env python3
# Copyright 2020 Fraunhofer IPA
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Expand Down Expand Up @@ -36,7 +36,6 @@ def transform_keys_in_dict(multilevel_dict, transformer):
return multilevel_dict
new_dict = {}
for k, v in multilevel_dict.items():

k = transformer(k)

if isinstance(v, dict):
Expand All @@ -49,6 +48,24 @@ def transform_keys_in_dict(multilevel_dict, transformer):
return new_dict


def transform_action_parameter_values_to_json_string(multilevel_dict):
if not isinstance(multilevel_dict, dict):
return multilevel_dict
new_dict = {}
for k, v in multilevel_dict.items():
if k == 'action_parameters' and isinstance(v, list):
v = [{'key': elem['key'], 'value': json.dumps(elem['value'])} for elem in v]
else:
if isinstance(v, dict):
v = transform_action_parameter_values_to_json_string(v)
if isinstance(v, list):
v = [transform_action_parameter_values_to_json_string(x) for x in v]

assert k not in new_dict
new_dict[k] = v
return new_dict


def dumps(d) -> str:
return json.dumps(transform_keys_in_dict(d, dromedary))

Expand All @@ -57,3 +74,9 @@ def loads(str_val) -> dict:
d = json.loads(str_val)

return transform_keys_in_dict(d, snakey)


# retransforms all instances of action_parameters to turn the values into
# an json encoded string to support arbitrary types in the string message
def loads_transforming_action_parameter_values_to_json_string(str_val) -> dict:
return transform_action_parameter_values_to_json_string(loads(str_val))