Discussion:
[capnproto] How to make a constant list of enumeration values in capn proto schema file
f***@prenav.com
2018-10-02 23:28:03 UTC
Permalink
Hi.

I am trying to make a list of constant enumeration values in a capn proto
schema file.

enum foo{
unset @0;
bar @1;
bars @2;
}


const fooStates :List(foo) = [foo.unset, foo.bar, foo.bars];


However, the report of the parser is that unset is not a member of foo. I tried foo.Unset, foo.UNSET, foo::unset, foo::UNSET and nothing worked. foo.unset and foo.UNSET also failed due to unset (UNSET) not being a member of foo and foo::XXX fails due to a parse error.


I can workaround the language limitation by making a list of ints but that is prone to error in the face of changes to the foo enumeration.


const fooStates :List(UInt16) = [1, 2, 3];


Is there a way to make a list of enum values as a constant in a captn proto schema file?


Thanks in advance!


Forest
--
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+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
'Kenton Varda' via Cap'n Proto
2018-10-02 23:54:10 UTC
Permalink
Hi Forest,

You can do:

const fooStates :List(foo) = [unset, bar, bars];

The parser knows that you're parsing values of type "foo", so it doesn't
need the "foo." context.

-Kenton
Post by f***@prenav.com
Hi.
I am trying to make a list of constant enumeration values in a capn proto
schema file.
enum foo{
}
const fooStates :List(foo) = [foo.unset, foo.bar, foo.bars];
However, the report of the parser is that unset is not a member of foo. I tried foo.Unset, foo.UNSET, foo::unset, foo::UNSET and nothing worked. foo.unset and foo.UNSET also failed due to unset (UNSET) not being a member of foo and foo::XXX fails due to a parse error.
I can workaround the language limitation by making a list of ints but that is prone to error in the face of changes to the foo enumeration.
const fooStates :List(UInt16) = [1, 2, 3];
Is there a way to make a list of enum values as a constant in a captn proto schema file?
Thanks in advance!
Forest
--
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
Visit this group at https://groups.google.com/group/capnproto.
--
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+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
f***@prenav.com
2018-10-03 00:33:43 UTC
Permalink
Thanks a ton!

Forest
Post by 'Kenton Varda' via Cap'n Proto
Hi Forest,
const fooStates :List(foo) = [unset, bar, bars];
The parser knows that you're parsing values of type "foo", so it doesn't
need the "foo." context.
-Kenton
Post by f***@prenav.com
Hi.
I am trying to make a list of constant enumeration values in a capn proto
schema file.
enum foo{
}
const fooStates :List(foo) = [foo.unset, foo.bar, foo.bars];
However, the report of the parser is that unset is not a member of foo. I tried foo.Unset, foo.UNSET, foo::unset, foo::UNSET and nothing worked. foo.unset and foo.UNSET also failed due to unset (UNSET) not being a member of foo and foo::XXX fails due to a parse error.
I can workaround the language limitation by making a list of ints but that is prone to error in the face of changes to the foo enumeration.
const fooStates :List(UInt16) = [1, 2, 3];
Is there a way to make a list of enum values as a constant in a captn proto schema file?
Thanks in advance!
Forest
--
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
Visit this group at https://groups.google.com/group/capnproto.
--
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+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
Loading...