use pyo3::{ffi, prelude::*, PyResult};
use std::os::raw::c_int;
use crate::Bytes;
#[pyclass(name = "Bytes")]
pub struct PyAnyBytes {
bytes: Bytes,
}
#[pymethods]
impl PyAnyBytes {
unsafe fn __getbuffer__(
slf: PyRefMut<Self>,
view: *mut ffi::Py_buffer,
flags: c_int,
) -> PyResult<()> {
let bytes = slf.bytes.as_slice();
let ret = ffi::PyBuffer_FillInfo(
view,
slf.as_ptr() as *mut _,
bytes.as_ptr() as *mut _,
bytes.len().try_into().unwrap(),
1, flags,
);
if ret == -1 {
return Err(PyErr::fetch(slf.py()));
}
Ok(())
}
}
impl PyAnyBytes {
pub fn new(bytes: Bytes) -> Self {
Self { bytes }
}
}