1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! Free-function convenience helpers for [`DynamicMessage`] field access.
//!
//! Each function looks up a field descriptor by name, then delegates to the
//! corresponding method on [`DynamicMessage`]. All return [`ReflectError::NotFound`]
//! when the given name is not a field of the message's descriptor.
use ;
use crateReflectError;
/// Set a field value by name.
///
/// # Errors
///
/// Returns [`ReflectError::NotFound`] if `name` is not a field of `msg`'s
/// message descriptor.
///
/// Returns [`ReflectError::Field`] if `value` is not type-compatible with the
/// field (e.g. passing a `Value::String` for an `int32` field).
/// Get the value of a field by name.
///
/// Returns `Ok(Some(value))` if the field is set to a non-default value.
/// Returns `Ok(None)` if the field exists but is not set (at its default).
///
/// # Errors
///
/// Returns [`ReflectError::NotFound`] if `name` is not a field of `msg`'s
/// message descriptor.
/// Check whether a field is set (non-default).
///
/// # Errors
///
/// Returns [`ReflectError::NotFound`] if `name` is not a field of `msg`'s
/// message descriptor.
/// Clear a field, resetting it to its default value.
///
/// After this call, [`has_field`] for the same name will return `false`.
///
/// # Errors
///
/// Returns [`ReflectError::NotFound`] if `name` is not a field of `msg`'s
/// message descriptor.
/// Returns an iterator over the unknown fields preserved on a decoded
/// [`DynamicMessage`].
///
/// Unknown fields arise when a message is decoded from bytes that contain
/// field numbers not present in the descriptor used for decoding. They are
/// preserved so that a re-encode of the same message does not silently drop
/// data added by a newer schema version.
///
/// For a freshly-constructed or unmodified message the iterator will be empty.
///
/// Note: prost-reflect 0.16 exposes unknown fields only as an iterator over
/// [`UnknownField`] values; there is no publicly-accessible `UnknownFieldSet`
/// type — that struct is `pub(crate)` inside prost-reflect.
///
/// # Examples
///
/// ```rust
/// use oxiproto_reflect::{unknown_fields, DynamicMessage, pool_from_fds};
/// use prost_types::{FileDescriptorSet, FileDescriptorProto, DescriptorProto};
///
/// let fds = FileDescriptorSet {
/// file: vec![FileDescriptorProto {
/// name: Some("test.proto".to_string()),
/// message_type: vec![DescriptorProto {
/// name: Some("Empty".to_string()),
/// ..Default::default()
/// }],
/// ..Default::default()
/// }],
/// };
/// let pool = pool_from_fds(fds).unwrap();
/// let desc = pool.get_message_by_name("Empty").unwrap();
/// let msg = DynamicMessage::new(desc);
/// assert_eq!(unknown_fields(&msg).count(), 0);
/// ```
+ '_