Giter Site home page Giter Site logo

dart-protoc-plugin's Introduction

Protoc compiler Dart plugin

This application provides a plugin for protoc compiler which generates pure Dart library to deal with protobufs.

Please, do not forget that generated libraries depend on runtime support library which can be found here.

How to build and use

Note: currently the workflow is POSIX-oriented.

To build standalone protoc plugin:

  • run pub install to install all dependecies
  • run make build-plugin. That will create a file out/protoc-gen-dart which is a plugin
  • Now you can use it either by adding into PATH or passing directly with protoc's --plugin option.

Please, remember that the plugin is pure Dart script and requires the presence of dart executable in your PATH.

When both the dart executable and out/protoc-gen-dart are in the PATH the protocol buffer compiler can be invoked to generate like this:

$ protoc --dart_out=. test.proto

Options to control the generated Dart code

The protocol buffer compiler accepts options for each plugin. For the Dart plugin, these options are passed together with the --dart_out option. The individial options are separated using comma, and the final output directive is separated from the options using colon. Pass options <option 1> and <option 2> like this:

--dart_out="<option 1>,<option 2>:."

Option for setting the name of field accessors

The following message definition has the field name has_field.

message MyMessage {
  optional string has_field = 1;
}

This poses the problem, that the Dart class will have a getter and a setter called hasField. This conflicts with the method hasField which is already defined on the superclass GeneratedMessage.

To work around this problem the option field_name can be used. Option field_name takes two values separated by the vertical bar. The first value is the full name of the field and the second value is the name of the field in the generated Dart code. Passing the following option:

--dart_out="field_name=MyMessage.has_field|HasFld:."

Will generate the following message field accessors:

String get hasFld => getField(1);
void set hasFld(String v) { setField(1, v); }
bool hasHasFld() => hasField(1);
void clearHasFld() => clearField(1);

Hacking

The main thing to remember is to run the tests. That is as easy as make run-tests.

Useful references

dart-protoc-plugin's People

Contributors

adam-singer avatar antonm avatar selkhateeb avatar sgjesse avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.