pub struct DynamicMessage { /* private fields */ }
Expand description

DynamicMessage provides encoding, decoding and reflection of a protobuf message.

It wraps a MessageDescriptor and the Value for each field of the message, and implements Message.

Implementations

Available on crate feature serde only.

Serialize this message into serializer using the encoding specified by options.

Available on crate feature serde only.

Deserialize an instance of the message type described by desc from deserializer.

Available on crate feature serde only.

Deserialize an instance of the message type described by desc from deserializer, using the encoding specified by options.

Creates a new, empty instance of DynamicMessage for the message type specified by the MessageDescriptor.

Decodes an instance of the message type specified by the MessageDescriptor from the buffer and merges it into a new instance of DynamicMessage.

Returns true if this message has the given field set.

If the field type supports distinguishing whether a value has been set (see supports_presence), such as for messages, then this method returns true only if a value has been set. For other types, such as integers, it returns true if the value is set to a non-default value.

If this method returns false, then the field will not be included in the encoded bytes of this message.

Gets the value of the given field, or the default value if it is unset.

Gets a mutable reference to the value ofthe given field. If the field is not set, it is inserted with its default value.

Sets the value of the given field.

Panics

This method may panic if the value type is not compatible with the field type, as defined by Value::is_valid_for_field.

Clears the given field.

After calling this method, has_field will return false for the field, and it will not be included in the encoded bytes of this message.

Returns true if this message has a field set with the given number.

See has_field for more details.

Gets the value of the field with the given number, or the default value if it is unset.

If the message has no field with the given number, None is returned.

See get_field for more details.

Gets a mutable reference to the value of the field with the given number. If the field is not set, it is inserted with its default value.

If the message has no field with the given number, None is returned.

See get_field_mut for more details.

Sets the value of the field with number number, or the default value if it is unset.

If no field with the given number exists, this method does nothing.

See set_field for more details.

Clears the field with the given number.

If no field with the given number exists, this method does nothing.

See clear_field for more details.

Returns true if this message has a field set with the given name.

See has_field for more details.

Gets the value of the field with the given name, or the default value if it is unset.

If the message has no field with the given name, None is returned.

See get_field for more details.

Gets a mutable reference to the value of the field with the given name. If the field is not set, it is inserted with its default value.

If the message has no field with the given name, None is returned.

See get_field_mut for more details.

Sets the value of the field with name name.

If no field with the given name exists, this method does nothing.

See set_field for more details.

Clears the field with the given name.

If no field with the given name exists, this method does nothing.

See clear_field for more details.

Returns true if this message has the given extension field set.

See has_field for more details.

Gets the value of the given extension field, or the default value if it is unset.

See get_field for more details.

Gets a mutable reference to the value of the given extension field. If the field is not set, it is inserted with its default value.

See get_field_mut for more details.

Sets the value of the given extension field.

See set_field for more details.

Clears the given extension field.

See clear_field for more details.

Merge a strongly-typed message into this one.

The message should be compatible with the type specified by descriptor, or the merge will likely fail with a DecodeError.

Convert this dynamic message into a strongly typed value.

The message should be compatible with the type specified by descriptor, or the conversion will likely fail with a DecodeError.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the encoded length of the message without a length delimiter.

Clears the message, resetting all fields to their default.

Encodes the message to a buffer. Read more

Encodes the message to a newly allocated buffer.

Encodes the message with a length-delimiter to a buffer. Read more

Encodes the message with a length-delimiter to a newly allocated buffer.

Decodes an instance of the message from a buffer. Read more

Decodes a length-delimited instance of the message from the buffer.

Decodes an instance of the message from a buffer, and merges it into self. Read more

Decodes a length-delimited instance of the message from buffer, and merges it into self. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Gets a MessageDescriptor describing the type of this message.

Converts this message into an instance of DynamicMessage by going through the byte representation. Read more

Serialize this message into serializer using the canonical JSON encoding.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.