Re: How to write a protocol buffer message which correspond to java.util.Map
-Thanks for all your replies On Aug 26, 9:19 pm, Kenton Varda wrote: > I'd recommend the array-of-pairs method because the parallel-arrays method > leaves you open to bugs where if the arrays aren't the same size and your > code doesn't carefully check for this, it could easily end up crashing due > to out-of-bounds accesses. This could be a security problem. Stick with > arrays of pairs and avoid the risk. The overhead isn't that big a deal. > > 2009/8/26 Alkis Evlogimenos ('Αλκης Ευλογημένος) > > > > > This incurs some serialization overhead and also in-memory/object overhead > > (in C++ it is not sure about Java). If that is not an issue (your strings > > are huge for example) what you suggest is a bit more self-documenting. > > > 2009/8/26 DeWitt Clinton > > > I've also used the pattern: > >> message Map { > >> message Entry { > >> optional string name = 1; > >> optional string value = 2; > >> } > >> repeated Entry entries = 1; > >> } > > >> Alkis, do you see benefits or downsides between the two approaches? > > >> To the second question, perhaps pick a universal representation for dates, > >> such as RFC 3339 (http://tools.ietf.org/html/rfc3339) and use a string? > > >> -DeWitt > > >> 2009/8/26 rajesh > > >>> -Thanks > > >>> On Aug 26, 2:46 pm, Alkis Evlogimenos ('Αλκης Ευλογημένος) > >>> wrote: > >>> > Protocol buffers do not have a protobuf map equivalent. What is usually > >>> done > >>> > is to put 2 repeated fields in the proto, one for the keys and one for > >>> the > >>> > values of the map you are trying to represent. > > >>> > On Wed, Aug 26, 2009 at 7:13 PM, rajesh wrote: > > >>> > > Hi All, > >>> > > Iam kinda new to using protocol buffers, so this could be a > >>> > > dumb question. I am curious as to how or what should be the syntax of > >>> > > the protocol buffer message for Map implementations in java. I looked > >>> > > in the documentation, but dint find any such example message. > >>> > > Similarly what should be the field type in the protocol buffer > >>> message > >>> > > which corresponds to Date implemetations in java. I would appreciate > >>> > > if some one can guide me through this or point me to the > >>> documentation > >>> > > which will help me understand this aspect better. Thanks in advance. > > >>> > > -Raj > > >>> > -- > > >>> > Alkis- Hide quoted text - > > >>> > - Show quoted text - > > > -- > > > Alkis- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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: How to write a protocol buffer message which correspond to java.util.Map
I'd recommend the array-of-pairs method because the parallel-arrays method leaves you open to bugs where if the arrays aren't the same size and your code doesn't carefully check for this, it could easily end up crashing due to out-of-bounds accesses. This could be a security problem. Stick with arrays of pairs and avoid the risk. The overhead isn't that big a deal. 2009/8/26 Alkis Evlogimenos ('Αλκης Ευλογημένος) > This incurs some serialization overhead and also in-memory/object overhead > (in C++ it is not sure about Java). If that is not an issue (your strings > are huge for example) what you suggest is a bit more self-documenting. > > 2009/8/26 DeWitt Clinton > > I've also used the pattern: >> message Map { >> message Entry { >>optional string name = 1; >>optional string value = 2; >> } >> repeated Entry entries = 1; >> } >> >> Alkis, do you see benefits or downsides between the two approaches? >> >> To the second question, perhaps pick a universal representation for dates, >> such as RFC 3339 (http://tools.ietf.org/html/rfc3339) and use a string? >> >> -DeWitt >> >> 2009/8/26 rajesh >> >> >>> -Thanks >>> >>> On Aug 26, 2:46 pm, Alkis Evlogimenos ('Αλκης Ευλογημένος) >>> wrote: >>> > Protocol buffers do not have a protobuf map equivalent. What is usually >>> done >>> > is to put 2 repeated fields in the proto, one for the keys and one for >>> the >>> > values of the map you are trying to represent. >>> > >>> > >>> > >>> > >>> > >>> > On Wed, Aug 26, 2009 at 7:13 PM, rajesh wrote: >>> > >>> > > Hi All, >>> > > Iam kinda new to using protocol buffers, so this could be a >>> > > dumb question. I am curious as to how or what should be the syntax of >>> > > the protocol buffer message for Map implementations in java. I looked >>> > > in the documentation, but dint find any such example message. >>> > > Similarly what should be the field type in the protocol buffer >>> message >>> > > which corresponds to Date implemetations in java. I would appreciate >>> > > if some one can guide me through this or point me to the >>> documentation >>> > > which will help me understand this aspect better. Thanks in advance. >>> > >>> > > -Raj >>> > >>> > -- >>> > >>> > Alkis- Hide quoted text - >>> > >>> > - Show quoted text - >>> >>> >> >> >> > > > -- > > Alkis > > > > > --~--~-~--~~~---~--~~ 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: How to write a protocol buffer message which correspond to java.util.Map
This incurs some serialization overhead and also in-memory/object overhead (in C++ it is not sure about Java). If that is not an issue (your strings are huge for example) what you suggest is a bit more self-documenting. 2009/8/26 DeWitt Clinton > I've also used the pattern: > message Map { > message Entry { >optional string name = 1; >optional string value = 2; > } > repeated Entry entries = 1; > } > > Alkis, do you see benefits or downsides between the two approaches? > > To the second question, perhaps pick a universal representation for dates, > such as RFC 3339 (http://tools.ietf.org/html/rfc3339) and use a string? > > -DeWitt > > 2009/8/26 rajesh > > >> -Thanks >> >> On Aug 26, 2:46 pm, Alkis Evlogimenos ('Αλκης Ευλογημένος) >> wrote: >> > Protocol buffers do not have a protobuf map equivalent. What is usually >> done >> > is to put 2 repeated fields in the proto, one for the keys and one for >> the >> > values of the map you are trying to represent. >> > >> > >> > >> > >> > >> > On Wed, Aug 26, 2009 at 7:13 PM, rajesh wrote: >> > >> > > Hi All, >> > > Iam kinda new to using protocol buffers, so this could be a >> > > dumb question. I am curious as to how or what should be the syntax of >> > > the protocol buffer message for Map implementations in java. I looked >> > > in the documentation, but dint find any such example message. >> > > Similarly what should be the field type in the protocol buffer message >> > > which corresponds to Date implemetations in java. I would appreciate >> > > if some one can guide me through this or point me to the documentation >> > > which will help me understand this aspect better. Thanks in advance. >> > >> > > -Raj >> > >> > -- >> > >> > Alkis- Hide quoted text - >> > >> > - Show quoted text - >> >> > > > > -- Alkis --~--~-~--~~~---~--~~ 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: How to write a protocol buffer message which correspond to java.util.Map
DeWitt Clinton writes: > I've also used the pattern: > > message Map { > message Entry { > optional string name = 1; > optional string value = 2; > } > repeated Entry entries = 1; > } > > Alkis, do you see benefits or downsides between the two approaches? With a message for each pair, you spend a few extra bytes to identify each embedded message (namely, the message tag and length), but you don't have to worry about keeping two arrays synchronized with each other. My personal inclination would be for the embedded message unless the dictionary has extremely many elements -- but if it were that large, I would probably not pass the whole thing in one chunk anyway. Michael Poole --~--~-~--~~~---~--~~ 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: How to write a protocol buffer message which correspond to java.util.Map
I've also used the pattern: message Map { message Entry { optional string name = 1; optional string value = 2; } repeated Entry entries = 1; } Alkis, do you see benefits or downsides between the two approaches? To the second question, perhaps pick a universal representation for dates, such as RFC 3339 (http://tools.ietf.org/html/rfc3339) and use a string? -DeWitt 2009/8/26 rajesh > > -Thanks > > On Aug 26, 2:46 pm, Alkis Evlogimenos ('Αλκης Ευλογημένος) > wrote: > > Protocol buffers do not have a protobuf map equivalent. What is usually > done > > is to put 2 repeated fields in the proto, one for the keys and one for > the > > values of the map you are trying to represent. > > > > > > > > > > > > On Wed, Aug 26, 2009 at 7:13 PM, rajesh wrote: > > > > > Hi All, > > > Iam kinda new to using protocol buffers, so this could be a > > > dumb question. I am curious as to how or what should be the syntax of > > > the protocol buffer message for Map implementations in java. I looked > > > in the documentation, but dint find any such example message. > > > Similarly what should be the field type in the protocol buffer message > > > which corresponds to Date implemetations in java. I would appreciate > > > if some one can guide me through this or point me to the documentation > > > which will help me understand this aspect better. Thanks in advance. > > > > > -Raj > > > > -- > > > > Alkis- Hide quoted text - > > > > - Show quoted text - > > > --~--~-~--~~~---~--~~ 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: How to write a protocol buffer message which correspond to java.util.Map
2009/8/26 Alkis Evlogimenos ('Αλκης Ευλογημένος) : > Protocol buffers do not have a protobuf map equivalent. What is usually done > is to put 2 repeated fields in the proto, one for the keys and one for the > values of the map you are trying to represent. Or a repeated embedded message with a key and a value. > > On Wed, Aug 26, 2009 at 7:13 PM, rajesh wrote: >> >> >> Hi All, >> Iam kinda new to using protocol buffers, so this could be a >> dumb question. I am curious as to how or what should be the syntax of >> the protocol buffer message for Map implementations in java. I looked >> in the documentation, but dint find any such example message. >> Similarly what should be the field type in the protocol buffer message >> which corresponds to Date implemetations in java. I would appreciate >> if some one can guide me through this or point me to the documentation >> which will help me understand this aspect better. Thanks in advance. >> >> -Raj >> > > > > -- > > Alkis > > > > --~--~-~--~~~---~--~~ 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: How to write a protocol buffer message which correspond to java.util.Map
-Thanks On Aug 26, 2:46 pm, Alkis Evlogimenos ('Αλκης Ευλογημένος) wrote: > Protocol buffers do not have a protobuf map equivalent. What is usually done > is to put 2 repeated fields in the proto, one for the keys and one for the > values of the map you are trying to represent. > > > > > > On Wed, Aug 26, 2009 at 7:13 PM, rajesh wrote: > > > Hi All, > > Iam kinda new to using protocol buffers, so this could be a > > dumb question. I am curious as to how or what should be the syntax of > > the protocol buffer message for Map implementations in java. I looked > > in the documentation, but dint find any such example message. > > Similarly what should be the field type in the protocol buffer message > > which corresponds to Date implemetations in java. I would appreciate > > if some one can guide me through this or point me to the documentation > > which will help me understand this aspect better. Thanks in advance. > > > -Raj > > -- > > Alkis- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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: How to write a protocol buffer message which correspond to java.util.Map
Protocol buffers do not have a protobuf map equivalent. What is usually done is to put 2 repeated fields in the proto, one for the keys and one for the values of the map you are trying to represent. On Wed, Aug 26, 2009 at 7:13 PM, rajesh wrote: > > > Hi All, > Iam kinda new to using protocol buffers, so this could be a > dumb question. I am curious as to how or what should be the syntax of > the protocol buffer message for Map implementations in java. I looked > in the documentation, but dint find any such example message. > Similarly what should be the field type in the protocol buffer message > which corresponds to Date implemetations in java. I would appreciate > if some one can guide me through this or point me to the documentation > which will help me understand this aspect better. Thanks in advance. > > -Raj > > > -- Alkis --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---