]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
rust/applayer: define AppLayerEvent trait
authorJason Ish <jason.ish@oisf.net>
Mon, 19 Oct 2020 16:30:29 +0000 (10:30 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 1 Sep 2021 06:33:52 +0000 (08:33 +0200)
The derive macro will implement this trait for app-layer
event enums.

rust/src/applayer.rs

index 58bb36723eeaed04970130ab30f17e84f6dc62f0..084e8d0bf9ca235e4770c1cf765e9387b1f07921 100644 (file)
@@ -415,3 +415,19 @@ macro_rules!export_tx_set_detect_state {
         }
     )
 }
+
+/// AppLayerEvent trait that will be implemented on enums that
+/// derive AppLayerEvent.
+pub trait AppLayerEvent {
+    /// Return the enum variant of the given ID.
+    fn from_id(id: i32) -> Option<Self> where Self: std::marker::Sized;
+
+    /// Convert the enum variant to a C-style string (suffixed with \0).
+    fn to_cstring(&self) -> &str;
+
+    /// Return the enum variant for the given name (as a CStr).
+    fn from_cstring(s: &std::ffi::CStr) -> Option<Self> where Self: std::marker::Sized;
+
+    /// Return the ID value of the enum variant.
+    fn as_i32(&self) -> i32;
+}