summaryrefslogtreecommitdiffstats
path: root/source/Protocol/Protocol.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/Protocol/Protocol.h')
-rw-r--r--source/Protocol/Protocol.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h
index 5071f5961..466cf874b 100644
--- a/source/Protocol/Protocol.h
+++ b/source/Protocol/Protocol.h
@@ -186,6 +186,27 @@ protected:
WriteInt(a_Vector.y);
WriteInt(a_Vector.z);
}
+
+ void WriteVarInt(UInt32 a_Value)
+ {
+ // A 32-bit integer can be encoded by at most 5 bytes:
+ unsigned char b[5];
+ int idx = 0;
+ do
+ {
+ b[idx] = (a_Value & 0x7f) | ((a_Value > 0x7f) ? 0x80 : 0x00);
+ a_Value = a_Value >> 7;
+ idx++;
+ } while (a_Value > 0);
+
+ SendData((const char *)b, idx);
+ }
+
+ void WriteVarUTF8String(const AString & a_String)
+ {
+ WriteVarInt(a_String.size());
+ SendData(a_String.data(), a_String.size());
+ }
} ;