Bitfield to boolean

Hello there. I’m new to zeek and to coding in general. Wanted to recreate the iec-104 parser project from 2019. (GitHub - jjchromik/hilti-104: Docker image with files for IEC-104 parser). But due to zeek and spicy development over the last years, the code should be adjusted for a new syntax at least. After I did that I realised that I cant run the code because in this project bitfield elements should be bool for functions to work properly. I’m curious how can I do that, there is not much of a documentation on this topic on the internet, sry if my question silly.

data_unit_identifier : bitfield (8) {
        seq : 7;
        num_ix : 0..6;};

So iirc self.data_unit_identifier.seq should be bool for the next part of the code to work.

Since you are extracting a bitfield(8), its fields are extracted as uint8. You can use Integer’s cast operator to convert its value to a bool (I’ll look into why that operator is not documented); the easiest way to use the converted value is probably to store it in a unit variable.

type X = unit {
	data_unit_identifier: bitfield(8) {
		seq: 7;
		num_ix: 0..6;
	} {
		self.seq = cast<bool>($$.seq);

	var seq: bool;
	on %init {
		self.seq = True; # TODO: Initialize to some reasonable default.