Hi folks,

I am just integrating protobuf in our distributed system to replace the 
slowly java serialization. Our system is written in Scala and we have much 
traffic of sending immutable data (Updates) among client and server.
So, I think we can improve our performance with protobuf.
Firstly I have serialized some easy objects, like a person:

case class Person(id: Int, name: String, email: String = "", phoneNumbers: 
List[PhoneNumber], address: Address)
Than, the java compiler generates java code. 
If I want to write my person into a stream, i have to bind the application 
object (MyPerson) to the generated java object (Person). 

So, I extend my class MyPerson with the method to create a java-person. 
Note, that we have written a bind method for every application object which 
we want to serialize. 
def bind(): Person = {
Now, we can write a myPerson into an output stream:
val myPerson = MyPerson(1234, "John Doe", "j...@example.com", 
List(PhoneNumber("00003", PhoneType.HOME)), Address("B1", 1111, 14))
val out = new ByteArrayOutputStream()

The next step is to unbind the java generated to our application object 
val deseriPerson = Person.parseFrom(in)
val result = Unbinder.unbind(deseriPerson)

Our unbinder creates a scala-MyPerson by the given generated java person. 
We have written an unbinder for each application object as well. 

class PersonUnbinder {

   def unbind(aMsg: Person): MyPerson = {
      val phones = aMsg.getPhoneList().asScala.map(msg => 
      val address = Unbinder.unbind(aMsg.getAddress()).asInstanceOf[Address]
      MyPerson(aMsg.getId(), aMsg.getName(), aMsg.getEmail(), phones, 
The unbinde of the person calls the unbind methods of his child’s.

So, that is our developing progress to use protobuf in our system. You see, 
we have a lot of maintenance extra work which we don´t have if we are use 
the java serialization. 
If we change our application object, we have to change the .proto file, the 
bind method and the unbind method as well. 
What do you think about this?
Are there some ideas or tools for improving this progress?

Best regards Florian

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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to