leejw51 / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

Unclear how default values 'work' (v1) #214

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using v1 of protobuf-net and I'm wondering how default values work.

For example:

I have a message with an optional uint32 field set to default '1'

I create that message and serialize as-is (didn't set any field) 

Will it:

1) serialize the field as '0' 
2) serialize the field as '1' 
3) serialize nothing (so on deserialization it'll use the configured default)

Also, does this behavior change when I set the optional field to 'required' ?

NOTE: I'm using the VS extension to generate .cs files from .proto files.

Original issue reported on code.google.com by tim@mylemans.com on 4 Aug 2011 at 9:18

GoogleCodeExporter commented 9 years ago
It depends ;p

When generating from .proto there is an optional "detectMissing" option, which 
can change the behaviour here. I *believe* that the template should configure 
things as either (2) or (3) depending on the option selected. If it is 
required, it should always be (2).

Marc

Original comment by marc.gravell on 4 Aug 2011 at 1:02

GoogleCodeExporter commented 9 years ago
I'm generating from .proto through the vs extension and I don't think I can 
specify such options there.

Original comment by tim@mylemans.com on 4 Aug 2011 at 5:27