]> source.dussan.org Git - tigervnc.git/commitdiff
Add efficient method to copy data between two streams
authorPierre Ossman <ossman@cendio.se>
Tue, 10 Nov 2015 16:13:27 +0000 (17:13 +0100)
committerPierre Ossman <ossman@cendio.se>
Fri, 27 Nov 2015 09:59:25 +0000 (10:59 +0100)
common/rdr/OutStream.h

index 94d57dd310189bcc20d98c040ddfc3b4391bcb6b..a749a208abfb9069e30ae9d6272a5cc6c452a030 100644 (file)
@@ -25,6 +25,7 @@
 #define __RDR_OUTSTREAM_H__
 
 #include <rdr/types.h>
+#include <rdr/InStream.h>
 #include <string.h> // for memcpy
 
 namespace rdr {
@@ -100,6 +101,17 @@ namespace rdr {
       }
     }
 
+    // copyBytes() efficiently transfers data between streams
+
+    void copyBytes(InStream* is, int length) {
+      while (length > 0) {
+        int n = check(1, length);
+        is->readBytes(ptr, n);
+        ptr += n;
+        length -= n;
+      }
+    }
+
     // writeOpaqueN() writes a quantity without byte-swapping.
 
     inline void writeOpaque8( U8  u) { writeU8(u); }