📄 bytestrm.h
字号:
/* <LIC_AMD_STD>
* Copyright (C) 2003-2005 Advanced Micro Devices, Inc. All Rights Reserved.
*
* Unless otherwise designated in writing, this software and any related
* documentation are the confidential proprietary information of AMD.
* THESE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY
* UNLESS OTHERWISE NOTED IN WRITING, EXPRESS OR IMPLIED WARRANTY OF ANY
* KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
* NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE AND IN NO
* EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER.
*
* AMD does not assume any responsibility for any errors which may appear
* in the Materials nor any responsibility to support or update the
* Materials. AMD retains the right to modify the Materials at any time,
* without notice, and is not obligated to provide such modified
* Materials to you. AMD is not obligated to furnish, support, or make
* any further information available to you.
* </LIC_AMD_STD> */
/* <CTL_AMD_STD>
* </CTL_AMD_STD> */
/* <DOC_AMD_STD>
* </DOC_AMD_STD> */
#ifndef _BYTE_STREAM_H
#define _BYTE_STREAM_H
#include "mai_types.h"
#ifndef DWORD
/* Windows related Type declarations */
/* should be using types defined in mai_type.h */
typedef m_s64 LONGLONG;
typedef long LONG;
typedef LONG HRESULT;
typedef unsigned int UINT;
typedef unsigned char UCHAR;
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned char BYTE;
typedef char* LPCSTR;
typedef BYTE* LPBYTE;
typedef BYTE* PBYTE;
typedef unsigned long PLONG;
#define BOOL m_bool
#ifndef FALSE
#define FALSE M_FALSE
#endif
#ifndef TRUE
#define TRUE M_TRUE
#endif
#endif
class Byte_Stream {
public:
void Initialize( LPBYTE lpByte, UINT len )
{
lpByteBufferStart = lpByteBuffer = lpByte;
lpByteBufferEnd = lpByte + len;
}
operator BOOL(){return !EndOfStream();};
UINT GetPosition() {
return lpByteBuffer - lpByteBufferStart;
}
UINT GetPositionFromEnd() {
return lpByteBufferEnd - lpByteBuffer;
}
BYTE GetByte() {
return *lpByteBuffer++;
}
BYTE PeekBYTE() {
return *lpByteBuffer;
}
UINT GetNextByte(UINT x) {
return (x << 8) + GetByte();
}
UINT GetWORD() {
return GetNextByte(GetByte());
}
BOOL EndOfStream() {
return lpByteBuffer >= lpByteBufferEnd;
}
UINT PeekUINT() {
return ByteSwap(lpByteBuffer);
}
DWORD GetUINT() {
DWORD dwx = ByteSwap(lpByteBuffer);
Advance(sizeof(DWORD));
return dwx;
}
UINT Peek4BYTES() {
return *( UINT *)lpByteBuffer;
}
void Advance(UINT Delta) {
lpByteBuffer += Delta;
}
void Retreat(UINT Delta) {
lpByteBuffer -= Delta;
}
LPBYTE GetBytePointer() {
return lpByteBuffer;
}
LPBYTE GetByteStartPointer() {
return lpByteBufferStart;
}
LPBYTE GetByteEndPointer() {
return lpByteBufferEnd;
}
inline DWORD ByteSwap(const BYTE* pData)
{
DWORD dw = (pData[0] << 24) |
(pData[1] << 16) |
(pData[2] << 8) |
(pData[3]);
return dw;
}
private:
LPBYTE lpByteBuffer;
LPBYTE lpByteBufferEnd;
LPBYTE lpByteBufferStart;
};
UINT inline BitField(UINT val, BYTE start=0, BYTE size=31)
{
BYTE start_bit;
BYTE bit_count;
UINT mask;
UINT value;
// calculate startbit (0-31)
start_bit=start;
// calculate bit count
bit_count= size;
// generate mask
if (bit_count == 32)
mask = 0xffffffff;
else
{
mask = 1;
mask = mask <<bit_count;
mask = mask -1;
mask = mask << start_bit;
}
value = val;
return ((value & mask) >> start_bit);
}
#endif /*_BYTE_STREAM_H*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -