Skip to content

Commit

Permalink
enum attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
krakow10 committed Feb 23, 2024
1 parent 6ccd30f commit 1d4f34c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions rbx_types/src/attributes/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ pub(crate) enum AttributeError {
#[error("couldn't read bytes to deserialize {0}")]
ReadType(&'static str),

#[error("enum contained invalid UTF-8 in {field}")]
EnumBadUnicode {
#[source]
source: FromUtf8Error,

field: &'static str,
},

#[error("font contained invalid UTF-8 in {field}")]
FontBadUnicode {
#[source]
Expand Down
19 changes: 18 additions & 1 deletion rbx_types/src/attributes/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use crate::{
BinaryString, BrickColor, CFrame, Color3, ColorSequence, ColorSequenceKeypoint, Font,
BinaryString, BrickColor, CFrame, Color3, ColorSequence, ColorSequenceKeypoint, Enum, Font,
FontStyle, FontWeight, Matrix3, NumberRange, NumberSequence, NumberSequenceKeypoint, Rect,
UDim, UDim2, Variant, VariantType, Vector2, Vector3,
};
Expand Down Expand Up @@ -161,6 +161,23 @@ pub(crate) fn read_attributes<R: Read>(
}
.into(),

VariantType::Enum => {
let _enum_name = {
let buf = read_string(&mut value)?;

String::from_utf8(buf).map_err(|source| AttributeError::EnumBadUnicode {
source,
field: "enum_name",
})?
};
let enum_value = read_u32(&mut value)?;

// enum_name is unused

Enum::from_u32(enum_value)
}
.into(),

VariantType::Font => {
let weight = read_u16(&mut value)?;
let style = read_u8(&mut value)?;
Expand Down
2 changes: 1 addition & 1 deletion rbx_types/src/attributes/type_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type_ids! {
// ??? => 0x12,
// ??? => 0x13,
CFrame => 0x14,
// ??? => 0x15,
Enum => 0x15,
// ??? => 0x16,
NumberSequence => 0x17,
// ??? => 0x18,
Expand Down

0 comments on commit 1d4f34c

Please sign in to comment.