Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

re-format log info for ImmutableData and StructruedData #638

Merged
merged 2 commits into from
Aug 24, 2015
Merged
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
10 changes: 9 additions & 1 deletion src/immutable_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<u8>,
Expand Down Expand Up @@ -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 {
Expand Down
44 changes: 43 additions & 1 deletion src/structured_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) -> 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,
Expand Down Expand Up @@ -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<String> = 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<String> = 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<String> = 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 {
Expand Down