[protobuf] Re: Issue 187 in protobuf: Command-line argument to override the optimize_for option

2010-07-28 Thread protobuf


Comment #11 on issue 187 by ken...@google.com: Command-line argument to  
override the optimize_for option

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

Hi all,

Attached is a little protoc plugin written in Python which converts all the  
inputs to LITE_RUNTIME -- including renaming so that they do not conflict  
-- and then passes them on to some other plugin.  See readme.txt in the  
archive for details.  Basically with this you can do:


  protoc --litify_out=cpp:. foo.proto

And this will produce foo_lite.pb.h and foo_lite.pb.cc, which contain foo's  
types compiled with optimize_for=LITE_RUNTIME.  You can do Java too:


  protoc --litify_out=java:. foo.proto

You can easily modify this plugin's code to produce any arbitrary  
transformation you want.  It's just a Python script that processes the  
FileDescriptorProtos representing the inputs.


I like this approach because it is completely general.  There is nothing  
that you can't express in a Turing-complete language.  In contrast, *none*  
of the other proposals made so far can express even what this simple plugin  
does (in particular no one has proposed a solution for the renaming part).


I also like that this requires no modification whatsoever to protoc.  Not  
just because I want to avoid work, but because keeping the code code as  
simple as possible ensures that it retains agile.


What do you think?

Attachments:
litify.tar.gz  4.1 KB

--
You received this message because you are subscribed to the Google Groups Protocol 
Buffers group.
To post to this group, send email to proto...@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] Re: Issue 187 in protobuf: Command-line argument to override the optimize_for option

2010-07-28 Thread protobuf


Comment #12 on issue 187 by ken...@google.com: Command-line argument to  
override the optimize_for option

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

s/code code/core code/

s/retains/remains/

*sigh*

--
You received this message because you are subscribed to the Google Groups Protocol 
Buffers group.
To post to this group, send email to proto...@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] Re: Best practice to parse extensions in c++

2010-07-28 Thread Johan Philips


On 27 jul, 22:22, Kenton Varda ken...@google.com wrote:

 I agree, but we don't have a good API for querying which extension is set.
  We might fix that someday by introducing language-level support for
 unions.

Ok. So my struggle to find this API is more or less justified :-)

  for each defined extension:

  fdExtensions.push_back(msgReflection.findKnownExtensionByName(extensionName 
  ));

  and then in the parse method

  for(int i;i fdExtensions; i++)
   if(msgReflection.HasField(msg,fdExtensions[i]) {
     Parser p = parsers.get(fdExtensions[i]);
     if(p != null) p.parse()
   }

 Just use:

   vectorFieldDescriptor* fields;
   msgReflection-ListFields(msg, fields);
   for (int i = 0; i  fields.size(); i++) {
     if (field[i]-is_extension()) {
       // handle extension
     }
   }

Ok thanks! Iterating over the number of fields might be faster than
iterating over the number of extensions as I did in my example.

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@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] Issue 209 in protobuf: Binary file generated with protoc leads to an error message.

2010-07-28 Thread protobuf

Status: New
Owner: ken...@google.com
Labels: Type-Defect Priority-Medium

New issue 209 by sebhub: Binary file generated with protoc leads to an  
error message.

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

What steps will reproduce the problem?
1. Download the attached files.
2. Run the test case in test-config.cc.

What is the expected output? What do you see instead?

0
0
0
0
0
0
0
libprotobuf ERROR ../../src/google/protobuf/message_lite.cc:123] Can't  
parse message of type Configuration because it is missing required  
fields: (cannot determine missing fields for lite message)

0
1

This error message is irritating.

What version of the product are you using? On what operating system?

SVN head from July 28.  openSUSE 11.2.


Attachments:
test-config.pb.bin  32.1 KB
test-config.cc  412 bytes
messages.proto  688 bytes

--
You received this message because you are subscribed to the Google Groups Protocol 
Buffers group.
To post to this group, send email to proto...@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] why ParseFromIstream using std::cin always returns true using a pipe?

2010-07-28 Thread jetcube
I have a simple app that received data using the stdin and i have this
loop:

for(;;) {
if(!request.ParseFromIstream(cin)) {
cerr  Cannot parse pb message.  endl;
return -1;
}
do_something();
}

I wanted to test my app so i serialized a protobuf message to a file
and run it like:

./a.out  message.ser

however i would expect some blocking after the parse from istream but
instead it is constantly returning true (although there is only 1
message in the file) making the do something function to be called
over and over when i expected it to be only once.

What am i doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@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 ParseFromIstream using std::cin always returns true using a pipe?

2010-07-28 Thread Jason Hsueh
Messages without any required fields are allowed to have an empty
serialization, so the library cannot assume that parsing empty input is an
error. You just need to test cin.eof() separately.

