THRIFT-5868: UUID Support for TCompactProtocol
Client: cpp
Patch: Carel Combrink
This closes #3137
diff --git a/lib/cpp/src/thrift/protocol/TCompactProtocol.tcc b/lib/cpp/src/thrift/protocol/TCompactProtocol.tcc
index a872c23..b57568f 100644
--- a/lib/cpp/src/thrift/protocol/TCompactProtocol.tcc
+++ b/lib/cpp/src/thrift/protocol/TCompactProtocol.tcc
@@ -61,10 +61,11 @@
CT_LIST = 0x09,
CT_SET = 0x0A,
CT_MAP = 0x0B,
- CT_STRUCT = 0x0C
+ CT_STRUCT = 0x0C,
+ CT_UUID = 0x0D
};
-const int8_t TTypeToCType[16] = {
+const int8_t TTypeToCType[17] = {
CT_STOP, // T_STOP
0, // unused
CT_BOOLEAN_TRUE, // T_BOOL
@@ -81,6 +82,7 @@
CT_MAP, // T_MAP
CT_SET, // T_SET
CT_LIST, // T_LIST
+ CT_UUID, // T_UUID
};
}} // end detail::compact namespace
@@ -286,6 +288,15 @@
return wsize;
}
+/**
+ * Write a TUuid to the wire
+ */
+template <class Transport_>
+uint32_t TCompactProtocolT<Transport_>::writeUUID(const TUuid& uuid) {
+ trans_->write(uuid.data(), uuid.size());
+ return uuid.size();
+}
+
//
// Internal Writing methods
//
@@ -719,6 +730,15 @@
return rsize + static_cast<uint32_t>(size);
}
+
+/**
+ * Read a TUuid from the wire.
+ */
+template <class Transport_>
+uint32_t TCompactProtocolT<Transport_>::readUUID(TUuid& uuid) {
+ return trans_->readAll(uuid.begin(), uuid.size());
+}
+
/**
* Read an i32 from the wire as a varint. The MSB of each byte is set
* if there is another byte to follow. This can read up to 5 bytes.
@@ -826,6 +846,8 @@
return T_MAP;
case detail::compact::CT_STRUCT:
return T_STRUCT;
+ case detail::compact::CT_UUID:
+ return T_UUID;
default:
throw TException(std::string("don't know what type: ") + static_cast<char>(type));
}
@@ -850,6 +872,7 @@
case T_MAP: return sizeof(int8_t); // element count
case T_SET: return sizeof(int8_t); // element count
case T_LIST: return sizeof(int8_t); // element count
+ case T_UUID: return 16; // 16 bytes
default: throw TProtocolException(TProtocolException::UNKNOWN, "unrecognized type code");
}
}