Skip to main content

JsonParseOptions

Struct JsonParseOptions 

Source
#[non_exhaustive]
pub struct JsonParseOptions { pub ignore_unknown_enum_values: bool, pub strict_extension_keys: bool, pub strict_any_type_urls: bool, }
Available on crate feature json only.
Expand description

Options controlling protobuf JSON parsing behavior.

Use JsonParseOptions::new plus builder methods to construct:

let opts = JsonParseOptions::new().ignore_unknown_enum_values(true);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§ignore_unknown_enum_values: bool

When true, an enum name that the enum does not declare is replaced with the default value, left unset, or dropped, depending on the kind of field. In an optional, repeated or map field of a closed enum, a number in the i32 range that the enum does not declare is left unset or dropped too. A value that cannot be an enum value, such as a bool or 1.5, is a parse error with the option on or off. See the module docs for each kind of field. Default: false.

§strict_extension_keys: bool

When true, "[pkg.ext]" JSON keys that are not in the extension registry produce a parse error instead of being silently dropped.

The default (false, lenient) matches the pre-extension-registry behavior where all unknown keys were dropped by serde’s derive. protobuf-go (protojson/decode.go:175) and protobuf-es (from-json.ts:251) both error on unregistered extension keys unless their respective ignore-unknown flags are set; set true here to match. The error pinpoints the missing registration.

Extendee mismatch (key IS registered but extends a different message) always errors regardless of this flag — that’s a contract violation, not a mere miss.

This flag covers "[pkg.ext]" keys only, and only for messages that preserve unknown fields. Ordinary unknown field names are governed by the codegen option buffa_build::Config::deny_unknown_json_fields, which also rejects "[pkg.ext]" keys on a message generated with preservation off.

§strict_any_type_urls: bool

When true, the @type of a google.protobuf.Any must be a type URL: it must contain a /. A bare message full name such as "pkg.Message" is a parse error.

With the default (false), a bare full name is accepted when the type registry has a JSON entry for a message of that name, and the Any keeps it as its type_url. protobuf-go and Python read such a name. C++ and Java reject it, and any.proto says that a type URL contains at least one /. Set true to reject what C++ and Java reject.

A bare name without a JSON entry is a parse error with the option on or off, and so is an @type that is empty or ends in /.

The option covers parsing, and generated message types only. Serialization writes the type_url an Any holds, and Any::type_name and Any::is_message in buffa-types read a bare name with the option on or off: test type_url for a / yourself where that matters. JSON parsing of a DynamicMessage does not read the option. Set DynamicMessageSeed::strict_any_type_urls in buffa-descriptor for that.

Implementations§

Source§

impl JsonParseOptions

Source

pub fn new() -> Self

Create new parse options with every flag at its default, false.

Source

pub fn ignore_unknown_enum_values(self, ignore: bool) -> Self

Set whether enum values that the enum does not declare are ignored instead of producing a parse error. See the module docs for what “ignored” means for each kind of field.

Source

pub fn strict_extension_keys(self, strict: bool) -> Self

Set whether unregistered "[pkg.ext]" JSON keys produce a parse error (true) or are silently dropped (false, the default).

Source

pub fn strict_any_type_urls(self, strict: bool) -> Self

Set whether the @type of a google.protobuf.Any must contain a / (true), or may also be the bare full name of a registered message (false, the default).

Trait Implementations§

Source§

impl Clone for JsonParseOptions

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for JsonParseOptions

Source§

impl Debug for JsonParseOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for JsonParseOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for JsonParseOptions

Source§

impl PartialEq for JsonParseOptions

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for JsonParseOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.