ClickHouse/dbms/src/Storages/MergeTree/ReplicatedMergeTreeAddress.h

62 lines
1.4 KiB
C++
Raw Normal View History

#include <IO/ReadBuffer.h>
#include <IO/ReadBufferFromString.h>
#include <IO/WriteBuffer.h>
#include <IO/WriteBufferFromString.h>
#include <IO/Operators.h>
2015-10-02 18:33:46 +00:00
namespace DB
{
2017-04-16 15:00:33 +00:00
/// Lets you know where to send requests to get to the replica.
2015-10-02 18:33:46 +00:00
struct ReplicatedMergeTreeAddress
{
String host;
UInt16 replication_port;
UInt16 queries_port;
String database;
String table;
2015-10-02 18:33:46 +00:00
ReplicatedMergeTreeAddress() {}
ReplicatedMergeTreeAddress(const String & str)
{
fromString(str);
}
2015-10-02 18:33:46 +00:00
void writeText(WriteBuffer & out) const
{
out
<< "host: " << escape << host << '\n'
<< "port: " << replication_port << '\n'
<< "tcp_port: " << queries_port << '\n'
<< "database: " << escape << database << '\n'
<< "table: " << escape << table << '\n';
}
2015-10-02 18:33:46 +00:00
void readText(ReadBuffer & in)
{
in
>> "host: " >> escape >> host >> "\n"
>> "port: " >> replication_port >> "\n"
>> "tcp_port: " >> queries_port >> "\n"
>> "database: " >> escape >> database >> "\n"
>> "table: " >> escape >> table >> "\n";
}
2015-10-02 18:33:46 +00:00
String toString() const
{
2017-07-31 21:39:24 +00:00
WriteBufferFromOwnString out;
writeText(out);
return out.str();
}
2015-10-02 18:33:46 +00:00
void fromString(const String & str)
{
ReadBufferFromString in(str);
readText(in);
}
2015-10-02 18:33:46 +00:00
};
}