[protobuf] Re: Issue 416 in protobuf: HasField is throwing UnsupportedOperationException on repeated fields

2012-09-10 Thread protobuf

Updates:
Status: WorkingAsIntended

Comment #1 on issue 416 by jas...@google.com: HasField is throwing  
UnsupportedOperationException on repeated fields

http://code.google.com/p/protobuf/issues/detail?id=416

Do you really get an UnsupportedOperationException? You should get  
IllegalArgumentException. Docs say that hasField throws exception on  
repeated fields:  
https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/MessageOrBuilder.html#hasField(com.google.protobuf.Descriptors.FieldDescriptor)


repeated fields don't have a has accessor, you should call  
getRepeatedFieldCount() instead.


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



[protobuf] protobuf test generation

2012-09-10 Thread Sean Larsson
Is there a tool that can be used to generated test cases given a .proto 
file? I'm looking for something that will take a .proto file, and then 
generate source code that creates the different message structures and 
assigns random values to fields for testing purposes. I'm specifically 
interested in a Python implementation, but anything else would suffice.

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/tCr-iO1Q0ZkJ.
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: [protobuf] Serializing List of Objects

2012-09-10 Thread Amina Khalique
Hi Marc, 
I had a similar question about the serialization of objects using protocol 
buffers.
I prefer using a single .proto file for generation of C# and Java file, and 
would like to know if my understanding of how to implement a generic list 
of objects in the .proto file is right or not.

Here is my .proto file:
package test;

option optimize_for = SPEED;

message Dp
{

optional string com = 1;

optional string arga = 2;

optional string dbName = 3;

optional string fName = 4;

optional string dateTime = 5;

optional string inputdataassembly = 6;

optional string inputDataType = 7;

optional string identity = 8;
 enum DataLocation 
{
SERVER = 1;
CLIENT = 2;
ADMIN = 3;
}

optional DataLocation datalocation = 9;

optional Object o = 10;

// I want this to be of the type ListObject
message Object
{ 
repeated Object objects = 1;
}

optional string ipaddress = 11;

optional int32 port = 12;

optional string authGuid = 13;

optional string moduleid = 14;

optional bool queued = 15;
}

Thank you.
Regards,
Amina K

On Wednesday, June 20, 2012 9:05:49 AM UTC-4, Marc Gravell wrote:

 (note: this is specific to protobuf-net, not protocol buffers more 
 widely), but yes: that (a generic list) would work fine, as long as the 
 property has been marked for serialization and given a number. There also 
 doesn't need to be a set accessor, although it can make full use of a 
 set - i.e. if it finds the list is null, it will create a new list of 
 the appropriate type and use the set to update the object.

 So, your code would be fine if it has been designated a number, or a 
 related example:

 [ProtoMember(4)]
 public ListOrder Orders { get  { return orders; } } 
 private readonly ListOrder orders = new ListOrder();

 Marc
 (protobuf-net)

 On 20 June 2012 13:08, Farooq Mushtaq farooqm...@gmail.com 
 javascript:wrote:

 How can we serialize list of objects by using protobuf-net? Is 
 protobuf-net support list of objects like 
 public List(ABC) DEF
 {
get;
set;
 }

 -- 
 You received this message because you are subscribed to the Google Groups 
 Protocol Buffers group.
 To view this discussion on the web visit 
 https://groups.google.com/d/msg/protobuf/-/W0yySDcbES8J.
 To post to this group, send email to prot...@googlegroups.comjavascript:
 .
 To unsubscribe from this group, send email to 
 protobuf+u...@googlegroups.com javascript:.
 For more options, visit this group at 
 http://groups.google.com/group/protobuf?hl=en.




 -- 
 Regards, 

 Marc
  

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/x_xlCL2obnsJ.
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.



[protobuf] Message Migration Practice?

2012-09-10 Thread Minhyuk Kwon
Hello,

I have plan for introducing protobuf to in our products for passing 
information of product's input project file structure.
And this information may frequently upgrade near future(via product version 
upgrade).

So, I have a question. 
If I remove old field from message and add new field, Can I (auto)migrate 
without breaking change?
And if you guys have(or know) document for this kind practice, please let 
me know.


Regards,

-Kwon

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/Jka1u_famjkJ.
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.



[protobuf] how make an DynamicMessage to known message?

2012-09-10 Thread qtom zheng
i do like following, and id does success;

ListFieldDescriptor fieldlist = 
 dynamicmsg.getDescriptorForType().getFields();
 Protocal.Builder buildermsg = Protocal.newBuilder();
 for(FieldDescriptor fieldDp : fieldlist){
 buildermsg.setField(fieldDp,  dynamicmsg .getField(fieldDp));
 }
 Protocal head = buildermsg.build();

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/tIhWP_d4DiMJ.
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.



[protobuf] how to createmessage by messagename

2012-09-10 Thread qtom zheng
 public static Message createMessage(String messageName) {
 FileDescriptor dps = Addressbook.getDescriptor();
 System.out.println(dps.getPackage());
 Descriptor dp = dps.findMessageTypeByName(messageName);

...
 return null;

}


