about summary refs log tree commit diff
path: root/tvix/nix-compat/src/wire/bytes/reader
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2024-04-30T07·15+0000
committeredef <edef@edef.eu>2024-04-30T09·55+0000
commit095f715a8045933159cb7daf3302246b9ca50658 (patch)
treed66389e63c9672974f210d0e0691aa16c51c720b /tvix/nix-compat/src/wire/bytes/reader
parentb3305ea6e26bef913cfa1a1d7b5cb0c13392ed4c (diff)
refactor(nix-compat/wire): drop primitive functions r/8042
These may as well be inlined, and hardly need tests, since they just
alias AsyncReadExt::read_u64_le / AsyncWriteExt::write_u64_le.

Boolean reading is worth making explicit, since callers may differ on
how they want to handle values other than 0 and 1.

Boolean writing simplifies to `.write_u64_le(x as u64)`, which is also
fine to inline.

Change-Id: Ief9722fe886688693feb924ff0306b5bc68dd7a2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11549
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/wire/bytes/reader')
-rw-r--r--tvix/nix-compat/src/wire/bytes/reader/mod.rs6
1 files changed, 2 insertions, 4 deletions
diff --git a/tvix/nix-compat/src/wire/bytes/reader/mod.rs b/tvix/nix-compat/src/wire/bytes/reader/mod.rs
index ef59e9c160e4..50398d9b9e40 100644
--- a/tvix/nix-compat/src/wire/bytes/reader/mod.rs
+++ b/tvix/nix-compat/src/wire/bytes/reader/mod.rs
@@ -5,9 +5,7 @@ use std::{
     pin::Pin,
     task::{self, ready, Poll},
 };
-use tokio::io::{AsyncRead, ReadBuf};
-
-use crate::wire::read_u64;
+use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf};
 
 use trailer::{read_trailer, ReadTrailer, Trailer};
 mod trailer;
@@ -52,7 +50,7 @@ where
 {
     /// Constructs a new BytesReader, using the underlying passed reader.
     pub async fn new<S: RangeBounds<u64>>(mut reader: R, allowed_size: S) -> io::Result<Self> {
-        let size = read_u64(&mut reader).await?;
+        let size = reader.read_u64_le().await?;
 
         if !allowed_size.contains(&size) {
             return Err(io::Error::new(io::ErrorKind::InvalidData, "invalid size"));