Hi again,
I have two classes where B extends from A. Since both classes are
legacy and as far as I understood protocol buffers I write a proto
file for class A. For serialization and deserialization I just add the
methods writeObject() and readObject() to class A.
Now I wonder how to write the proto file for class B which is a
subclass of A? Is it like this that I define in the B proto file the
attributes defined in B and then in Class B's methods I do this:
private void writeObject(java.io.ObjectOutputStream out) throws
IOException {
Builder builder = A.AttributeA.newBuilder();
builder.setAttributeA(attributeA);
A.AttributeA message = builder.build();
message.writeTo(out);
Builder builder2 = B.AttributeB.newBuilder();
builder2.setAttributeB(attributeB);
B.AttributeB message2 = builder2.build();
message2.writeTo(out);
}
private void readObject(java.io.ObjectInputStream in)
throws ClassNotFoundException, IOException {
A.AttributeA message = A.AttributeA.parseFrom(in);
attributeA = message.getAttributeA();
B.AttributeB message2 = B.AttributeB.parseFrom(in);
attributeB = message2.getAttributeB();
}
Is this the standard approach?
Thanks Tai
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---