steam_vdf_parser/binary/
types.rs

1//! Type definitions for binary VDF format.
2
3/// Binary type byte values used in Steam's binary VDF format.
4#[repr(u8)]
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6#[non_exhaustive]
7pub enum BinaryType {
8    /// Nested object start marker.
9    ///
10    /// Named `None` to match Steam SDK's `TYPE_NONE`, which indicates a subsection
11    /// with child keys rather than a leaf value. In binary VDF, `0x00` followed by
12    /// a key name starts a new nested object that continues until `ObjectEnd` (0x08).
13    None = 0x00,
14    /// String value (null-terminated).
15    String = 0x01,
16    /// 32-bit integer value.
17    Int32 = 0x02,
18    /// 32-bit float value.
19    Float = 0x03,
20    /// Pointer value.
21    Ptr = 0x04,
22    /// Wide string value (UTF-16).
23    WString = 0x05,
24    /// Color value (RGBA).
25    Color = 0x06,
26    /// 64-bit unsigned integer value.
27    UInt64 = 0x07,
28    /// End of object marker.
29    ObjectEnd = 0x08,
30}
31
32impl BinaryType {
33    /// Attempts to convert a byte to a `BinaryType`.
34    ///
35    /// Returns `None` if the byte doesn't correspond to a known type.
36    #[inline]
37    pub fn from_byte(b: u8) -> Option<Self> {
38        match b {
39            0x00 => Some(BinaryType::None),
40            0x01 => Some(BinaryType::String),
41            0x02 => Some(BinaryType::Int32),
42            0x03 => Some(BinaryType::Float),
43            0x04 => Some(BinaryType::Ptr),
44            0x05 => Some(BinaryType::WString),
45            0x06 => Some(BinaryType::Color),
46            0x07 => Some(BinaryType::UInt64),
47            0x08 => Some(BinaryType::ObjectEnd),
48            _ => None,
49        }
50    }
51}
52
53/// Magic number for appinfo.vdf format version 40.
54///
55/// This format uses null-terminated UTF-8 keys.
56pub const APPINFO_MAGIC_40: u32 = 0x07564428;
57
58/// Magic number for appinfo.vdf format version 41 (with string table).
59///
60/// This format uses u32 indices into a string table for keys, enabling O(1) lookups.
61pub const APPINFO_MAGIC_41: u32 = 0x07564429;
62
63/// Magic base for packageinfo.vdf format (upper 3 bytes).
64pub const PACKAGEINFO_MAGIC_BASE: u32 = 0x065655;
65
66/// Magic number for packageinfo.vdf format version 39.
67pub const PACKAGEINFO_MAGIC_39: u32 = 0x06565527;
68
69/// Magic number for packageinfo.vdf format version 40 (with PICS token).
70pub const PACKAGEINFO_MAGIC_40: u32 = 0x06565528;