Skip to content

Commit

Permalink
Rename ProtobufValueRef to ReflectValueRef
Browse files Browse the repository at this point in the history
Old name is kept for compatibility
  • Loading branch information
stepancheg committed Aug 11, 2019
1 parent 60cba9e commit 65667cb
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 99 deletions.
38 changes: 19 additions & 19 deletions protobuf/src/reflect/accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::repeated::ReflectRepeated;
use super::repeated::ReflectRepeatedEnum;
use super::repeated::ReflectRepeatedMessage;
use super::value::ProtobufValue;
use super::value::ProtobufValueRef;
use super::value::ReflectValueRef;
use super::ReflectFieldRef;

/// this trait should not be used directly, use `FieldDescriptor` instead
Expand Down Expand Up @@ -85,7 +85,7 @@ trait GetRepeatedEnum<M: Message + 'static> {
}

trait GetSetCopyFns<M> {
fn get_field<'a>(&self, m: &'a M) -> ProtobufValueRef<'a>;
fn get_field<'a>(&self, m: &'a M) -> ReflectValueRef<'a>;
}

struct GetSetCopyFnsImpl<M, V: ProtobufValue + Copy> {
Expand All @@ -94,7 +94,7 @@ struct GetSetCopyFnsImpl<M, V: ProtobufValue + Copy> {
}

impl<M, V: ProtobufValue + Copy> GetSetCopyFns<M> for GetSetCopyFnsImpl<M, V> {
fn get_field<'a>(&self, m: &'a M) -> ProtobufValueRef<'a> {
fn get_field<'a>(&self, m: &'a M) -> ReflectValueRef<'a> {
(&(self.get)(m) as &ProtobufValue).as_ref_copy()
}
}
Expand All @@ -108,13 +108,13 @@ enum SingularGetSet<M> {
}

impl<M: Message + 'static> SingularGetSet<M> {
fn get_ref<'a>(&self, m: &'a M) -> ProtobufValueRef<'a> {
fn get_ref<'a>(&self, m: &'a M) -> ReflectValueRef<'a> {
match self {
&SingularGetSet::Copy(ref copy) => copy.get_field(m),
&SingularGetSet::String(get, _) => ProtobufValueRef::String(get(m)),
&SingularGetSet::Bytes(get, _) => ProtobufValueRef::Bytes(get(m)),
&SingularGetSet::Enum(ref get) => ProtobufValueRef::Enum(get.get_enum(m)),
&SingularGetSet::Message(ref get) => ProtobufValueRef::Message(get.get_message(m)),
&SingularGetSet::String(get, _) => ReflectValueRef::String(get(m)),
&SingularGetSet::Bytes(get, _) => ReflectValueRef::Bytes(get(m)),
&SingularGetSet::Enum(ref get) => ReflectValueRef::Enum(get.get_enum(m)),
&SingularGetSet::Message(ref get) => ReflectValueRef::Message(get.get_message(m)),
}
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ struct FieldAccessorImpl<M> {
}

impl<M: Message> FieldAccessorImpl<M> {
fn get_value_option<'a>(&self, m: &'a M) -> Option<ProtobufValueRef<'a>> {
fn get_value_option<'a>(&self, m: &'a M) -> Option<ReflectValueRef<'a>> {
match self.fns {
FieldAccessorFunctions::Repeated(..) | FieldAccessorFunctions::Map(..) => {
panic!("repeated")
Expand Down Expand Up @@ -239,7 +239,7 @@ impl<M: Message + 'static> FieldAccessor for FieldAccessorImpl<M> {
.expect("field unset")
.as_ref()
{
ProtobufValueRef::Message(m) => m,
ReflectValueRef::Message(m) => m,
_ => panic!("not a message"),
}
}
Expand All @@ -259,71 +259,71 @@ impl<M: Message + 'static> FieldAccessor for FieldAccessorImpl<M> {

fn get_str_generic<'a>(&self, m: &'a Message) -> &'a str {
match self.get_value_option(message_down_cast(m)) {
Some(ProtobufValueRef::String(v)) => v,
Some(ReflectValueRef::String(v)) => v,
Some(_) => panic!("wrong type"),
None => "", // TODO: check type
}
}

