google / openrtb

OpenRTB model for Java and other languages via protobuf; Helper OpenRTB libraries for Java including JSON serialization
Apache License 2.0
398 stars 190 forks source link

Creating protbuf extensions for openrtb.proto in this library #83

Closed pratikkumar19 closed 8 years ago

pratikkumar19 commented 8 years ago

Hi, I am trying to use this library for open rtb integration. The problem I am facing is that for adding extension(ext field) corresponding to a particular exchange , I created a .proto file but the openrtb.proto file cannot be extended without copying it from the library. Even if I copy the file(openrtb.proto) an OpenRtb.java file is generated by the protoc compiler. How can I exclude a particular proto file from generating the java code? If not how can I directly import the proto file from an external dependency, in this case your own library?

Also how can I add a list type to proto schema?(not like repeated field)

avitaleli commented 8 years ago

Hi,

I am facing the exact same problem, did you find any solution? I would appreciate your help.

Regards.

opinali commented 8 years ago

The OpenRTB-extension mechanism used by the library is designed to be modular, not requiring any changes to the core proto; you define the extensions in a different proto (which imports openrtb.proto). I realize the documentation provided in the wiki is very summarized, it's already planned to be improved, will try to work on that soon. But you can check the examples hidden inside the unit tests, look at the test-*.proto files and the code that uses them (not the most didactic material because it's written as test and not as sample code, but I guess better than nothing for now). A better source of sample code would be the companion DoubleClick OpenRTB library, see this proto and if you need JSON support for extensions see also this package, it's a decent real-world example.

@pratikkumar19

avitaleli commented 8 years ago

Thanks, I will try it and will update, hopefully I will get it working.

Please approve if it is correct:

  1. In my source directory I create my own proto (e.g. Ext.proto) and I import openrtb.proto and I write:
extend BidRequest {
    optional int32 bar = 110;
}
  1. How do I compile it, where will it find the reference to the actual place the JAR from open rtb resides? It is somewhere in the maven repositories. I am not sure how to point to the openrtb.proto in my import.

Thank you

opinali commented 8 years ago

Yes that's a correct start; to compile you will need the core openrtb.proto and you need an import "openrtb.proto"; in your file. You could just make a copy of the openrtb.proto to your project, but if you want to automatically keep it in sync with the library as you move to newer versions, you can use Maven's download-maven-plugin (or something equivalent in other build systems). Basically your build file needs to download openrtb.proto from this github repo, put it in a local directory and add that to the import path for protoc. You can copy the necessary configurations from this build file; the pieces you need are the following:

pratikkumar19 commented 8 years ago

Thanks @opinali

avitaleli commented 8 years ago

Thanks @opinali I managed following your assistance

YoavNordmann commented 7 years ago

I was able to solve this as follows: in my new *.proto file I added the import as so: import "openrtb.proto";

I then added the dependency as usual in maven.

I used the protobuf-maven-plugin plugin which makes me put the .proto files in the "src.main.proto" directory, but the import works and code is being generated as reuested.

digitebs commented 5 years ago

im using scala and the generated proto has "openrtb.openrtb" as package name for the ext how to fix?

found it flatPackage => true in sbt package