适配转换成四字节未对齐的情况
This commit is contained in:
parent
54bc32a046
commit
e0134dc0a5
|
@ -290,9 +290,14 @@ ushort Buffer::ToUInt16() const
|
||||||
return p[0] | (p[1] << 8);
|
return p[0] | (p[1] << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint Buffer::ToUInt32() const
|
//根据数据格式不同选择不同的转换方式,默认高位在后
|
||||||
|
uint Buffer::ToUInt32(bool ishigh) const
|
||||||
{
|
{
|
||||||
auto p = GetBuffer();
|
auto p = GetBuffer();
|
||||||
|
if (ishigh)
|
||||||
|
{
|
||||||
|
return (p[2] << 8) | (p[1] << 0x10) | (p[0] << 0x18);
|
||||||
|
}
|
||||||
// 字节对齐时才能之前转为目标整数
|
// 字节对齐时才能之前转为目标整数
|
||||||
if (((int)p & 0x03) == 0) return *(uint*)p;
|
if (((int)p & 0x03) == 0) return *(uint*)p;
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ public:
|
||||||
String ToHex(char sep = 0, int newLine = 0) const;
|
String ToHex(char sep = 0, int newLine = 0) const;
|
||||||
|
|
||||||
ushort ToUInt16() const;
|
ushort ToUInt16() const;
|
||||||
uint ToUInt32() const;
|
uint ToUInt32(bool ishigh = false) const;
|
||||||
UInt64 ToUInt64() const;
|
UInt64 ToUInt64() const;
|
||||||
void Write(ushort value, int index = 0);
|
void Write(ushort value, int index = 0);
|
||||||
void Write(short value, int index = 0);
|
void Write(short value, int index = 0);
|
||||||
|
|
Loading…
Reference in New Issue