Skip to content

Commit 954e53f

Browse files
committed
proto: flatten rendering of move enums
Flatten the rendering of move enums to an internally-tagged format, using `@variant` as the key which contains the variant name.
1 parent 71d90c9 commit 954e53f

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

crates/sui-types/src/proto_value.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,33 +310,26 @@ impl<'b, 'l> Visitor<'b, 'l> for ProtoVisitor {
310310

311311
fn visit_variant(&mut self, driver: &mut VariantDriver<'_, 'b, 'l>) -> Result<Value, Error> {
312312
self.inc_depth()?;
313-
self.inc_depth()?;
314313

315-
let mut variant = Struct::default();
314+
let mut map = Struct::default();
316315
self.debit_value()?;
317-
self.debit_str(driver.variant_name().as_str())?;
318316

319-
let mut variant_fields = Struct::default();
320-
self.debit_value()?;
317+
self.debit_str("@variant")?;
318+
self.debit_string_value(driver.variant_name().as_str())?;
319+
320+
map.fields
321+
.insert("@variant".to_owned(), driver.variant_name().as_str().into());
321322

322323
for field in driver.variant_layout() {
323324
self.debit_str(field.name.as_str())?;
324325
}
325326

326327
while let Some((field, elem)) = driver.next_field(self)? {
327-
variant_fields
328-
.fields
329-
.insert(field.name.as_str().to_owned(), elem);
328+
map.fields.insert(field.name.as_str().to_owned(), elem);
330329
}
331330

332-
variant.fields.insert(
333-
driver.variant_name().as_str().to_owned(),
334-
Value::from(Kind::StructValue(variant_fields)),
335-
);
336-
337-
self.dec_depth();
338331
self.dec_depth();
339-
Ok(Value::from(Kind::StructValue(variant)))
332+
Ok(Value::from(Kind::StructValue(map)))
340333
}
341334
}
342335

0 commit comments

Comments
 (0)