Skip to content

Commit 431af2c

Browse files
committed
Add an option to print 64-bit integers without quotes
1 parent 330b786 commit 431af2c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

protobuf-json-mapping/src/print.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,19 @@ impl PrintableToJson for f64 {
130130
impl PrintableToJson for u64 {
131131
fn print_to_json(&self, w: &mut Printer) -> PrintResult<()> {
132132
// 64-bit integers are quoted by default
133+
if w.print_options.unquoted_64bit_integers {
134+
return Ok(write!(w.buf, "{}", self)?);
135+
}
133136
Ok(write!(w.buf, "\"{}\"", self)?)
134137
}
135138
}
136139

137140
impl PrintableToJson for i64 {
138141
fn print_to_json(&self, w: &mut Printer) -> PrintResult<()> {
139142
// 64-bit integers are quoted by default
143+
if w.print_options.unquoted_64bit_integers {
144+
return Ok(write!(w.buf, "{}", self)?);
145+
}
140146
Ok(write!(w.buf, "\"{}\"", self)?)
141147
}
142148
}
@@ -563,6 +569,8 @@ pub struct PrintOptions {
563569
pub proto_field_name: bool,
564570
/// Output field default values.
565571
pub always_output_default_values: bool,
572+
/// Do not quote 64-bit integers.
573+
pub unquoted_64bit_integers: bool,
566574
/// Prevent initializing `PrintOptions` enumerating all field.
567575
pub _future_options: (),
568576
}

0 commit comments

Comments
 (0)