summaryrefslogtreecommitdiff
path: root/rld-compression.h
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2012-11-26 11:04:57 +1100
committerChris Johns <chrisj@rtems.org>2012-11-26 11:04:57 +1100
commit8fdabca48d74b70a5d35ea31bca09261a587b7f3 (patch)
treecc0b4308d6b305df34ad0c91f9ea874ce7259e5a /rld-compression.h
parent9af1f3cde74c58deeade11469bf095576fa48ad7 (diff)
Add writing from images as well as streaming operators.
Add the ability to write to the compressed stream directly from files::images. Add streaming operator support which is always in a standard byte format in the output image.
Diffstat (limited to 'rld-compression.h')
-rw-r--r--rld-compression.h54
1 files changed, 52 insertions, 2 deletions
diff --git a/rld-compression.h b/rld-compression.h
index 624ab8a..7e510f1 100644
--- a/rld-compression.h
+++ b/rld-compression.h
@@ -54,8 +54,8 @@ namespace rld
~compressor ();
/**
- * Write to the output buffer and the image once full
- * and compressed.
+ * Write the data to the output buffer and once the image buffer is full
+ * compress and write the compressed data to the image.
*
* @param data The data to write to the image compressed
* @param length The mount of data in bytes to write.
@@ -63,6 +63,17 @@ namespace rld
void write (const void* data, size_t length);
/**
+ * Write the section of the input image file to the output buffer and
+ * once the image buffer is full compress and write the compressed data
+ * to the image.
+ *
+ * @param input The input image.
+ * @param offset The input image offset to read from.
+ * @param length The mount of data in bytes to write.
+ */
+ void write (files::image& input, off_t offset, size_t length);
+
+ /**
* Flush the output buffer is data is present.
*/
void flush ();
@@ -94,9 +105,48 @@ namespace rld
// transferred.
};
+ /**
+ * Compressor template function for writing data to the compressor..
+ */
+ template < typename T >
+ void write (compressor& comp, const T value)
+ {
+ uint8_t bytes[sizeof (T)];
+ T v = value;
+ int b = sizeof (T) - 1;
+ while (b > 0)
+ {
+ bytes[b--] = (uint8_t) v;
+ v >>= 8;
+ }
+ comp.write (bytes, sizeof (T));
+ }
+
}
+}
+
+static inline rld::compress::compressor& operator<< (rld::compress::compressor& comp,
+ const uint64_t value) {
+ rld::compress::write < uint64_t > (comp, value);
+ return comp;
+}
+static inline rld::compress::compressor& operator<< (rld::compress::compressor& comp,
+ const uint32_t value) {
+ rld::compress::write < uint32_t > (comp, value);
+ return comp;
+}
+
+static inline rld::compress::compressor& operator<< (rld::compress::compressor& comp,
+ const size_t value) {
+ comp << (uint32_t) value;
+ return comp;
+}
+static inline rld::compress::compressor& operator<< (rld::compress::compressor& comp,
+ const std::string& str) {
+ comp.write (str.c_str (), str.size ());
+ return comp;
}
#endif