Git Product home page Git Product logo

jprotobuf's Introduction

JProtobuf

A very useful utility library for java programmer to use google protobuf library.

Build Status Maven Central codecov

What is jprotobuf

jprotobuf是针对Java程序开发一套简易类库,目的是简化java语言对protobuf类库的使用
使用jprotobuf可以无需再去了解proto文件操作与语法,直接使用java注解定义字段类型即可。

How it works

jprotobuf工作原理如下:

  1. 扫描类上的注解的信息,进行分析(与protobuf读取proto文件进行分析过程相似)
  2. 根据注解分析的结果,动态生成java代码进行protobuf序列化与反序列化的功能实现
  3. 使用JDK6及以上的 code compile API进行编译后加载到classloader

Performace

jprotobuf 主要性能消耗在 扫描类上注解,动态生成代码编译的过程。
在执行序列化与反序列化的过程中,几乎与protobuf生成的代码效率等同。
如果使用预编译插件,则无需在运行中进行代码生成与编译,效率更高

Fetures

  1. 无需编写proto文件及繁琐的手工编译过程,支持基于POJO对象的注解方式,方便快捷。
    支持protobuf所有类型,包括对象嵌套,数组,枚举类型
  2. 提供根据proto文件,动态生成代理对象,可省去POJO对象的编写工作。
    完整支持proto文件所有功能,包括内联对象,匿名对象,枚举类型
  3. 提供从POJO对象的注解方式自动生成proto文件的功能, 方便proto描述文件的管理与维护
  4. 提供预编译Maven插件,进一步提升运行性能
  5. 新增预编译gradle插件
  6. 2.x版本。 支持TimeStamp类型, 与原生protobuf保持一致。 支持Date类型,使用long类型传递 docs

Which version

  1. jprotobuf-1.x supports google protocol buffer v2.5.x
  2. jprotobuf-2.x supports google protocol buffer v3.0.0. 实现对MAP结构的支持. 文档
  3. jprotobuf-android Android development supports

关联项目:

JProtobuf-rpc-socket 基于socket的高性能RPC实现
访问地址:https://github.com/jhunters/Jprotobuf-rpc-socket
JProtobuf-rpc-http 基于JProtobuf的RPC实现,支持直接从IDL定义脚本发布RPC服务
访问地址:https://github.com/jhunters/JProtobuf-rpc-http

Quick Start

@ProtobufClass
public class SimpleTypeTest {
    private String name;
    private int value;

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

}


// example code for usage
Codec<SimpleTypeTest> simpleTypeCodec = ProtobufProxy
        .create(SimpleTypeTest.class);

SimpleTypeTest stt = new SimpleTypeTest();
stt.name = "abc";
stt.value = 100
try {
    // 序列化
    byte[] bb = simpleTypeCodec.encode(stt);
    // 反序列化
    SimpleTypeTest newStt = simpleTypeCodec.decode(bb);
} catch (IOException e) {
    e.printStackTrace();
}

Download

jprotobuf-1.x JDK 6 或以上版本

<dependency>
  <groupId>com.baidu</groupId>
  <artifactId>jprotobuf</artifactId>
  <version>1.13.0</version>
</dependency>

下载发行包

jprotobuf-2.x JDK 7 或以上版本

<dependency>
  <groupId>com.baidu</groupId>
  <artifactId>jprotobuf</artifactId>
  <version>2.4.0</version>
</dependency>

下载发行包

jprotobuf-android

<dependency>
  <groupId>com.baidu</groupId>
  <artifactId>jprotobuf-android</artifactId>
  <version>1.1.2</version>
</dependency>

下载发行包

Download plugin

插件使用方法,请阅读文档Full docs

maven插件

jprotobuf-precompile-plugin 支持maven编译时同时进行jprotobuf对象的预编译操作.
注:plugin版本建议使用>=1.2.0, jprotobuf 支持版本>=1.9.4
1.2.15和2.0.11版本之后,支持在预编译阶段生成 proto声明文件的功能, 文件生成位置在当前类的相同目录下。具体使用方式详见下面插件使用说明

<dependency>
  <groupId>com.baidu</groupId>
  <artifactId>jprotobuf-precompile-plugin</artifactId>
  <version>1.4.0</version>
</dependency>

备注: precompile-plugin的版本 1.2.11 只支持 jprotobuf 1.11.5 及以上的版本。 其它版本请有 1.2.10及以下precompile plugin

// 2.x支持版本

<dependency>
  <groupId>com.baidu</groupId>
  <artifactId>jprotobuf-precompile-plugin</artifactId>
  <version>2.2.0</version>
</dependency>

备注: precompile-plugin的版本 2.0.5 只支持 jprotobuf 2.2.6 及以上的版本。 其它版本请有2.0.4及以下precompile plugin

gradle插件


plugins {
    id 'com.baidu.jprotobuf' version '1.0.7'
}

查看版本信息

Document

Contact us

QQ: 644867264

License

JProtobuf is Apache 2.0 licensed.

jprotobuf's People

Contributors

chinesejie avatar jhunters avatar xiemalin 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.