]> source.dussan.org Git - tigervnc.git/commitdiff
Added readCompactLength and writeCompactLength
authorPeter Åstrand <astrand@cendio.se>
Tue, 16 Nov 2004 13:46:33 +0000 (13:46 +0000)
committerPeter Åstrand <astrand@cendio.se>
Tue, 16 Nov 2004 13:46:33 +0000 (13:46 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@12 3789f03b-4d11-0410-bbf8-ca57d06f2519

rdr/InStream.h
rdr/OutStream.h

index 2048daa623624a18505cda80dab2e5db6ef2ac41..a3eeaadad7d042b59fca87c4bfce6e05e070b2e1 100644 (file)
@@ -71,6 +71,23 @@ namespace rdr {
     inline S16 readS16() { return (S16)readU16(); }
     inline S32 readS32() { return (S32)readU32(); }
 
+    // readCompactLength() reads 1..3 bytes representing length of the data
+    // following.  This method is used by the Tight decoder.
+
+    inline unsigned int readCompactLength() {
+      U8 b = readU8();
+      int result = (int)b & 0x7F;
+      if (b & 0x80) {
+        b = readU8();
+        result |= ((int)b & 0x7F) << 7;
+        if (b & 0x80) {
+          b = readU8();
+          result |= ((int)b & 0xFF) << 14;
+        }
+      }
+      return result;
+    }
+
     // readString() reads a string - a U32 length followed by the data.
     // Returns a null-terminated string - the caller should delete[] it
     // afterwards.
index a064bcc95e401bb90dc5bb79968ea17a98bfff7d..aed2eea189fd366538a57fa47d7c630c2a94d485 100644 (file)
@@ -65,6 +65,25 @@ namespace rdr {
     inline void writeS16(S16 s) { writeU16((U16)s); }
     inline void writeS32(S32 s) { writeU32((U32)s); }
 
+    // writeCompactLength() writes 1..3 bytes representing length of the data
+    // following.  This method is used by the Tight encoder.
+
+    inline void writeCompactLength(unsigned int len) {
+      U8 b = len & 0x7F;
+      if (len <= 0x7F) {
+        writeU8(b);
+      } else {
+        writeU8(b | 0x80);
+        b = len >> 7 & 0x7F;
+        if (len <= 0x3FFF) {
+          writeU8(b);
+        } else {
+          writeU8(b | 0x80);
+          writeU8(len >> 14 & 0xFF);
+        }
+      }
+    }
+
     // writeString() writes a string - a U32 length followed by the data.  The
     // given string should be null-terminated (but the terminating null is not
     // written to the stream).