Hi Evan,
Thanks for your reply. I am trying to do more along the lines of a).
I am trying to write a "DataFormat" for use with Apache Camel. In
Camel there is the notion of data transformations performed by the
framework before and after they are sent over transports. So you say
for example take this object, turn it into JSON, then send it over
JMS.
Below is the implementation of the Protobuf DataFormat. The steps that
take place are:
1) Use the generated protobuf builder to create an instance of object
to be transferred.
2) Give the object to Camel
3) Camel invokes the DataFormat using the descriptor that matches. A
new DataFormat is instantiated for each type of message, so the
Descriptor is unique.
4) The DataFormat marshals the object to the OutputStream. This is
easy as the Message interface contains a writeTo method.
5) Camel then sends the message over the transport
6) On the other side Camel receives the message then attempts to
unmarhsal it.
7) Camel invokes unmarshal on my ProtobufDataFormat. This is the part
I'm stuck on. I have the descriptor but I don't want to "hard code"
in the builder as then it is no longer generic.
8) The framework then casts the result and returns it to the
recipient.
The result of all this means that the client should be able to use the
Camel DSL to do things such as:
from("bean:somebean").marshal().protobuf(descriptor).to
("jms:queuename");
from("jms:queuename").unmarhal().protobuf(descriptor).to("file://
output.txt");
public class ProtobufDataFormat implements DataFormat {
private Descriptor descriptor;
public ProtobufDataFormat(Descriptor descriptor) {
this.descriptor = descriptor;
}
public void marshal(Exchange exchange, Object graph, OutputStream
outputStream)
throws Exception {
((Message)graph).writeTo(outputStream);
}
public Object unmarshal(Exchange exchange, InputStream inputStream)
throws Exception {
//TODO what happens here?
return null;