From: Jason Ish Date: Mon, 19 Oct 2020 16:30:29 +0000 (-0600) Subject: rust/applayer: define AppLayerEvent trait X-Git-Tag: suricata-7.0.0-beta1~1472 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbea7d636f5f9d85856c024b7462fbe3d4229d72;p=thirdparty%2Fsuricata.git rust/applayer: define AppLayerEvent trait The derive macro will implement this trait for app-layer event enums. --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 58bb36723e..084e8d0bf9 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -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 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 where Self: std::marker::Sized; + + /// Return the ID value of the enum variant. + fn as_i32(&self) -> i32; +}