Re: Field of Class type
Ah. Sure, that sounds reasonable. On Mon, Aug 3, 2009 at 2:15 PM, Tai wrote: > > Sorry but maybe my post is somehow confusing. I try to migrate my java > class into a protocal message class. Now I have a field like: > > publiy MyClass { > >Class anotherClass > > } > > I wonder how I should define that in a proto file (MyClassMessage). > Maybe like this: > > message MyClass { >required string anotherClassName = 1; > } > > Since I still have to use MyClass I just implement the writeObject() > and readObject() and use the the Class.forName(): > >private void writeObject(java.io.ObjectOutputStream out) throws > IOException { >Builder builder = MyClassMessage.MyClass.newBuilder(); >builder.setAnotherClassName(anotherClassName.getName()); >MyClassMessage.MyClass message = builder.build(); >message.writeTo(out); >} > >private void readObject(java.io.ObjectInputStream in) >throws ClassNotFoundException, IOException { >MyClassMessage.MyClass message = > MyClassMessage.MyClass.parseFrom(in); >anotherClassName= Class.forName(message.getAnotherClassName > ()); > } > > > On 3 Aug., 23:06, Kenton Varda wrote: > > Protocol message classes can only contain other protocol message classes, > > not arbitrary Java classes. Otherwise, what would happen when you > compile > > the same .proto file in C++ or another language? > > > > On Mon, Aug 3, 2009 at 1:14 PM, Tai wrote: > > > > > Hi, > > > > > I guess this is a simple question. I have a Java class with an > > > attribute which is a class. How do I define that in a proto file? > > > Maybe the full qualified class name? > > > > > 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 protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: Field of Class type
Protocol message classes can only contain other protocol message classes, not arbitrary Java classes. Otherwise, what would happen when you compile the same .proto file in C++ or another language? On Mon, Aug 3, 2009 at 1:14 PM, Tai wrote: > > Hi, > > I guess this is a simple question. I have a Java class with an > attribute which is a class. How do I define that in a proto file? > Maybe the full qualified class name? > > 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 protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: Field of Class type
Sorry but maybe my post is somehow confusing. I try to migrate my java class into a protocal message class. Now I have a field like: publiy MyClass { Class anotherClass } I wonder how I should define that in a proto file (MyClassMessage). Maybe like this: message MyClass { required string anotherClassName = 1; } Since I still have to use MyClass I just implement the writeObject() and readObject() and use the the Class.forName(): private void writeObject(java.io.ObjectOutputStream out) throws IOException { Builder builder = MyClassMessage.MyClass.newBuilder(); builder.setAnotherClassName(anotherClassName.getName()); MyClassMessage.MyClass message = builder.build(); message.writeTo(out); } private void readObject(java.io.ObjectInputStream in) throws ClassNotFoundException, IOException { MyClassMessage.MyClass message = MyClassMessage.MyClass.parseFrom(in); anotherClassName= Class.forName(message.getAnotherClassName ()); } On 3 Aug., 23:06, Kenton Varda wrote: > Protocol message classes can only contain other protocol message classes, > not arbitrary Java classes. Otherwise, what would happen when you compile > the same .proto file in C++ or another language? > > On Mon, Aug 3, 2009 at 1:14 PM, Tai wrote: > > > Hi, > > > I guess this is a simple question. I have a Java class with an > > attribute which is a class. How do I define that in a proto file? > > Maybe the full qualified class name? > > > 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 protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Field of Class type
Hi, I guess this is a simple question. I have a Java class with an attribute which is a class. How do I define that in a proto file? Maybe the full qualified class name? 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 protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---