diff options
author | edef <edef@edef.eu> | 2024-04-29T13·57+0000 |
---|---|---|
committer | edef <edef@edef.eu> | 2024-04-29T15·33+0000 |
commit | 44bd9543a6d23afd9b735bd8149341ea071019c2 (patch) | |
tree | b6016202187948fdcff6a71be56177e6c503ef76 /tvix/nix-compat/src/wire/bytes/reader/mod.rs | |
parent | 5070f9eff73e2c8f781aceb34df980dbfe929cc7 (diff) |
feat(nix-compat/wire/bytes/reader): expose the remaining data length r/8029
The API is a bit odd here, because we don't have a distinct type for a known-length reader. Change-Id: I4a1dd07fbed0a400004dbe4aa2095c51898ad3bd Reviewed-on: https://cl.tvl.fyi/c/depot/+/11538 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de> Reviewed-by: Brian Olsen <me@griff.name>
Diffstat (limited to 'tvix/nix-compat/src/wire/bytes/reader/mod.rs')
-rw-r--r-- | tvix/nix-compat/src/wire/bytes/reader/mod.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tvix/nix-compat/src/wire/bytes/reader/mod.rs b/tvix/nix-compat/src/wire/bytes/reader/mod.rs index 78615faf0f4c..9f7013a4e9b1 100644 --- a/tvix/nix-compat/src/wire/bytes/reader/mod.rs +++ b/tvix/nix-compat/src/wire/bytes/reader/mod.rs @@ -89,6 +89,20 @@ where }, } } + + /// Remaining data length, ie not including data already read. + /// + /// If the size has not been read yet, this is [None]. + #[allow(clippy::len_without_is_empty)] // if size is unknown, we can't answer that + pub fn len(&self) -> Option<u64> { + match self.state { + State::Size { .. } => None, + State::Body { + consumed, user_len, .. + } => Some(user_len - consumed), + State::Trailer(ref r) => Some(r.len() as u64), + } + } } impl<R: AsyncRead + Unpin> AsyncRead for BytesReader<R> { |