Skip to content

Commit

Permalink
Use proto2ros/Bytes for bytes fields too
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
mhidalgo-bdai committed Dec 8, 2023
1 parent ad89e0e commit 23b6c37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion proto2ros/proto2ros/equivalences.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def translate_type(name: str, repeated: bool, config: Configuration) -> Type:
if repeated:
ros_type_name += "[]"
else:
ros_type_name = "string[]" if repeated else "uint8[]"
ros_type_name = "proto2ros/Bytes[]" if repeated else "uint8[]"
return Type(ros_type_name)


Expand Down
12 changes: 6 additions & 6 deletions proto2ros/proto2ros/output/templates/conversions.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ for {{ input_item }} in {{ source }}:
{{ ros_to_proto_composite_field_code_block(source, destination, spec) }}
{%- endif -%}
{%- elif spec.annotations["proto-type"] == "bytes" -%}
{#- Handle bytes case i.e. extract them from string equivalents. -#}
{%- if spec.type.type == "string" -%}
{{ destination }}.extend(blob.encode("ascii") for blob in {{ source }})
{#- Handle bytes case. -#}
{%- if to_ros_base_type(spec.type) == "proto2ros/Bytes" -%}
{{ destination }}.extend(blob.data.tobytes() for blob in {{ source }})
{%- else -%}
{{ destination }} = {{ source }}.tobytes()
{%- endif -%}
Expand Down Expand Up @@ -162,9 +162,9 @@ for {{ input_item }} in {{ input_iterable }}:
{{ proto_to_ros_composite_field_code_block(source, destination, spec) }}
{%- endif -%}
{%- elif spec.annotations["proto-type"] == "bytes" -%}
{#- Handle bytes case i.e. convert them to string equivalents. -#}
{%- if spec.type.type == "string" -%}
{{ destination }} = [blob.decode("ascii") for blob in {{ source }}]
{#- Handle bytes case. -#}
{%- if to_ros_base_type(spec.type) == "proto2ros/Bytes" -%}
{{ destination }} = [proto2ros.msg.Bytes(data=array.array("B", blob)) for blob in {{ source }}]
{%- else -%}
{{ destination }} = array.array("B", {{ source }})
{%- endif -%}
Expand Down

0 comments on commit 23b6c37

Please sign in to comment.