[Spice-devel] [PATCH 2/5] improve lz4 protocol

Frediano Ziglio fziglio at redhat.com
Mon May 16 15:59:38 UTC 2016


Reduce size if not compressed and compute compressed size using message
length

This should be merged in previous patch
---
 common/messages.h |  2 +-
 spice.proto       | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/common/messages.h b/common/messages.h
index d001850..516a345 100644
--- a/common/messages.h
+++ b/common/messages.h
@@ -59,7 +59,7 @@ typedef struct SpiceMsgCompressedData {
     uint8_t type;
     uint32_t uncompressed_size;
     uint32_t compressed_size;
-    uint8_t compressed_data[0];
+    uint8_t *compressed_data;
 } SpiceMsgCompressedData;
 
 typedef struct SpiceMsgEmpty {
diff --git a/spice.proto b/spice.proto
index a515aef..0bfc515 100644
--- a/spice.proto
+++ b/spice.proto
@@ -121,16 +121,25 @@ message Data {
 } @nocopy;
 
 enum8 data_compression_type {
-    INVALID,
     NONE,
     LZ4,
 };
 
+struct EmptyStructure {
+};
+
 message CompressedData {
     data_compression_type type;
-    uint32 uncompressed_size;
-    uint32 compressed_size;
-    uint8 compressed_data[] @end;
+    switch (type) {
+    /* we cannot use !NONE (works only with flags) */
+    case NONE:
+        /* due to the way cases are defined after NONE we must have something */
+        /* due to a bug we cannot use @virtual to write 0 to compressed_size */
+        EmptyStructure empty;
+    default:
+        uint32 uncompressed_size;
+    } u @anon;
+    uint8 compressed_data[] @as_ptr(compressed_size);
 } @ctype(SpiceMsgCompressedData);
 
 struct ChannelWait {
-- 
2.7.4



More information about the Spice-devel mailing list