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

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/03f1f05d-a9ef-4490-bf6a-469f16212f9f%40googlegroups.com.

Reply via email to