use endianity::{Endianity, EndianBuf};
use parser::{parse_null_terminated_string, ParseResult};
use std::ffi;
use std::marker::PhantomData;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DebugStrOffset(pub u64);
#[derive(Debug, Clone, Copy)]
pub struct DebugStr<'input, Endian>
where Endian: Endianity
{
debug_str_section: EndianBuf<'input, Endian>,
}
impl<'input, Endian> DebugStr<'input, Endian>
where Endian: Endianity
{
pub fn new(debug_str_section: &'input [u8]) -> DebugStr<'input, Endian> {
DebugStr { debug_str_section: EndianBuf(debug_str_section, PhantomData) }
}
pub fn get_str(&self, offset: DebugStrOffset) -> ParseResult<&ffi::CStr> {
let result = parse_null_terminated_string(&self.debug_str_section[offset.0 as usize ..]);
result.map(|(_, cstr)| cstr)
}
}