本文整理汇总了C++中CByteBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ CByteBuffer类的具体用法?C++ CByteBuffer怎么用?C++ CByteBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CByteBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetResourceInformation
DWORD GetResourceInformation(const CResourceW &resource,
CResourceW &destResource, UString &systemPathPart)
{
if (g_IsNT)
{
CByteBuffer byteBuffer;
const DWORD kBufferSize = 16384;
byteBuffer.SetCapacity(kBufferSize);
LPNETRESOURCEW lpnrLocal = (LPNETRESOURCEW) (BYTE *)(byteBuffer);
ZeroMemory(lpnrLocal, kBufferSize);
DWORD bufferSize = kBufferSize;
NETRESOURCEW netResource;
ConvertCResourceToNETRESOURCE(resource, netResource);
LPWSTR lplpSystem;
DWORD result = ::WNetGetResourceInformationW(&netResource,
lpnrLocal, &bufferSize, &lplpSystem);
if (result != NO_ERROR)
return result;
if (lplpSystem != 0)
systemPathPart = lplpSystem;
ConvertNETRESOURCEToCResource(lpnrLocal[0], destResource);
return result;
}
CResource resourceA, destResourceA;
ConvertResourceWToResource(resource, resourceA);
AString systemPathPartA;
DWORD result = GetResourceInformation(resourceA, destResourceA, systemPathPartA);
ConvertResourceToResourceW(destResourceA, destResource);
systemPathPart = GetUnicodeString(systemPathPartA);
return result;
}
示例2: Parse
HRESULT CHandler::Open2(ISequentialInStream *stream)
{
const UInt32 kBufSize = 1 << 18;
const UInt32 kSigSize = 4;
CByteBuffer buffer;
buffer.SetCapacity(kBufSize);
Byte *buf = buffer;
size_t processed = kSigSize;
RINOK(ReadStream_FALSE(stream, buf, processed));
UInt32 sig = GetUi32(buf);
bool be, mode64;
switch(sig)
{
case 0xCEFAEDFE: be = true; mode64 = false; break;
case 0xCFFAEDFE: be = true; mode64 = true; break;
case 0xFEEDFACE: be = false; mode64 = false; break;
case 0xFEEDFACF: be = false; mode64 = true; break;
default: return S_FALSE;
}
processed = kBufSize - kSigSize;
RINOK(ReadStream(stream, buf + kSigSize, &processed));
_mode64 = mode64;
_be = be;
return Parse(buf, (UInt32)processed + kSigSize) ? S_OK : S_FALSE;
}
示例3: CompareBuffers
static int CompareBuffers(const CByteBuffer &a1, const CByteBuffer &a2)
{
size_t c1 = a1.GetCapacity();
size_t c2 = a2.GetCapacity();
RINOZ_COMP(c1, c2);
for (size_t i = 0; i < c1; i++)
RINOZ_COMP(a1[i], a2[i]);
return 0;
}
示例4: CreateInArchive
static int CreateInArchive(pU7ZipFunctions pFunctions,
const C7ZipObjectPtrArray & formatInfos,
CMyComPtr<IInStream> & inStream,
wstring ext,
CMyComPtr<IInArchive> & archive,
bool fCheckFileTypeBySignature)
{
for (C7ZipObjectPtrArray::const_iterator it = formatInfos.begin();
it != formatInfos.end();it++) {
const C7ZipFormatInfo * pInfo = dynamic_cast<const C7ZipFormatInfo *>(*it);
if (!fCheckFileTypeBySignature) {
for(WStringArray::const_iterator extIt = pInfo->Exts.begin(); extIt != pInfo->Exts.end(); extIt++) {
if (MyStringCompareNoCase((*extIt).c_str(), ext.c_str()) == 0) {
return pFunctions->v.CreateObject(&pInfo->m_ClassID,
&IID_IInArchive, (void **)&archive);
}
}
} else {
#if MY_VER_MAJOR >= 15
if (pInfo->Signatures.Size() == 0 /*&& pInfo->m_FinishSignature.length() == 0*/)
#else
if (pInfo->m_StartSignature.GetCapacity() == 0 /*&& pInfo->m_FinishSignature.length() == 0*/)
#endif
continue; //no signature
#if MY_VER_MAJOR >= 15
for(unsigned i = 0; i < pInfo->Signatures.Size(); i++) {
CByteBuffer signature(pInfo->Signatures[i].Size());
if (!ReadStream(inStream, pInfo->SignatureOffset, FILE_BEGIN, signature))
continue; //unable to read signature
if (signature == pInfo->Signatures[i]) {
return pFunctions->v.CreateObject(&pInfo->m_ClassID,
&IID_IInArchive, (void **)&archive);
}
}
#else
CByteBuffer signature;
signature.SetCapacity(pInfo->m_StartSignature.GetCapacity());
if (!ReadStream(inStream, 0, FILE_BEGIN, signature))
continue; //unable to read signature
if (signature == pInfo->m_StartSignature) {
return pFunctions->v.CreateObject(&pInfo->m_ClassID,
&IID_IInArchive, (void **)&archive);
}
#endif
} //check file type by signature
}
return CLASS_E_CLASSNOTAVAILABLE;
}
示例5: TestTCPClientKeepAlive_SendData
static void TestTCPClientKeepAlive_SendData(CTcpClient& tcpClient, const CStringBuffer& buffer)
{
CStringBuffer sBuffer;
CByteBuffer bBuffer;
dword numBytesSend;
sBuffer.FormatString(__FILE__LINE__ _T("##%05d## %s"), buffer.GetLength(), buffer.GetString());
sBuffer.convertToByteBuffer(bBuffer);
tcpClient.SendData(bBuffer.get_Buffer(), bBuffer.get_BufferSize(), &numBytesSend);
assert(numBytesSend == bBuffer.get_BufferSize());
}
示例6: ReadStreams
HRESULT ReadStreams(IInStream *inStream, const CHeader &h, CDatabase &db)
{
CByteBuffer offsetBuf;
RINOK(UnpackData(inStream, h.OffsetResource, h.IsLzxMode(), offsetBuf, NULL));
for (size_t i = 0; i + kStreamInfoSize <= offsetBuf.GetCapacity(); i += kStreamInfoSize)
{
CStreamInfo s;
GetStream((const Byte *)offsetBuf + i, s);
if (s.PartNumber == h.PartNumber)
db.Streams.Add(s);
}
return S_OK;
}
示例7: SendData
void SendData(CTcpClient* tcpClient, const CStringBuffer& buffer)
{
CScopedLock _lock;
CStringBuffer sBuffer;
CByteBuffer bBuffer;
dword numBytesSend;
sBuffer.FormatString(__FILE__LINE__ _T("##%05d## %s"), buffer.GetLength(), buffer.GetString());
sBuffer.convertToByteBuffer(bBuffer);
_lock.unlock();
tcpClient->SendData(bBuffer.get_Buffer(), bBuffer.get_BufferSize(), &numBytesSend);
assert(numBytesSend == bBuffer.get_BufferSize());
}
示例8: RINOK
HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
{
RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));
if (TestSignature2(_header))
return S_OK;
CByteBuffer byteBuffer;
const UInt32 kBufferSize = (1 << 16);
byteBuffer.SetCapacity(kBufferSize);
Byte *buffer = byteBuffer;
UInt32 numPrevBytes = kHeaderSize;
memcpy(buffer, _header, kHeaderSize);
UInt64 curTestPos = _arhiveBeginStreamPosition;
for (;;)
{
if (searchHeaderSizeLimit != NULL)
if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)
break;
do
{
UInt32 numReadBytes = kBufferSize - numPrevBytes;
UInt32 processedSize;
RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));
numPrevBytes += processedSize;
if (processedSize == 0)
return S_FALSE;
}
while (numPrevBytes <= kHeaderSize);
UInt32 numTests = numPrevBytes - kHeaderSize;
for (UInt32 pos = 0; pos < numTests; pos++)
{
for (; buffer[pos] != '7' && pos < numTests; pos++);
if (pos == numTests)
break;
if (TestSignature(buffer + pos))
{
memcpy(_header, buffer + pos, kHeaderSize);
curTestPos += pos;
_arhiveBeginStreamPosition = curTestPos;
return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);
}
}
curTestPos += numTests;
numPrevBytes -= numTests;
memmove(buffer, buffer + numTests, numPrevBytes);
}
return S_FALSE;
}
示例9: UnpackData
static HRESULT UnpackData(IInStream *inStream, const CResource &resource, bool lzxMode, CByteBuffer &buf, Byte *digest)
{
size_t size = (size_t)resource.UnpackSize;
if (size != resource.UnpackSize)
return E_OUTOFMEMORY;
buf.Free();
buf.SetCapacity(size);
CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2();
CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
outStreamSpec->Init((Byte *)buf, size);
CUnpacker unpacker;
return unpacker.Unpack(inStream, resource, lzxMode, outStream, NULL, digest);
}
示例10: GetResourceParent
DWORD GetResourceParent(const CResource &resource, CResource &parentResource)
{
CByteBuffer byteBuffer;
const DWORD kBufferSize = 16384;
byteBuffer.SetCapacity(kBufferSize);
LPNETRESOURCE lpnrLocal = (LPNETRESOURCE) (BYTE *)(byteBuffer);
ZeroMemory(lpnrLocal, kBufferSize);
DWORD bufferSize = kBufferSize;
NETRESOURCE netResource;
ConvertCResourceToNETRESOURCE(resource, netResource);
DWORD result = ::WNetGetResourceParent(&netResource, lpnrLocal, &bufferSize);
if (result != NO_ERROR)
return result;
ConvertNETRESOURCEToCResource(lpnrLocal[0], parentResource);
return result;
}
示例11: Next
DWORD CEnum::Next(CResource &resource)
{
CByteBuffer byteBuffer;
const DWORD kBufferSize = 16384;
byteBuffer.SetCapacity(kBufferSize);
LPNETRESOURCE lpnrLocal = (LPNETRESOURCE) (BYTE *)(byteBuffer);
ZeroMemory(lpnrLocal, kBufferSize);
DWORD bufferSize = kBufferSize;
DWORD numEntries = 1;
DWORD result = Next(&numEntries, lpnrLocal, &bufferSize);
if (result != NO_ERROR)
return result;
if (numEntries != 1)
return (DWORD)E_FAIL;
ConvertNETRESOURCEToCResource(lpnrLocal[0], resource);
return result;
}
示例12: GetReparseData
bool GetReparseData(CFSTR path, CByteBuffer &reparseData, BY_HANDLE_FILE_INFORMATION *fileInfo)
{
reparseData.Free();
CInFile file;
if (!file.OpenReparse(path))
return false;
if (fileInfo)
file.GetFileInformation(fileInfo);
const unsigned kBufSize = MAXIMUM_REPARSE_DATA_BUFFER_SIZE;
CByteArr buf(kBufSize);
DWORD returnedSize;
if (!file.DeviceIoControlOut(my_FSCTL_GET_REPARSE_POINT, buf, kBufSize, &returnedSize))
return false;
reparseData.CopyFrom(buf, returnedSize);
return true;
}
示例13: QueryValue
LONG CKey::QueryValue(LPCTSTR name, CByteBuffer &value, UInt32 &dataSize)
{
DWORD type = 0;
dataSize = 0;
LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type, NULL, (DWORD *)&dataSize);
if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
return res;
value.Alloc(dataSize);
return QueryValue(name, (BYTE *)value, dataSize);
}
示例14: OpenArchive
HRESULT OpenArchive(IInStream *inStream, const CHeader &h, CByteBuffer &xml, CDatabase &db)
{
RINOK(UnpackData(inStream, h.XmlResource, h.IsLzxMode(), xml, NULL));
RINOK(ReadStreams(inStream, h, db));
bool needBootMetadata = !h.MetadataResource.IsEmpty();
if (h.PartNumber == 1)
{
int imageIndex = 1;
for (int j = 0; j < db.Streams.Size(); j++)
{
// if (imageIndex > 1) break;
const CStreamInfo &si = db.Streams[j];
if (!si.Resource.IsMetadata() || si.PartNumber != h.PartNumber)
continue;
Byte hash[kHashSize];
CByteBuffer metadata;
RINOK(UnpackData(inStream, si.Resource, h.IsLzxMode(), metadata, hash));
if (memcmp(hash, si.Hash, kHashSize) != 0)
return S_FALSE;
wchar_t sz[32];
ConvertUInt64ToString(imageIndex++, sz);
UString s = sz;
s += WCHAR_PATH_SEPARATOR;
RINOK(ParseDir(metadata, metadata.GetCapacity(), s, db.Items));
if (needBootMetadata)
if (h.MetadataResource.Offset == si.Resource.Offset)
needBootMetadata = false;
}
}
if (needBootMetadata)
{
CByteBuffer metadata;
RINOK(UnpackData(inStream, h.MetadataResource, h.IsLzxMode(), metadata, NULL));
RINOK(ParseDir(metadata, metadata.GetCapacity(), L"0" WSTRING_PATH_SEPARATOR, db.Items));
}
return S_OK;
}
示例15: RINOK
HRESULT CHandler::Open2(IInStream *stream)
{
const UInt32 kBufSize = 1 << 18;
const UInt32 kSigSize = 4;
CByteBuffer buffer;
buffer.SetCapacity(kBufSize);
Byte *buf = buffer;
size_t processed = kSigSize;
RINOK(ReadStream_FALSE(stream, buf, processed));
if (buf[0] != 0x7F || buf[1] != 'E' || buf[2] != 'L' || buf[3] != 'F')
return S_FALSE;
processed = kBufSize - kSigSize;
RINOK(ReadStream(stream, buf + kSigSize, &processed));
processed += kSigSize;
if (!Parse(buf, (UInt32)processed))
return S_FALSE;
UInt64 fileSize;
RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
return (fileSize == _totalSize) ? S_OK : S_FALSE;
}