Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Latest commit

 

History

History
55 lines (32 loc) · 2.26 KB

File metadata and controls

55 lines (32 loc) · 2.26 KB

Hyperledger Composer Protobuf

This module converts Google Protobuf files into Hyperledger Composer models. It is currently experimental and has a number of limitations.

Despite these limitations it is a useful tool to convert protobuf data definitions from an existing project to bootstrap a new Composer project. After conversion the generated Composer models will need to be edited to convert some Concepts into Assets, Participants or Transactions.

Approach

All protobuf types with fields are converted to Composer Concepts.

The protobuf type system is mapped to the Composer type system:

  • Bytes are converted to Strings
  • 32 bit int numeric types are mapped to Integer
  • 64 bit int numeric types are mapped to Long
  • double and float are mapped to Double
  • Bool is mapped to Boolean

Repeated and optional fields are mapped to Composer [] and optional respectively.

Default values are supported for Composer primitive types only.

Enumerations are converted.

Nested Types

Composer does not support type nesting, so all types in a protobuf package are put in the same Composer namespace.

Namespaces

A Composer file has a single namespace. The namespace of the Composer model is set to the namespace of the last type processed in the protobuf file.

Imports

The converter does not correctly resolve protobuf imports. If your protobuf files use imports some types may be missing from the generated Composer model.

Usage

Install node

Go the composer-protobuf directory and run below command: npm install

Command Line

You can batch convert a set of .proto files under a root directory by running:

node ./lib/protobuf.js -i <inputDir> -o <outputDir>

APIs

You can use the ProtobufConverter class to convert a single .proto file to a single Composer model file, or use the ProtobufBatchConverter class to convert all .proto files beneath a directory.

License

Hyperledger Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Hyperledger Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.