by the messageName   I have got the Descriptor dp;
then i want to generated message by Descriptor dp;
but i don't know how to do, any one can tell me?

thanks!!!

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/sPMJ6uPundUJ.
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: [protobuf] Creating Dummy Protos

2012-09-10 Thread Jason Hsueh
Are you using the getFooBuilder() methods?

A common practice for tests is to use the TextFormat: you can write out the
string representation of the pb you want, and then parse into a PB object.
Or you could narrow the API of your methods under test to take only the
submessages that they need.


On Wed, Aug 29, 2012 at 3:50 PM, Carl Mastrangelo notc...@google.comwrote:

 Noogler here,

 I am wondering if there is a good way to test methods that take protos as
 parameters?  For each of my test methods, I seem to have to create a pretty
 complicated proto only to set a single field nested deep inside.  This
 results in a lot of setup code for my tests.  Is there a faster way to make
 test protos that only have a couple fields set (or intentionally not set) ?
  So far I have been using .buildPartial() to shorten code, but it still
 seems pretty long.

 The language is Java for reference.

 --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/protobuf/-/83boIWdtqcoJ.
 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.


-- 
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: [protobuf] how to createmessage by messagename

2012-09-10 Thread Jason Hsueh
You would need to list out all the message types you want to use, and
maintain a map from their Descriptor to their default instance (accessible
with getDefaultInstance()). You can then call newBuilder or other
construction methods.

If you are ok with using a dynamic rather than generated message
implementation, you can use the DynamicMessage class.


On Sun, Sep 2, 2012 at 2:40 AM, qtom zheng zhfnj...@gmail.com wrote:

 public static Message createMessage(String messageName) {
   FileDescriptor dps = Addressbook.getDescriptor();

  System.out.println(dps.getPackage());
  Descriptor dp = dps.findMessageTypeByName(messageName);

 ...
  return null;

 }


 by the messageName   I have got the Descriptor dp;
 then i want to generated message by Descriptor dp;
 but i don't know how to do, any one can tell me?

 thanks!!!

 --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/protobuf/-/sPMJ6uPundUJ.
 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.


-- 
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: [protobuf] how make an DynamicMessage to known message?

2012-09-10 Thread Jason Hsueh
You can also copy via serialization:
Protocal.parseFrom(dynamicmsg.toByteArray());


On Sun, Sep 2, 2012 at 8:32 PM, qtom zheng zhfnj...@gmail.com wrote:

 i do like following, and id does success;

 ListFieldDescriptor fieldlist =
 dynamicmsg.getDescriptorForType().getFields();
 Protocal.Builder buildermsg = Protocal.newBuilder();
 for(FieldDescriptor fieldDp : fieldlist){
 buildermsg.setField(fieldDp,  dynamicmsg .getField(fieldDp));
 }
 Protocal head = buildermsg.build();

  --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/protobuf/-/tIhWP_d4DiMJ.
 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.


-- 
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: [protobuf] Why not using deque instead of vector in function: ListFields to avoid frequently new/delete

2012-09-10 Thread Jason Hsueh
You can control whether the vector is empty or not: you can reserve memory
for the vector based on the descriptor size, or reuse a vector previously
passed to ListFields - calling vector::clear() does not delete the
allocated memory.

Admittedly, the reflection code is not heavily optimized. But any choice of
container is likely to run into some issues; there just hasn't been much
effort into picking these tradeoffs. In general messages are encouraged to
be small so that the allocation size for the output vector should not be
that significant.


On Fri, Sep 7, 2012 at 2:54 AM, jaycee xujay...@gmail.com wrote:

 When using protobuf , there comes the performance bottleneck.
 Then I found the hot point is focus on
 GeneratedMessageReflection::ListFields (which costs 30%+ CPU idle) by
 gprofiler,  which indicates that there is too much new and delete .

 API of ListFields-
 void
 GeneratedMessageReflection::ListFields(

 const Message
 message,

 vectorconst FieldDescriptor** output) const;

 -

 As the function called, the second arg : output is always a empty
 vector. So it will cause new/delete for many times in case of plenty fields
 So as title mentioned, Why don't we use deque or other container to avoid
 too much new/delte, instead of using vector.

 --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/protobuf/-/AhsFq2N6IxEJ.
 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.


-- 
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: [protobuf] Message Migration Practice?

2012-09-10 Thread Jason Hsueh
The general practices for changing messages are listed here:
https://developers.google.com/protocol-buffers/docs/proto#updating.


On Wed, Sep 5, 2012 at 7:04 PM, Minhyuk Kwon mug...@gmail.com wrote:

 Hello,

 I have plan for introducing protobuf to in our products for passing
 information of product's input project file structure.
 And this information may frequently upgrade near future(via product
 version upgrade).

 So, I have a question.
 If I remove old field from message and add new field, Can I (auto)migrate
 without breaking change?
 And if you guys have(or know) document for this kind practice, please let
 me know.


 Regards,

 -Kwon

  --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/protobuf/-/Jka1u_famjkJ.
 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.


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