Merge pull request #43 from tomaka/multihash-to-bytes

Rename Multihash::as_bytes() to to_bytes()
This commit is contained in:
Marek Kotewicz 2017-11-24 11:39:14 +01:00 committed by GitHub
commit db6940df56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -68,13 +68,13 @@ impl<'a> Peerstore for &'a JsonPeerstore {
#[inline]
fn peer(self, peer_id: &PeerId) -> Option<Self::PeerAccess> {
let hash = peer_id.clone().as_bytes().to_base58();
let hash = peer_id.to_bytes().to_base58();
self.store.lock(hash.into()).map(JsonPeerstoreAccess)
}
#[inline]
fn peer_or_create(self, peer_id: &PeerId) -> Self::PeerAccess {
let hash = peer_id.clone().as_bytes().to_base58();
let hash = peer_id.to_bytes().to_base58();
JsonPeerstoreAccess(self.store.lock_or_create(hash.into()))
}

View File

@ -130,11 +130,11 @@ impl FromHex for Multihash {
impl Multihash {
/// Returns a byte vec representing the encoded multihash
pub fn as_bytes(&mut self) -> Vec<u8> {
pub fn to_bytes(&self) -> Vec<u8> {
let mut v = Vec::new();
v.write_u64::<BigEndian>(self.code).expect("writing to a locally owned vec should never yield I/O errors");
v.write_u64::<BigEndian>(self.length).expect("writing to a locally owned vec should never yield I/O errors");
v.append(&mut self.digest);
v.extend_from_slice(&self.digest);
v
}
@ -210,7 +210,7 @@ mod tests {
};
let expected_bytes = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 44, 38, 180, 107, 104, 255, 198, 143, 249, 155, 69, 60, 29, 48, 65, 52, 19, 66, 45, 112, 100, 131, 191, 160, 249, 138, 94, 136, 98, 102, 231, 174];
assert_eq!(hash.clone().as_bytes(), expected_bytes);
assert_eq!(hash.to_bytes(), expected_bytes);
assert_eq!(Multihash::decode_bytes(expected_bytes).unwrap(), hash);
}