Skip to content

Commit e51706b

Browse files
committed
Clean up some comments in header
1 parent 51cedc4 commit e51706b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Diff for: lazuli_core/src/header.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Contains the PacketHeader struct. This struct is used to prepend a header to a packet.
2+
//!
3+
//! The header is used to ensure that the data is sent and received correctly.
4+
15
use std::{
26
fmt::Debug,
37
hash::{DefaultHasher, Hash, Hasher},
@@ -6,18 +10,18 @@ use std::{
610

711
use crate::{hash_type_id, Result, Sendable};
812

13+
// RSOCK was the development name for this project.
14+
// TODO: Maybe change this to lazi or something similar.
915
const HEADER: [u8; 5] = *b"RSOCK";
1016

1117
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
1218
#[repr(C)] // This is important for the safety of the from_bytes_unchecked function.
1319
/// The header of a packet. When a packet is sent over a socket, it is prepended with this header.
14-
/// # Why the type parameter?
15-
/// The type parameter is used to have some sort of type safety.
16-
/// Without the type parameter, it would be possible to create a PacketHeader with a `type_id` that does not match the actual type of the payload.
17-
/// This would lead to undefined behavior.
18-
///
19-
/// The type parameter is used to ensure that the `type_id` matches the actual type of the payload.
20-
/// You can make an untyped PacketHeader by using `PacketHeader<UnknownType>`, but this is only intended for receiving packets.
20+
/// This contains the type_id of the payload, the size of the payload, and a checksum of the payload.
21+
/// The checksum is used to verify that the payload was received correctly.
22+
/// The type_id is used to determine the type of the payload.
23+
/// The payload_size is used to determine the size of the payload.
24+
// TODO: Remove the type parameter. It was never used, and ended up causing some issues.
2125
pub struct PacketHeader<T>
2226
where
2327
T: 'static + Sendable,
@@ -43,6 +47,7 @@ impl<T: Sendable> Debug for PacketHeader<T> {
4347
.finish_non_exhaustive()
4448
}
4549
}
50+
4651
/// A ZST that represents an unknown type.
4752
/// This is used when the type of the payload is unknown.
4853
#[derive(Clone, Copy, Debug)]
@@ -91,7 +96,7 @@ where
9196
}
9297
}
9398
/// Calculates the checksum of the payload. Sets the checksum field to the calculated checksum.
94-
pub fn calculate_checksum(&mut self, payload: &[u8]) {
99+
pub(crate) fn calculate_checksum(&mut self, payload: &[u8]) {
95100
let mut hasher = DefaultHasher::new();
96101
hasher.write(payload);
97102
self.checksum = hasher.finish() as u32;
@@ -119,7 +124,8 @@ where
119124
}
120125
}
121126

122-
pub fn id(&self) -> u32 {
127+
/// Gets the type_id of the payload.
128+
pub(crate) fn id(&self) -> u32 {
123129
self.type_id
124130
}
125131
}

0 commit comments

Comments
 (0)