alphaHeavy / protobuf

An implementation of Google's Protocol Buffers in Haskell.
http://hackage.haskell.org/package/protobuf
BSD 3-Clause "New" or "Revised" License
96 stars 18 forks source link

Default values for optional fields #20

Open jabolopes opened 8 years ago

jabolopes commented 8 years ago

Hi,

Do you have any plans to implement default values for optional fields?

Thanks, Jose

NathanHowell commented 8 years ago

I wasn't really planning to do it myself but it should be easy to add (at least for message decoding), and would certainly increase compatibility with existing descriptors.

If you'd like to take a stab at it, I'd start by adding a function similar to decodeMessage that also takes a default message argument... and use that instead of HashMap.empty here: https://github.com/alphaHeavy/protobuf/blob/master/src/Data/ProtocolBuffers/Decode.hs#L40