|
| 1 | +.. _iconventions: |
| 2 | + |
| 3 | +Interface Conventions |
| 4 | +====================== |
| 5 | + |
| 6 | +When adding new messages, enums, field messages and field enums to OSI we enforce a few naming conventions for each type like in the `style guide <https://developers.google.com/protocol-buffers/docs/style>`_ from protobuf. |
| 7 | + |
| 8 | +Message Naming |
| 9 | +--------------- |
| 10 | +A message definition should always be in camel case. This means that the first letter of each word in a message should be upper case without any spaces. See example below: |
| 11 | + |
| 12 | +.. code-block:: protobuf |
| 13 | +
|
| 14 | + message EnvironmentalConditions |
| 15 | + { |
| 16 | + } |
| 17 | +
|
| 18 | +Top-Level Messages |
| 19 | +------------------- |
| 20 | +All messages that are intended to be exchanged as a stand-alone message, i.e. not required to be embedded in another message, like e.g. ``SensorView`` or ``SensorViewConfiguration``, are required to carry an ``InterfaceVersion`` field as their first field, and a ``Timestamp`` field as their second field, e.g.: |
| 21 | + |
| 22 | +.. code-block:: protobuf |
| 23 | +
|
| 24 | + message TopLevel |
| 25 | + { |
| 26 | + // The interface version used by the sender (simulation environment). |
| 27 | + // |
| 28 | + optional InterfaceVersion version = 1; |
| 29 | + |
| 30 | + // The data timestamp of the simulation environment. Zero time is arbitrary |
| 31 | + // but must be identical for all messages. Zero time does not need to |
| 32 | + // coincide with the UNIX epoch. Recommended is the starting time point of |
| 33 | + // the simulation. |
| 34 | + // |
| 35 | + optional Timestamp timestamp = 2; |
| 36 | + } |
| 37 | +
|
| 38 | +Field Message Naming |
| 39 | +--------------------- |
| 40 | +After defining a message fields can be added to it in snake case format. This means every letter is lower case and the words are connected through an underline character. See example below: |
| 41 | + |
| 42 | +.. code-block:: protobuf |
| 43 | +
|
| 44 | + message EnvironmentalConditions |
| 45 | + { |
| 46 | + optional double atmospheric_pressure = 1; |
| 47 | + } |
| 48 | +
|
| 49 | +Field Numbering |
| 50 | +---------------- |
| 51 | + |
| 52 | +Fields should be numbered consecutively starting from 1 on first definition. During maintenance, the rules of backward/forward-compatibility require that fields are never renumbered, and field numbers never re-used unless a major release is performed. |
| 53 | + |
| 54 | +All field numbers of 10000 and above are reserved for user-defined extensions and will thus never be used by OSI message fields. |
| 55 | + |
| 56 | +Enum Naming |
| 57 | +------------ |
| 58 | +The naming of an enum should be camel case. See example below: |
| 59 | + |
| 60 | +.. code-block:: protobuf |
| 61 | +
|
| 62 | + message EnvironmentalConditions |
| 63 | + { |
| 64 | + optional double atmospheric_pressure = 1; |
| 65 | +
|
| 66 | + enum AmbientIllumination |
| 67 | + { |
| 68 | + } |
| 69 | + } |
| 70 | +
|
| 71 | +Enum Field Naming |
| 72 | +------------ |
| 73 | +The naming of an enum field should be all in upper case. The start should be converted from the enum name camel case to upper case snake case. It is mandatory to add to the first enum field name the postfix ``_UNKNOWN`` and to the second the postfix ``_OTHER``. After that the naming can be decided by the user. It is often mentioned that the value ``_UNKNOWN`` should not be used in a ``GroundTruth`` message as there are now uncertanties by definition in ``the truth``. These values are mostly used in messages like ``SensorData`` where the content is subject to interpretation. See example below: |
| 74 | + |
| 75 | +.. code-block:: protobuf |
| 76 | +
|
| 77 | + message EnvironmentalConditions |
| 78 | + { |
| 79 | + optional double atmospheric_pressure = 1; |
| 80 | +
|
| 81 | + enum AmbientIllumination |
| 82 | + { |
| 83 | + AMBIENT_ILLUMINATION_UNKNOWN = 0; |
| 84 | + |
| 85 | + AMBIENT_ILLUMINATION_OTHER = 1; |
| 86 | +
|
| 87 | + AMBIENT_ILLUMINATION_LEVEL1 = 2; |
| 88 | + } |
| 89 | + } |
| 90 | +
|
| 91 | +Summary |
| 92 | +-------- |
| 93 | +Here a small summary for the naming conventions: |
| 94 | + |
| 95 | +Messages: camel case |
| 96 | + |
| 97 | +Message Fields: snake case |
| 98 | + |
| 99 | +Enum: camel case |
| 100 | + |
| 101 | +Enum Fields: upper case, name of enum converted in upper case snake case and then following the specified name |
| 102 | + |
| 103 | +After defining the messages do not forget to comment them. See also the `section for commenting <https://opensimulationinterface.github.io/osi-documentation/open-simulation-interface/doc/commenting.html>`_ of fields and messages. |
0 commit comments