[pbs-devel] [RFC v2 pxar 6/23] fix #3174: encoder: helper to add to encoder position

Christian Ebner c.ebner at proxmox.com
Mon Oct 9 13:51:22 CEST 2023


Adds a helper to allow to increase the encoder position by a given
size. This is used to increase the position when adding an appendix
section to the pxar stream, as these bytes are never encoded directly
but rather referenced by already existing chunks.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
Changes since v1:
- add unsafe function signature in order to make it clear that calling
  `position_add` with incorrect size values will break the pxar
  archive encoding.

 src/encoder/aio.rs  | 5 +++++
 src/encoder/mod.rs  | 6 ++++++
 src/encoder/sync.rs | 5 +++++
 3 files changed, 16 insertions(+)

diff --git a/src/encoder/aio.rs b/src/encoder/aio.rs
index 5c7c7b9..8ff1364 100644
--- a/src/encoder/aio.rs
+++ b/src/encoder/aio.rs
@@ -112,6 +112,11 @@ impl<'a, T: SeqWrite + 'a> Encoder<'a, T> {
         self.inner.finish().await
     }
 
+    /// Add size to encoders position and return new position.
+    pub unsafe fn position_add(&mut self, size: u64) -> u64 {
+        unsafe { self.inner.position_add(size) }
+    }
+
     /// Add reference to archive appendix
     pub async fn add_appendix_ref<PF: AsRef<Path>>(
         &mut self,
diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs
index 3270d52..de23728 100644
--- a/src/encoder/mod.rs
+++ b/src/encoder/mod.rs
@@ -673,6 +673,12 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
         self.state.write_position
     }
 
+    #[inline]
+    pub unsafe fn position_add(&mut self, size: u64) -> u64 {
+        self.state.write_position += size;
+        self.state.write_position
+    }
+
     pub async fn create_directory(
         &mut self,
         file_name: &Path,
diff --git a/src/encoder/sync.rs b/src/encoder/sync.rs
index 2aaa6f2..a7f6b20 100644
--- a/src/encoder/sync.rs
+++ b/src/encoder/sync.rs
@@ -110,6 +110,11 @@ impl<'a, T: SeqWrite + 'a> Encoder<'a, T> {
         poll_result_once(self.inner.finish())
     }
 
+    /// Add size to encoders position and return new position.
+    pub unsafe fn position_add(&mut self, size: u64) -> u64 {
+        unsafe { self.inner.position_add(size) }
+    }
+
     /// Add reference to archive appendix
     pub async fn add_appendix_ref<PF: AsRef<Path>>(
         &mut self,
-- 
2.39.2






More information about the pbs-devel mailing list