2 unstable releases

new 0.2.0 Feb 13, 2025
0.1.0 Feb 12, 2025

#91 in FFI

Download history 320/week @ 2025-02-11

320 downloads per month

MIT license

17KB
223 lines

Java Bytecode Descriptor Parser for Rust

Crate Docs MIT Licensed

Introduction

Effortlessly parse and manipulate Java bytecode descriptors in Rust. This crate provides a lightweight, efficient, and easy-to-use solution for working with Java class, field, and method descriptors. To use it, add the following lines to your Cargo.toml file:

[dependencies]
jdescriptor = "0.2.0"

Why Use This Crate?

Parse Java Method Signatures – Extract return types, parameters, and more from JVM bytecode descriptors.
Ultra-Lightweight – Zero dependencies and minimal runtime overhead.
Rust & Java Interoperability – Perfect for Rust tools interacting with Java class files.
Beyond Classfiles – Useful for RPC, static analysis, IDE plugins, serialization, and more!
Optimized for Performance – Designed to handle large-scale descriptor processing efficiently.

For more details about Java bytecode descriptors, check out the relevant sections in the Java Virtual Machine Specification (JVMS):

Usage

Dealing with Type Descriptors

let parsed: TypeDescriptor = "[[Ljava/lang/String;".parse().unwrap();
println!("Rust representation: {:?}", parsed); // Array(Object("java/lang/String"), 2)
println!("Java representation: {}", parsed); // [[Ljava/lang/String;

Dealing with Method Descriptors

let parsed: MethodDescriptor = "(FIB)S".parse().unwrap();
println!("Rust structure: {:?}", parsed); // MethodDescriptor { parameter_types: [Float, Integer, Byte], return_type: Short }
println!("Java representation: {}", parsed); // (FIB)S

Use Cases

  • Java Classfile Parsing – Helper for parsing .class files and analyze type and method signatures.
  • Interoperability – Bridge Rust and Java, ensuring type correctness in JNI/FFI calls.
  • Code Generation – Generate Java bindings, stubs, and DSLs with validated signatures.
  • Static Analysis – Build security tools that detect unsafe Java method patterns.
  • IDE Plugins & Developer Tools – Provide type hints and method signature insights.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License – see the LICENSE file for details.

Dependencies

~0.3–0.9MB
~20K SLoC