Using Protobuf Files as Reference Libraries

Learn how to use Protobuf files as references for other Protobuf files.

Programming languages allow developers to create sharable components, such as libraries, that can be imported into any software package. This is a very useful feature that allows a common functionality to be shared between different applications. This way, if we want to implement a specific functionality in our application that already exists in a separate module or library, we can just import this module or library into our application. We don't have to write it from scratch.

Protobuf can do it too. A Protobuf file can refer to other Protobuf files and import custom data types from it, such as message and enum. We've already seen this feature when we imported the packages with the well-known types into our main Protobuf file. This time, we'll create our own package and import it.

Creating a reference package in Protobuf

We'll use the following code editor to apply our changes for this lesson. It contains the complete setup we have built previously.

Get hands-on with 1200+ tech skills courses.