Oak Protobuf Parser
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.
Overview
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.
Features
- ✅ Complete Protobuf Support: Parse messages, enums, services, fields, options, and imports
- ✅ Modern Rust API: Type-safe parsing with comprehensive error handling
- ✅ High Performance: Built on the efficient Oak parser combinator framework
- ✅ Rich AST: Detailed Abstract Syntax Tree with source location tracking
- ✅ Extensible: Easy to extend for custom Protobuf dialects
- ✅ Well Tested: Comprehensive test suite with real-world examples
Quick Start
Parsing Examples
Basic Message Parsing
use ;
use ProtobufLanguage;
Complex Schema with Services
use ;
use ProtobufLanguage;
Advanced Features
Custom Options
Oak Protobuf supports parsing custom options:
let source = r#"
kind = "proto3";
message MyMessage {
string value = 1 [(custom_option) = "test"];
}
"#;
Enum Definitions
Parse enum types with aliases and custom options:
let source = r#"
enum Status {
UNKNOWN = 0;
ACTIVE = 1;
INACTIVE = 2 [(custom_option) = "deprecated"];
}
"#;
AST Structure
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 elements
Performance
Oak Protobuf is designed for high performance:
- Zero-copy parsing where possible
- Streaming support for large files
- Efficient memory usage with minimal allocations
- Fast error recovery for better developer experience
Integration
Oak Protobuf integrates seamlessly with the Oak ecosystem:
use ;
use ProtobufLanguage;
// Use with other Oak parsers
let mut parser = new;
let result = parser.parse;
Examples
More examples can be found in the examples directory:
Contributing
We welcome contributions! Please see our Contributing Guide for details.