[protobuf] gcc4.4 fixes: std::tr1::unordered_map
Hey Kenton, attached is a patch that clears "deprecated headers" warnings emitted when building protobuf with g++4.4. The fix has two parts: a) discover and use std::tr1::unordered_map when it is available b) ensure that string hashing is available and working I've tested the updated code with g++4.4, g++4.1 and g++3.4. Unfortunately the last two share the same old crusty libstdc++ due to the way Redhad built it... P.S. I've taken a liberty to reformat and re-order declarations in .../stubs/hash.h while debugging the hash issue. Oleg. -- 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-map.patch Description: Binary data
Re: [protobuf] Re: Builders containing builders
toBuilder() makes only a shallow copy of the object. It does not copy the contents of individual Strings, ByteStrings, sub-messages, etc.; it just reuses the existing values. This means that it's generally reasonably cheap, although obviously not quite as cheap as if the builders for sub-objects were kept around by the parent. I'd suggest doing tests to see if this is a problem for your app before trying to change protocol buffers. On Wed, Dec 16, 2009 at 5:37 PM, Mark wrote: > Yes, this seems nice: > > Foo.Builder builder; > builder.setBar(builder.getBar().toBuilder().setA(...).build()); > > But I guess I'm a little worried about its hidden cost if I use it a > lot. If message Bar was very large, then would converting it to a > builder, setting one value, and converting it back to a message again > incur a large cost? That is, is the time cost of setting one of a > builder's sub-message's values proportional to the total size of the > sub-message? That would be quite different than the cost of setting > one of a builder's values, which is constant. > > If I know that a message of type Foo contains some Foo-specific > information, then I'd want to be able to write code that reads a > message of type Foo and gives me back that information. Like in your > example, I know that a Foo message has some "a" information and some > "b" information. I could write a method GetA(Foo) : int32 ... well, > Option anyway. (It might be null.) Then if I later decided to > move the field "a" from Bar to Foo I wouldn't have to change client > code of GetA(Foo) at all. It would be just as fast, too, because there > really isn't any difference between msg.getBar().getA() and msg.getA > (). I can do this right now, which is great. > > But writing is a different story. Let's say I moved "a" from Bar to > Foo. I know that I can write to a builder of type Foo.Builder some "a" > information and some "b" information. I could write a method SetA > (Foo.Builder, int32) : unit that just invokes the setA method in > Foo.Builder. But then, if I decided to move "a" back to Bar, then my > implementation of SetA(Foo.Builder, int32) : unit has to change a lot. > I might have to convert Foo's bar from a message to a builder, set "a" > in it, and rebuild the updated Bar message. That doesn't change the > type signature of SetA but it might have a big effect on the cost of > calling the method. > > If builders could contain builders, however, then I'd know for sure > that I could change where "a" lives without significantly affecting > the performance of methods like SetA! > > And I do those kinds of changes to my protocol a lot--I'm always > rearranging how information relates to each other as my applications > evolve. Is it just me? > > On Dec 16, 11:55 am, Jason Hsueh wrote: > > You should be able to pass a builder to some method, and have the method > > modify some value of the builder just fine. > > > > Modifying a value in a sub-message is a bit more inconvenient, but still > > doable. If you have some type Bar in type Foo like: > > message Bar { > > optional int32 a = 1; > > optional int32 b = 2; > > > > } > > > > message Foo { > > optional Bar bar = 1; > > > > } > > > > Foo.Builder builder; > > builder.setBar(builder.getBar().toBuilder().setA(...).build()); > > > > Would that work for you? > > > > > > > > On Wed, Dec 16, 2009 at 9:24 AM, Mark wrote: > > > I wish I could pass a builder object to a method and have the method > > > modify either a value of the builder or a value of a sub-message in > > > the builder! > > > > > I came across this thread, which described exactly the problem I have. > > > The Car/Engine example in the thread is perfectly illustrative of my > > > scenario. > > > > >http://groups.google.com/group/protobuf/browse_thread/thread/16997910. > .. > > > > > Has anyone else been in this same situation? What have you done to > > > ameliorate the problem? > > > > > -- > > > > > 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. > > > -- 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://g
[protobuf] Re: Builders containing builders
Yes, this seems nice: Foo.Builder builder; builder.setBar(builder.getBar().toBuilder().setA(...).build()); But I guess I'm a little worried about its hidden cost if I use it a lot. If message Bar was very large, then would converting it to a builder, setting one value, and converting it back to a message again incur a large cost? That is, is the time cost of setting one of a builder's sub-message's values proportional to the total size of the sub-message? That would be quite different than the cost of setting one of a builder's values, which is constant. If I know that a message of type Foo contains some Foo-specific information, then I'd want to be able to write code that reads a message of type Foo and gives me back that information. Like in your example, I know that a Foo message has some "a" information and some "b" information. I could write a method GetA(Foo) : int32 ... well, Option anyway. (It might be null.) Then if I later decided to move the field "a" from Bar to Foo I wouldn't have to change client code of GetA(Foo) at all. It would be just as fast, too, because there really isn't any difference between msg.getBar().getA() and msg.getA (). I can do this right now, which is great. But writing is a different story. Let's say I moved "a" from Bar to Foo. I know that I can write to a builder of type Foo.Builder some "a" information and some "b" information. I could write a method SetA (Foo.Builder, int32) : unit that just invokes the setA method in Foo.Builder. But then, if I decided to move "a" back to Bar, then my implementation of SetA(Foo.Builder, int32) : unit has to change a lot. I might have to convert Foo's bar from a message to a builder, set "a" in it, and rebuild the updated Bar message. That doesn't change the type signature of SetA but it might have a big effect on the cost of calling the method. If builders could contain builders, however, then I'd know for sure that I could change where "a" lives without significantly affecting the performance of methods like SetA! And I do those kinds of changes to my protocol a lot--I'm always rearranging how information relates to each other as my applications evolve. Is it just me? On Dec 16, 11:55 am, Jason Hsueh wrote: > You should be able to pass a builder to some method, and have the method > modify some value of the builder just fine. > > Modifying a value in a sub-message is a bit more inconvenient, but still > doable. If you have some type Bar in type Foo like: > message Bar { > optional int32 a = 1; > optional int32 b = 2; > > } > > message Foo { > optional Bar bar = 1; > > } > > Foo.Builder builder; > builder.setBar(builder.getBar().toBuilder().setA(...).build()); > > Would that work for you? > > > > On Wed, Dec 16, 2009 at 9:24 AM, Mark wrote: > > I wish I could pass a builder object to a method and have the method > > modify either a value of the builder or a value of a sub-message in > > the builder! > > > I came across this thread, which described exactly the problem I have. > > The Car/Engine example in the thread is perfectly illustrative of my > > scenario. > > >http://groups.google.com/group/protobuf/browse_thread/thread/16997910... > > > Has anyone else been in this same situation? What have you done to > > ameliorate the problem? > > > -- > > > 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 > om> > > . > > 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.
Re: [protobuf] Builders containing builders
> I wish I could pass a builder object to a method and have the method > modify either a value of the builder or a value of a sub-message in > the builder! > > I came across this thread, which described exactly the problem I have. > The Car/Engine example in the thread is perfectly illustrative of my > scenario. > > http://groups.google.com/group/protobuf/browse_thread/thread/1699791071e92c83/fc77205a755721f0 > > Has anyone else been in this same situation? What have you done to > ameliorate the problem? Generally speaking, I use non-PB model objects as my primary in-memory representation, and then I serialize them on demand to get the PB representation when I need it. For instance, something like: public class Engine { private String make; private double volumeLiters; public EnginePb serialize() { return EnginePb.newBuilder().setMake(make).setVolumeLiters(volumeLiters).build(); } } public class Car { private Engine engine; private String make; private String name; public CarPb serialize() { return CarPb.newBuilder().setMake(make).setName(name).setEngine(engine.serialize()).build(); } } - Adam -- 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] Builders containing builders
You should be able to pass a builder to some method, and have the method modify some value of the builder just fine. Modifying a value in a sub-message is a bit more inconvenient, but still doable. If you have some type Bar in type Foo like: message Bar { optional int32 a = 1; optional int32 b = 2; } message Foo { optional Bar bar = 1; } Foo.Builder builder; builder.setBar(builder.getBar().toBuilder().setA(...).build()); Would that work for you? On Wed, Dec 16, 2009 at 9:24 AM, Mark wrote: > I wish I could pass a builder object to a method and have the method > modify either a value of the builder or a value of a sub-message in > the builder! > > I came across this thread, which described exactly the problem I have. > The Car/Engine example in the thread is perfectly illustrative of my > scenario. > > > http://groups.google.com/group/protobuf/browse_thread/thread/1699791071e92c83/fc77205a755721f0 > > Has anyone else been in this same situation? What have you done to > ameliorate the problem? > > -- > > 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] Builders containing builders
I wish I could pass a builder object to a method and have the method modify either a value of the builder or a value of a sub-message in the builder! I came across this thread, which described exactly the problem I have. The Car/Engine example in the thread is perfectly illustrative of my scenario. http://groups.google.com/group/protobuf/browse_thread/thread/1699791071e92c83/fc77205a755721f0 Has anyone else been in this same situation? What have you done to ameliorate the problem? -- 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.