float is 4 bytes on wire, while double is 8 bytes on wire. If you change float to double, in the case of old data and new parser, the parser will take the additional 4 bytes as double (these additional 4 bytes should belong to the next field in wire), in the case of new data and old parser, the parser will only take 4 bytes (which should be 8 bytes.)
On Wed, Nov 15, 2017 at 10:18 PM James Philbin <[email protected]> wrote: > But the type stored on the wire is known - so it seems like it could be > supported (simply static_cast<double>(float_val)). By 'some libraries': > does the C++ ParseFromString method do this or not? > > Thanks! > James > > On Wed, Nov 15, 2017 at 3:57 PM Marc Gravell <[email protected]> > wrote: > >> Not really, no. They take different amounts of space on the wire, and >> have a different declared wire type (header). Some libraries may choose to >> be gracious and apply the conversion silently, but other libraries could >> just say "unexpected wire type" and stop processing. >> >> You could perhaps do it as a `oneof`, and have the client check both? >> >> On 15 Nov 2017 11:51 p.m., "James Philbin" <[email protected]> wrote: >> >>> Hi, >>> >>> Is it safe to upgrade float fields to doubles for serialized protos? If >>> not, why not? >>> >>> Thanks, >>> James >>> >>> -- >>> >> 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 [email protected]. >> >> >>> To post to this group, send email to [email protected]. >>> 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 [email protected]. > To post to this group, send email to [email protected]. > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
