diff --git a/src/immutable_data.rs b/src/immutable_data.rs index 68bd2be547..ed391a1a73 100644 --- a/src/immutable_data.rs +++ b/src/immutable_data.rs @@ -15,6 +15,8 @@ // Please review the Licences for the specific language governing permissions and limitations // relating to use of the SAFE Network Software. +use std::fmt::{Debug, Formatter, Error}; + use rustc_serialize::{Decoder, Encodable, Encoder}; use NameType; use sodiumoxide::crypto; @@ -28,7 +30,7 @@ pub enum ImmutableDataType { /// ImmutableData /// hash == SHA512 -#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable)] pub struct ImmutableData { type_tag: ImmutableDataType, value: Vec, @@ -67,6 +69,12 @@ impl ImmutableData { } } +impl Debug for ImmutableData { + fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> { + formatter.write_str(&format!(" {:?}, {:?} ", self.type_tag, self.name())) + } +} + #[cfg(test)] mod test { diff --git a/src/structured_data.rs b/src/structured_data.rs index 2c50aa85bf..79a2c1a7fe 100644 --- a/src/structured_data.rs +++ b/src/structured_data.rs @@ -15,19 +15,33 @@ // Please review the Licences for the specific language governing permissions and limitations // relating to use of the SAFE Network Software. +use std::fmt::{Debug, Formatter, Error}; + use rustc_serialize::{Encodable, Encoder, Decoder}; use cbor; use error::RoutingError; use NameType; use sodiumoxide::crypto; + +fn get_debug_id(input: Vec) -> String { + format!("{:02x}{:02x}{:02x}..{:02x}{:02x}{:02x}", + input[0], + input[1], + input[2], + input[input.len()-3], + input[input.len()-2], + input[input.len()-1]) +} + /// Maximum allowed size for a Structured Data to grow to pub const MAX_STRUCTURED_DATA_SIZE_IN_BYTES: usize = 102400; + /// StructuredData /// These types may be stored unsigned with previous and current owner keys /// set to the same keys. Updates though require a signature to validate -#[derive(Debug, Eq, PartialEq, PartialOrd, Ord, Clone, RustcDecodable, RustcEncodable)] +#[derive(Eq, PartialEq, PartialOrd, Ord, Clone, RustcDecodable, RustcEncodable)] pub struct StructuredData { type_tag: u64, identifier: NameType, @@ -223,6 +237,34 @@ impl StructuredData { } } +impl Debug for StructuredData { + fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> { + let _ = formatter.write_str(&format!(" type_tag: {:?} , name: {:?} , version: {:?} , data: {:?}", + self.type_tag, self.name(), self.version, get_debug_id(self.data.clone()))); + + let prev_owner_keys : Vec = self.previous_owner_keys.iter().map(|pub_key| get_debug_id(::types::array_as_vector(&pub_key.0))).collect(); + let _ = formatter.write_str(&format!(" , previous_owner_keys : (")); + for itr in prev_owner_keys.iter() { + let _ = formatter.write_str(&format!("{:?} ", itr)); + } + let _ = formatter.write_str(&format!(")")); + + let current_owner_keys : Vec = self.current_owner_keys.iter().map(|pub_key| get_debug_id(::types::array_as_vector(&pub_key.0))).collect(); + let _ = formatter.write_str(&format!(" , current_owner_keys : (")); + for itr in current_owner_keys.iter() { + let _ = formatter.write_str(&format!("{:?} ", itr)); + } + let _ = formatter.write_str(&format!(") ")); + + let prev_owner_signatures : Vec = self.previous_owner_signatures.iter().map(|signature| get_debug_id(::types::array_as_vector(&signature.0))).collect(); + let _ = formatter.write_str(&format!(" , prev_owner_signatures : (")); + for itr in prev_owner_signatures.iter() { + let _ = formatter.write_str(&format!("{:?} ", itr)); + } + formatter.write_str(&format!(") ")) + } +} + #[cfg(test)] mod test {