Fixed zigzag decode

This commit is contained in:
Martin Tůma 2025-01-06 10:04:41 +01:00
parent b630d1d205
commit c12c2b4497

View File

@ -13,6 +13,12 @@ struct CTX
quint64 tag;
};
static inline qint64 zigzag64decode(quint64 value)
{
return static_cast<qint64>((value >> 1u) ^ static_cast<quint64>(
-static_cast<qint64>(value & 1u)));
}
template<typename T>
static bool varint(CTX &ctx, T &val)
{
@ -155,7 +161,7 @@ static bool value(CTX &ctx, QVariant &val)
case 4:
if (!varint(ctx, num))
return false;
val = QVariant((qint64)num);
val = QVariant(static_cast<qint64>(num));
break;
case 5:
if (!varint(ctx, num))
@ -165,7 +171,7 @@ static bool value(CTX &ctx, QVariant &val)
case 6:
if (!varint(ctx, num))
return false;
val = QVariant((qint64)((num >> 1) ^ -(num & 1)));
val = QVariant(zigzag64decode(num));
break;
case 7:
if (!varint(ctx, num))