You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Doug Cutting <cu...@apache.org> on 2013/08/13 18:25:13 UTC
Re: Explicit Values for Enums
Changing the serialization of schemas to use schema-specified values
would be difficult to achieve in a compatible manner. However
changing the values used in some programming languages might not be
difficult. In Java the ordinal value is not user-specifiable, but in
C and C++ it is. So such a schema property might be used by the C++
code generator.
Doug
On Sun, Jun 2, 2013 at 1:35 PM, William McKenzie
<ws...@cartewright.com> wrote:
> I did a few searches on Jira and couldn't find anything it, so apologies if
> this has been requested previously.
>
> It seems like it would be useful to allow an explicit value for enumeration
> members. I suppose the biggest argument against it would be that might have
> to be a breaking change to the schemas, since the current list of values is
> just an array of strings, but maybe it could be added as an optional schema
> field which would override the implicit sequential numbering.
>
> // Maybe?
> {
> "type": "enum",
> "name": "Roles",
> "symbols": [ "Producer", "Consumer" ]
> "values": [ 100, 101 ]
> }
>
> // This is just too ugly
> {
> "type": "enum",
> "name": "Roles",
> "symbols": [ "Producer=100", "Consumer=101" ]
> }
>
> // Alternating strings and values? still pretty ugly.
> {
> "type": "enum",
> "name": "Roles",
> "symbols": [ "Producer", 100, "Consumer", 101 ]
> }
>
> ~Bill