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

Serialize and deserialize arrays #45

Merged
merged 2 commits into from
Sep 16, 2016
Merged

Serialize and deserialize arrays #45

merged 2 commits into from
Sep 16, 2016

Conversation

esteve
Copy link
Member

@esteve esteve commented Jun 29, 2016

This PR serializes and deserializes unbounded arrays. Tested locally with two Python scripts (listener and talker), using different permutations of OpenSplice and FastRTPS.

@esteve esteve added the in review Waiting for review (Kanban column) label Jun 29, 2016
@@ -259,6 +259,7 @@ void serialize_array(
printf("vector overcomes the maximum length\n");
throw std::runtime_error("vector overcomes the maximum length");
}
ser << (int32_t)data.size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of replicating the wire format here this should use the API of Cdr to perform the serialization. I guess in this case it should call serializeSequence instead of serializing the size and calling serializeArray.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


auto & string_array_field = *reinterpret_cast<rosidl_generator_c__String__Array *>(field);
if(!rosidl_generator_c__String__Array__init(&string_array_field, cpp_string_vector.size())) {
printf("unable to initialize rosidl_generator_c__String array\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All error messages should go to stderr. But since the exception is thrown anyway I would say the error message is redundant and can be removed.

@wjwwood
Copy link
Member

wjwwood commented Jun 30, 2016

Thanks for the patch @esteve! I agree that the printf statements, while useful when debugging, are probably better left out.

With that comment addressed the changes lgtm. I'll just start some CI (assuming that removing the printf's won't impact the result):

  • Linux:
    • Build Status / Build Status
  • OS X:
    • Build Status / Build Status

@@ -514,6 +514,12 @@ void deserialize_array(
(void)call_new;
if (member->array_size_ && !member->is_upper_bound_) {
deser.deserializeArray((T*)field, member->array_size_);
} else {
auto & data = *reinterpret_cast<typename GenericCArray<T>::type *>(field);
int32_t dsize;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like cppcheck is concerned about this not be initialized:

http://ci.ros2.org/job/ci_linux/1606/testReport/(root)/projectroot/cppcheck/

You could either give it a default value or use the no lint comment to squelch cppcheck.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@esteve
Copy link
Member Author

esteve commented Jul 6, 2016

@wjwwood the printf statements next to throwing exceptions seem to be a recurring pattern in eProsima's code:

https://github.com/eProsima/ROS-RMW-Fast-RTPS-cpp/blob/master/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.h#L402

https://github.com/eProsima/ROS-RMW-Fast-RTPS-cpp/blob/master/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.h#L481

https://github.com/eProsima/ROS-RMW-Fast-RTPS-cpp/blob/master/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.h#L239

so I'm going to leave the printf statements in this PR, just for consistency, though I agree they all should be removed since they don't add much value.

@esteve
Copy link
Member Author

esteve commented Sep 1, 2016

@richiprosima I've rebased this and removed the printf calls, this should be mergeable now.

@dirk-thomas
Copy link
Member

Can you please trigger the CI builds for these changes.

@wjwwood
Copy link
Member

wjwwood commented Sep 1, 2016

CI:

  • Linux:
    • Build Status
  • OS X:
    • Build Status

@dirk-thomas
Copy link
Member

  • Windows:
    • Build Status

@firesurfer
Copy link

I tested this PR with my .Net wrapper and it seems to work fine, apart from passing c-typesupport messages to cpp.

What works:

  • Sending and recieving messages in program(s) that use c-typesupport
  • Recieving messages sent from a cpp program in a program that uses the same messages but with c-typesupport.

What doesn't work:

  • Sending messages from a program that uses messages with c-typesupport and recieving them in a cpp program.

@esteve
Copy link
Member Author

esteve commented Sep 9, 2016

@firesurfer thanks for testing this PR. That's weird, once the messages go through the wire, the typesupport should matter. Do you have a concrete example which I can test? I recall I tested this between rclpy (c-typesupport) and rclpp (c++-typesupport), and it seemed to work, but I'll check again.

@firesurfer
Copy link

@esteve I tested it only with my C# wrapper so far. In my testing workspace ( https://github.com/firesurfer/rclcs_testing_ws ) I got one program that uses in C# - test_cs.exe (c-typesupport) and one program that uses c++ - test_cpp (c++-typesupport). Sending a message from the C# program to another program that uses the C# wrapper works. But sending a message from the C# wrapper to the C++ program doesn't work.

On the other side a program that uses the C# wrapper receives the message published from a C++ program. I haven't had the time yet to investigate this issue further but I think I can find some time to have a deeper look at it tomorrow.

@esteve
Copy link
Member Author

esteve commented Sep 9, 2016

@firesurfer do you have the message definition you used? I can test it out and see if I can find the problem.

@firesurfer
Copy link

@esteve
Copy link
Member Author

esteve commented Sep 9, 2016

@firesurfer thanks!

@mikaelarguedas
Copy link
Member

CI with fastrtps whitelisted in test_communication
Master:
Build Status
This PR:
Build Status

@mikaelarguedas
Copy link
Member

TD;DR this PR does fix the serialisation/deserialisation of dynamic primitive array messages (DynamicArrayPrimitives and BoundedArrayPrimitives) but doesn't fix the other arrays test cases, it can be merged as is without resulting in any regression.

@esteve do you prefer:

  1. to merge this as is and we'll create a follow-up PR to address the remaining array test failures
  2. allow us to push commits on your branch and merge this PR once it fixes all the array serialization problems ?

Here is the results of my investigation for the remaining test failures:

  • All non array test failures (Nested/Primitives) are due to rclpy.spin_once() behaving differently with fastrtps and other rmw implementations, need more investigation to figure out why, quick fix: relax test timeout
  • StaticArrayPrimitives fails because fixed size string arrays are not serialized/deserialized properly (the function serializeArray is only applied the first rosidl_generator_c__String element and the rest of the array is dropped (c.f. https://github.com/esteve/ROS-RMW-Fast-RTPS-cpp/blob/a4d829308e18d3c3d24b58f903f803bd8f1ada18/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.h#L267)). It uses the size of the String array instead of the size of the char array so the communication works only if you have an array longer than the individual strings in that array
  • StaticArrayNested IMO same string (de)serialization problem as StaticArrayPrimitives, works well if we remove strings from the equation
  • DynamicArrayNested feature not implemented (c.f. this todo)
  • BoundedArrayNested I assume it is the same as DynamicArrayNested but we may uncover more modifications to be done once the previous test case is fixed

@esteve
Copy link
Member Author

esteve commented Sep 16, 2016

Thank you so much for looking into this @mikaelarguedas!

I think it'd be fine to just merge this PR and continue any remaining bits
in a follow-up PR, so that @firesurfer and I can keep working on our stuff.
What's in this PR, while not complete, is still some progress.

On Sep 16, 2016 03:47, "Mikael Arguedas" notifications@github.com wrote:

TD;DR this PR does fix the serialisation/deserialisation of dynamic
primitive array messages (DynamicArrayPrimitives and
BoundedArrayPrimitives) but doesn't fix the other arrays test cases, it
can be merged as is without resulting in any regression.

@esteve https://github.com/esteve do you prefer:

  1. to merge this as is and we'll create a follow-up PR to address the
    remaining array test failures
  2. allow us to push commits on your branch
    https://github.com/blog/2247-improving-collaboration-with-forks and
    merge this PR once it fixes all the array serialization problems ?

Here is the results of my investigation for the remaining test failures:


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#45 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACDVIOcRlEGX1RVF878mh2RClBpLFYoks5qqfUtgaJpZM4JA9Vl
.

@dirk-thomas
Copy link
Member

After talking to @mikaelarguedas we will merge this as-is and go from there. Thanks.

@dirk-thomas dirk-thomas merged commit 71aed1a into ros2:master Sep 16, 2016
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label Sep 16, 2016
@esteve esteve deleted the array-serialization branch September 16, 2016 17:19
@mikaelarguedas
Copy link
Member

@esteve @firesurfer #58 may solve some of the issues you encountered. The tests are passing in both rclcpp -> rclpy and rclpy -> rclcpp for all message types

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

Successfully merging this pull request may close these issues.

None yet

5 participants