Bug 1231793: Part 1 - Added read functions for Little Endian integers to ByteReader.h. r=jya

This commit is contained in:
Louis Christie 2016-02-12 14:40:08 +13:00 committed by Jean-Yves Avenard
parent 48d0f8b9fa
commit e7c36cac63

View File

@ -87,6 +87,16 @@ public:
return mozilla::BigEndian::readUint16(ptr);
}
int16_t ReadLE16()
{
auto ptr = Read(2);
if (!ptr) {
MOZ_ASSERT(false);
return 0;
}
return mozilla::LittleEndian::readInt16(ptr);
}
uint32_t ReadU24()
{
auto ptr = Read(3);
@ -102,6 +112,20 @@ public:
return (uint32_t)ReadU24();
}
int32_t ReadLE24()
{
auto ptr = Read(3);
if (!ptr) {
MOZ_ASSERT(false);
return 0;
}
int32_t result = int32_t(ptr[2] << 16 | ptr[1] << 8 | ptr[0]);
if (result & 0x00800000u) {
result -= 0x1000000;
}
return result;
}
bool CanRead32() { return mRemaining >= 4; }
uint32_t ReadU32()