On Wed, Jul 28, 2010 at 7:18 AM, jetcube pmlo...@gmail.com wrote:

 I have a simple app that received data using the stdin and i have this
 loop:

 for(;;) {
if(!request.ParseFromIstream(cin)) {
cerr  Cannot parse pb message.  endl;
return -1;
}
do_something();
 }

 I wanted to test my app so i serialized a protobuf message to a file
 and run it like:

 ./a.out  message.ser

 however i would expect some blocking after the parse from istream but
 instead it is constantly returning true (although there is only 1
 message in the file) making the do something function to be called
 over and over when i expected it to be only once.

 What am i doing wrong?

 --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To post to this group, send email to proto...@googlegroups.com.
 To unsubscribe from this group, send email to
 protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@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 proto...@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] Re: Issue 209 in protobuf: Binary file generated with protoc leads to an error message.

2010-07-28 Thread protobuf

Updates:
Status: WorkingAsIntended
Owner: ---

Comment #1 on issue 209 by jas...@google.com: Binary file generated with  
protoc leads to an error message.

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

The logging message is there to differentiate between parse failures (bad  
data) and initialization errors (missing fields). You can disable the  
logging using a LogSilencer, or setting the LogHandler to NULL (see  
stubs/common.h). You can also avoid calling this code path by using the  
Partial variants of the parsing routines, which don't do the initialization  
check.


--
You received this message because you are subscribed to the Google Groups Protocol 
Buffers group.
To post to this group, send email to proto...@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] Re: why ParseFromIstream using std::cin always returns true using a pipe?

2010-07-28 Thread jetcube
Right, that is it! I think this explanation should be in the
documentation :) (maybe it is but i didn't search hard enough)

Thanks!

On Jul 28, 6:34 pm, Jason Hsueh jas...@google.com wrote:
 Messages without any required fields are allowed to have an empty
 serialization, so the library cannot assume that parsing empty input is an
 error. You just need to test cin.eof() separately.

 On Wed, Jul 28, 2010 at 7:18 AM, jetcube pmlo...@gmail.com wrote:
  I have a simple app that received data using the stdin and i have this
  loop:

  for(;;) {
         if(!request.ParseFromIstream(cin)) {
                 cerr  Cannot parse pb message.  endl;
                 return -1;
         }
         do_something();
  }

  I wanted to test my app so i serialized a protobuf message to a file
  and run it like:

  ./a.out  message.ser

  however i would expect some blocking after the parse from istream but
  instead it is constantly returning true (although there is only 1
  message in the file) making the do something function to be called
  over and over when i expected it to be only once.

  What am i doing wrong?

  --
  You received this message because you are subscribed to the Google Groups
  Protocol Buffers group.
  To post to this group, send email to proto...@googlegroups.com.
  To unsubscribe from this group, send email to
  protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@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 proto...@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] libcurl integrtion

2010-07-28 Thread Birch
I am not well versed in c++, just a disclamer.  I have muddled through
creating a small client and I want to post the binary output via
HTTP.  Here is the source I have so far:

#define CURL_STATICLIB
#include iostream
#include fstream
#include string
#include mvm.pb.h
#include curl/curl.h
#include curl/types.h
#include curl/easy.h

using namespace std;

int main(int argc, char* argv[]) {
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;

mvm::protobuf::prov::prov prov;
mvm::protobuf::prov_Artifact* artifact = prov.mutable_object();
mvm::protobuf::prov_Execution* action = prov.mutable_action();
artifact-set_uuid(foo);
artifact-set_classification(unclassified);
action-set_action(mvm::protobuf::prov_Action_CREATED);
mvm::protobuf::prov_Actor* actor = action-mutable_performedby();
mvm::protobuf::prov_Person* person = actor-mutable_person();
person-set_uuid(person_uuid);
mvm::protobuf::prov_TimeStamp* timestamp = action-
mutable_performedat();
timestamp-set_datetime(1234567890);

fstream output(mvm.out, ios::out | ios::trunc | ios::binary);
ostrstream os; // - what to use here?
if (!prov.SerializeToOstream(output)) {
cerr  Failed to write mvm.  endl;
return -1;
}
if (!prov.SerializeToOstream(os)) {
cerr  Failed to write mvm to os.  endl;
return -1;
}
CURL *curl;

curl = curl_easy_init();
char *url = http://localhost:8080/Protobuf/PostServlet;;
curl_easy_setopt(curl, CURLOPT_URL, url);
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
curl_formadd(formpost, lastptr,
CURLFORM_COPYNAME, mydata,
CURLFORM_PTRCONTENTS, test\0test, // - should
point to os
   CURLFORM_CONTENTSLENGTH, 50, // - need to know the
size of os
   CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

curl_easy_perform(curl);
curl_easy_cleanup(curl);

// Optional:  Delete all global objects allocated by libprotobuf.
google::protobuf::ShutdownProtobufLibrary();

return 0;
}


I added comments where I am having trouble.  I basically just wan to
populate the body (content) of the HTTP post message with the binary
output of the SerializeToOStream call.  Any help would be greatly
appreciated!

Birch

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@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.