serialize message to UDP socket
Hello all, I am having trouble figuring out how to serialize data over a socket utilizing UDP protocol. I am in C++ environment. When writing to the socket without protocol buffers, I use the standard sendto() socket call which allows me to specify the port and IP address of the intended receiver of my UDP message. When trying to send a protocol buffers message, this seems to be the recommended strategy on the google docs: ZeroCopyOutputStream* raw_output = new FileOutputStream (sock); CodedOutputStream*coded_output = new CodedOutputStream (raw_output); coded_output-WriteRaw(send_data,strlen(send_data)); There is no way to specify what the port and IP address is here, analogous to when using the standard sendto() socket writing call. So my message never gets received by the intended recipient on the network. I am aware that this is a raw message, not a PB message. Getting this raw message over the network is a first step in accomplishing the ultimate goal of getting the PB message over the network. Is there a way to get all of the bytes of a serialized PB message into raw form and then send them with sendto()? Any ideas? Thanks for any help. Jay --~--~-~--~~~---~--~~ 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: serialize message to UDP socket
One other thing I wanted to say was that I chose to use CodedOutputStream to send data because ultimately I have to manually encode a length prefix in front of my PB message. With the C++ environment, I understand that this is the only way to do this (ugh is right; I am sure this is a common problem with using PB over sockets that remain in use). I am fully aware that there are methods to serialize directly from the object but those will not serve my ultimate aim of getting a length prefix ahead of the data bytes. Thanks Jay On Sep 18, 12:19 pm, jayt0...@gmail.com jayt0...@gmail.com wrote: Hello all, I am having trouble figuring out how to serialize data over a socket utilizing UDP protocol. I am in C++ environment. When writing to the socket without protocol buffers, I use the standard sendto() socket call which allows me to specify the port and IP address of the intended receiver of my UDP message. When trying to send a protocol buffers message, this seems to be the recommended strategy on the google docs: ZeroCopyOutputStream* raw_output = new FileOutputStream (sock); CodedOutputStream* coded_output = new CodedOutputStream (raw_output); coded_output-WriteRaw(send_data,strlen(send_data)); There is no way to specify what the port and IP address is here, analogous to when using the standard sendto() socket writing call. So my message never gets received by the intended recipient on the network. I am aware that this is a raw message, not a PB message. Getting this raw message over the network is a first step in accomplishing the ultimate goal of getting the PB message over the network. Is there a way to get all of the bytes of a serialized PB message into raw form and then send them with sendto()? Any ideas? Thanks for any help. Jay --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
mutable
I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? Thanks! Jay --~--~-~--~~~---~--~~ 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: mutable
wow. I will try that. Yes, I am trying to set a complete 'foo' message. Is there documentation anywhere on this? I am coming up empty with web searches... On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ 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: mutable
message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ 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: mutable
so this has to be done whenever there is a compound type? I.e. types used for messages that are defined in other messages? If not, what is the rule for when a mutable pointer has to be obtained? I am also noticing that I am having what appears to be this same problem when using 'string' type for foo1. Trying to find a pattern here... Thanks so much for your help. You are a life saver... Jay On Sep 23, 8:47 am, Henner Zeller h.zel...@acm.org wrote: On Wed, Sep 23, 2009 at 08:45, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. Yeah, that will work with CopyFrom() msg_foo2.mutable_stuff1()-CopyFrom(foo1); On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ 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: mutable
so this has to be done whenever there is a compound type? I.e. types used for messages that are defined in other messages? If not, what is the rule for when a mutable pointer has to be obtained? I am also noticing that I am having what appears to be this same problem when using 'string' type for foo1. Trying to find a pattern here... Thanks so much for your help. You are a life saver... Jay On Sep 23, 8:47 am, Henner Zeller h.zel...@acm.org wrote: On Wed, Sep 23, 2009 at 08:45, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. Yeah, that will work with CopyFrom() msg_foo2.mutable_stuff1()-CopyFrom(foo1); On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ 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: mutable
so this has to be done whenever there is a compound type? I.e. types used for messages that are defined in other messages? If not, what is the rule for when a mutable pointer has to be obtained? I am also noticing that I am having what appears to be this same problem when using 'string' type for foo1. Trying to find a pattern here... Thanks so much for your help. You are a life saver... Jay On Sep 23, 8:47 am, Henner Zeller h.zel...@acm.org wrote: On Wed, Sep 23, 2009 at 08:45, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. Yeah, that will work with CopyFrom() msg_foo2.mutable_stuff1()-CopyFrom(foo1); On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ 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: mutable
what about if you have something like message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { repeated foo1 stuff1 = 1; optional foo1 stuff2 = 2; } do you know how to add another stuff1 to foo2 structure? On Sep 23, 8:45 am, jayt0...@gmail.com jayt0...@gmail.com wrote: message foo1 { optional int32 value1 = 1; optional int32 value2 = 2; } message foo2 { optional foo1 stuff1 = 1; optional foo2 stuff2 = 2; } foo1 msg_foo1; foo2 msg_foo2; msg_foo2.set_stuff1(foo1); This is the concept of what I'm trying to do. On Sep 23, 8:25 am, Henner Zeller h.zel...@acm.org wrote: Hi, On Wed, Sep 23, 2009 at 08:13, jayt0...@gmail.com jayt0...@gmail.com wrote: I am having trouble accessing many members of my .proto file. It seems that compound members are not accessible with set_() method calls. I saw in your example code the use of mutable_() calls. What does this apply to and is there documentation on it? could this be the solution to my problem? You should describe your problem more closely, it is not quite clear what you mean. If you have a message Bar, that contains a message Foo, say: message Foo { optional int32 value = 1; } message Bar { optional Foo foo = 1; } you would access 'foo' to set a value with Bar message; message.mutable_foo()-set_value(42); If there is no 'foo', it will implicitly be created (so has_bar() will return 'true' afterwards'). .. while accessing can be const if (message.has_foo()) printf(%d, message.bar().value()); But it sounds like you would like to 'set' a complete Foo message. So if you want to 'set' a complete Foo, you would use CopyFrom() Foo foo_message; foo_message.set_value(42); Bar bar_message; bar_message.mutable_bar()-CopyFrom(foo_message); -h --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---