urlyy commented on issue #2851:
URL: https://github.com/apache/fory/issues/2851#issuecomment-3466540403
@chaokunyang So Fory needs to support handling enum like this.
```rust
enum Token {
Plus,
Number(i64),
Ident(String),
Assign { target: String, value: i32 },
Other(Option<i64>),
}
```
Generated code:
```rust
impl Token{
fn serialize(&self, context: &mut WriteContext) {
match self {
Self::Plus => {
context.write_i8(0);
}
Self::Number(f1) => {
context.write_i8(1);
i64::write(*f1, context);
}
Self::Ident(f1) => {
context.write_i8(2);
String::write(f1, context);
}
Self::Assign { target, value } => {
context.write_i8(3);
String::write(target, context);
i32::write(*value, context);
}
Self::Other(f1) => {
context.write_i8(4);
Option::<i64>::write(f1, context);
}
}
}
fn deserialize(context: &mut ReadContext) -> Self {
let tag = context.read_i8();
match tag {
0 => Self::Plus,
1 => {
let f1 = i64::read(context);
Self::Number(f1)
}
2 => {
let f1 = String::read(context);
Self::Ident(f1)
}
3 => {
let target = String::read(context);
let value = i32::read(context);
Self::Assign { target, value }
}
4 => {
let f1 = Option::<i64>::read(context);
Self::Other(f1)
}
_ => panic!("Unknown tag for Token: {}", tag),
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]