| Crates.io | oak-protobuf |
| lib.rs | oak-protobuf |
| version | 0.0.1 |
| created_at | 2025-10-22 04:56:38.920336+00 |
| updated_at | 2026-01-23 05:17:37.983735+00 |
| description | High-performance incremental Protocol Buffers parser for the oak ecosystem with flexible configuration, optimized for structured data serialization. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1894984 |
| size | 118,391 |
A high-performance Protobuf parser for Rust, built with the Oak parser combinator framework. Parse Protocol Buffer definitions with comprehensive AST generation and error handling.
Oak Protobuf provides robust parsing capabilities for Protocol Buffer schema files, supporting messages, enums, services, fields, options, and all major Protobuf constructs. Built on the Oak parser combinator framework, it delivers excellent performance and detailed error messages.
use oak::{Parser, Language};
use oak_protobuf::ProtobufLanguage;
fn main() {
let source = r#"
kind = "proto3";
package example;
message Person {
string name = 1;
int32 age = 2;
repeated string emails = 3;
}
"#;
let mut parser = Parser::<ProtobufLanguage>::new();
match parser.parse(&source) {
Ok(ast) => {
println!("Parsed AST: {:#?}", ast);
}
Err(error) => {
eprintln!("Parse error: {}", error);
}
}
}
use oak::{Parser, Language};
use oak_protobuf::ProtobufLanguage;
fn main() {
let source = r#"
kind = "proto3";
package bookstore;
import "google/protobuf/timestamp.proto";
message Book {
string isbn = 1;
string title = 2;
repeated string authors = 3;
google.protobuf.Timestamp published_date = 4;
}
service BookService {
rpc GetBook(GetBookRequest) returns (Book);
rpc ListBooks(ListBooksRequest) returns (stream Book);
}
message GetBookRequest {
string isbn = 1;
}
message ListBooksRequest {
int32 page_size = 1;
string page_token = 2;
}
"#;
let mut parser = Parser::<ProtobufLanguage>::new();
match parser.parse(&source) {
Ok(ast) => {
println!("Service definitions parsed successfully!");
}
Err(error) => {
eprintln!("Parse error: {}", error);
}
}
}
Oak Protobuf supports parsing custom options:
let source = r#"
kind = "proto3";
message MyMessage {
string value = 1 [(custom_option) = "test"];
}
"#;
Parse enum types with aliases and custom options:
let source = r#"
enum Status {
UNKNOWN = 0;
ACTIVE = 1;
INACTIVE = 2 [(custom_option) = "deprecated"];
}
"#;
The parser generates a rich AST with the following main node types:
ProtobufFile - Root node containing the entire fileSyntax - Syntax version declarationPackage - Package declarationImport - Import statementsMessage - Message definitions with fieldsEnum - Enum type definitionsService - Service definitions with RPC methodsField - Message fields with types and optionsOption - Custom options for various elementsOak Protobuf is designed for high performance:
Oak Protobuf integrates seamlessly with the Oak ecosystem:
use oak::{Parser, Language};
use oak_protobuf::ProtobufLanguage;
// Use with other Oak parsers
let mut parser = Parser::<ProtobufLanguage>::new();
let result = parser.parse(protobuf_source);
More examples can be found in the examples directory:
We welcome contributions! Please see our Contributing Guide for details.