本文整理汇总了C++中MemoryBuffer::setBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBuffer::setBuffer方法的具体用法?C++ MemoryBuffer::setBuffer怎么用?C++ MemoryBuffer::setBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBuffer
的用法示例。
在下文中一共展示了MemoryBuffer::setBuffer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decompressResource
extern DLLSERVER_API bool decompressResource(size32_t len, const void *data, StringBuffer &result)
{
bool hasVersion = len && (*(const byte *)data == 0x80);
MemoryBuffer src;
src.setBuffer(len, const_cast<void *>(data), false);
byte version = 1;
if (hasVersion)
{
src.skip(1);
src.read(version);
}
MemoryBuffer tgt;
switch (version)
{
case 1:
decompressToBuffer(tgt, src);
break;
default:
throwUnexpected();
}
tgt.append((char)0);
unsigned expandedLen = tgt.length();
result.setBuffer(expandedLen, reinterpret_cast<char *>(tgt.detach()), expandedLen-1);
return true;
}
示例2: checkSavedFileCRC
bool checkSavedFileCRC(IFile * ifile, bool & timesDiffer, unsigned & storedCrc)
{
StringBuffer s(ifile->queryFilename());
s.append(".crc");
Owned<IFile> crcFile = createIFile(s.str());
size32_t crcSz = (size32_t)crcFile->size();
Owned<IFileIO> crcIO = crcFile->open(IFOread);
bool performCrc = false;
timesDiffer = false;
if (crcIO)
{
Owned<IFileIOStream> crcStream = createIOStream(crcIO);
if (sizeof(storedCrc) == crcSz) // backward compat. if = in size to just crc (no date stamps)
{
verifyex(crcSz == crcStream->read(crcSz, &storedCrc));
performCrc = true;
}
else
{
size32_t sz;
verifyex(sizeof(sz) == crcStream->read(sizeof(sz), &sz));
void *mem = malloc(sz);
MemoryBuffer mb;
mb.setBuffer(sz, mem, true);
verifyex(sz == crcStream->read(sz, mem));
CDateTime storedCreateTime(mb);
CDateTime storedModifiedTime(mb);
CDateTime createTime, modifiedTime, accessedTime;
ifile->getTime(&createTime, &modifiedTime, &accessedTime);
if (!storedCreateTime.equals(createTime) || !storedModifiedTime.equals(modifiedTime))
timesDiffer = true;
else
{
mb.read(storedCrc);
performCrc = true;
}
}
}
return performCrc;
}
示例3: aesDecryptWithRSAEncryptedKey
size32_t aesDecryptWithRSAEncryptedKey(MemoryBuffer &out, size32_t inSz, const void *inBytes, const CLoadedKey &privateKey)
{
MemoryBuffer in;
in.setBuffer(inSz, (void *)inBytes, false);
// read encrypted AES key
size32_t encryptedAESKeySz;
in.read(encryptedAESKeySz);
MemoryBuffer aesKey;
size32_t decryptedAesKeySz = privateKeyDecrypt(aesKey, encryptedAESKeySz, in.readDirect(encryptedAESKeySz), privateKey);
if (decryptedAesKeySz != aesMaxKeySize)
throw makeStringException(0, "aesDecryptWithRSAEncryptedKey - invalid input");
unsigned iVPos = in.getPos(); // read directly further down
in.skip(aesBlockSize);
size32_t aesEncryptedSz;
in.read(aesEncryptedSz);
return aesDecrypt(out, aesEncryptedSz, in.readDirect(aesEncryptedSz), aesMaxKeySize, (const char *)aesKey.bytes(), (const char *)in.bytes()+iVPos);
}
示例4: decompressResource
extern DLLSERVER_API bool decompressResource(size32_t len, const void *data, MemoryBuffer &result)
{
bool hasVersion = len && (*(const byte *)data == 0x80);
MemoryBuffer src;
src.setBuffer(len, const_cast<void *>(data), false);
byte version = 1;
if (hasVersion)
{
src.skip(1);
src.read(version);
}
switch (version)
{
case 1:
decompressToBuffer(result, src);
break;
default:
throwUnexpected();
}
return true;
}
示例5: gatherData
void gatherData(HeartBeatPacket &hb)
{
CriticalBlock b(crit);
hb.sender = self;
hb.progressSize = 0;
if (progressEnabled)
{
CriticalBlock b(crit);
MemoryBuffer mb;
mb.setBuffer(DATA_MAX, hb.perfdata);
mb.rewrite();
ForEachItemIn(g, activeGraphs)
{
CGraphBase &graph = activeGraphs.item(g);
graph.serializeStats(mb);
if (mb.length() > (DATA_MAX-30))
{
WARNLOG("Progress packet too big!");
break;
}
}
hb.progressSize = mb.length();
}
示例6: getResource
bool HelperDll::getResource(size32_t & len, const void * & data, const char * type, unsigned id, bool trace) const
{
#ifdef _WIN32
HINSTANCE dllHandle = so.getInstanceHandle();
HRSRC hrsrc = FindResource(dllHandle, MAKEINTRESOURCE(id), type);
if (!hrsrc)
return false;
len = SizeofResource(dllHandle, hrsrc);
data = (const byte *) LoadResource(dllHandle, hrsrc);
return true;
#else
StringBuffer symName;
symName.append(type).append("_").append(id).append("_txt_start");
data = (const void *) getEntry(symName.str());
if (!data)
{
if (trace)
printf("Failed to locate symbol %s\n", symName.str());
return false;
}
byte bom;
byte version;
bool compressed;
MemoryBuffer mb;
mb.setBuffer(resourceHeaderLength, const_cast<void *>(data));
mb.read(bom);
if (bom!=0x80)
return false;
mb.read(version);
if (version>resourceHeaderVersion)
return false;
mb.read(compressed).read(len);
len+=resourceHeaderLength;
return true;
#endif
}
示例7: despray
int CDfuPlusHelper::despray()
{
const char* srcname = globals->queryProp("srcname");
if(srcname == NULL)
throw MakeStringException(-1, "srcname not specified");
const char* dstxml = globals->queryProp("dstxml");
const char* dstip = globals->queryProp("dstip");
const char* dstfile = globals->queryProp("dstfile");
bool nowait = globals->getPropBool("nowait", false);
MemoryBuffer xmlbuf;
if(dstxml == NULL)
{
if(dstfile == NULL)
throw MakeStringException(-1, "dstfile not specified");
if(dstip == NULL) {
#ifdef DAFILESRV_LOCAL
progress("dstip not specified - assuming spray from local machine\n");
dstip = ".";
#else
throw MakeStringException(-1, "dstip not specified");
#endif
}
}
else
{
if(dstip != NULL || dstfile != NULL)
throw MakeStringException(-1, "dstip/dstfile and dstxml can't be used at the same time");
StringBuffer buf;
buf.loadFile(dstxml);
int len = buf.length();
xmlbuf.setBuffer(len, buf.detach(), true);
}
if(dstxml == NULL)
info("\nDespraying %s to host %s file %s\n", srcname, dstip, dstfile);
else
info("\nDespraying %s\n", srcname);
Owned<IClientDespray> req = sprayclient->createDesprayRequest();
req->setSourceLogicalName(srcname);
if(dstxml == NULL)
{
req->setDestIP(dstip);
req->setDestPath(dstfile);
}
else
req->setDstxml(xmlbuf);
req->setOverwrite(globals->getPropBool("overwrite", false));
if(globals->hasProp("connect"))
req->setMaxConnections(globals->getPropInt("connect"));
if(globals->hasProp("throttle"))
req->setThrottle(globals->getPropInt("throttle"));
if(globals->hasProp("transferbuffersize"))
req->setTransferBufferSize(globals->getPropInt("transferbuffersize"));
if(globals->hasProp("norecover"))
req->setNorecover(globals->getPropBool("norecover", false));
else if(globals->hasProp("noRecover"))
req->setNorecover(globals->getPropBool("noRecover", false));
if(globals->hasProp("splitprefix"))
req->setSplitprefix(globals->queryProp("splitprefix"));
else if(globals->hasProp("splitPrefix"))
req->setSplitprefix(globals->queryProp("splitPrefix"));
if(globals->hasProp("wrap"))
req->setWrap(globals->getPropBool("wrap", false));
if(globals->hasProp("multicopy"))
req->setMultiCopy(globals->getPropBool("multicopy", false));
else if(globals->hasProp("multiCopy"))
req->setMultiCopy(globals->getPropBool("multiCopy", false));
if(globals->hasProp("compress"))
req->setCompress(globals->getPropBool("compress", false));
if(globals->hasProp("encrypt"))
req->setEncrypt(globals->queryProp("encrypt"));
if(globals->hasProp("decrypt"))
req->setDecrypt(globals->queryProp("decrypt"));
SocketEndpoint localep;
StringBuffer localeps;
if (checkLocalDaFileSvr(dstip,localep))
dstip = localep.getUrlStr(localeps).str();
Owned<IClientDesprayResponse> result = sprayclient->Despray(req);
const char* wuid = result->getWuid();
if(wuid == NULL || *wuid == '\0')
exc(result->getExceptions(),"despraying");
else
{
const char* jobname = globals->queryProp("jobname");
if(jobname && *jobname)
updatejobname(wuid, jobname);
info("Submitted WUID %s\n", wuid);
if(!nowait)
//.........这里部分代码省略.........
示例8: spray
int CDfuPlusHelper::spray()
{
const char* srcxml = globals->queryProp("srcxml");
const char* srcip = globals->queryProp("srcip");
const char* srcfile = globals->queryProp("srcfile");
bool nowait = globals->getPropBool("nowait", false);
MemoryBuffer xmlbuf;
if(srcxml == NULL)
{
if(srcfile == NULL)
throw MakeStringException(-1, "srcfile not specified");
if(srcip == NULL) {
#ifdef DAFILESRV_LOCAL
progress("srcip not specified - assuming spray from local machine\n");
srcip = ".";
#else
throw MakeStringException(-1, "srcip not specified");
#endif
}
}
else
{
if(srcip != NULL || srcfile != NULL)
throw MakeStringException(-1, "srcip/srcfile and srcxml can't be used at the same time");
StringBuffer buf;
buf.loadFile(srcxml);
int len = buf.length();
xmlbuf.setBuffer(len, buf.detach(), true);
}
const char* dstname = globals->queryProp("dstname");
if(dstname == NULL)
throw MakeStringException(-1, "dstname not specified");
const char* dstcluster = globals->queryProp("dstcluster");
if(dstcluster == NULL)
throw MakeStringException(-1, "dstcluster not specified");
const char* format = globals->queryProp("format");
if(format == NULL)
format = "fixed";
SocketEndpoint localep;
StringBuffer localeps;
if (checkLocalDaFileSvr(srcip,localep))
srcip = localep.getUrlStr(localeps).str();
StringBuffer wuid;
StringBuffer errmsg;
bool ok;
if ((stricmp(format, "fixed") == 0)||(stricmp(format, "recfmvb") == 0)||(stricmp(format, "recfmv") == 0)||(stricmp(format, "variablebigendian") == 0))
ok = fixedSpray(srcxml,srcip,srcfile,xmlbuf,dstcluster,dstname,format,wuid,errmsg);
else if((stricmp(format, "csv") == 0) ||(stricmp(format, "xml") == 0)||(stricmp(format, "variable") == 0))
ok = variableSpray(srcxml,srcip,srcfile,xmlbuf,dstcluster,dstname,format,wuid, errmsg);
else
throw MakeStringException(-1, "format %s not supported", format);
if (!ok) {
if(errmsg.length())
error("%s\n", errmsg.str());
else
throw MakeStringException(-1, "unknown error spraying");
}
else {
const char* jobname = globals->queryProp("jobname");
if(jobname && *jobname)
updatejobname(wuid.str(), jobname);
info("Submitted WUID %s\n", wuid.str());
if(!nowait)
waitToFinish(wuid.str());
}
return 0;
}
示例9: add
int CDfuPlusHelper::add()
{
const char* lfn = globals->queryProp("dstname");
if(lfn == NULL || *lfn == '\0')
throw MakeStringException(-1, "dstname not specified");
bool isRemote = false;
const char* xmlfname = globals->queryProp("srcxml");
const char* srcname = globals->queryProp("srcname");
const char* srcdali = globals->queryProp("srcdali");
const char* srcusername = globals->queryProp("srcusername");
const char* srcpassword = globals->queryProp("srcpassword");
if(xmlfname == NULL || *xmlfname == '\0')
{
if(srcname == NULL || *srcname == '\0')
throw MakeStringException(-1, "Please specify srcxml for adding from xml, or srcname for adding from remote dali");
else
{
isRemote = true;
if(srcdali == NULL || *srcdali == '\0')
throw MakeStringException(-1, "srcdali not specified for adding remote");
}
}
if(!isRemote)
{
MemoryBuffer xmlbuf;
StringBuffer buf;
buf.loadFile(xmlfname);
int len = buf.length();
xmlbuf.setBuffer(len, buf.detach(), true);
Owned<IClientAddRequest> req = dfuclient->createAddRequest();
req->setDstname(lfn);
req->setXmlmap(xmlbuf);
Owned<IClientAddResponse> resp = dfuclient->Add(req);
const IMultiException* excep = &resp->getExceptions();
if(excep != NULL && excep->ordinality() > 0)
{
StringBuffer errmsg;
excep->errorMessage(errmsg);
error("%s\n", errmsg.str());
return -1;
}
}
else
{
Owned<IClientAddRemoteRequest> req = dfuclient->createAddRemoteRequest();
req->setDstname(lfn);
req->setSrcname(srcname);
req->setSrcdali(srcdali);
if(srcusername != NULL)
req->setSrcusername(srcusername);
if(srcpassword != NULL)
req->setSrcpassword(srcpassword);
Owned<IClientAddRemoteResponse> resp = dfuclient->AddRemote(req);
const IMultiException* excep = &resp->getExceptions();
if(excep != NULL && excep->ordinality() > 0)
{
StringBuffer errmsg;
excep->errorMessage(errmsg);
error("%s\n", errmsg.str());
return -1;
}
}
info("%s successfully added", lfn);
return 0;
}