aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Core/MySQL/IMySQLWritePacket.h
blob: b00ffbaacaee03cb5c84fdb1e6b08f2f6a967618 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include <IO/WriteBuffer.h>

namespace DB
{

namespace MySQLProtocol
{

class IMySQLWritePacket
{
public:
    IMySQLWritePacket() = default;

    virtual ~IMySQLWritePacket() = default;

    IMySQLWritePacket(IMySQLWritePacket &&) = default;

    virtual void writePayload(WriteBuffer & buffer, uint8_t & sequence_id) const;

protected:
    virtual size_t getPayloadSize() const = 0;

    virtual void writePayloadImpl(WriteBuffer & buffer) const = 0;
};

size_t getLengthEncodedNumberSize(uint64_t x);
size_t getLengthEncodedStringSize(const String & s);

void writeLengthEncodedNumber(uint64_t x, WriteBuffer & buffer);
void writeLengthEncodedString(const String & s, WriteBuffer & buffer);
void writeNulTerminatedString(const String & s, WriteBuffer & buffer);

}

}