📄 instream.cpp
字号:
/* Copyright (C) 2006 Lucas Gomez All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// INCLUDE FILES
#include "InStream.h"
#include "VncViewer.pan"
//LITERALS
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// InStream::InStream()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
InStream::InStream()
{
}
// ---------------------------------------------------------------------------
// InStream::~InStream()
// Destructor.
// ---------------------------------------------------------------------------
//
InStream::~InStream()
{
iBuf.Close();
}
TInt InStream::Check(TInt aItemSize,TInt aNItems)
{
if((iPtr+(aItemSize*aNItems))>iEnd)
{
if((iPtr+aItemSize)>iEnd)
return Overrun(aItemSize,aNItems);
aNItems=(iEnd-iPtr)/aItemSize;
}
return aNItems;
}
void InStream::Check(TInt aItemSize)
{
if(iPtr+aItemSize>iEnd)
Overrun(aItemSize,1);
}
TInt InStream::ReadS8()
{
Check(1);
return iBuf[iPtr++];
}
TInt InStream::ReadS16()
{
Check(2);
TInt b0=iBuf[iPtr++];
TInt b1=iBuf[iPtr++] & 0xff;
return b0<<8 | b1;
}
TInt InStream::ReadS32()
{
Check(4);
TInt b0=iBuf[iPtr++];
TInt b1=iBuf[iPtr++] & 0xff;
TInt b2=iBuf[iPtr++] & 0xff;
TInt b3=iBuf[iPtr++] & 0xff;
return b0<<24 | b1<<16 | b2<<8 | b3;
}
TInt InStream::ReadU8()
{
return ReadS8() & 0xff;
}
TInt InStream::ReadU16()
{
return ReadS16() & 0xffff;
}
TInt InStream::ReadU32()
{
return ReadS32() & 0xffffffff;
}
void InStream::ReadString(TDes8& aStr)
{
TInt len=ReadU32();
if(len>KMaxStringLength)
User::Leave(EVncViewerMaxStringLengthExceeded);
TInt i=0;
while(i<len)
{
TInt j=i+Check(1,len-i);
while(i<j)
{
aStr.Append(static_cast<TChar>(iBuf[iPtr++]));
i++;
}
}
}
void InStream::ReadBytes(RBuf8& aData,TInt aOffset,TInt aLength)
{
TInt offsetEnd=aOffset+aLength;
while(aOffset<offsetEnd)
{
TInt n=Check(1,offsetEnd-aOffset);
for(TInt i=0;i<n;i++)
{
aData[aOffset++]=iBuf[iPtr++];
}
}
}
void InStream::Skip(TInt aBytes)
{
while(aBytes>0)
{
TInt n=Check(1,aBytes);
iPtr+=n;
aBytes-=n;
}
}
TInt InStream::ReadOpaque8()
{
return ReadU8();
}
TInt InStream::ReadOpaque16()
{
return ReadU16();
}
TInt InStream::ReadOpaque32()
{
return ReadU32();
}
TInt InStream::ReadOpaque24A()
{
Check(3);
TInt b0=iBuf[iPtr++];
TInt b1=iBuf[iPtr++];
TInt b2=iBuf[iPtr++];
return b0<<24 | b1<<16 | b2<<8;
}
TInt InStream::ReadOpaque24B()
{
Check(3);
TInt b0=iBuf[iPtr++];
TInt b1=iBuf[iPtr++];
TInt b2=iBuf[iPtr++];
return b0<<16 | b1<<8 | b2;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -