pichunkstream support full uint
This commit is contained in:
@@ -127,8 +127,8 @@ int PIChunkStream::peekVInt(Version version_, uchar * data_, int sz, uint & ret)
|
|||||||
switch (version_) {
|
switch (version_) {
|
||||||
case Version_1: memcpy(&ret, data_, 4); return 4;
|
case Version_1: memcpy(&ret, data_, 4); return 4;
|
||||||
case Version_2: {
|
case Version_2: {
|
||||||
PIByteArray hdr(data_, piMini(4, sz));
|
PIByteArray hdr(data_, piMini(5, sz));
|
||||||
hdr.resize(4);
|
hdr.resize(5);
|
||||||
uchar hsz = 0;
|
uchar hsz = 0;
|
||||||
ret = readVInt(hdr, &hsz);
|
ret = readVInt(hdr, &hsz);
|
||||||
return hsz;
|
return hsz;
|
||||||
@@ -222,15 +222,22 @@ uint PIChunkStream::readVInt(PIByteArray & s, uchar * bytes_cnt) {
|
|||||||
uchar bytes[4];
|
uchar bytes[4];
|
||||||
uchar abc;
|
uchar abc;
|
||||||
s >> bytes[0];
|
s >> bytes[0];
|
||||||
for (abc = 0; abc < 3; ++abc) {
|
if (bytes[0] == 0xf0) {
|
||||||
uchar mask = (0x80 >> abc);
|
abc = 3;
|
||||||
if ((bytes[0] & mask) == mask) {
|
for (int i = 0; i < 4; ++i)
|
||||||
bytes[0] &= (mask - 1);
|
s >> bytes[i];
|
||||||
s >> bytes[abc + 1];
|
if (bytes_cnt) *bytes_cnt = 5;
|
||||||
} else
|
} else {
|
||||||
break;
|
for (abc = 0; abc < 3; ++abc) {
|
||||||
|
uchar mask = (0x80 >> abc);
|
||||||
|
if ((bytes[0] & mask) == mask) {
|
||||||
|
bytes[0] &= (mask - 1);
|
||||||
|
s >> bytes[abc + 1];
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (bytes_cnt) *bytes_cnt = (abc + 1);
|
||||||
}
|
}
|
||||||
if (bytes_cnt) *bytes_cnt = (abc + 1);
|
|
||||||
uint ret = 0;
|
uint ret = 0;
|
||||||
for (int i = 0; i <= abc; ++i) {
|
for (int i = 0; i <= abc; ++i) {
|
||||||
ret += (bytes[i] << (8 * ((int)abc - i)));
|
ret += (bytes[i] << (8 * ((int)abc - i)));
|
||||||
@@ -240,18 +247,15 @@ uint PIChunkStream::readVInt(PIByteArray & s, uchar * bytes_cnt) {
|
|||||||
|
|
||||||
|
|
||||||
void PIChunkStream::writeVInt(PIByteArray & s, uint val) {
|
void PIChunkStream::writeVInt(PIByteArray & s, uint val) {
|
||||||
if (val > 0xfffffff) return;
|
|
||||||
if (val <= 0x7f) {
|
if (val <= 0x7f) {
|
||||||
s << uchar(val);
|
s << uchar(val);
|
||||||
return;
|
} else if (val <= 0x3fff) {
|
||||||
}
|
|
||||||
if (val <= 0x3fff) {
|
|
||||||
s << uchar((val >> 8) | 0x80) << uchar(val & 0xff);
|
s << uchar((val >> 8) | 0x80) << uchar(val & 0xff);
|
||||||
return;
|
} else if (val <= 0x1fffff) {
|
||||||
}
|
|
||||||
if (val <= 0x1fffff) {
|
|
||||||
s << uchar((val >> 16) | 0xc0) << uchar((val >> 8) & 0xff) << uchar(val & 0xff);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -304,6 +304,6 @@ private:
|
|||||||
//! \relatesalso PIByteArray
|
//! \relatesalso PIByteArray
|
||||||
//! \~english Output operator to \a PICout
|
//! \~english Output operator to \a PICout
|
||||||
//! \~russian Оператор вывода в \a PICout
|
//! \~russian Оператор вывода в \a PICout
|
||||||
PICout operator<<(PICout s, const PIBitArray & ba);
|
PIP_EXPORT PICout operator<<(PICout s, const PIBitArray & ba);
|
||||||
|
|
||||||
#endif // PIBITARRAY_H
|
#endif // PIBITARRAY_H
|
||||||
|
|||||||
Reference in New Issue
Block a user