A library that provides extension functions for parsing the basic descriptors of Protocol Buffers, which allows you to create descriptors without code compilation, which is especially useful when working with dynamic messages.
You can change any parsing method by calling toBuilder()
Wire Schema class name |
Protobuf Kotlin class name |
Method name |
---|---|---|
EnumConstantElement | EnumValueDescriptorProto | enumValueDescriptorProto |
EnumElement | EnumDescriptorProto | enumDescriptorProto |
FieldElement | FieldDescriptorProto | fieldDescriptorProto |
MessageElement | DescriptorProto | descriptorProto |
ProtoFileElement | FileDescriptorProto | fileDescriptorProto |
RpcElement | MethodDescriptorProto | methodDescriptorProto |
ServiceElement | ServiceDescriptorProto | serviceDescriptorProto |
You can exclude dependencies if they are already in use
Documentation - v3.23.4
Documentation - v4.8.0
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation('com.github.numq:protobuf-descriptor-parser:1.0.0') {
exclude group: 'com.google.protobuf', module: 'protobuf-kotlin'
exclude group: 'com.squareup.wire', module: 'wire-schema'
}
}
allprojects {
repositories {
maven("https://jitpack.io")
}
}
dependencies {
implementation("com.github.numq:protobuf-descriptor-parser:1.0.0") {
exclude(group = "com.google.protobuf", module = "protobuf-kotlin")
exclude(group = "com.squareup.wire", module = "wire-schema")
}
}
val protoFile = File("./path/to/*.proto")
val schema = ProtoParser.parse(Location.get(path), proto.readText())
val descriptor = Descriptors.FileDescriptor.buildFrom(schema.parseDescriptor(protoFile.name), arrayOf())
// Use descriptor to create a dynamic message or for other purposes