diff options
| author | vitalyisaev <[email protected]> | 2023-11-14 09:58:56 +0300 |
|---|---|---|
| committer | vitalyisaev <[email protected]> | 2023-11-14 10:20:20 +0300 |
| commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
| tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Core/MySQL/PacketEndpoint.cpp | |
| parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Core/MySQL/PacketEndpoint.cpp')
| -rw-r--r-- | contrib/clickhouse/src/Core/MySQL/PacketEndpoint.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Core/MySQL/PacketEndpoint.cpp b/contrib/clickhouse/src/Core/MySQL/PacketEndpoint.cpp new file mode 100644 index 00000000000..97b5d3b4d11 --- /dev/null +++ b/contrib/clickhouse/src/Core/MySQL/PacketEndpoint.cpp @@ -0,0 +1,71 @@ +#include <Core/MySQL/PacketEndpoint.h> +#include <IO/ReadBufferFromPocoSocket.h> +#include <Common/typeid_cast.h> + +namespace DB +{ + +namespace ErrorCodes +{ + extern const int LOGICAL_ERROR; +} + +namespace MySQLProtocol +{ + +PacketEndpoint::PacketEndpoint(WriteBuffer & out_, uint8_t & sequence_id_) + : sequence_id(sequence_id_), in(nullptr), out(&out_) +{ +} + +PacketEndpoint::PacketEndpoint(ReadBuffer & in_, WriteBuffer & out_, uint8_t & sequence_id_) + : sequence_id(sequence_id_), in(&in_), out(&out_) +{ +} + +MySQLPacketPayloadReadBuffer PacketEndpoint::getPayload() +{ + return MySQLPacketPayloadReadBuffer(*in, sequence_id); +} + +void PacketEndpoint::receivePacket(IMySQLReadPacket & packet) +{ + packet.readPayload(*in, sequence_id); +} + +bool PacketEndpoint::tryReceivePacket(IMySQLReadPacket & packet, UInt64 millisecond) +{ + if (millisecond != 0) + { + ReadBufferFromPocoSocket * socket_in = typeid_cast<ReadBufferFromPocoSocket *>(in); + + if (!socket_in) + throw Exception(ErrorCodes::LOGICAL_ERROR, "LOGICAL ERROR: Attempt to pull the duration in a non socket stream"); + + if (!socket_in->poll(millisecond * 1000)) + return false; + } + + packet.readPayload(*in, sequence_id); + return true; +} + +void PacketEndpoint::resetSequenceId() +{ + sequence_id = 0; +} + +String PacketEndpoint::packetToText(const String & payload) +{ + String result; + for (auto c : payload) + { + result += ' '; + result += std::to_string(static_cast<unsigned char>(c)); + } + return result; +} + +} + +} |
