#[cfg(not(zisk_guest))]
use crate::read_input;
use serde::{de::DeserializeOwned, Serialize};
pub fn read<T: DeserializeOwned>() -> T {
let bytes = read_slice();
let (val, _): (T, usize) =
bincode::serde::decode_from_slice(bytes.as_ref(), bincode::config::standard())
.expect("Deserialization failed");
val
}
#[cfg(zisk_guest)]
pub fn read_slice<'a>() -> &'a [u8] {
crate::read_slice_zerocopy()
}
#[allow(unused)]
#[cfg(not(zisk_guest))]
pub fn read_slice() -> Box<[u8]> {
read_input().into_boxed_slice()
}
#[cfg(zisk_guest)]
#[deprecated(since = "1.0.0-alpha", note = "renamed to `read_slice`")]
pub fn read_input_slice<'a>() -> &'a [u8] {
read_slice()
}
#[allow(unused)]
#[cfg(not(zisk_guest))]
#[deprecated(since = "1.0.0-alpha", note = "renamed to `read_slice`")]
pub fn read_input_slice() -> Box<[u8]> {
read_slice()
}
pub fn commit<T: Serialize>(value: &T) {
let bytes = bincode::serde::encode_to_vec(value, bincode::config::standard())
.expect("Serialization failed");
commit_slice(&bytes);
}
pub fn commit_slice(buf: &[u8]) {
unsafe { crate::zisklib::zkvm_io::write_output(buf.as_ptr(), buf.len()) };
}
pub fn write_output_reset() {
crate::zisklib::zkvm_io::reset_output();
}