[toc]
protoc-gen-bean
中文说明文档在这里 README
Java Value Object Generator Plugin For Protobuf
Requirement
Download and install the protocol buffer compiler.
you can find it here
Github
or here
Google
Installation
Homebrew
brew tap master-g/tap
brew install master-g/tap/protoc-gen-bean
Manually
After install protocol buffer compiler, you can build protoc-gen-bean or download pre-built binary from release page
Usage
protoc --plugin=protoc-gen-bean --bean_out=. *.proto
if you install via homebrew or had protoc-gen-bean
added to your env PATH
protoc --plugin=bean --bean_out=. *.proto
Parameters
To pass extra parameters to the plugin, use a comma-separated parameter list separated from the output directory by a colon:
protoc --plugin=protoc-gen-bean --bean_out=vopkg=vo,notime=false,flavor=kotlin:. *.proto
vopkg=xxx
- java value object package
notime=true|false
- generate timestamp to file header
flavor=kotlin|java
- generate source code flavor, default is kotlin (we might deprecate java output in the future)
Consider file test.proto, containing
syntax = "proto3";
package proto.common;
option java_package = "com.acme.model.protobuf";
option java_outer_classname = "PbCommon";
message Hello {
string msg = 1;
int32 code = 2;
}
To create and play with a Test object from the example package,
Java Value Object
package com.acme.model.vo.proto.common
// Code generated by protoc-gen-bean. DO NOT EDIT.
// 2021-12-08 Wed 17:15:25 UTC+0800
//
// test.proto
//
class Hello {
var msg: String = ""
var code: Int = 0
override fun toString(): String {
return "Hello{" +
"msg='" + msg + '\'' +
", code=" + code +
"}"
}
}
Output Package Structure
.
└── com
└── acme
└── model
└── vo
└── common
└── Hello.java