[protobuf] Re: Alternate names for enumeration values
I have just the solution for you... I'll start by warning you that I use PB mainly in Java, so things may look slightly different in C++ - but this method should still work. You're going to want to define an extension to google.protobuf.EnumValueOptions in your .proto file you will need to add an import for descriptor.proto import descriptor.proto; then you will need to extent EnumValueOptions extend google.protobuf.EnumValueOptions { optional string friendly_name = 5000; } you will now have defined an EnumValueOption for your friendly name... you can use it by adding... enum my_enum { FOO = 1 [(my.package.name.name)=Foo];; BAR = 2 [(my.package.name.name)=Bar];; } Note that if you have a package defined - you will need to use it when referencing your extension.. If not, just use [(friendly_name)=] The () are important as this tells PB that you are referencing an Extension. In Java you can access these by calling (probably similar in C++) enumValueDescriptor.getOptions().getExtension(MyProtobufOuterClass.friendly_name); You will now have successfully defined a fixed string for each enum value you want one for - you can do the same to associate the ordinals of an existing enumeration with one you're using in protobuf by defining an ordinal extension of type uint32. -Benjamin Wright On Feb 3, 9:42 pm, MahlerFive jefflegw...@gmail.com wrote: Is there a way to assign alternate names to enumeration values? I have a piece of C++ code that processes protocol buffer messages which have a lot of enums in them, and I need to print out the contents in a user- friendly, readable way. I know that I can get the enum value name by doing something like: pb::constants::EnumName_descriptor()-FindValueByNumber()-name() But if my enum value name is DEVICE_CATEGORY_TABLET, I would rather output something like Tablet. I can make a bunch of big maps of enum values to strings in my C++ code, but this means that any time I change the protocol buffers I need to update the C++ code. If there is no alternate name available, is there perhaps a better way to approach this where I don't have to make updates in two places for every change? Thanks! -- 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] Re: Generate .proto file from FileDescriptor?
Anyone know if this can be accomplished without resorting to JNI? On Feb 3, 4:01 pm, Jason Hsueh jas...@google.com wrote: C++'s FileDescriptor::DebugString() produces text that is reparsable as a .proto file On Thu, Feb 3, 2011 at 12:52 PM, Ben Wright compuware...@gmail.com wrote: I've started a project generating new FileDescriptors at runtime in Java using FileDescriptorProto in order to dynamically extend a base type. I have a class that generates .proto files (StringBuilder) and one that generates FileDescriptorProto. What I was wondering was if there was a class (in java or c++ that can turn a FileDescriptor / FileDescriptorProto into a .proto text file. -- 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. -- 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] Re: Compilation error for ppc/440 target
Unfortunately we have to use the particular compiler in question and cannot upgrade. Is the DescriptorBuilder::OptionInterpreter::AggregateOptionFinder new code ? I dont see this problem with protobuf-2.3.0. -- 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] Number of Bits Written to Memory
On Thu, Feb 3, 2011 at 8:58 AM, Tanya turtle...@gmail.com wrote: Basically, we need some way of specifying how the bytes are encoded/ written to memory, and we need to specify the number of bits written each time. Is this possible to do in protocol buffers? And if so, how would it be accomplished? Hi, Tanya. I'm not a protocol buffer expert at all, and you know your problem domain best, of course, but are you sure that you've fully identified your needs? You can use protocol buffers as data storage where you access fields, and you can use them to efficiently transmit data across the wire, but protobufs don't seem well suited to this sort of micromanaged control that you're talking about. -- 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] Re: New protobuf feature proposal: Generated classes for streaming / visitors
On Wed, Feb 2, 2011 at 10:13 AM, Henner Zeller henner.zel...@googlemail.com wrote: I guess the naming is confusing in the example. The Visit is per field-name; but since the typed is named the same as the field in this example, it is confusing. Yes, sorry. Better example: message MyStream { option generate_visitors = true; repeated Foo bar = 1; repeated Foo baz = 2; } creates: class MyStream::Visitor { public: virtual ~Visitor(); virtual void VisitBar(const Foo value); virtual void VisitBaz(const Foo value); }; -- 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] 2.4.0a released.
On Wed, Feb 2, 2011 at 9:59 PM, David Yu david.yu@gmail.com wrote: Where the jars at? (Or do we have to build the jars from source?) Have to build from source. (Though we're going to try to get the Maven repo updated. Long story.) I'm trying to benchmark 2.4.0a with its java perf improvements. The lazy decoding support is cool (like the activemq impl of protobuf). Note that lazy decoding only applies to strings -- they are decoded from UTF-8 bytes to String objects on first access. Sub-messages are still eagerly decoded, although we've been thinking about adding support for lazy sub-messages. (It's not always as great as it seems -- lazy decoding adds a lot of bookkeeping overhead, especially if you want to be thread-safe. We've actually discovered that the lazy UTF-8 decoding is a loss in some use cases; it will be tuned further for the next release.) -- 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] where is input_stream.py?
This file was deleted as part of the python serialization optimizations that were released in 2.3.0. A lot of the functionality now exists in decoder.py. You shouldn't be relying on internal parts of the package though, so it should only serve as a reference point for you. On Fri, Feb 4, 2011 at 3:05 PM, maxw mwindi...@videotron.ca wrote: Hello, I'm a relatively new user of protocol buffers in python. Recently I have used them successfully to deserialize whole-messages, but am now interested in a more granular streaming method (read field by field). I found several signs that a file named input_stream.py is or was part of some distribution (e.g. http://code.google.com/p/python-twitter/source/browse/google/protobuf/internal/input_stream.py?r=ea4e8dcae50dcee70d2668b5dce62766ec0620dd ). Yet, the 2.3.0 and 2.4.0a distributions don't seem to contain this file. Any hint would be greatly appreciated. - Max -- 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. -- 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] Multiple messages using std::streams
I had a hard time trying to serialize multiple messages in a std::ostream, and then trying to parse them one at a time from an std::istream, so I'm sharing my code for two reasons: - It may be useful for someone else. - To receive comments from more experienced people. template typename TMessage bool serialize_delimited(std::ostream stream, TMessage message) { assert(message.IsInitialized()); google::protobuf::io::OstreamOutputStream ostreamWrapper(stream); google::protobuf::io::CodedOutputStream codedOStream(ostreamWrapper); // Write the message size first. int messageSize = message.ByteSize(); assert(messageSize 0); codedOStream.WriteLittleEndian32(messageSize); // Write the message. message.SerializeWithCachedSizes(codedOStream); return stream.good(); } template typename TMessage bool parse_delimited(std::istream stream, TMessage message) { uint32_t messageSize = 0; // Read the message size. { google::protobuf::io::IstreamInputStream istreamWrapper(stream, sizeof(uint32_t)); google::protobuf::io::CodedInputStream codedIStream(istreamWrapper); // Don't consume more than sizeof(uint32_t) from the stream. google::protobuf::io::CodedInputStream::Limit oldLimit = codedIStream.PushLimit(sizeof(uint32_t)); codedIStream.ReadLittleEndian32(messageSize); codedIStream.PopLimit(oldLimit); assert(messageSize 0); assert(istreamWrapper.ByteCount() == sizeof(uint32_t)); } // Read the message. { google::protobuf::io::IstreamInputStream istreamWrapper(stream, messageSize); google::protobuf::io::CodedInputStream codedIStream(istreamWrapper); // Read the message, but don't consume more than messageSize bytes from the stream. google::protobuf::io::CodedInputStream::Limit oldLimit = codedIStream.PushLimit(messageSize); message.ParseFromCodedStream(codedIStream); codedIStream.PopLimit(oldLimit); assert(istreamWrapper.ByteCount() == messageSize); } return stream.good(); } serialize_delimited is pretty simple. I write the message size first, and then the message. The tricky part was parsing from a stream. The problem that I was facing was that after CodedInputStream got constructed, my stream was consumed more than I wanted to. The first message was parsed correctly, but for the rest the stream was not in the right position. The only way I found to avoid that was by setting the block_size parameter while constructing IstreamInputStream instances, and that is why I construct them twice (first to parse the size, then to parse the message). -- 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] Protobuf 2.4 and Android
The protobuf in android source code is a branched protobuf for google voice, which is not intended for public use, and may change in the future. Generally, you should use the opensource version of protobuf in your app, set the option optimize_for = LITE_RUNTIME; in your proto file and use the protobuf-lite library. On Thu, Feb 3, 2011 at 3:52 PM, pprados philippe.pra...@gmail.com wrote: Hello, With Android source code, we can find a specific version of Protobuf. The version 2.4 is it compatible with Android ? What is the best approch to use a lite and optimized version, parameter, options of Protobuf with Android ? Regards Philippe -- 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. -- 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] Re: Issue 241 in protobuf: Java Tutorial / Generated code doc lacks reference to ExtensionRegistry
Updates: Status: Fixed Comment #2 on issue 241 by liuj...@google.com: Java Tutorial / Generated code doc lacks reference to ExtensionRegistry http://code.google.com/p/protobuf/issues/detail?id=241 (No comment was entered for this change.) -- 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] Re: Issue 230 in protobuf: Documentation of the import behavior
Updates: Status: Fixed Comment #2 on issue 230 by liuj...@google.com: Documentation of the import behavior http://code.google.com/p/protobuf/issues/detail?id=230 (No comment was entered for this change.) -- 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] Re: Issue 250 in protobuf: [PATCH] Maven-plugin does not work with M2Eclipse
Updates: Owner: g...@google.com Comment #1 on issue 250 by liuj...@google.com: [PATCH] Maven-plugin does not work with M2Eclipse http://code.google.com/p/protobuf/issues/detail?id=250 (No comment was entered for this change.) -- 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.