Re: Subclass of a Proto Message

2009-08-03 Thread Kenton Varda
Your approach actually won't work (at least, as you've written the code)
because if you write two messages to a stream without any sort of delimiter,
it's impossible to figure out later where one message ends and the other
starts.
But I suggest doing this instead:

message A {
  ...
}

message B {
  required A a = 1;
  ...
}

In other words, change inheritance to composition.

On Mon, Aug 3, 2009 at 2:00 PM, Tai  wrote:

>
> 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 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
-~--~~~~--~~--~--~---



Fix compile error due to string literal overflow on large proto files.

2009-08-03 Thread kenton

Reviewers: eric.perie_hp.com,

Description:
Hi Eric, I decided to do this patch a little differently -- in
particular, I moved the actual string concatenation to occur in
Descriptors.java rather than in generated code.  I also added a test.
At Google we have a policy of reviewing all changes before submission,
so can you take a look and tell me if this code looks good to you?

Please review this at http://codereview.appspot.com/99043

Affected files:
   M java/pom.xml
   M java/src/main/java/com/google/protobuf/Descriptors.java
   M java/src/test/java/com/google/protobuf/DescriptorsTest.java
   M src/Makefile.am
   M src/google/protobuf/compiler/java/java_file.cc
   A src/google/protobuf/unittest_enormous_descriptor.proto



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Subclass of a Proto Message

2009-08-03 Thread Tai

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 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

2009-08-03 Thread Kenton Varda
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

2009-08-03 Thread Kenton Varda
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

2009-08-03 Thread Tai

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: Add a protobuf-config script like the old gtk-config

2009-08-03 Thread Jeff Bailey
lgtm
New version is much nicer.  Suck about the crashing bug in pkg-config. =(

Jeff Bailey >|< Google, Inc. >|< +1 514 670-8754


On Thu, Jul 30, 2009 at 3:00 PM, Kenton Varda  wrote:

> New patch:  Use pkg-config instead.  Much simpler.
>
>
> On Thu, Jul 30, 2009 at 10:05 AM, Jeff Bailey wrote:
>
>> I haven't done pkg-config stuff yet.  Maybe check in on #autotools in
>> freenode.  I'm usually there, as are other people.
>> Jeff Bailey >|< Google, Inc. >|< +1 514 670-8754
>>
>>
>> On Thu, Jul 30, 2009 at 12:12 PM, Kenton Varda  wrote:
>>
>>> Yeargh, I'm behind the times.  pkg-config?  I guess I should be
>>> integrating with that rather than writing my own script?
>>>
>>>
>>> On Thu, Jul 30, 2009 at 9:05 AM, Jeff Bailey wrote:
>>>
 lgtm

 42 Packages which depend on Protocol Buffers should call this script
 automatically   43 as part of their own configure script.

 Provide an example with PKG_CONFIG or something like that.

 Otherwise, looks good.  Thanks!

 Jeff Bailey >|< Google, Inc. >|< +1 514 670-8754


 On Thu, Jul 30, 2009 at 12:00 PM, Kenton Varda wrote:

> (New patch set uploaded.)
>
>
> On Thu, Jul 30, 2009 at 8:59 AM, Kenton Varda wrote:
>
>>
>>
>> On Wed, Jul 29, 2009 at 6:34 PM, Jeff Bailey 
>> wrote:
>>
>>> *sigh*  It looks like the version at appspot.com isn't GA+ enabled,
>>> so I sign in and it thinks I'm not signed in.
>>> Anyhow, a few comments:
>>>
>>> Since it's generated by configure.ac, do you need it in bin_SCRIPTS?
>>>  I think that might cause it to get looked at twice.
>>>
>>
>> The purpose of putting it in bin_SCRIPTS is to make sure that it is
>> installed, which configure is not going to do automatically.  The 
>> automake
>> docs say that bin_SCRIPTS are by default not included in the dist, which 
>> is
>> what we want here (since configure generates it).
>>
>>
>>> You should pretty much always do a set -e at the top of a shell
>>> script to catch errors early on.
>>>
>>
>> Oops, fixed.
>>
>>
>>>
>>>  *73* if test "@prefix@" != /usr -a "@prefix" != / -a "@prefix" !=
>>> ""; then
>>>
>>> Should those all be @pre...@?
>>>
>>
>> Yes.  :/
>>
>>
>>> Also, I think test -a might be a bashism in this case.
>>>
>>
>> Changed to "&& test".
>>
>>
>>> Same for this line:
>>>
>>>
>>>  *79* if test $full_library = true -o $explicit_library = false;
>>> then
>>>
>>
>> Done.
>>
>> Also, I added --ldflags as a separate option since LDFLAGS and LIBS
>> are traditionally separate.  Not sure why gtk-config itself does not do
>> this.
>>
>> Also also, I expanded the help text.
>>
>> Also^3, I made --version strip the suffix ("-pre", "rc1", etc.) since
>> I doubt anyone will correctly parse it otherwise (since people will code
>> against official releases which have no suffix).
>>
>
>

>>>
>>
>

--~--~-~--~~~---~--~~
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

2009-08-03 Thread Tai

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: "Lite" mode is in SVN -- mostly

2009-08-03 Thread Kenton Varda
On Sat, Aug 1, 2009 at 4:42 AM, Jon Skeet  wrote:

> Out of interest Kenton, does this make the bootstrapping code simpler?
> I'd imagine that can be built with just a "lite" version. It would be
> nice to get rid of some of the nastiness that's involved in C# just to
> get the PB-specific types to work :)


In theory, descriptor.proto could become "lite", and this might simplify
bootstrapping. In practice, though, we actually use "heavy" features on the
types in descriptor.proto, which is part of the reason why bootstrapping is
so complicated.  So, no, I don't think that would work.


>
>
> Jon
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---