chunkstream support full uint

This commit is contained in:
2023-05-24 22:15:36 +03:00
parent 21f0f67fdf
commit ed9d0002f0

View File

@@ -79,14 +79,20 @@ uint ChunkStream::readVInt(QDataStream & s) {
uchar bytes[4];
s >> bytes[0];
uchar abc = 0;
for (abc = 0; abc < 3; ++abc) {
uchar mask = (0x80 >> abc);
if ((bytes[0] & mask) == mask) {
// if (s.isEmpty()) return 0;
bytes[0] &= (mask - 1);
s >> bytes[abc + 1];
} else
break;
if (bytes[0] == 0xf0) {
abc = 3;
for (int i = 0; i < 4; ++i)
s >> bytes[i];
} else {
for (abc = 0; abc < 3; ++abc) {
uchar mask = (0x80 >> abc);
if ((bytes[0] & mask) == mask) {
// if (s.isEmpty()) return 0;
bytes[0] &= (mask - 1);
s >> bytes[abc + 1];
} else
break;
}
}
uint ret = 0;
for (int i = 0; i <= abc; ++i) {
@@ -97,18 +103,15 @@ uint ChunkStream::readVInt(QDataStream & s) {
void ChunkStream::writeVInt(QDataStream & s, uint val) {
if (val > 0xfffffff) return;
if (val <= 0x7f) {
s << uchar(val);
return;
}
if (val <= 0x3fff) {
} else if (val <= 0x3fff) {
s << uchar((val >> 8) | 0x80) << uchar(val & 0xff);
return;
}
if (val <= 0x1fffff) {
} else if (val <= 0x1fffff) {
s << uchar((val >> 16) | 0xc0) << uchar((val >> 8) & 0xff) << uchar(val & 0xff);
return;
} else if (val <= 0xfffffff) {
s << uchar((val >> 24) | 0xe0) << uchar((val >> 16) & 0xff) << uchar((val >> 8) & 0xff) << uchar(val & 0xff);
} else {
s << uchar(0xf0) << uchar((val >> 24) & 0xff) << uchar((val >> 16) & 0xff) << uchar((val >> 8) & 0xff) << uchar(val & 0xff);
}
s << uchar((val >> 24) | 0xe0) << uchar((val >> 16) & 0xff) << uchar((val >> 8) & 0xff) << uchar(val & 0xff);
}