Skip to content

Commit

Permalink
feat: make DynamicMessage public
Browse files Browse the repository at this point in the history
  • Loading branch information
nerodesu017 committed Jan 18, 2025
1 parent a542121 commit a125197
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions protobuf/src/reflect/dynamic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! This module contains dynamic reflection.
//!
//! It is used for dynamically getting fields' values.
#![doc(hidden)]

use std::any::Any;
use std::any::TypeId;
use std::fmt;
Expand Down Expand Up @@ -95,8 +101,11 @@ impl DynamicFieldValue {
}
}

/// Structure used for dynamic reflection.
///
/// It is mostly used for dynamically getting fields' values.
#[derive(Debug, Clone)]
pub(crate) struct DynamicMessage {
pub struct DynamicMessage {
descriptor: MessageDescriptor,
/// Fields by index in the description.
/// This field is lazy-init: it is empty when created.
Expand Down Expand Up @@ -127,7 +136,8 @@ impl DynamicMessage {
}
}

pub(crate) fn get_reflect<'a>(&'a self, field: &FieldDescriptor) -> ReflectFieldRef<'a> {
/// Get a field reference for a field descriptor.
pub fn get_reflect<'a>(&'a self, field: &FieldDescriptor) -> ReflectFieldRef<'a> {
let (descriptor, index) = field.regular();
assert_eq!(self.descriptor, descriptor);
if self.fields.is_empty() {
Expand All @@ -137,6 +147,7 @@ impl DynamicMessage {
}
}

/// Clear a field.
pub fn clear_field(&mut self, field: &FieldDescriptor) {
let (descriptor, index) = field.regular();
assert_eq!(self.descriptor, descriptor);
Expand Down
2 changes: 1 addition & 1 deletion protobuf/src/reflect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! Some minor adjustements are made to make code more idiomatic to rust.
mod acc;
mod dynamic;
pub mod dynamic;
mod enums;
pub(crate) mod error;
mod field;
Expand Down

0 comments on commit a125197

Please sign in to comment.