about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorPicnoir <picnoir@alternativebit.fr>2024-04-03T08·54+0200
committerpicnoir picnoir <picnoir@alternativebit.fr>2024-04-03T11·32+0000
commit9cec50cb2eb1606511d8e8d3e8a4137e0feb6ffa (patch)
tree0995ac48c2d1ac96cde0292d6db10cd5ff168e45 /tvix
parentc35a5ff611eed94c4cf32de4e26baca4fe38889e (diff)
refactor(tvix/nix-compat): drop read_u32 r/7846
Actually these are all u64 LE encoded on the wire.

Change-Id: I5ca22c7639607ac47117cd946e036a444271885a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11348
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/nix-compat/src/wire/primitive.rs34
1 files changed, 1 insertions, 33 deletions
diff --git a/tvix/nix-compat/src/wire/primitive.rs b/tvix/nix-compat/src/wire/primitive.rs
index a925bd00df53..119053b89d87 100644
--- a/tvix/nix-compat/src/wire/primitive.rs
+++ b/tvix/nix-compat/src/wire/primitive.rs
@@ -11,25 +11,6 @@ pub static MAGIC_HELLO_RESPONSE: [u8; 8] = *b"oixd\0\0\0\0";
 // LE-encoded protocol version.
 pub static PROTOCOL_VERSION: [u8; 8] = [0x23, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
 
-/// Read a LE u32 from the least-significant bytes of a LE u64.
-///
-/// Overall, it looks like this on the wire:
-///
-/// 00 0x12 0x32 0x00 0x00 0x00 0x00 0x00 0x00
-///    |------------------|-------------------|
-///          LE u32            padding
-///
-/// Not sure why the protocol does this instead of using a plain u64,
-/// but well, it is what it is.
-///
-/// Analogous to the readInt function in cppnix.
-pub async fn read_u32<R: AsyncReadExt + Unpin>(r: &mut R) -> std::io::Result<u32> {
-    let val64 = r.read_u64_le().await?;
-    u32::try_from(val64).map_err(|_| {
-        std::io::Error::new(std::io::ErrorKind::InvalidData, "padding is not all zeroes")
-    })
-}
-
 #[allow(dead_code)]
 /// Read a u64 from the AsyncRead (little endian).
 pub async fn read_u64<R: AsyncReadExt + Unpin>(r: &mut R) -> std::io::Result<u64> {
@@ -56,8 +37,7 @@ pub async fn write_bool<W: AsyncWrite + Unpin>(w: &mut W, v: bool) -> std::io::R
 #[cfg(test)]
 mod tests {
     use super::*;
-    use hex_literal::hex;
-    use tokio_test::{assert_err, io::Builder};
+    use tokio_test::io::Builder;
 
     // Integers.
     #[tokio::test]
@@ -98,16 +78,4 @@ mod tests {
         let mut mock = Builder::new().write(&1u64.to_le_bytes()).build();
         write_bool(&mut mock, true).await.unwrap();
     }
-    #[tokio::test]
-    async fn test_read_u32() {
-        let mut mock = Builder::new().read(&hex!("7856341200000000")).build();
-        let res = read_u32(&mut mock).await.unwrap();
-        assert_eq!(res, 0x12345678);
-    }
-    #[tokio::test]
-    async fn test_read_too_large_u32_fail() {
-        let mut mock = Builder::new().read(&hex!("7856341298760000")).build();
-        let res = read_u32(&mut mock).await;
-        assert_err!(res);
-    }
 }