godot_binary_serialization/types/
mod.rs

1pub mod primitive;
2pub mod structures;
3pub mod variant;
4
5pub const TYPE_PADDING: u8 = 4;
6
7/// The different serialization flags from Godot's binary serialization
8#[derive(PartialEq, Eq, Debug)]
9pub enum SerializeFlag {
10    /// The encoder has no flags
11    None = 0,
12    /// Used for integers and floats, shows whether they are represented as a 64 bit or 32 bit
13    /// value. 0 = 32 bit, 1 = 64 Bit
14    Bit64 = 1,
15}
16
17impl TryFrom<u16> for SerializeFlag {
18    type Error = ();
19
20    fn try_from(value: u16) -> Result<SerializeFlag, Self::Error> {
21        match value {
22            0 => Ok(SerializeFlag::None),
23            1 => Ok(SerializeFlag::Bit64),
24            _ => Err(()),
25        }
26    }
27}
28
29/// The Godot type indexes based on Godot's binary serialization API
30#[derive(PartialEq, Eq, Debug)]
31pub enum GodotTypeIndex {
32    Nil = 0,
33    Bool = 1,
34    Integer = 2,
35    Float = 3,
36    String = 4,
37    Vector2 = 5,
38    Vector2I = 6,
39    Rect2 = 7,
40    Rect2I = 8,
41    Vector3 = 9,
42    Vector3I = 10,
43    Transform2D = 11,
44    Vector4 = 12,
45    Vector4I = 13,
46    Plane = 14,
47    Quaternion = 15,
48    Aabb = 16,
49    Basis = 17,
50    Transform3D = 18,
51    Projection = 19,
52    Color = 20,
53    StringName = 21,
54    NodePath = 22,
55    RID = 23,
56    Object = 24,
57    Callable = 25,
58    Signal = 26,
59    Dictionary = 27,
60    Array = 28,
61}
62
63impl TryFrom<u16> for GodotTypeIndex {
64    type Error = ();
65    fn try_from(value: u16) -> Result<Self, Self::Error> {
66        match value {
67            0 => Ok(GodotTypeIndex::Nil),
68            1 => Ok(GodotTypeIndex::Bool),
69            2 => Ok(GodotTypeIndex::Integer),
70            3 => Ok(GodotTypeIndex::Float),
71            4 => Ok(GodotTypeIndex::String),
72            5 => Ok(GodotTypeIndex::Vector2),
73            6 => Ok(GodotTypeIndex::Vector2I),
74            7 => Ok(GodotTypeIndex::Rect2),
75            8 => Ok(GodotTypeIndex::Rect2I),
76            9 => Ok(GodotTypeIndex::Vector3),
77            10 => Ok(GodotTypeIndex::Vector3I),
78            11 => Ok(GodotTypeIndex::Transform2D),
79            12 => Ok(GodotTypeIndex::Vector4),
80            13 => Ok(GodotTypeIndex::Vector4I),
81            14 => Ok(GodotTypeIndex::Plane),
82            15 => Ok(GodotTypeIndex::Quaternion),
83            16 => Ok(GodotTypeIndex::Aabb),
84            17 => Ok(GodotTypeIndex::Basis),
85            18 => Ok(GodotTypeIndex::Transform3D),
86            19 => Ok(GodotTypeIndex::Projection),
87            20 => Ok(GodotTypeIndex::Color),
88            21 => Ok(GodotTypeIndex::StringName),
89            22 => Ok(GodotTypeIndex::NodePath),
90            23 => Ok(GodotTypeIndex::RID),
91            24 => Ok(GodotTypeIndex::Object),
92            25 => Ok(GodotTypeIndex::Callable),
93            26 => Ok(GodotTypeIndex::Signal),
94            27 => Ok(GodotTypeIndex::Dictionary),
95            28 => Ok(GodotTypeIndex::Array),
96            _ => Err(()),
97        }
98    }
99}