fn get_bytes_generic<'a>(&self, m: &'a Message) -> &'a [u8] {
match self.get_value_option(message_down_cast(m)) {
Some(ProtobufValueRef::Bytes(v)) => v,
Some(ReflectValueRef::Bytes(v)) => v,
Some(_) => panic!("wrong type"),
None => b"", // TODO: check type
}
}

fn get_u32_generic(&self, m: &Message) -> u32 {
match self.get_value_option(message_down_cast(m)) {
Some(ProtobufValueRef::U32(v)) => v,
Some(ReflectValueRef::U32(v)) => v,
Some(_) => panic!("wrong type"),
None => 0, // TODO: check type
}
}

fn get_u64_generic(&self, m: &Message) -> u64 {
match self.get_value_option(message_down_cast(m)) {
Some(ProtobufValueRef::U64(v)) => v,
Some(ReflectValueRef::U64(v)) => v,
Some(_) => panic!("wrong type"),
None => 0, // TODO: check type
}
}

fn get_i32_generic(&self, m: &Message) -> i32 {
match self.get_value_option(message_down_cast(m)) {
Some(ProtobufValueRef::I32(v)) => v,
Some(ReflectValueRef::I32(v)) => v,
Some(_) => panic!("wrong type"),
None => 0, // TODO: check type
}
}

fn get_i64_generic(&self, m: &Message) -> i64 {
match self.get_value_option(message_down_cast(m)) {
Some(ProtobufValueRef::I64(v)) => v,
Some(ReflectValueRef::I64(v)) => v,
Some(_) => panic!("wrong type"),
None => 0, // TODO: check type
}
}

fn get_f32_generic(&self, m: &Message) -> f32 {
match self.get_value_option(message_down_cast(m)) {
Some(ProtobufValueRef::F32(v)) => v,
Some(ReflectValueRef::F32(v)) => v,
Some(_) => panic!("wrong type"),
None => 0.0, // TODO: check type
}
}

fn get_f64_generic(&self, m: &Message) -> f64 {
match self.get_value_option(message_down_cast(m)) {
Some(ProtobufValueRef::F64(v)) => v,
Some(ReflectValueRef::F64(v)) => v,
Some(_) => panic!("wrong type"),
None => 0.0, // TODO: check type
}
}

