Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make DynamicMessage public #753

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading