Skip to content

Commit 27daa3c

Browse files
author
Vadim Averin
committed
More refactoring
1 parent 0136b9c commit 27daa3c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ydb/library/yql/udfs/common/ip_base/lib/ip_base_udf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ namespace {
7878
SIMPLE_STRICT_UDF(TFromString, TOptionalString(TAutoMapString)) {
7979
TIpv6Address addr = TIpv6Address::FromString(args[0].AsStringRef());
8080
auto res = SerializeAddress(addr);
81-
return res ? valueBuilder->NewString(res.GetRef()) : TUnboxedValue(TUnboxedValuePod());
81+
return res ? valueBuilder->NewString(res.GetRef()) : TUnboxedValue();
8282
}
8383

8484
SIMPLE_UDF(TToString, char*(TAutoMapString)) {
@@ -122,7 +122,8 @@ namespace {
122122
if (ref.Size() == 16) {
123123
return valueBuilder->NewString(ref);
124124
} else if (ref.Size() == 4) {
125-
auto addr6 = TIpv6Address::FromString("::ffff:" + DeserializeAddress(ref).ToString(false));
125+
TIpv6Address addr4 = DeserializeAddress(ref);
126+
auto addr6 = TIpv6Address(ui128(addr4) | ui128(0xFFFF) << 32, TIpv6Address::Ipv6);
126127
return valueBuilder->NewString(SerializeAddress(addr6).GetRef());
127128
} else {
128129
ythrow yexception() << "Incorrect size of input, expected "
@@ -152,8 +153,7 @@ namespace {
152153
ythrow yexception() << "Incorrect size of input, expected "
153154
<< "4 or 16, got " << ref.Size();
154155
}
155-
ui128 mask = ui128(-1) << int((addr.Type() == TIpv6Address::Ipv6 ? 128 : 32) - subnetSize);
156-
TIpv6Address beg(ui128(addr) & mask, addr.Type());
156+
TIpv6Address beg = LowerBoundForPrefix(addr, subnetSize);
157157
return valueBuilder->NewString(SerializeAddress(beg).GetRef());
158158
}
159159

0 commit comments

Comments
 (0)