>All pointer fields can be null. Because all types in Cap'n Proto have a default value, you don't need to return optionals; you can return the default value when a `getFoo()` accessor reads a null. You should additionally provide `hasFoo()` accessors for when the user actually wants to distinguish the null case.
I'm a little confused by the documentation on this one. What is the default value of a struct? This section <https://capnproto.org/encoding.html#default-values> seems to only be about structs inside lists, but even so I'm struggling to understand where I should be looking. If I have an all-zero pointer, where is the default value stored? Where would I store the value a user sets? >However, if you were decoding Cap'n Proto messages into stand-alone Swift-native plain-old-data structs, then yes, you would in general need to make pointer fields optional, because otherwise values of a recursive type (e.g. `struct Bar { bar @0 :Bar; }`) would be infinitely large. Gotcha. Unrelated note: making the properties optional does not work in swift, the following does not compile (recursive values need to be wrapped in a reference type, optionals are still a value type. You would need a `class Box` of some sort, which is messy) struct Foo { let foo: Foo? } Dan On Wed, Sep 21, 2016 at 6:08 AM David Renshaw <da...@sandstorm.io> wrote: > On Tue, Sep 20, 2016 at 9:48 PM, Dan Appel <dan.appe...@gmail.com> wrote: > >> Does this mean that every field (including lists) is nullable? That's >> quite a shame. Looks like all my generated fields are going to be >> implicitly-unwrapped-optional, then (reminds me of objective-c translated >> into swift). >> >> > All pointer fields can be null. Because all types in Cap'n Proto have a > default value, you don't need to return optionals; you can return the > default value when a `getFoo()` accessor reads a null. You should > additionally provide `hasFoo()` accessors for when the user actually wants > to distinguish the null case. > > However, if you were decoding Cap'n Proto messages into stand-alone > Swift-native plain-old-data structs, then yes, you would in general need to > make pointer fields optional, because otherwise values of a recursive type > (e.g. `struct Bar { bar @0 :Bar; }`) would be infinitely large. > > - David > > > -- > You received this message because you are subscribed to the Google Groups > "Cap'n Proto" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to capnproto+unsubscr...@googlegroups.com. > Visit this group at https://groups.google.com/group/capnproto. > -- Dan Appel -- You received this message because you are subscribed to the Google Groups "Cap'n Proto" group. To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+unsubscr...@googlegroups.com. Visit this group at https://groups.google.com/group/capnproto.