use serde::Serialize;
use serde_json::Value;
#[cfg(target_pointer_width = "64")]
pub use sonic_rs::Error as JsonError;
#[cfg(target_pointer_width = "32")]
pub use simd_json::Error as JsonError;
#[cfg(target_pointer_width = "64")]
#[inline]
pub fn from_str(s: &str) -> Result<Value, JsonError> {
sonic_rs::from_str(s)
}
#[cfg(target_pointer_width = "32")]
#[inline]
pub fn from_str(s: &str) -> Result<Value, JsonError> {
let mut bytes = s.as_bytes().to_vec();
simd_json::serde::from_slice(&mut bytes)
}
#[cfg(target_pointer_width = "64")]
#[inline]
pub fn to_string<T: Serialize>(value: &T) -> Result<String, JsonError> {
sonic_rs::to_string(value)
}
#[cfg(target_pointer_width = "32")]
#[inline]
pub fn to_string<T: Serialize>(value: &T) -> Result<String, JsonError> {
simd_json::serde::to_string(value)
}
#[inline]
pub(crate) fn parse_json(json: &str) -> Result<Value, crate::error::JsonToolsError> {
from_str(json).map_err(crate::error::JsonToolsError::json_parse_error)
}