Protobuf-ify --> PB-IFY -> Pibify
Serve Java pojos as protobuf over the wire
Refer to the list of test cases here
This is the annotation to be added on any field of a Pojo class that has to be transported
@Pibify(1)
private String aStringVariable;
@Pibify(2)
private int anIntegerVariable;
This is the generated source corresponding to the Pojo where a @Pibify
annotation is present.
public abstract class PibifyGenerated<T> {
public abstract byte[] serialize(T object) throws PibifyCodeExecException;
public abstract T deserialize(byte[] bytes) throws PibifyCodeExecException;
}
This is the class that the clients use to get an instance of Handler for the supplied class and then call the serialize or deserialize method on it.
- Add the dependency on
pibify-core
library - Add the
pibify-maven-plugin
-
- Use mvn target to annotate all classes within a given module using the mvn goal:
mvn com.flipkart.pibify:pibify-maven-plugin:annotate
- Or, In the desired pojos, add the
@Pibify(<index>)
annotation manually
- Use mvn target to annotate all classes within a given module using the mvn goal:
- The maven plugin scans the source of the project during the build phase and collects all pojos which have the
@Pibify
annotation. - This plugin generates the
Handler
andPibifyHandlerCache
for the configured module and places them at a suitable place in the package(jar) - Clients use the
PibifyHandlerCache
to get a reference to aHandler
and call theserialize
/deserialize
method on it.
- Add the
pibify-core
dependency
<dependency>
<groupId>com.flipkart.pibify</groupId>
<artifactId>pibify-core</artifactId>
<scope>compile</scope>
<version>1.5</version>
</dependency>
- Configure the model mvn module by adding the below plugin config
<plugin>
<groupId>com.flipkart.pibify</groupId>
<artifactId>pibify-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<excludes>
<exclude>com/flipkart/pibify/toskip/**</exclude>
<exclude>com/flipkart/pibify/toskip2/**</exclude>
</excludes>
</configuration>
<dependencies>
<!--
Due to a current limitation in dependency management, the mvn plugin will not be able
to resolve transition dependencies of the module. They need to be copied over explicitly,
if they are needed to compile the models
-->
<!-- Copy over all module dependencies here -->
</dependencies>
<executions>
<execution>
<id>generate-pibify-sources</id>
<goals>
<goal>generate</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-pibify-source</id>
<phase>process-classes</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/pibify</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<executions>
<execution>
<id>compile-generated-pibify-sources</id>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
- Either manually tag fields with the
@Pibify
annotation or run the mvn goalmvn com.flipkart.pibify:pibify-maven-plugin:annotate
to scan through all pojos in the module and add the@Pibify
annotation. You can also pass an optional system property-Dreindex
to force overwrite existing Pibify annotations. Make use of theexclude
config. Refer to docs for more details. - As part of the
package
mvn goal, the handler code will be generated