THRIFT-5923: UUID python
Client: py
Patch: CJCombrink
This closes #3330
diff --git a/lib/py/src/protocol/TCompactProtocol.py b/lib/py/src/protocol/TCompactProtocol.py
index a3527cd..b58095a 100644
--- a/lib/py/src/protocol/TCompactProtocol.py
+++ b/lib/py/src/protocol/TCompactProtocol.py
@@ -19,6 +19,7 @@
from .TProtocol import TType, TProtocolBase, TProtocolException, TProtocolFactory, checkIntegerLimits
from struct import pack, unpack
+import uuid
__all__ = ['TCompactProtocol', 'TCompactProtocolFactory']
@@ -80,6 +81,7 @@
shift += 7
+# As per TCompactProtocol.tcc
class CompactType(object):
STOP = 0x00
TRUE = 0x01
@@ -94,6 +96,7 @@
SET = 0x0A
MAP = 0x0B
STRUCT = 0x0C
+ UUID = 0x0D
CTYPES = {
@@ -109,6 +112,7 @@
TType.LIST: CompactType.LIST,
TType.SET: CompactType.SET,
TType.MAP: CompactType.MAP,
+ TType.UUID: CompactType.UUID,
}
TTYPES = {}
@@ -276,6 +280,10 @@
def writeDouble(self, dub):
self.trans.write(pack('<d', dub))
+ @writer
+ def writeUuid(self, uuid):
+ self.trans.write(uuid.bytes)
+
def __writeBinary(self, s):
self.__writeSize(len(s))
self.trans.write(s)
@@ -416,6 +424,12 @@
val, = unpack('<d', buff)
return val
+ @reader
+ def readUuid(self):
+ buff = self.trans.readAll(16)
+ val = uuid.UUID(bytes=buff)
+ return val
+
def __readBinary(self):
size = self.__readSize()
self._check_string_length(size)