use odpi::structs::ODPIEncodingInfo;
use std::ffi::CStr;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Info {
encoding: String,
nchar_encoding: String,
max_bytes_per_char: i32,
max_bytes_per_nchar: i32,
}
impl Info {
pub fn encoding(&self) -> &str {
&self.encoding
}
pub fn nchar_encoding(&self) -> &str {
&self.nchar_encoding
}
pub fn max_bytes_per_char(&self) -> i32 {
self.max_bytes_per_char
}
pub fn max_bytes_per_nchar(&self) -> i32 {
self.max_bytes_per_nchar
}
}
impl From<ODPIEncodingInfo> for Info {
fn from(oei: ODPIEncodingInfo) -> Self {
unsafe {
let enc = CStr::from_ptr(oei.encoding);
let nchar_enc = CStr::from_ptr(oei.nchar_encoding);
Self {
encoding: enc.to_string_lossy().into_owned(),
nchar_encoding: nchar_enc.to_string_lossy().into_owned(),
max_bytes_per_char: oei.max_bytes_per_character,
max_bytes_per_nchar: oei.nchar_max_bytes_per_character,
}
}
}
}