Skip to content

Add an option to print 64-bit integers without quotes #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions protobuf-json-mapping/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,19 @@ impl PrintableToJson for f64 {
impl PrintableToJson for u64 {
fn print_to_json(&self, w: &mut Printer) -> PrintResult<()> {
// 64-bit integers are quoted by default
if w.print_options.unquoted_64bit_integers {
return Ok(write!(w.buf, "{}", self)?);
}
Ok(write!(w.buf, "\"{}\"", self)?)
}
}

impl PrintableToJson for i64 {
fn print_to_json(&self, w: &mut Printer) -> PrintResult<()> {
// 64-bit integers are quoted by default
if w.print_options.unquoted_64bit_integers {
return Ok(write!(w.buf, "{}", self)?);
}
Ok(write!(w.buf, "\"{}\"", self)?)
}
}
Expand Down Expand Up @@ -563,6 +569,8 @@ pub struct PrintOptions {
pub proto_field_name: bool,
/// Output field default values.
pub always_output_default_values: bool,
/// Do not quote 64-bit integers.
pub unquoted_64bit_integers: bool,
/// Prevent initializing `PrintOptions` enumerating all field.
pub _future_options: (),
}
Expand Down
Loading