How to Generate Protocol Buffer Definition

This tutorial shows you how to generate a service definition in protocol buffer format from a UML class diagram.

Software Ideas Modeler can be used as a protocol buffer generator tool. If you want to generate a Protocol Buffer definition, you should create a UML class diagram first. You need to define a service class (or several service classes) and classes for custom complex types.

Setup UML Class Diagram

If you want to generate a Protocol Buffer definition is good to use the Protocol Buffer type set. You can change it using the Diagram Properties dialog. Right-click on an empty space in the class diagram and choose Properties from the context menu. On the General tab, there is a Type set field. Click on the ellipsis button on the right of the Type set line. Check the Protocol Buffer item in the list of type sets and confirm the choice using the OK button. Confirm also the Diagram Properties dialog using the OK button. From now on, you can set Protocol Buffer types using the context menus and ribbon galleries.

Define Service Class

You can create a service class first. Add a UML class to the class diagram, and enter the class name according to your service name. Set Ā«serviceĀ» stereotype to the service class to let known the generator this class represents a service.

Set the service stereotype to the service class
Set the service stereotype to the service class

Then add particular service methods as class operations using the Add Operation button.

Add a new operation to the service class
Add a new operation to the service class

Define Custom Complex Types

Create all the classes that are needed for other complex types used in your service interface. Complex types will be defined using Message definitions.

Generate Protocol Buffer Definition

If you want to generate the final Protocol Buffer definition for your model, proceed with this action:

  • using Ribbon / Process (tab) / Generation (group) / Source Code (button)
  • or using Menu / Tools / Generate Source Code

Source Code Generation dialog will show. Choose the Protocol Buffer option from the Language drop-down. It offers two different templates:

  • Default
  • Request Response Type

Choose Default template, if you want to specify the name of your request and response types for the service operations. In that case, all the operations in the service class should have only one input parameter and one output parameter - both will be defined as separate UML classes in your model.

The Request Response Type template allows you to choose as many operation parameters as you want. In this case, the protocol buffer generator automatically creates message definitions for requests (defined according to operation parameters) and responses (defined according to operation return types).

The generator produces proto definitions:

  • service definitions for service classes
  • rpc definitions for service operations
  • message definitions for custom complex types, requests and responses

New Comment

Comment