Last active
May 22, 2017 01:01
-
-
Save danbills/1494a34174ae311f7adb4458c95c4a61 to your computer and use it in GitHub Desktop.
ammonite protobuf code generation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create run.sh w/ : cat - | amm -s compileprotobuffiledescriptor.sc | |
//protoc --plugin=protoc-gen-custom=run.sh --custom_out=out t.proto | |
import $ivy.`com.google.protobuf:protobuf-java:3.3.1` | |
import com.google.protobuf.compiler.PluginProtos.{CodeGeneratorRequest,CodeGeneratorResponse} | |
val fdp:CodeGeneratorRequest = CodeGeneratorRequest.parseFrom(System.in) | |
System.err.println(s"fdp was ${Option(fdp.getProtoFileCount)}") | |
System.err.println(s"fdp was ${Option(fdp.getProtoFile(0))}") | |
val f = CodeGeneratorResponse.File.newBuilder().setName("f.sc").setContent("import $ivy.`co.fs2::fs2-io:0.9.6`").build() | |
val b = CodeGeneratorResponse.newBuilder.addFile(f).build() | |
b.writeTo(System.out) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create run.sh w/ : cat - | amm -s compileprotobuffiledescriptor.sc | |
//protoc --plugin=protoc-gen-custom=run.sh --custom_out=out t.proto | |
//compile google service rpc | |
//protoc --plugin=protoc-gen-custom=run.sh --custom_out=out --proto_path=/home/dan/googleapis/ --proto_path=/home/dan/protobuf/src/ /home/dan/googleapis/google/cloud/speech/v1/cloud_speech.proto 2> out.txt | |
import $ivy.`com.google.protobuf:protobuf-java:3.3.1` | |
import $ivy.`co.fs2::fs2-io:0.9.6` | |
import scala.collection.JavaConverters._ | |
import com.google.protobuf.compiler.PluginProtos.{CodeGeneratorRequest,CodeGeneratorResponse} | |
import fs2.Task | |
import com.google.protobuf.DescriptorProtos.{FileDescriptorSet, FileDescriptor} | |
val fdp:CodeGeneratorRequest = CodeGeneratorRequest.parseFrom(System.in) | |
System.err.println(s"fdp was ${Option(fdp.getProtoFileCount)}") | |
case class ResponseFile(name: String, content: String) | |
def f: FileDescriptorSet => Task[List[ResponseFile]] = fds.traverse(g)//fds => Task[ResponseFile]):Task[List[ResponseFile]} | |
def g: FileDescriptor => Task[ResponseFile] = { | |
??? | |
} | |
fdp.getProtoFileList.asScala.foreach(System.err.println) | |
//call something that does kk | |
val f = CodeGeneratorResponse.File.newBuilder().setName("f.sc").setContent("import $ivy.`co.fs2::fs2-io:0.9.6`").build() | |
val b = CodeGeneratorResponse.newBuilder.addFile(f).build() | |
b.writeTo(System.out) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment