Hi,
I have proto files which contain valid proto messages and services and my own DSL which I want to transpile into proto messages and services.
My idea is to invoke protoc and have it process "my proto" with a protoc plugin that will emmit "standard proto" (which I'll later feed into protoc again).
The reason I'm going through the intermediate proto files is because we need them to integrate with other systems.
I'm trying to write this plugin using protobuf-java (jvm developer) but the proto file that is emitted is incorrect.
I think (and hope) I'm doing something stupid and maybe someone here can point me to the right direction.
Thanks in advance...
Some of my code (to generate a hardcoded proto file with one message and one field):
DescriptorProtos.DescriptorProto protoMessage = DescriptorProtos.DescriptorProto.newBuilder()
.setName("messageGreeting")
.addField(DescriptorProtos.FieldDescriptorProto.newBuilder()
.setName("greeting")
.setType(FieldDescriptorProto.Type.TYPE_STRING)
.setNumber(0)
.setDefaultValue("hi")
.build()
)
.build();
DescriptorProtos.FileDescriptorProto proto = DescriptorProtos.FileDescriptorProto.newBuilder()
.addMessageType(
protoMessage
)
.build();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
proto.writeTo(byteArrayOutputStream); // should be lazy?
CodeGeneratorResponse.File file = CodeGeneratorResponse.File.newBuilder()
.setName("yo.proto")
.setContentBytes(ByteString.copyFrom(byteArrayOutputStream.toByteArray))
// I also tried:
// .mergeFrom(protoMessage)
// .setContent(byteArrayOutputStream.toString) // should be lazy?
// .mergeFrom(byteArrayOutputStream.toByteArray)
.build();
file.toByteArray
Unfortunately what I get is:
cat yo.proto:
"%
messageGreeting greeting( :hi%
and in a text editor:
2225 0a0f 6d65 7373 6167 6547 7265 6574
696e 6712 120a 0867 7265 6574 696e 6718
0028 093a 0268 69