Re: [protobuf] How to use oneOf as a type?

2019-01-21 Thread Brian Palmer
oneof is a property of the message that the fields are in; it's not really
a type of its own. Instead, you could do something like

message Event {
  required int32 event_id = 1;
  optional EventSpecifics specifics = 2;
}

message EventSpecifics {
  oneof EventType {
 optional FooEvent foo_event = 1;
 optional BarEvent bar_event = 2;
  }
}



On Thu, Jan 10, 2019 at 9:16 AM Suhas N  wrote:

> Given a message that looks like this,
>
> message Event {
> required int32 event_id = 1;
>
> oneof EventType {
> FooEvent foo_event = 2;
> BarEvent bar_event = 3;
> BazEvent baz_event = 4;
> }
> }
>
>
> I want to define another map which uses the EventType oneof as a type.
> Precisely, I want to define something like this
>
> message Sample {
> map someMap = 1;
> }
>
>
> But, this is not working. I get the error that
>
>
> PROTOC FAILED: "Event.EventTypeCase" is not defined.
>
> How can I use the oneof as a type?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] How to calculate protobuf size?

2017-12-10 Thread Brian Palmer
The simplest way would be to serialize your messages into bytes and then
measure the size directly, right?

On Sun, Dec 10, 2017 at 11:26 AM, Tomer Praizler 
wrote:

> Couldn't find a nice and easy way to calculate my protobuf sizes using
> python. Is there a recommended way?
>
> I am sending my protobufs into rabbitmq, and huge messages causing my
> connection to break. I want to be able to validate the size before sending
> a message.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Is there being a way to modify/define the .proto file with python?

2017-06-21 Thread Brian Palmer
Just peeking at
https://github.com/BVLC/caffe/blob/master/src/caffe/proto/caffe.proto (which
I'm guessing is the proto in question), I don't think it allows extension
at the moment.

On Wed, Jun 21, 2017 at 5:39 PM Bo Yang <tebor...@google.com> wrote:

> For option 2, I think you can extend caffe.LayerParameter by your self,
> given that LayerParameter allows extension.
>
> On Wed, Jun 21, 2017 at 1:12 AM Brian Palmer <bpal...@gmail.com> wrote:
>
>> Hi,
>>
>> it sounds to me like you should explore defining a new message that
>> contains the LayerParameter as a field. For example,
>>
>> syntax = "proto2";
>>
>> package lynxcommando;
>>
>> message AugmentedLayerParameter {
>>   optional caffe.LayerParameter base = 1;
>>   optional MyNewParameter my_new_parameter = 2;
>> }
>>
>> message MyNewParameter {
>>
>> };
>>
>> Alternatively, you could ask the caffe authors to add in an extension
>> range to their messages, so that you can do
>>
>> extend caffe.LayerParameter {
>>   optional MyNewParameter my_new_parameter = 12345;
>> }
>> in your my_new_parameter.proto.  See
>> https://developers.google.com/protocol-buffers/docs/proto#extensions
>>
>> As a last resort, there is support for creating "dynamic messages," but
>> most of the examples I found searching around were doing it in java or c++.
>> https://stackoverflow.com/questions/18836727/protocol-buffer-objects-generated-at-runtime
>>
>>
>>
>> On Thu, Jun 15, 2017 at 11:30 PM, Lynx Commando <lynxcomma...@gmail.com>
>> wrote:
>>
>>>
>>> First, is caffe managed by yourself?
>>> >No
>>> Otherwise, I don't suggest change it by your own (may cause
>>> incompatibility issues).
>>> >Unfortunately I have to
>>> Second, this seems like a python question instead of protobuf.
>>> >What I want to know is that if protobuf has a python api making it
>>> easier.
>>> >>More specifically , I am looking for something equivalent to a
>>> boost::xml_parser that parses xml
>>> >> In another word, I want to know if there is somepkg allows me to do
>>> the following thing
>>> >>> proto = somepkg.somecls.parse("src/caffe/caffe.proto")
>>> >>>
>>> proto['LayerParameter'].append(somepkg.somecls.optional_field("MyNewParam","my_new_param",param_id))
>>> >>> for fields in my_field_list:
>>> >>>  proto['MyNewParam'].append(field)
>>> >>> somepkg.somecls.write(proto,"src/caffe/caffe.proto")
>>>
>>>
>>>
>>>
>>> On Friday, June 16, 2017 at 2:21:17 AM UTC+8, Bo Yang wrote:
>>>>
>>>> First, is caffe managed by yourself? Otherwise, I don't suggest change
>>>> it by your own (may cause incompatibility issues).
>>>> Second, this seems like a python question instead of protobuf.
>>>>
>>>> On Wed, Jun 14, 2017 at 8:54 PM Lynx Commando <lynxco...@gmail.com>
>>>> wrote:
>>>>
>>>>> More specifically, I am using caffe and I'd like to add new layers to
>>>>> it.
>>>>> Then I need to modify the caffe.proto file by adding(or removing) some
>>>>> messages and corresponding fields to some other messages.
>>>>> I'd want to  know if I can do this automatically with a python script.
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Protocol Buffers" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to protobuf+u...@googlegroups.com.
>>>>> To post to this group, send email to prot...@googlegroups.com.
>>>>> Visit this group at https://groups.google.com/group/protobuf.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Protocol Buffers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to protobuf+unsubscr...@googlegroups.com.
>>> To post to this group, send email to protobuf@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/protobuf.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to protobuf+unsubscr...@googlegroups.com.
>> To post to this group, send email to protobuf@googlegroups.com.
>> Visit this group at https://groups.google.com/group/protobuf.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Is there being a way to modify/define the .proto file with python?

2017-06-21 Thread Brian Palmer
Hi,

