Hello
I'm writing a parser for GDTF-Format to start an open source lighting control project. GDTF is a new standard in entertainment industry to describe moving-heads and other fixtures in any possible way. Because there is not only an xml that describes it but also png, 3ds files aso. and because for practical use I will need some elements to be stored in hash-maps etc. I've decided not to use serde
but implement xml deparsing manually for more flexibilitiy. I've achieved much so far with quick-xml
.
Now I have a problem regarding an enum. In the GDTF spec there are multiple possible control attributes for lamps listed (like intensity, shutter, color red...) These possible attributes come in as &str. Because these attributes are important to access fast for controlling a light I've decided to setup an enum with all possible values.
I can match the &str and return the correct enum value on deparsing, but a lot of them have wildard placeholders for enumerate them in case of multiple control attributes that are the same. I've decided to set this placeholders as u8 to the enums that can use them.
Example
"Dimmer" -> AttributeName::Dimmer,
"Pan" -> AttributeName::Pan,
"Gobo1WheelShake" -> AttributeName::GoboNWheelShake(1),
"Gobo2WheelShake" -> AttributeName::GoboNWheelShake(2),
"VideoEffect1Parameter1" -> AttributeName::VideoEffectNParameterM(1,1),
"VideoEffect2Parameter1" -> AttributeName::VideoEffectNParameterM(2,1),
"VideoEffect1Parameter2" -> AttributeName::VideoEffectNParameterM(1,2)
I hope you get the idea out of these examples.
Now I could just have a long list of regex matches but the enum has over 250 items and I'm afraid that this would immensly slow down the deparsing.
I'm looking for something like this:
match my_str {
"Dimmer" => AttributeName::Dimmer,
"Pan" => AttributeName::Pan,
"Gobo(\d{1})WheelShake"(n) => AttributeName::GoboNWheelShake(n),
"VideoEffect(\d{1})Parameter(\d{1})"(n, m) => AttributeName::VideoEffectNParameterM(n,m),
}
Is there a possibility to regex match a string or any other way to solve this problem efficiently?
Any help ans suggestion appreciated.