Generate Messages

7.Generate Messages

The messages, consisting of data records, are to be used for communications between clients and services. They can be generated using the message generator.

The message generator generates three files from the JSON file:

  • .capnp — Cap’n Proto of the message.
  • .h – the declaration of the message and inline functions for encode/decode the message to/from Cap’n Proto.
  • .cpp – implementation of the PrepareToSend function that fills in message header.

7.1 JSON

Refer to Appendix A, Message Generator JSON Example.

Here are the explanations:

  • fullname – the class name of the message, including the full name spaces. The name is in camel style, first letter in upper case.
  • descriptor – description of the message.
  • upperid – the 4 byte upper id of the message in hex format.
  • lowered – the 4 byte lower id of the message in hex format.
  • fields – array of field definitions of the message. Each field definition consists of:
    • name – name of the field. The name is camel style, first letter in lower case.
    • type – type of the field. Supported types are:
    • Int8, Int16, Int32, Int64,

      UInt8, UInt16, UInt32, UInt64,

      Float32, Float64, Text, Bool,

      CompAddress, UliUuid,

      Enums defined in the data records. The enum name needs to append “Enum”. For example: “SubsystemTypeEnum”.

      Data Records defined in the generated data records. For example: “PoseStatesRec”.

      List of all types mentioned above. It needs to prepend “ListOf”. For example: “ListOfFloat32”, “ListOfPoseStatesRec”, etc…

7.2 Important Notes

Message generator generates codes in code_gen/mesages directory. You need to copy the codes to proper directory, for example: the generated experimental_report_pose_states codes are copied to uli_sdk/services/experimental/messages/.

Message generator does not create BUILD file for building the generated message codes. You can use the same BUILD file for Record Generator.

In the BUILD file, add the generated .capnp file to the protos array of the messages_proto capnp library target, add the generated .cpp file to the srcs array in the messages cc_library target, and add the generated .h file to the hdrs array in the same messages cc_library target.

Message generator does not create the uuid required by Cap’n Proto in the generated .capnp file. The bazel build will fail the first time, but it generates a uuid during the build. You need to copy the uuid to the first line of the .capnp file.