# Policy script enums (and event engine interaction)

**URL:** <https://community.zeek.org/t/policy-script-enums-and-event-engine-interaction/1748>\
**Category:** Development\
**Tags:** development\
**Created:** [December 8, 2010, 2:31am UTC](https://community.zeek.org/t/policy-script-enums-and-event-engine-interaction/1748 "2010-12-08T02:31:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregor\_Maier](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Gregor\_Maier](https://community.zeek.org/u/Gregor_Maier)\
**Post date:** [December 8, 2010, 2:31am UTC](https://community.zeek.org/t/policy-script-enums-and-event-engine-interaction/1748/1 "2010-12-08T02:31:19Z")

</div>

Hi,

another question:  
it seems that I can't specify the value that my enums should have, i.e.,  
I can't do a  
&nbsp;&nbsp;enum { foo = 2, bar = 3 }

So, it seems that I'll have to use global const to simulate the  
behavior. But the nice feature of enums is that if I print them with %s,  
I get their name instead of their value. Is there any way to simulate  
this (without using a table to map values-\>names?)

Looking a bit more at the event engine, it seems that there's no case in  
which an enum is passed from the event engine to the policy layer as  
part of an event. It also seems that there's no way to coerce an integer  
into an enum, right (neither policy layer nor event engine).

I'm wondering whether there was a reason for not implementing that  
(e.g., would break something, enums should be policy layer only). If  
not, I guess my question is whether it would make sense to add it (at  
some stage) as I think it would make handling of binary protocols easier.

(There seems to be one case (transport\_proto) were there's interaction  
in bro.bif, but it requires a lot of glue functions).

cu  
gregor

---

<div class="post-metadata">

**Author:** ![Gregor\_Maier](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Gregor\_Maier](https://community.zeek.org/u/Gregor_Maier)\
**Post date:** [December 8, 2010, 6:26am UTC](https://community.zeek.org/t/policy-script-enums-and-event-engine-interaction/1748/2 "2010-12-08T06:26:29Z")

</div>

Hmm, I partially found the solution. Adding an enum in const.bif seem to  
do the trick for using one enum definition in both the policy layer and  
the event engine.

Also found how to coerce integer into EnumVal in the event engine (but  
still don't know how to achieve this in the policy layer).

Enums with pre-assigned values still don't work though ☹

cu  
Gregor

---

<div class="post-metadata">

**Author:** ![Gregor\_Maier](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Gregor\_Maier](https://community.zeek.org/u/Gregor_Maier)\
**Post date:** [December 8, 2010, 7:54am UTC](https://community.zeek.org/t/policy-script-enums-and-event-engine-interaction/1748/3 "2010-12-08T07:54:53Z")

</div>

I think I'll actually add this to the bif-language and the  
bro-policy-lanague, so that one can indeed specify  
&nbsp;&nbsp;&nbsp;&nbsp;enum { ASDF=4, FOO=7, BAR=0, }  
in .bro and .bif files.

.... unless somebody thinks this is a bad idea.

cu  
Gregor

---

<div class="post-metadata">

**Author:** ![Vern](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/vern/32/630_2.png) [@Vern](https://community.zeek.org/u/Vern)\
**Post date:** [December 8, 2010, 9:37pm UTC](https://community.zeek.org/t/policy-script-enums-and-event-engine-interaction/1748/4 "2010-12-08T21:37:03Z")

</div>

> .... unless somebody thinks this is a bad idea.

For completeness, Gregor & I just discussed this and the plan is to go  
ahead with adding this feature at some point. (Note, the support won't  
include enum\<-\>int conversion.)

&nbsp;&nbsp;&nbsp;&nbsp;Vern

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [December 9, 2010, 10:58am UTC](https://community.zeek.org/t/policy-script-enums-and-event-engine-interaction/1748/5 "2010-12-09T10:58:36Z")

</div>

Can you guys elaborate on this? I would think we dont' want implicit  
conversions, but some form of explicit cast would be nice to have  
both ways.

Robin

---

<div class="post-metadata">

**Author:** ![Vern](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/vern/32/630_2.png) [@Vern](https://community.zeek.org/u/Vern)\
**Post date:** [December 9, 2010, 5:25pm UTC](https://community.zeek.org/t/policy-script-enums-and-event-engine-interaction/1748/6 "2010-12-09T17:25:17Z")

</div>

> \> (Note, the support won't  
> \> include enum\<-\>int conversion.)
> 
> Can you guys elaborate on this? I would think we dont' want implicit  
> conversions, but some form of explicit cast would be nice to have  
> both ways.

I resist adding language features/flexibility without clear use cases.

Casting enum\<-\>int weakens type safety, so there should be a clear need  
to have it anyway. So far, we don't have that. If we do, then we can  
revisit it to determine whether general explicit coercion is indeed the  
best way to support the need.

&nbsp;&nbsp;&nbsp;&nbsp;Vern

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:39pm UTC](https://community.zeek.org/t/policy-script-enums-and-event-engine-interaction/1748/7 "2022-05-06T15:39:19Z")

</div>

Closed on May 6, 2022, 3:39pm UTC


