Skip to content

Commit 1dffd05

Browse files
authored
Add int/float widening from 32 to 64 bits for rbx_binary (#305)
This PR supports widening ints & floats from 32 bits to 64 bits.
1 parent fd147f7 commit 1dffd05

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

rbx_binary/src/deserializer/state.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,19 @@ impl<'a, R: Read> DeserializerState<'a, R> {
489489
add_property(instance, &property, value.into());
490490
}
491491
}
492+
// This branch allows values serialized as Int32 to be converted to Int64 when we expect a Int64
493+
// Basically, we convert Int32 to Int64 when we expect a Int64 but read a Int32
494+
// See: #301
495+
VariantType::Int64 => {
496+
let mut values = vec![0; type_info.referents.len()];
497+
chunk.read_interleaved_i32_array(&mut values)?;
498+
499+
for (value, referent) in values.into_iter().zip(&type_info.referents) {
500+
let instance = self.instances_by_ref.get_mut(referent).unwrap();
501+
let value_converted = i64::from(value);
502+
add_property(instance, &property, value_converted.into());
503+
}
504+
}
492505
invalid_type => {
493506
return Err(InnerError::PropTypeMismatch {
494507
type_name: type_info.type_name.clone(),
@@ -525,6 +538,19 @@ impl<'a, R: Read> DeserializerState<'a, R> {
525538
add_property(instance, &property, value.into());
526539
}
527540
}
541+
// This branch allows values serialized as Float32 to be converted to Float64 when we expect a Float64
542+
// Basically, we convert Float32 to Float64 when we expect a Float64 but read a Float32
543+
// See: #301
544+
VariantType::Float32 => {
545+
let mut values = vec![0.0; type_info.referents.len()];
546+
chunk.read_interleaved_f32_array(&mut values)?;
547+
548+
for (value, referent) in values.into_iter().zip(&type_info.referents) {
549+
let instance = self.instances_by_ref.get_mut(referent).unwrap();
550+
let converted_value = f64::from(value);
551+
add_property(instance, &property, converted_value.into());
552+
}
553+
}
528554
invalid_type => {
529555
return Err(InnerError::PropTypeMismatch {
530556
type_name: type_info.type_name.clone(),

0 commit comments

Comments
 (0)