Skip to content

Commit

Permalink
Lower the file-id to 32bit
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVentura committed Nov 28, 2024
1 parent 066d081 commit 8684aa5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl TransferPlan {

/// The index of a file in the transfer plan.
#[derive(BorshDeserialize, BorshSerialize, Copy, Clone, Debug, Eq, Hash, PartialEq)]
struct FileId(u64);
struct FileId(u32);

impl FileId {
fn from_usize(i: usize) -> FileId {
Expand Down Expand Up @@ -205,7 +205,7 @@ enum SendResult {

/// Metadata about a chunk of data that follows.
///
/// The Borsh-generated representation of this is zero-overhead (20 bytes).
/// The Borsh-generated representation of this is zero-overhead (16 bytes).
#[derive(BorshDeserialize, BorshSerialize, Debug)]
struct ChunkHeader {
/// Which file is the chunk from?
Expand All @@ -219,8 +219,8 @@ struct ChunkHeader {
}

impl ChunkHeader {
fn to_bytes(&self) -> [u8; 20] {
let mut buffer = [0_u8; 20];
fn to_bytes(&self) -> [u8; 16] {
let mut buffer = [0_u8; 16];
let mut cursor = std::io::Cursor::new(&mut buffer[..]);
self.serialize(&mut cursor)
.expect("Writing to memory never fails.");
Expand Down Expand Up @@ -503,7 +503,6 @@ impl FileReceiver {
self.offset += chunk.data.len() as u64;
}

//self.out_file = Some(out_file);
Ok(())
}
}
Expand Down Expand Up @@ -586,7 +585,7 @@ fn main_recv(
// Read a chunk header. If we hit EOF, that is not an error, it
// means that the sender has nothing more to send so we can just
// exit here.
let mut buf = [0u8; 20];
let mut buf = [0u8; 16];
match stream.read_exact(&mut buf) {
Ok(..) => {}
Err(err) if err.kind() == ErrorKind::UnexpectedEof => break,
Expand Down

0 comments on commit 8684aa5

Please sign in to comment.