aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/IO/MySQLPacketPayloadWriteBuffer.h
blob: d4ce8a8955e86deaae7707e729dd18ce4d83ad18 (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
#pragma once

#include <IO/WriteBuffer.h>

namespace DB
{

/** Writing packets.
 *  https://dev.mysql.com/doc/internals/en/mysql-packet.html
 */
class MySQLPacketPayloadWriteBuffer : public WriteBuffer
{
public:
    MySQLPacketPayloadWriteBuffer(WriteBuffer & out_, size_t payload_length_, uint8_t & sequence_id_);

    bool remainingPayloadSize() const { return total_left; }

protected:
    void nextImpl() override;

private:
    WriteBuffer & out;
    uint8_t & sequence_id;

    size_t total_left = 0;
    size_t payload_length = 0;
    size_t bytes_written = 0;
    bool eof = false;

    void startNewPacket();

    /// Sets working buffer to the rest of current packet payload.
    void setWorkingBuffer();
};

}