Define a Data Schema
If your schema does not incorporate any elements from other schemas, you need to define only those protobuf definitions that are located in the proto
module. You can break down your definitions into multiple files or import other protobuf files.
For more details, see the Protocol Buffers Language Guide.
Example Schema Project Definition
Based on the schema project generated in the previous chapter, let's add an altitude field to our schema. For this, edit the proto/src/main/proto/com/here/example/v1/test_schema.proto
file as follows:
syntax = "proto3";
package com.here.example.v1;
message MainProtobufMessage {
int32 lat = 1;
int32 lon = 2;
int32 alt = 3;
}
To verify the change, enter the following command:
mvn package
Extend a Schema
By extending a schema, you avoid having to define data structures that already exist in other schemas. If you need to make a schema dependent on another schema, add the required dependencies as described below:
- For the
proto
module, add the dependency definition in the POM file. The dependency must be on another proto
module packaged with an archetype-generated project. - For the
java
module, add the dependency definition in the POM file. The dependency must be on another java
module packaged with an archetype-generated project. - For the
scala
module, add the dependency definition in the POM file. The dependency must be on another scala
module packaged with an archetype-generated project. - Import and use the protobuf definitions from the dependency in your
proto
module definitions where it's needed.
The project is now ready, and you can define your custom data structure.
Note: Maven
A schema created from archetype 1.0.0 and later can only be extended with a schema created from archetype versions 1.0.0 and later.
Example Schema Project Extension
Based on the schema project generated above, let's use the HERE-provided HMC Address Attribution (v2.53.0) schema to extend your schema by adding a postal code field. To find this schema, in the HERE platform portal, select the Data tab and click Browse schemas.
Follow the steps below to extend the schema:
-
Add the following dependency to the proto/pom.xml
file:
<dependency>
<groupId>com.here.schema.rib</groupId>
<artifactId>address-attributes_v2_proto</artifactId>
<version>2.53.0</version>
<type>zip</type>
</dependency>
-
Add the following dependency to the java/pom.xml
file:
<dependency>
<groupId>com.here.schema.rib</groupId>
<artifactId>address-attributes_v2_java</artifactId>
<version>2.53.0</version>
<type>jar</type>
</dependency>
-
Add the following dependency to the scala/pom.xml
file:
<dependency>
<groupId>com.here.schema.rib</groupId>
<artifactId>address-attributes_v2_scala</artifactId>
<version>2.53.0</version>
<type>jar</type>
</dependency>
-
Edit the proto/src/main/proto/com/here/example/v1/test_schema.proto
file as follows:
syntax = "proto3";
package com.here.example.v1;
import "com/here/schema/rib/v2/address_attributes.proto";
message MainProtobufMessage {
int32 lat = 1;
int32 lon = 2;
com.here.schema.rib.v2.PostalCode postal_code = 3;
}
-
To verify the change, run the following command:
mvn package