本文整理汇总了C++中JsonWriter::setCompact方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonWriter::setCompact方法的具体用法?C++ JsonWriter::setCompact怎么用?C++ JsonWriter::setCompact使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonWriter
的用法示例。
在下文中一共展示了JsonWriter::setCompact方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveUserConfig
bool NodeConfigManager::saveUserConfig(UserId userId)
{
// FIXME: do we need locking for load/save/get/remove?
bool rval;
string path;
rval = getUserConfigPath(this, userId, path);
if(rval)
{
MO_CAT_DEBUG(BM_NODE_CAT,
"NodeConfigManager: save user config: id=%" PRIu64 ", path=%s",
userId, path.c_str());
// FIXME: how to check if config is "empty" of useful data?
Config c = getUserConfig(userId, true);
File file(path.c_str());
rval = file->mkdirs();
if(rval)
{
FileOutputStream fos(file);
JsonWriter writer;
writer.setCompact(false);
rval = writer.write(c, &fos);
fos.close();
}
}
return true;
}
示例2: mos
bool Id3v2TagFrameIO::getContractData(
ByteBuffer* b, uint32_t* uncompressed, uint32_t* compressed)
{
bool rval;
// create output stream
OutputStream* os = (b == NULL) ?
static_cast<OutputStream*>(new NullOutputStream()) :
static_cast<OutputStream*>(new ByteArrayOutputStream(b, false));
// zlib-compress data
Deflater def;
def.startDeflating(-1, false);
MutatorOutputStream mos(os, true, &def, false);
// produce JSON-formatted contract data
JsonWriter writer;
writer.setCompact(true);
rval = writer.write(mContract, &mos);
mos.close();
// store uncompressed bytes
if(uncompressed != NULL)
{
*uncompressed = def.getTotalInputBytes();
}
// store compressed bytes
if(compressed != NULL)
{
*compressed = def.getTotalOutputBytes();
}
return rval;
}
示例3: saveSystemUserConfig
// FIXME: This code has an issue if the config file has a changed id or
// FIXME: changed contents since it was first loaded. Just assuming this code
// FIXME: is the only code that manages the file for now.
bool NodeConfigManager::saveSystemUserConfig()
{
bool rval;
Config cfg = getNodeConfig();
const char* suPath;
string path;
rval = !cfg.isNull();
if(rval)
{
// get system user config and expand any home path
suPath = cfg["systemUserConfig"]->getString();
rval = expandBitmunkHomePath(suPath, path);
}
if(rval)
{
// FIXME: do we need locking for load/save/get/remove?
MO_CAT_DEBUG(BM_NODE_CAT,
"NodeConfigManager: save system user config: path=%s",
path.c_str());
// read
File file(path.c_str());
// new config
Config c;
if(file->exists())
{
FileInputStream fis(file);
JsonReader reader;
reader.start(c);
rval = reader.read(&fis) && reader.finish();
fis.close();
}
else
{
c[ConfigManager::VERSION] = MO_DEFAULT_CONFIG_VERSION;
c[ConfigManager::ID] = "custom system user";
c[ConfigManager::GROUP] = "system user";
}
// update
if(rval &&
getConfigManager()->hasConfig(c[ConfigManager::ID]->getString()))
{
// get old raw config
Config active = getConfigManager()->getConfig(
c[ConfigManager::ID]->getString(), true);
c.merge(active, false);
}
// backup old file
if(rval && file->exists())
{
string backupPath = path + ".bak";
File backupFile(backupPath.c_str());
rval = file->rename(backupFile);
}
// make sure dirs exist
rval = rval && file->mkdirs();
// write
if(rval)
{
FileOutputStream fos(file);
JsonWriter writer;
writer.setCompact(false);
rval = writer.write(c, &fos);
fos.close();
}
}
if(!rval)
{
ExceptionRef e = new Exception(
"Could not save system user config.",
"bitmunk.node.NodeConfigManager.ConfigError");
e->getDetails()["path"] = path.c_str();
Exception::push(e);
}
return rval;
}