Can `<field>` override presence of its type?
OleksandrKvl opened this issue · 2 comments
This is a generalization of unanswered #153. Documentation says that <field> inherits presence from its type but it doesn't say if or when it can be overridden. I believe documentation is a bit wrong because it says that the default value for presence is required, however looks like this can be true only if a field is of a built-in type, in all other cases presence by default is inherited from a custom type.
Here's a couple of tricky cases:
- type is
const, field using it is non-const, is it valid at all? - enum/set don't have
presenceat all, they are alwaysrequired, hencefield.presencedoesn't make much sense for them. - type is
optional, field isrequired, this has no implementation problems since one can just ignorenullValuebut does it make any sense? - type is
required, field isoptional, what should benullValuefor such a field? Btw, this means that field creates new type which is against field's nature (see below).
Current design feels like field was not intended to introduce new types, only reuse them. Because of that I think that the right way is to allow field to have presence only for built-in types. For all other cases it should be inherited (and can't be overridden) from type itself.
Please clarify how it should work.
The inheritance of attributes from elements to was a feature of SBE v1.0, but it was eliminated in v2.x because it was deemed confusing. In the v2.x schema, presence attribute is only used on <field> and the members of a composite type.
Nevertheless, v1.0 specification states that "presence mismatch" is an error. If the attribute is specified on both a field and the encoding that it references, the values must be identical.
Current design feels like field was not intended to introduce new types, only reuse them.
Agree.
Because of that I think that the right way is to allow field to have presence only for built-in types.
"built-in" is not a term used by the specification. Perhaps you mean primitives.
Thank you!