pub struct FormatOptions { /* private fields */ }
text-format
only.Expand description
Options to control printing of the protobuf text format.
Implementations§
Source§impl FormatOptions
impl FormatOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates new instance of FormatOptions
with default options.
Sourcepub fn pretty(self, yes: bool) -> Self
pub fn pretty(self, yes: bool) -> Self
Whether to prettify the format output.
If set to true
, each field will be printed on a new line, and nested messages will be indented.
The default value is false
.
Sourcepub fn skip_unknown_fields(self, yes: bool) -> Self
pub fn skip_unknown_fields(self, yes: bool) -> Self
Whether to include unknown fields in the output.
If set to false
, unknown fields will be printed. The protobuf format does not include type information,
so the formatter will attempt to infer types.
The default value is true
.
§Examples
let dynamic_message = DynamicMessage::decode(message_descriptor, b"\x08\x96\x01\x1a\x02\x10\x42".as_ref()).unwrap();
assert_eq!(dynamic_message.to_text_format(), "");
let options = FormatOptions::new().skip_unknown_fields(false);
assert_eq!(dynamic_message.to_text_format_with_options(&options), "1:150,3{2:66}");
Sourcepub fn skip_default_fields(self, yes: bool) -> Self
pub fn skip_default_fields(self, yes: bool) -> Self
Whether to skip fields which have their default value.
If true
, any fields for which has_field
returns false
will
not be included. If false
, they will be included with their default value.
The default value is true
.
Sourcepub fn print_message_fields_in_index_order(self, yes: bool) -> Self
pub fn print_message_fields_in_index_order(self, yes: bool) -> Self
Whether to print message fields in the order they were defined in source code.
If set to true
, message fields will be printed in the order they were defined in the source code.
Otherwise, they will be printed in field number order.
The default value is false
.
Sourcepub fn expand_any(self, yes: bool) -> Self
pub fn expand_any(self, yes: bool) -> Self
Whether to use the expanded form of the google.protobuf.Any
type.
If set to true
, Any
fields will use an expanded form:
[type.googleapis.com/package.MyMessage] {
foo: 150
}
If set to false
, the normal text format representation will be used:
type_url: "type.googleapis.com/package.MyMessage"
value: "\x08\x96\x01"
The default value is true
.
§Examples
let message_descriptor = pool.get_message_by_name("google.protobuf.Any").unwrap();
let mut dynamic_message = DynamicMessage::new(message_descriptor);
dynamic_message.set_field_by_name("type_url", Value::String("type.googleapis.com/package.MyMessage".to_owned()));
dynamic_message.set_field_by_name("value", Value::Bytes(Bytes::from_static(b"\x08\x96\x01\x1a\x02\x10\x42".as_ref())));
assert_eq!(dynamic_message.to_text_format(), "[type.googleapis.com/package.MyMessage]{foo:150,nested{bar:66}}");
let options = FormatOptions::new().expand_any(false);
assert_eq!(dynamic_message.to_text_format_with_options(&options), r#"type_url:"type.googleapis.com/package.MyMessage",value:"\010\226\001\032\002\020B""#);
Trait Implementations§
Source§impl Clone for FormatOptions
impl Clone for FormatOptions
Source§fn clone(&self) -> FormatOptions
fn clone(&self) -> FormatOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more