tail_core 0.1.1

Core library for the Tail operating system
Documentation
// Copyright 2025, TAIL OS. All Rights Reserved.
//
// You must obtain a written license from and pay applicable license fees to TAIL OS
// before you may reproduce, modify, or distribute this software, or any work that
// includes all or part of this software.
//
// Free development licenses are available for evaluation, research, and non-commercial
// purposes, which may include access to the source code under these terms. Redistribution
// or commercial use without a license is strictly prohibited.
//
// This file may contain contributions from others. Please review this entire file for
// other proprietary rights or license notices, as well as the TAIL OS License Guide at
// https://tail-os.com/license-guide/ for more information.
//
// For licensing inquiries, visit https://tail-os.com or email license@tail-os.com.


use core::marker::PhantomData;
use crate::error_kind::ErrorKind;

pub struct ServiceReplyData<T: ?Sized> {
    reply_message_ptr: *const u8,
    reply_message_size: usize,
    reply_message_error: Option<i64>,
    _marker: PhantomData<T>,
}

impl<T: Sized> ServiceReplyData<T> {
    pub fn new(reply_message_ptr: *const T, reply_message_size: usize, reply_message_error: Option<ErrorKind>) -> ServiceReplyData<T> {
        ServiceReplyData {
            reply_message_ptr: reply_message_ptr as *const u8,
            reply_message_size,
            reply_message_error: reply_message_error.map(|e| e.into()),
            _marker: PhantomData,
        }
    }

    pub fn get_reply_message_ref(&self) -> &T {
        unsafe { &*(self.reply_message_ptr as *const T) }
    }

    pub fn get_reply_message_ptr(&self) -> *const u8 {
        self.reply_message_ptr
    }

    pub fn get_reply_message_ptr_mut(&mut self) -> *mut u8 {
        self.reply_message_ptr as *mut u8
    }

    pub fn get_reply_message_size(&self) -> usize {
        self.reply_message_size
    }

    pub fn get_reply_message_error(&self) -> Option<i64> {
        self.reply_message_error
    }

    pub fn set_reply_message_size(&mut self, reply_message_size: usize) {
        self.reply_message_size = reply_message_size;
    }

    pub fn set_reply_message_error(&mut self, reply_message_error: Option<ErrorKind>) {
        self.reply_message_error = reply_message_error.map(|e| e.into());
    }
}