Protobuf4j
Pure Java Protobuf tools
Install / Use
/learn @roastedroot/Protobuf4jREADME
protobuf4j
protobuf4j is protobuf running as pure Java bytecode.
Why?
protoc is widely used by Java developers, unfortunately, invoking it and plugins requires native dependencies or relying on rewrites of the functionality.
By compiling protobuf to Wasm and Wasm to Java bytecode thanks to Chicory we don't need to port the original source code and we have 1:1 functionality out-of-the-box.
Version Support
protobuf4j provides separate artifacts for different Protocol Buffers major versions:
| Group ID | Artifact | Protobuf Version | Use When |
|----------|----------|------------------|----------|
| io.roastedroot | protobuf4j-v3 | 3.25.x | Your app uses protobuf-java 3.x |
| io.roastedroot | protobuf4j-v4 | 4.28.x | Your app uses protobuf-java 4.x |
Which version should I use?
- Use the version that matches your application's
protobuf-javadependency. - Most enterprise applications currently use v3.
- v4 is the latest version but has breaking changes from v3. Consult the official protobuf repository for the full details.
Quick Start
For Protobuf 3.x Applications
Add protobuf4j-v3 as a Maven dependency:
<dependency>
<groupId>io.roastedroot</groupId>
<artifactId>protobuf4j-v3</artifactId>
<version>0.0.1</version>
</dependency>
For Protobuf 4.x Applications
Add protobuf4j-v4 as a Maven dependency:
<dependency>
<groupId>io.roastedroot</groupId>
<artifactId>protobuf4j-v4</artifactId>
<version>0.0.1</version>
</dependency>
Code Generation
| Plugin | Equivalent protoc flag | Output |
|--------|--------------------------|--------|
| JAVA | --java_out | Java message classes |
| KOTLIN | --kotlin_out | Kotlin DSL wrappers around Java classes |
| GRPC_JAVA | --grpc-java_out | Java gRPC service stubs |
Building the Project
To build this project, you'll need:
- Docker (for building WASM modules)
- JDK 11 or newer
- Maven
Build Everything
Build both WASM modules and all Maven artifacts:
# Build WASM modules for both v3 and v4
make build
# Build and install Maven artifacts
mvn clean install
Build Individual Versions
Build only what you need:
# Build only v3
make build-v3
mvn install -am -pl core-v3
# Build only v4
make build-v4
mvn install -am -pl core-v4
Skip WASM Build
If you already have the WASM modules built:
# Just build/test Java code
mvn clean install
Project Structure
protobuf4j/
├── core-v3/ → protobuf4j-v3 artifact (Protobuf 3.25.x)
├── core-v4/ → protobuf4j-v4 artifact (Protobuf 4.28.x)
├── buildtools-v3/ → WASM build config for v3
├── buildtools-v4/ → WASM build config for v4
└── wasm/ → Compiled WASM modules
Acknowledgements
This project stands on the shoulders of giants:
- go-protoc-gen-grpc-java - enables invoking protoc and plugins in pure Go thanks to wazero
- Chicory – a native JVM WebAssembly runtime
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
