Skip to content

Commit

Permalink
Merge pull request #6 from n0-computer/remove-entry-newtype
Browse files Browse the repository at this point in the history
refactor: remove entry newtype
  • Loading branch information
rklaehn authored Nov 13, 2024
2 parents 3802d6f + 1d8c60d commit 9166b22
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 52 deletions.
59 changes: 7 additions & 52 deletions src/rpc/client/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ use quic_rpc::{client::BoxedConnector, message::RpcMsg, Connector};
use serde::{Deserialize, Serialize};

use super::flatten;
#[doc(inline)]
pub use crate::engine::{LiveEvent, Origin, SyncEvent, SyncReason};
use crate::{
actor::OpenState,
rpc::proto::{
Expand All @@ -32,7 +30,12 @@ use crate::{
StartSyncRequest, StatusRequest,
},
store::{DownloadPolicy, Query},
AuthorId, Capability, CapabilityKind, DocTicket, NamespaceId, PeerIdBytes, RecordIdentifier,
AuthorId, Capability, CapabilityKind, DocTicket, NamespaceId, PeerIdBytes,
};
#[doc(inline)]
pub use crate::{
engine::{LiveEvent, Origin, SyncEvent, SyncReason},
Entry,
};

/// Iroh docs client.
Expand Down Expand Up @@ -265,7 +268,7 @@ impl<C: Connector<RpcService>> Doc<C> {
.0
.rpc
.server_streaming(ExportFileRequest {
entry: entry.0,
entry,
path: path.as_ref().into(),
mode,
})
Expand Down Expand Up @@ -428,54 +431,6 @@ where
}
}

/// A single entry in a [`Doc`].
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct Entry(crate::Entry);

impl From<crate::Entry> for Entry {
fn from(value: crate::Entry) -> Self {
Self(value)
}
}

impl From<crate::SignedEntry> for Entry {
fn from(value: crate::SignedEntry) -> Self {
Self(value.into())
}
}

impl Entry {
/// Returns the [`RecordIdentifier`] for this entry.
pub fn id(&self) -> &RecordIdentifier {
self.0.id()
}

/// Returns the [`AuthorId`] of this entry.
pub fn author(&self) -> AuthorId {
self.0.author()
}

/// Returns the [`struct@Hash`] of the content data of this record.
pub fn content_hash(&self) -> Hash {
self.0.content_hash()
}

/// Returns the length of the data addressed by this record's content hash.
pub fn content_len(&self) -> u64 {
self.0.content_len()
}

/// Returns the key of this entry.
pub fn key(&self) -> &[u8] {
self.0.key()
}

/// Returns the timestamp of this entry.
pub fn timestamp(&self) -> u64 {
self.0.timestamp()
}
}

/// Progress messages for an doc import operation
///
/// An import operation involves computing the outboard of a file, and then
Expand Down
15 changes: 15 additions & 0 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,21 @@ impl Entry {
&self.record
}

/// Get the content hash of the record.
pub fn content_hash(&self) -> Hash {
self.record.hash
}

/// Get the content length of the record.
pub fn content_len(&self) -> u64 {
self.record.len
}

/// Get the timestamp of the record.
pub fn timestamp(&self) -> u64 {
self.record.timestamp
}

/// Serialize this entry into its canonical byte representation used for signing.
pub fn encode(&self, out: &mut Vec<u8>) {
self.id.encode(out);
Expand Down

0 comments on commit 9166b22

Please sign in to comment.