6.Generate Data Records
Data records used in the messages belong to the same service category are created in the same file. For example, data records used by the experiment messages are defined in the experiment_messages_defs.json in uli_sdk/services/experiment/messages/json directory.
The record generating JSON file contains definitions of one or more records. For each record, it generates:
- Structure of the record.
- Typedef of the Expirable class of the structure of the record. Expirable class is used to track whether the data is fresh.
- ToString function of the record
- ToPtree function of the record that converts the record into boost property tree. The ptree can be serialized to JSON.
- FromPtree function of the record that retrieves the data structure from boost property tree. The ptree can be retrieved from JSON.
- Structure of the list of the record.
- Typedef of the Expirable class of the list of the structure.
- ToString function of the list of the record.
- ToPtree function of the list of the record.
- FromPtree function of the list of the record.
The following files are created in the code_gen/records directory:
- .capnp – Cap’n Proto of the records.
- _proto_tools.h – inline functions that encode and decode the records to Cap’n Proto.
- .h – declaration of the records, typedefs of vector of records, functions to encode/decode records to/from boost property trees.
- .cpp – implementation of the declarations and functions for the records.
For example, modulename “ExperimentalMessagesDefs”, generates the following files:
Refer to Appendix A, Record Generator JSON Example. Here are the explanations:
- modulename – name of this record module. The name includes the full name spaces. The name is in camel style, first letter in upper case.
- enums – array of enum definitions. Each enum definition contains
- name – name of enum. The name is in camel style, first letter in upper case.
- elems – array of names of enum elements. The name is in camel style, first letter in lower case. Note that an element of “unknown” is required.
- records — array of record definitions. Each record definition contains
- name – name of record. The name is in camel style, first letter in upper case.
- fields – array of field definitions. Each field definition contains
- name – name of the field. The name in 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,
Enums defined in the enums. The enum name needs to append “Enum”.
Records defined in this section.
List of all types mentioned above. It needs to prepend “ListOf”.
6.2 Important Notes
Record generator generates codes in code_gen/records directory. You need to copy the codes to proper directory, for example: the generated experimental_message_defs codes are copied to uli_sdk/services/experimental/messages/.
Record generator does not create BUILD file for building the generated record codes. You need to add the BUILD file to the directory where the generated record codes are copied to. Refer to Appendix A, Record Generator BUILD File Example.
Record 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.