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

Opt As Array with default content #2

Open
asmodehn opened this issue Feb 3, 2017 · 0 comments
Open

Opt As Array with default content #2

asmodehn opened this issue Feb 3, 2017 · 0 comments

Comments

@asmodehn
Copy link
Member

asmodehn commented Feb 3, 2017

with opt_as_array, an optional string is declared as :
string[] mystring

However the behavior of rostools (`rosservice call is an often use example) create such data :

mystring:
  - ''

similar thing with [u]int[8|16|32|64] :
uint8[] myint
produces :

myint:
  - 0

opt_as_array policy is to consider empty array as not passed.
But we need to address this default argument issue to make it easier when using command line ros tools.

However it is unlikely that ROS1 will change anything, since all fields are mandatory, and it follows C semantics (doesnt have referense semantics or None element) it makes sense in that context to pregenerate the data structure with default values.

Some options :

  • expect user to handle this in code, when needed. simple. just what we do now, but not user friendly.
    Our current patching strategy anyway requires code on user side for optional fields... but maybe it s best not to make it too complicated.
  • field decorator ? We need to find a way to add "comments" in a message type definition, in a way that can be somehow retrieved by an extra tool to handle optional fields, or maybe more logic ( ie. break if == 42 )
  • new type of field ? This probably menas patching genpy and a bunch of things. not likely.
  • opt_as_nested might be extendable for this usecase... this might be worth reinvestigating after opt_as_nested is implemented and working as expected for optional fields.
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