fn get_bool_generic(&self, m: &Message) -> bool {
match self.get_value_option(message_down_cast(m)) {
Some(ProtobufValueRef::Bool(v)) => v,
Some(ReflectValueRef::Bool(v)) => v,
Some(_) => panic!("wrong type"),
None => false, // TODO: check type
}
Expand Down
6 changes: 4 additions & 2 deletions protobuf/src/reflect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use self::map::ReflectMap;
use self::repeated::ReflectRepeated;

pub use self::value::ProtobufValue;
pub use self::value::ProtobufValueRef;
pub use self::value::ReflectValueRef;
#[doc(hidden)]
pub use self::value::ReflectValueRef as ProtobufValueRef;

pub use self::field::FieldDescriptor;

Expand Down Expand Up @@ -241,5 +243,5 @@ pub enum ReflectFieldRef<'a> {
/// Map field
Map(&'a ReflectMap),
/// Optional field
Optional(Option<ProtobufValueRef<'a>>),
Optional(Option<ReflectValueRef<'a>>),
}
30 changes: 15 additions & 15 deletions protobuf/src/reflect/repeated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::slice;

use super::value::ProtobufValue;
use super::value::ProtobufValueRef;
use super::value::ReflectValueRef;

use repeated::RepeatedField;

Expand Down Expand Up @@ -100,13 +100,13 @@ impl<'a> IntoIterator for &'a ReflectRepeated {
pub trait ReflectRepeatedEnum<'a> {
fn len(&self) -> usize;

fn get(&self, index: usize) -> ProtobufValueRef<'a>;
fn get(&self, index: usize) -> ReflectValueRef<'a>;
}

pub trait ReflectRepeatedMessage<'a> {
fn len(&self) -> usize;

fn get(&self, index: usize) -> ProtobufValueRef<'a>;
fn get(&self, index: usize) -> ReflectValueRef<'a>;
}

pub enum ReflectRepeatedRef<'a> {
Expand Down Expand Up @@ -142,18 +142,18 @@ impl<'a> ReflectRepeatedRef<'a> {
}
}

fn get(&self, index: usize) -> ProtobufValueRef<'a> {
fn get(&self, index: usize) -> ReflectValueRef<'a> {
match *self {
ReflectRepeatedRef::Generic(ref r) => r.get(index).as_ref(),
ReflectRepeatedRef::U32(ref r) => ProtobufValueRef::U32(r[index]),
ReflectRepeatedRef::U64(ref r) => ProtobufValueRef::U64(r[index]),
ReflectRepeatedRef::I32(ref r) => ProtobufValueRef::I32(r[index]),
ReflectRepeatedRef::I64(ref r) => ProtobufValueRef::I64(r[index]),
ReflectRepeatedRef::F32(ref r) => ProtobufValueRef::F32(r[index]),
ReflectRepeatedRef::F64(ref r) => ProtobufValueRef::F64(r[index]),
ReflectRepeatedRef::Bool(ref r) => ProtobufValueRef::Bool(r[index]),
ReflectRepeatedRef::String(ref r) => ProtobufValueRef::String(&r[index]),
ReflectRepeatedRef::Bytes(ref r) => ProtobufValueRef::Bytes(&r[index]),
ReflectRepeatedRef::U32(ref r) => ReflectValueRef::U32(r[index]),
ReflectRepeatedRef::U64(ref r) => ReflectValueRef::U64(r[index]),
ReflectRepeatedRef::I32(ref r) => ReflectValueRef::I32(r[index]),
ReflectRepeatedRef::I64(ref r) => ReflectValueRef::I64(r[index]),
ReflectRepeatedRef::F32(ref r) => ReflectValueRef::F32(r[index]),
ReflectRepeatedRef::F64(ref r) => ReflectValueRef::F64(r[index]),
ReflectRepeatedRef::Bool(ref r) => ReflectValueRef::Bool(r[index]),
ReflectRepeatedRef::String(ref r) => ReflectValueRef::String(&r[index]),
ReflectRepeatedRef::Bytes(ref r) => ReflectValueRef::Bytes(&r[index]),
ReflectRepeatedRef::Enum(ref r) => r.get(index),
ReflectRepeatedRef::Message(ref r) => r.get(index),
}
Expand All @@ -166,7 +166,7 @@ pub struct ReflectRepeatedRefIter<'a> {
}

impl<'a> Iterator for ReflectRepeatedRefIter<'a> {
type Item = ProtobufValueRef<'a>;
type Item = ReflectValueRef<'a>;

fn next(&mut self) -> Option<Self::Item> {
if self.pos < self.repeated.len() {
Expand All @@ -181,7 +181,7 @@ impl<'a> Iterator for ReflectRepeatedRefIter<'a> {

impl<'a> IntoIterator for &'a ReflectRepeatedRef<'a> {
type IntoIter = ReflectRepeatedRefIter<'a>;
type Item = ProtobufValueRef<'a>;
type Item = ReflectValueRef<'a>;

fn into_iter(self) -> Self::IntoIter {
ReflectRepeatedRefIter {
Expand Down
Loading

0 comments on commit 65667cb

Please sign in to comment.