From cb8e9d15dec878db03e53fee1dbc97c89b2b6f73 Mon Sep 17 00:00:00 2001 From: heroichornet Date: Sun, 11 Feb 2024 16:00:35 +0100 Subject: [PATCH] refactoring example --- src/ffi/mod.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index 4e1accd..97e3bd8 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -1,7 +1,8 @@ -extern crate libc; +#![no_std] + use libc::{uint8_t, size_t}; +use core::slice; -// Representing the C enum in Rust #[repr(C)] #[derive(Debug, PartialEq)] pub enum ParseStatus { @@ -9,23 +10,17 @@ pub enum ParseStatus { ParseError = 1, } -extern "C" { - pub fn parse_mbus(data: *const uint8_t, length: size_t) -> ParseStatus; -} - - #[no_mangle] pub extern "C" fn parse_mbus(data: *const uint8_t, length: size_t) -> ParseStatus { - if data.is_null() || length == 0 { return ParseStatus::ParseError; } let slice = unsafe { - std::slice::from_raw_parts(data, length as usize) + slice::from_raw_parts(data, length as usize) }; - /* dummy code */ + // Implement your parsing logic here if slice.len() == 5 { ParseStatus::ParseOk } else {