pub enum Value {
}dynamic only.Expand description
A protobuf field value carried by super::DynamicMessage.
One variant per scalar wire type, plus EnumNumber (open-enum
semantics — any i32 is acceptable so unknown variants round-trip
losslessly), Message, List, and Map. The variant set mirrors
prost-reflect’s Value for consumer migration.
Variants§
Bool(bool)
bool.
I32(i32)
int32 / sint32 / sfixed32.
I64(i64)
int64 / sint64 / sfixed64.
U32(u32)
uint32 / fixed32.
U64(u64)
uint64 / fixed64.
F32(f32)
float.
F64(f64)
double.
String(String)
string (UTF-8).
Bytes(Bytes)
bytes.
EnumNumber(i32)
Enum variant by number.
i32 rather than a typed variant so forward-compat decoding (an
unknown enum number) round-trips byte-identically. Matches
proto3’s open-enum semantics.
Message(DynamicMessage)
Sub-message.
List(Vec<Value>)
Repeated value (every element validated against the list’s
declared element Kind).
Map(HashMap<MapKey, Value>)
map<K, V> field.
Implementations§
Source§impl Value
impl Value
Sourcepub fn default_value(kind: &Kind) -> Self
pub fn default_value(kind: &Kind) -> Self
The proto default for the given Kind (singular form).
For Message returns an empty super::DynamicMessage of the
declared sub-message type. For Enum, the zero variant.
Sourcepub fn default_value_for_field(field: &FieldDescriptor) -> Self
pub fn default_value_for_field(field: &FieldDescriptor) -> Self
The proto default for field accounting for cardinality (lists
and maps default to the empty collection).
Reads any pre-parsed [default = …] from the descriptor pool.
When the descriptor declares no explicit default this returns
the zero value for the field’s Kind.
Sourcepub fn is_default(&self, kind: &Kind) -> bool
pub fn is_default(&self, kind: &Kind) -> bool
True iff self equals the proto default for kind.
Lists and maps are default iff empty. Message is default iff
it is a fresh, populated-fields-empty instance.
Sourcepub fn is_valid_for_field(&self, field: &FieldDescriptor) -> bool
pub fn is_valid_for_field(&self, field: &FieldDescriptor) -> bool
Validate that self matches field’s declared shape.
Recursive: list elements validate against the element kind, map keys/values against their declared kinds, and sub-message values must share the field’s expected message descriptor (compared pool-pointer + index).
Sourcepub fn as_enum_number(&self) -> Option<i32>
pub fn as_enum_number(&self) -> Option<i32>
Returns the enum-number payload, if any.
Sourcepub fn as_message(&self) -> Option<&DynamicMessage>
pub fn as_message(&self) -> Option<&DynamicMessage>
Returns the super::DynamicMessage payload, if any.
Sourcepub fn as_message_mut(&mut self) -> Option<&mut DynamicMessage>
pub fn as_message_mut(&mut self) -> Option<&mut DynamicMessage>
Mutable form of Self::as_message.
Sourcepub fn as_list_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_list_mut(&mut self) -> Option<&mut Vec<Value>>
Mutable form of Self::as_list.
Sourcepub fn as_map_mut(&mut self) -> Option<&mut HashMap<MapKey, Value>>
pub fn as_map_mut(&mut self) -> Option<&mut HashMap<MapKey, Value>>
Mutable form of Self::as_map.