[WIP] [PATCH v0.0-20200229 09/11] ez: lzma: checkpoint feature for range encoder
Gao Xiang
hsiangkao at aol.com
Sat Feb 29 15:50:15 AEDT 2020
which is used to save the current state of range
encoder for later recovery in order to implement
LZMA fixed-sized output compression.
Signed-off-by: Gao Xiang <hsiangkao at aol.com>
---
lzma/rc_encoder_ckpt.h | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
create mode 100644 lzma/rc_encoder_ckpt.h
diff --git a/lzma/rc_encoder_ckpt.h b/lzma/rc_encoder_ckpt.h
new file mode 100644
index 0000000..415bf0c
--- /dev/null
+++ b/lzma/rc_encoder_ckpt.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * ez/lzma/rc_encoder_ckpt.h - checkpoint for range encoder
+ *
+ * Copyright (C) 2020 Gao Xiang <hsiangkao at aol.com>
+ */
+#ifndef __EZ_LZMA_RC_ENCODER_CKPT_H
+#define __EZ_LZMA_RC_ENCODER_CKPT_H
+
+#include "rc_encoder.h"
+
+struct lzma_rc_ckpt {
+ uint64_t low;
+ uint64_t extended_bytes;
+ uint32_t range;
+ uint8_t firstbyte;
+};
+
+void rc_write_checkpoint(struct lzma_rc_encoder *rc, struct lzma_rc_ckpt *cp)
+{
+ *cp = (struct lzma_rc_ckpt) { .low = rc->low,
+ .extended_bytes = rc->extended_bytes,
+ .range = rc->range,
+ .firstbyte = rc->firstbyte
+ };
+}
+
+void rc_restore_checkpoint(struct lzma_rc_encoder *rc, struct lzma_rc_ckpt *cp)
+{
+ rc->low = cp->low;
+ rc->extended_bytes = cp->extended_bytes;
+ rc->range = cp->range;
+ rc->firstbyte = cp->firstbyte;
+
+ rc->pos = 0;
+ rc->count = 0;
+}
+
+#endif
+
--
2.20.1
More information about the Linux-erofs
mailing list