protobuf3_parser
Protobuf3 messages, services, documentations parser and more for dart!
Features
- Parsing messages, services, enums.
- Documentation and comments for messages, services and enums.
- Message fields and service fields.
Example
import 'package:protobuf3_parser/protobuf3_parser.dart';
void main(List<String> arguments) async {
final parser = Protobuf3Parser.fromString("""
syntax = "proto3";
/// A simple documentations for `User`.
message User {
/// Field documentations!
string name = 1;
Status status = 2;
}
/// Empty message.
message Empty {}
enum Status {
offline = 0;
online = 1;
}
/// My app service.
service App {
rpc GetUsers (Empty) returns (stream User);
}
""");
await for (final message in parser.messages) {
for (final field in message.fields) {
if (field.isCoreString) {
print(
"- In the message `${message.name}` the field `${field.name}` is a core protobuf3 type!");
}
}
}
await for (final enum3 in parser.enums) {
print("- The enum `${enum3.name}` has ${enum3.fields.length + 1} field!");
}
await for (final service in parser.services) {
print(
"- The service `${service.name}` has the following documenations: `${service.documentations.map((e) => e.actualText).join("")}`.");
}
}
And the output would be:
- In the message
User
the fieldname
is a core protobuf3 type! - The enum
Status
has 3 field! - The service
App
has the following documenations:/// My app service.
.