orbe_proto 0.1.5
orbe_proto: ^0.1.5 copied to clipboard
Build proto files without protoc compiler.
orbe_proto #
Protocol Buffer parser and code generator for the Orbe framework.
This package provides:
- Parser: Parses Protocol Buffer (.proto) files into FileDescriptorProto
- Tokenizer: Lexical analysis of proto files
- Analyzer: Scans and analyzes proto files in a project
- Compiler: Generates Dart code from proto files without requiring protoc
- CLI: Command-line tool for building proto files
CLI Usage #
The orbe_proto command-line tool allows you to generate Dart code from .proto files without needing to install protoc.
Installation #
dart pub global activate orbe_proto
Commands #
Build
Generate Dart code from .proto files in a directory:
# Build protos in current directory
orbe_proto build
# Build protos in specific directory
orbe_proto build path/to/proto/dir
# Specify output directory
orbe_proto build -o lib/generated
# Build without cleaning (keep existing generated files)
orbe_proto build --no-clean
# Verbose output
orbe_proto build -v
Options:
-o, --output: Path to the output directory (defaults to input directory)-c, --clean: Delete generated files before building (default: true)-v, --verbose: Show verbose output including file details
Clean
Remove generated protobuf files (.pb.dart, .pbjson.dart, .pbenum.dart):
# Clean current directory
orbe_proto clean
# Clean specific directory
orbe_proto clean path/to/proto/dir
# Verbose output
orbe_proto clean -v
Options:
-v, --verbose: Show verbose output including deleted files
Library Usage #
import 'dart:io';
import 'package:orbe_proto/orbe_proto.dart';
// Parse a single proto file
final analyzer = ProtoAnalyzer();
final protoFile = await analyzer.analyzeFile(File('messages.proto'));
// Access the descriptor
print(protoFile.descriptor.messageType);
print(protoFile.descriptor.enumType);
// Parse multiple proto files
final files = [File('messages.proto'), File('services.proto')];
final protoFiles = await analyzer.analyzeFiles(files);
// Generate Dart code
final compiler = ProtoCompiler();
for (var proto in protoFiles) {
final generated = compiler.compile(proto, root: Directory('.'));
for (var file in generated) {
print('Generated: ${file.path}');
// Write file.content to disk
}
}
Features #
- Full Protocol Buffer syntax support (proto2 and proto3)
- Message, enum, and service definitions
- Nested types and imports
- Field options and annotations
- Error reporting with line and column information
- Pure Dart implementation - no protoc installation required
- Direct code generation from
.protofiles