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

serializing bytes over json #163

Open
aelhadee opened this issue Jan 15, 2023 · 0 comments
Open

serializing bytes over json #163

aelhadee opened this issue Jan 15, 2023 · 0 comments

Comments

@aelhadee
Copy link

aelhadee commented Jan 15, 2023

Hello,
I am trying to send bytes rather than a string. I am using the following in the xml file:
<member name="var1" type="short" sequenceMaxLength="9000" key="False" />
and trying to send the bytes using:
output.instance.set_dictionary(dict)

where dict is define as
{"var1": b'bytes to be sent (random)'}

but I get this error
File "/usr/local/lib/python3.8/dist-packages/rticonnextdds_connector/rticonnextdds_connector.py", line 1062, in set_dictionary json_str = json.dumps(dictionary) File "/usr/lib/python3.8/json/__init__.py", line 231, in dumps return _default_encoder.encode(obj) File "/usr/lib/python3.8/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/usr/lib/python3.8/json/encoder.py", line 179, in default raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type bytes is not JSON serializable

and when I use base64 I get his error:
DDS_DynamicDataParser_parse_json_node:!parse json node can DDS_DynamicDataFormatter_from_json_w_params:!parse json node RTILuaDynamicData_set_from_json:DDS_DynamicDataFormatter_from_json_w_params RTILuaMetamethodImpl_OutData:!set from JSON operation failed with retcode 3 RTI_Connector_set_json_instance:!set Failed to set JSON Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/rticonnextdds_connector/rticonnextdds_connector.py", line 1063, in set_dictionary _check_retcode(connector_binding.set_json_instance( File "/usr/local/lib/python3.8/dist-packages/rticonnextdds_connector/rticonnextdds_connector.py", line 89, in _check_retcode raise Error("DDS Exception: " + _get_last_dds_error_message()) rticonnextdds_connector.rticonnextdds_connector.Error: DDS Exception: DDS_DynamicDataParser_parse_json_node:!parse json node can DDS_DynamicDataFormatter_from_json_w_params:!parse json node RTILuaDynamicData_set_from_json:DDS_DynamicDataFormatter_from_json_w_params RTILuaMetamethodImpl_OutData:!set from JSON operation failed with retcode 3 RTI_Connector_set_json_instance:!set Failed to set JSON
Any idea how to get this to work serializing bytes?

Thanks,
AE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant