https://github.com/nithanim/protoreverse
https://github.com/nithanim/protoreverse
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nithanim/protoreverse
- Owner: Nithanim
- Created: 2025-05-07T06:41:07.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-07T06:41:58.000Z (about 1 year ago)
- Last Synced: 2025-06-26T19:03:44.902Z (11 months ago)
- Language: Java
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ProtobufReverter
A Java library that converts Protocol Buffer FileDescriptor objects back to .proto file format. This allows for reverse engineering compiled protobuf definitions back to their source format.
## Overview
Protocol Buffers (protobuf) is a language-neutral, platform-neutral, extensible mechanism for serializing structured data. When working with protobuf in Java, the protoc compiler generates Java classes from .proto files. These generated classes contain a `getDescriptor()` method that returns a `FileDescriptor` object, which contains all the information about the original .proto file.
This library provides a way to convert that `FileDescriptor` back to a .proto file format, effectively reversing the compilation process.
## Features
- Converts a FileDescriptor to a proto file string
- Handles all protobuf elements:
- Messages
- Fields (including repeated and map fields)
- Enums
- Nested types
- Oneofs
- Services and methods
- Options
- Imports
## Usage
```java
import org.example.protobuf.reverter.ProtobufReverter;
import com.google.protobuf.Descriptors.FileDescriptor;
// Get the FileDescriptor from a generated protobuf class
FileDescriptor fileDescriptor = YourGeneratedProtoClass.getDescriptor();
// Convert the FileDescriptor to a proto file
String protoFile = ProtobufReverter.toProtoFile(fileDescriptor);
// Use the proto file content as needed
System.out.println(protoFile);
// or save to a file
Files.writeString(Path.of("reversed.proto"), protoFile);
```
## Example
If you have a generated protobuf class called `Person.java` from a `person.proto` file, you can reverse it back to a .proto file like this:
```java
import org.example.protobuf.reverter.ProtobufReverter;
import com.example.protos.Person;
// Get the FileDescriptor from the Person class
FileDescriptor fileDescriptor = Person.getDescriptor();
// Convert it back to a proto file
String protoFile = ProtobufReverter.toProtoFile(fileDescriptor);
// Print the proto file content
System.out.println(protoFile);
```
## Requirements
- Java 21 or higher
- Protocol Buffers Java library (com.google.protobuf:protobuf-java)
## Installation
Add the following dependency to your Maven project:
```xml
org.example
ProtobufReverter
1.0-SNAPSHOT
```
## License
This project is licensed under the MIT License - see the LICENSE file for details.