#![allow(deprecated)]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, num_enum::TryFromPrimitive)]
pub enum FlexBufferType {
Null = 0,
Int = 1,
UInt = 2,
Float = 3,
Bool = 26,
Key = 4,
String = 5,
IndirectInt = 6,
IndirectUInt = 7,
IndirectFloat = 8,
Map = 9,
Vector = 10,
VectorInt = 11,
VectorUInt = 12,
VectorFloat = 13,
VectorKey = 14,
#[deprecated(
note = "Please use Vector or VectorKey instead. See https://github.com/google/flatbuffers/issues/5627"
)]
VectorString = 15,
VectorBool = 36,
VectorInt2 = 16,
VectorUInt2 = 17,
VectorFloat2 = 18,
VectorInt3 = 19,
VectorUInt3 = 20,
VectorFloat3 = 21,
VectorInt4 = 22,
VectorUInt4 = 23,
VectorFloat4 = 24,
Blob = 25,
}
use FlexBufferType::*;
impl Default for FlexBufferType {
fn default() -> Self {
Null
}
}
macro_rules! is_ty {
($is_T: ident, $FTy: ident) => {
#[inline(always)]
pub fn $is_T(self) -> bool {
self == $FTy
}
};
}
impl FlexBufferType {
pub fn is_inline(self) -> bool {
match self {
Null | Int | UInt | Float | Bool => true,
_ => false,
}
}
pub fn is_reference(self) -> bool {
!self.is_inline()
}
pub fn is_vector(self) -> bool {
let d = self as u8;
9 <= d && d < 25 || self == VectorBool
}
pub fn has_length_slot(self) -> bool {
!self.is_fixed_length_vector() && self.is_vector() || self == String || self == Blob
}
pub fn is_fixed_length_vector(self) -> bool {
self.fixed_length_vector_length().is_some()
}
pub fn typed_vector_type(self) -> Option<FlexBufferType> {
match self {
VectorInt | VectorInt2 | VectorInt3 | VectorInt4 => Some(Int),
VectorUInt | VectorUInt2 | VectorUInt3 | VectorUInt4 => Some(UInt),
VectorFloat | VectorFloat2 | VectorFloat3 | VectorFloat4 => Some(Float),
VectorKey => Some(Key),
VectorString => Some(Key),
VectorBool => Some(Bool),
_ => None,
}
}
pub fn fixed_length_vector_length(self) -> Option<usize> {
match self {
VectorInt2 | VectorUInt2 | VectorFloat2 => Some(2),
VectorInt3 | VectorUInt3 | VectorFloat3 => Some(3),
VectorInt4 | VectorUInt4 | VectorFloat4 => Some(4),
_ => None,
}
}
pub fn is_heterogenous(self) -> bool {
self == Map || self == Vector
}
pub fn to_direct(self) -> Option<Self> {
match self {
IndirectInt => Some(Int),
IndirectUInt => Some(UInt),
IndirectFloat => Some(Float),
_ => None,
}
}
is_ty!(is_null, Null);
is_ty!(is_int, Int);
is_ty!(is_uint, UInt);
is_ty!(is_float, Float);
is_ty!(is_bool, Bool);
is_ty!(is_key, Key);
is_ty!(is_string, String);
is_ty!(is_indirect_int, IndirectInt);
is_ty!(is_indirect_uint, IndirectUInt);
is_ty!(is_indirect_float, IndirectFloat);
is_ty!(is_map, Map);
is_ty!(is_heterogenous_vector, Vector);
is_ty!(is_vector_int, VectorInt);
is_ty!(is_vector_uint, VectorUInt);
is_ty!(is_vector_float, VectorFloat);
is_ty!(is_vector_key, VectorKey);
is_ty!(is_vector_string, VectorString);
is_ty!(is_vector_bool, VectorBool);
is_ty!(is_vector_int2, VectorInt2);
is_ty!(is_vector_uint2, VectorUInt2);
is_ty!(is_vector_float2, VectorFloat2);
is_ty!(is_vector_int3, VectorInt3);
is_ty!(is_vector_uint3, VectorUInt3);
is_ty!(is_vector_float3, VectorFloat3);
is_ty!(is_vector_int4, VectorInt4);
is_ty!(is_vector_uint4, VectorUInt4);
is_ty!(is_vector_float4, VectorFloat4);
is_ty!(is_blob, Blob);
}