it sounds to me like you should explore defining a new message that
contains the LayerParameter as a field. For example,

syntax = "proto2";

package lynxcommando;

message AugmentedLayerParameter {
  optional caffe.LayerParameter base = 1;
  optional MyNewParameter my_new_parameter = 2;
}

message MyNewParameter {

};

Alternatively, you could ask the caffe authors to add in an extension range
to their messages, so that you can do

extend caffe.LayerParameter {
  optional MyNewParameter my_new_parameter = 12345;
}
in your my_new_parameter.proto.  See
https://developers.google.com/protocol-buffers/docs/proto#extensions

As a last resort, there is support for creating "dynamic messages," but
most of the examples I found searching around were doing it in java or c++.
https://stackoverflow.com/questions/18836727/protocol-buffer-objects-generated-at-runtime



On Thu, Jun 15, 2017 at 11:30 PM, Lynx Commando 
wrote:

>
> First, is caffe managed by yourself?
> >No
> Otherwise, I don't suggest change it by your own (may cause
> incompatibility issues).
> >Unfortunately I have to
> Second, this seems like a python question instead of protobuf.
> >What I want to know is that if protobuf has a python api making it easier.
> >>More specifically , I am looking for something equivalent to a
> boost::xml_parser that parses xml
> >> In another word, I want to know if there is somepkg allows me to do the
> following thing
> >>> proto = somepkg.somecls.parse("src/caffe/caffe.proto")
> >>> proto['LayerParameter'].append(somepkg.somecls.
> optional_field("MyNewParam","my_new_param",param_id))
> >>> for fields in my_field_list:
> >>>  proto['MyNewParam'].append(field)
> >>> somepkg.somecls.write(proto,"src/caffe/caffe.proto")
>
>
>
>
> On Friday, June 16, 2017 at 2:21:17 AM UTC+8, Bo Yang wrote:
>>
>> First, is caffe managed by yourself? Otherwise, I don't suggest change it
>> by your own (may cause incompatibility issues).
>> Second, this seems like a python question instead of protobuf.
>>
>> On Wed, Jun 14, 2017 at 8:54 PM Lynx Commando 
>> wrote:
>>
>>> More specifically, I am using caffe and I'd like to add new layers to it.
>>> Then I need to modify the caffe.proto file by adding(or removing) some
>>> messages and corresponding fields to some other messages.
>>> I'd want to  know if I can do this automatically with a python script.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Protocol Buffers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to protobuf+u...@googlegroups.com.
>>> To post to this group, send email to prot...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/protobuf.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] How to distinguish between messages?

2017-02-21 Thread Brian Palmer
On Sun, Feb 19, 2017 at 5:26 PM pbaranov  wrote:

> It's probably something trivial but I can't figure it out :( I have 2
> messages that have similar structure and when I try to encode message #1
> and decode it as message #2 it works just fine. Why??? If that's how it is
> supposed to work how to distinguish between them? Please advise.
>

You're not missing anything; the standard wire format for protocol buffers
does not include the names of anything, only the fields and types.  Your
communication protocol will need some higher level coordination to handle
what types of message should be sent.

One possible way of encoding this sort of information into a protocol
buffer is to use a container message, such as

message OuterMessage {
  oneof messages {
 Msg1 msg1 = 1;
 Msg2 msg2 = 2;
   }
}

Where each possible message is specified in the oneof group. Then in your
C++ code handling the received outer message, you can switch on the result
of messages_case() to know which inner message was actually sent.

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Number of Bits Written to Memory

2011-02-04 Thread Brian Palmer
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] New Ruby Protocol Buffers library

2010-10-27 Thread Brian Palmer
I think just the github page for the project would be great. Thanks!

http://github.com/mozy/ruby-protocol-buffers

-- Brian

On Oct 26, 2010, at 10:56 PM, Kenton Varda wrote:

 I'd like to add this to the third-party wiki, but I'm not sure which link to 
 use.  Can you suggest (or create) a general-purpose landing page?
 
 On Thu, Oct 21, 2010 at 10:02 AM, Brian Palmer br...@codekitchen.net wrote:
 Mozy has just open sourced their implementation of Protocol Buffers
 for Ruby. The implementation has been in use internally at Mozy for
 over a year. This implementation has put a lot of focus on
 serialization/deserialization performance, and completeness.
 
 The ruby protobuf compiler calls out to protoc to do the heavy
 lifting, so it's using the same parser as the official compiler. It
 looks like now there's a plugin system for protoc itself, so if we
 were writing this project today we probably would've just made the
 compile-to-ruby functionality a plugin.
 
 Enjoy!
 
 The repo: http://github.com/mozy/ruby-protocol-buffers
 The gem: https://rubygems.org/gems/ruby-protocol-buffers
 The docs: http://rubydoc.info/gems/ruby-protocol-buffers/0.8.4/frames
 
 -- Brian Palmer
 
 --
 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.
 
 

-- 
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] New Ruby Protocol Buffers library

2010-10-21 Thread Brian Palmer
Mozy has just open sourced their implementation of Protocol Buffers
for Ruby. The implementation has been in use internally at Mozy for
over a year. This implementation has put a lot of focus on
serialization/deserialization performance, and completeness.

The ruby protobuf compiler calls out to protoc to do the heavy
lifting, so it's using the same parser as the official compiler. It
looks like now there's a plugin system for protoc itself, so if we
were writing this project today we probably would've just made the
compile-to-ruby functionality a plugin.

Enjoy!

The repo: http://github.com/mozy/ruby-protocol-buffers
The gem: https://rubygems.org/gems/ruby-protocol-buffers
The docs: http://rubydoc.info/gems/ruby-protocol-buffers/0.8.4/frames

-- Brian Palmer

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