use crate::context::ReadContext;
use crate::ensure;
use crate::error::Error;
use crate::serializer::Serializer;
use crate::type_id::TypeId;
use crate::type_id::{is_user_type, ENUM, NAMED_ENUM, NAMED_UNION, TYPED_UNION, UNION, UNKNOWN};
#[inline(always)]
pub(crate) fn read_basic_type_info<T: Serializer>(context: &mut ReadContext) -> Result<(), Error> {
let local_type_id = T::static_type_id();
let local_type_id_u32 = local_type_id as u32;
let remote_type_id = context.reader.read_u8()? as u32;
ensure!(
local_type_id_u32 == remote_type_id,
Error::type_mismatch(local_type_id_u32, remote_type_id)
);
Ok(())
}
#[inline(always)]
pub const fn field_need_read_type_info(type_id: u32) -> bool {
if type_id == ENUM || type_id == NAMED_ENUM || type_id == UNION {
return false;
}
type_id == UNKNOWN || is_user_type(type_id)
}
#[inline(always)]
pub const fn field_need_write_type_info(static_type_id: TypeId) -> bool {
let static_type_id = static_type_id as u32;
if static_type_id == ENUM
|| static_type_id == NAMED_ENUM
|| static_type_id == UNION
|| static_type_id == TYPED_UNION
|| static_type_id == NAMED_UNION
{
return false;
}
static_type_id == UNKNOWN || is_user_type(static_type_id)
}
#[inline]
pub const fn field_need_write_ref_into(_type_id: u32, nullable: bool) -> bool {
nullable
}
pub(crate) mod send_sync {
use std::any::Any;
#[inline(always)]
pub fn box_send_sync<T>(value: T) -> Box<dyn Any + Send + Sync>
where
T: Any + Send + Sync,
{
Box::new(value)
}
}