Skip to content

Commit

Permalink
feat: add more int value handle
Browse files Browse the repository at this point in the history
  • Loading branch information
passchaos committed Nov 29, 2024
1 parent 896279b commit dc4fe72
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion prost-reflect/src/dynamic/text_format/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,19 @@ impl<'a> Parser<'a> {
Some((Token::Ident("true"), _))
| Some((Token::Ident("True"), _))
| Some((Token::Ident("t"), _)) => Ok((true, self.bump())),
Some((Token::IntLiteral(v), _)) => Ok((v.value == "1", self.bump())),
Some((Token::IntLiteral(v), _)) => {
let value = match u8::from_str_radix(v.value, v.radix) {
Ok(v) => v,
Err(_e) => return self.unexpected_token("u8 int value"),
};
if value == 1 {
Ok((true, self.bump()))
} else if value == 0 {
Ok((false, self.bump()))
} else {
self.unexpected_token("0 or 1 int value")
}
}
_ => self.unexpected_token("'true' or 'false'"),
}
}
Expand Down

0 comments on commit dc4fe72

Please sign in to comment.