mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Merge pull request #49933 from ClickHouse/fix-ipv6-proto-serialization
Fix IPv6 encoding in protobuf
This commit is contained in:
commit
a2c3de5082
@ -1852,25 +1852,26 @@ namespace
|
||||
|
||||
write_function = [this](IPv6 value)
|
||||
{
|
||||
ipToString(value, text_buffer);
|
||||
text_buffer = String(IPV6_BINARY_LENGTH, '\0');
|
||||
memcpy(text_buffer.data(), &value.toUnderType(), IPV6_BINARY_LENGTH);
|
||||
writeStr(text_buffer);
|
||||
};
|
||||
|
||||
read_function = [this]() -> IPv6
|
||||
{
|
||||
readStr(text_buffer);
|
||||
return parse<IPv6>(text_buffer);
|
||||
if (text_buffer.size() != IPV6_BINARY_LENGTH)
|
||||
throw Exception(ErrorCodes::PROTOBUF_BAD_CAST,
|
||||
"Could not convert bytes field {} to IPv6 for inserting into column {} - field size {} is not equal to IPv6 size {}",
|
||||
field_descriptor.full_name(), column_name, text_buffer.size(), IPV6_BINARY_LENGTH);
|
||||
IPv6 value;
|
||||
memcpy(&value.toUnderType(), text_buffer.data(), IPV6_BINARY_LENGTH);
|
||||
return value;
|
||||
};
|
||||
|
||||
default_function = [this]() -> IPv6 { return parse<IPv6>(field_descriptor.default_value_string()); };
|
||||
}
|
||||
|
||||
static void ipToString(const IPv6 & ip, String & str)
|
||||
{
|
||||
WriteBufferFromString buf{str};
|
||||
writeText(ip, buf);
|
||||
}
|
||||
|
||||
std::function<void(IPv6)> write_function;
|
||||
std::function<IPv6()> read_function;
|
||||
std::function<IPv6()> default_function;
|
||||
|
2
tests/queries/0_stateless/02751_protobuf_ipv6.reference
Normal file
2
tests/queries/0_stateless/02751_protobuf_ipv6.reference
Normal file
@ -0,0 +1,2 @@
|
||||
::ffff:1.2.3.4
|
||||
::ffff:1.2.3.4
|
14
tests/queries/0_stateless/02751_protobuf_ipv6.sh
Executable file
14
tests/queries/0_stateless/02751_protobuf_ipv6.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tags: no-fasttest
|
||||
|
||||
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CURDIR"/../shell_config.sh
|
||||
|
||||
SCHEMADIR=$CURDIR/format_schemas
|
||||
|
||||
|
||||
echo -ne '\x12\x1a\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x01\x02\x03\x04' | $CLICKHOUSE_LOCAL --input-format Protobuf --format_schema="$SCHEMADIR/02751_protobuf_ipv6:Message" --structure="ipv6_bytes IPv6" -q "select * from table"
|
||||
|
||||
$CLICKHOUSE_LOCAL -q "select '::ffff:1.2.3.4'::IPv6 as ipv6_bytes format Protobuf settings format_schema = '$SCHEMADIR/02751_protobuf_ipv6:Message'" | $CLICKHOUSE_LOCAL --input-format Protobuf --format_schema="$SCHEMADIR/02751_protobuf_ipv6:Message" --structure="ipv6_bytes IPv6" -q "select * from table"
|
||||
|
@ -0,0 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
message Message
|
||||
{
|
||||
bytes ipv6_bytes = 3;
|
||||
}
|
Loading…
Reference in New Issue
Block a user