本文整理汇总了C++中SXMPMeta::SerializeToBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ SXMPMeta::SerializeToBuffer方法的具体用法?C++ SXMPMeta::SerializeToBuffer怎么用?C++ SXMPMeta::SerializeToBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SXMPMeta
的用法示例。
在下文中一共展示了SXMPMeta::SerializeToBuffer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: catch
static void
ProcessPacket ( const char * fileName,
FILE * inFile,
size_t offset,
size_t length )
{
std::string xmlString;
xmlString.append ( length, ' ' );
fseek ( inFile, offset, SEEK_SET );
fread ( (void*)xmlString.data(), 1, length, inFile );
char title [1000];
sprintf ( title, "// Dumping raw input for \"%s\" (%d..%d)", fileName, offset, (offset + length - 1) );
printf ( "// " );
for ( size_t i = 3; i < strlen(title); ++i ) printf ( "=" );
printf ( "\n\n%s\n\n%.*s\n\n", title, length, xmlString.c_str() );
fflush ( stdout );
SXMPMeta xmpObj;
try {
xmpObj.ParseFromBuffer ( xmlString.c_str(), length );
} catch ( ... ) {
printf ( "## Parse failed\n\n" );
return;
}
xmpObj.DumpObject ( DumpCallback, stdout );
fflush ( stdout );
string xmpString;
xmpObj.SerializeToBuffer ( &xmpString, kXMP_OmitPacketWrapper );
printf ( "\nPretty serialization, %d bytes :\n\n%s\n", xmpString.size(), xmpString.c_str() );
fflush ( stdout );
xmpObj.SerializeToBuffer ( &xmpString, (kXMP_OmitPacketWrapper | kXMP_UseCompactFormat) );
printf ( "Compact serialization, %d bytes :\n\n%s\n", xmpString.size(), xmpString.c_str() );
fflush ( stdout );
} // ProcessPacket
示例2: xmp_serialize_and_format
bool xmp_serialize_and_format(XmpPtr xmp, XmpStringPtr buffer,
uint32_t options,
uint32_t padding, const char *newline,
const char *tab, int32_t indent)
{
CHECK_PTR(xmp, false);
CHECK_PTR(buffer, false);
RESET_ERROR;
SXMPMeta *txmp = (SXMPMeta *)xmp;
try {
txmp->SerializeToBuffer(STRING(buffer), options, padding,
newline, tab, indent);
}
catch(const XMP_Error & e)
{
set_error(e);
return false;
}
return true;
}
示例3: Create
AssetMediaInfoPtr AssetMediaInfo::Create(
AssetMediaType inType,
ASL::Guid const& inGuid,
ASL::String const& inMediaPath,
XMPText inXMP,
ASL::String const& inFileContent,
ASL::String const& inCustomMetadata,
ASL::String const& inCreateTime,
ASL::String const& inLastModifyTime,
ASL::String const& inTimeBase,
ASL::String const& inNtsc,
ASL::String const& inAliasName,
bool inNeedSavePreCheck)
{
XMPText xmp = inXMP;
if (inXMP == NULL || inXMP->empty() || !TestValidXMPString(inXMP))
{
SXMPMeta metadata;
XMPText fileXMPBuffer(new ASL::StdString);
metadata.SerializeToBuffer(fileXMPBuffer.get(), kXMP_OmitPacketWrapper);
xmp = fileXMPBuffer;
}
return AssetMediaInfoPtr(new AssetMediaInfo(
inType,
inGuid,
inMediaPath,
xmp,
inFileContent,
inCustomMetadata,
inCreateTime,
inLastModifyTime,
inTimeBase,
inNtsc,
inAliasName,
inNeedSavePreCheck));
}
示例4: encode
int XmpParser::encode( std::string& xmpPacket,
const XmpData& xmpData,
uint16_t formatFlags,
uint32_t padding)
{ try {
if (xmpData.empty()) {
xmpPacket.clear();
return 0;
}
if (!initialize()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "XMP Toolkit initialization failed.\n";
#endif
return 2;
}
SXMPMeta meta;
for (XmpData::const_iterator i = xmpData.begin(); i != xmpData.end(); ++i) {
const std::string ns = XmpProperties::ns(i->groupName());
XMP_OptionBits options = 0;
if (i->typeId() == langAlt) {
// Encode Lang Alt property
const LangAltValue* la = dynamic_cast<const LangAltValue*>(&i->value());
if (la == 0) throw Error(43, i->key());
int idx = 1;
// write the default first
LangAltValue::ValueType::const_iterator k = la->value_.find("x-default");
if (k != la->value_.end()) {
#ifdef DEBUG
printNode(ns, i->tagName(), k->second, 0);
#endif
meta.AppendArrayItem(ns.c_str(), i->tagName().c_str(), kXMP_PropArrayIsAlternate, k->second.c_str());
const std::string item = i->tagName() + "[" + toString(idx++) + "]";
meta.SetQualifier(ns.c_str(), item.c_str(), kXMP_NS_XML, "lang", k->first.c_str());
}
for (k = la->value_.begin(); k != la->value_.end(); ++k) {
if (k->first == "x-default") continue;
#ifdef DEBUG
printNode(ns, i->tagName(), k->second, 0);
#endif
meta.AppendArrayItem(ns.c_str(), i->tagName().c_str(), kXMP_PropArrayIsAlternate, k->second.c_str());
const std::string item = i->tagName() + "[" + toString(idx++) + "]";
meta.SetQualifier(ns.c_str(), item.c_str(), kXMP_NS_XML, "lang", k->first.c_str());
}
continue;
}
// Todo: Xmpdatum should have an XmpValue, not a Value
const XmpValue* val = dynamic_cast<const XmpValue*>(&i->value());
assert(val);
options = xmpArrayOptionBits(val->xmpArrayType())
| xmpArrayOptionBits(val->xmpStruct());
if ( i->typeId() == xmpBag
|| i->typeId() == xmpSeq
|| i->typeId() == xmpAlt) {
#ifdef DEBUG
printNode(ns, i->tagName(), "", options);
#endif
meta.SetProperty(ns.c_str(), i->tagName().c_str(), 0, options);
for (int idx = 0; idx < i->count(); ++idx) {
const std::string item = i->tagName() + "[" + toString(idx + 1) + "]";
#ifdef DEBUG
printNode(ns, item, i->toString(idx), 0);
#endif
meta.SetProperty(ns.c_str(), item.c_str(), i->toString(idx).c_str());
}
continue;
}
if (i->typeId() == xmpText) {
if (i->count() == 0) {
#ifdef DEBUG
printNode(ns, i->tagName(), "", options);
#endif
meta.SetProperty(ns.c_str(), i->tagName().c_str(), 0, options);
}
else {
#ifdef DEBUG
printNode(ns, i->tagName(), i->toString(0), options);
#endif
meta.SetProperty(ns.c_str(), i->tagName().c_str(), i->toString(0).c_str(), options);
}
continue;
}
// Don't let any Xmpdatum go by unnoticed
throw Error(38, i->tagName(), TypeInfo::typeName(i->typeId()));
}
std::string tmpPacket;
meta.SerializeToBuffer(&tmpPacket, xmpFormatOptionBits(static_cast<XmpFormatFlags>(formatFlags)), padding); // throws
xmpPacket = tmpPacket;
return 0;
}
catch (const XMP_Error& e) {
#ifndef SUPPRESS_WARNINGS
std::cerr << Error(40, e.GetID(), e.GetErrMsg()) << "\n";
#endif
return 3;
}} // XmpParser::decode
示例5: main
//.........这里部分代码省略.........
cout << status << endl;
cout << filename << " is opened successfully" << endl;
// Create the XMP object and get the XMP data
SXMPMeta meta;
myFile.GetXMP(&meta);
// Display some properties in the console
displayPropertyValues(&meta);
///////////////////////////////////////////////////
// Now modify the XMP
if(meta.DoesPropertyExist(kXMP_NS_XMP, "CreatorTool"))
{
// Update xap:CreatorTool - we don't need to set any option bits
meta.SetProperty(kXMP_NS_XMP, "CreatorTool", "Updated By XMP SDK", 0);
}
// Update the Metadata Date
XMP_DateTime updatedTime;
// Get the current time. This is a UTC time automatically
// adjusted for the local time
SXMPUtils::CurrentDateTime(&updatedTime);
if(meta.DoesPropertyExist(kXMP_NS_XMP, "MetadataDate"))
{
meta.SetProperty_Date(kXMP_NS_XMP, "MetadataDate", updatedTime, 0);
}
// Add an item onto the dc:creator array
// Note the options used, kXMP_PropArrayIsOrdered, if the array does not exist it will be created
meta.AppendArrayItem(kXMP_NS_DC, "creator", kXMP_PropArrayIsOrdered, "Author Name", 0);
meta.AppendArrayItem(kXMP_NS_DC, "creator", kXMP_PropArrayIsOrdered, "Another Author Name", 0);
// Now update alt-text properties
meta.SetLocalizedText(kXMP_NS_DC, "title", "en", "en-US", "An English title");
meta.SetLocalizedText(kXMP_NS_DC, "title", "fr", "fr-FR", "Un titre Francais");
// Display the properties again to show changes
cout << "After update:" << endl;
displayPropertyValues(&meta);
// Create a new XMP object from an RDF string
SXMPMeta rdfMeta = createXMPFromRDF();
// Append the newly created properties onto the original XMP object
// This will:
// a) Add ANY new TOP LEVEL properties in the source (rdfMeta) to the destination (meta)
// b) Replace any top level properties in the source with the matching properties from the destination
SXMPUtils::ApplyTemplate(&meta, rdfMeta, kXMPTemplate_AddNewProperties | kXMPTemplate_ReplaceExistingProperties | kXMPTemplate_IncludeInternalProperties);
// Display the properties again to show changes
cout << "After Appending Properties:" << endl;
displayPropertyValues(&meta);
// Serialize the packet and write the buffer to a file
// Let the padding be computed and use the default linefeed and indents without limits
string metaBuffer;
meta.SerializeToBuffer(&metaBuffer, 0, 0, "", "", 0);
// Write the packet to a file as RDF
writeRDFToFile(&metaBuffer, filename+"_XMP_RDF.txt");
// Write the packet to a file but this time as compact RDF
XMP_OptionBits outOpts = kXMP_OmitPacketWrapper | kXMP_UseCompactFormat;
meta.SerializeToBuffer(&metaBuffer, outOpts);
writeRDFToFile(&metaBuffer, filename+"_XMP_RDF_Compact.txt");
// Check we can put the XMP packet back into the file
if(myFile.CanPutXMP(meta))
{
// If so then update the file with the modified XMP
myFile.PutXMP(meta);
}
// Close the SXMPFile. This *must* be called. The XMP is not
// actually written and the disk file is not closed until this call is made.
myFile.CloseFile();
}
else
{
cout << "Unable to open " << filename << endl;
}
}
catch(XMP_Error & e)
{
cout << "ERROR: " << e.GetErrMsg() << endl;
}
// Terminate the toolkit
SXMPFiles::Terminate();
SXMPMeta::Terminate();
}
else
{
cout << "Could not initialize SXMPFiles.";
return -1;
}
return 0;
}
示例6: DoTest
static void DoTest ( FILE * log )
{
SXMPMeta meta;
size_t u8Count, u32Count;
SXMPMeta meta8, meta16b, meta16l, meta32b, meta32l;
std::string u8Packet, u16bPacket, u16lPacket, u32bPacket, u32lPacket;
InitializeUnicodeConversions();
// ---------------------------------------------------------------------------------------------
fprintf ( log, "// ------------------------------------------------\n" );
fprintf ( log, "// Test basic serialization and parsing using ASCII\n\n" );
// ----------------------------------------------------
// Create basic ASCII packets in each of the encodings.
meta.ParseFromBuffer ( kSimpleRDF, kXMP_UseNullTermination );
meta.SerializeToBuffer ( &u8Packet, (kXMP_OmitPacketWrapper | kXMP_EncodeUTF8) );
meta.SerializeToBuffer ( &u16bPacket, (kXMP_OmitPacketWrapper | kXMP_EncodeUTF16Big) );
meta.SerializeToBuffer ( &u16lPacket, (kXMP_OmitPacketWrapper | kXMP_EncodeUTF16Little) );
meta.SerializeToBuffer ( &u32bPacket, (kXMP_OmitPacketWrapper | kXMP_EncodeUTF32Big) );
meta.SerializeToBuffer ( &u32lPacket, (kXMP_OmitPacketWrapper | kXMP_EncodeUTF32Little) );
#if 0
FILE* dump;
dump = fopen ( "u8Packet.txt", "w" );
fwrite ( u8Packet.c_str(), 1, u8Packet.size(), dump );
fclose ( dump );
dump = fopen ( "u16bPacket.txt", "w" );
fwrite ( u16bPacket.c_str(), 1, u16bPacket.size(), dump );
fclose ( dump );
dump = fopen ( "u16lPacket.txt", "w" );
fwrite ( u16lPacket.c_str(), 1, u16lPacket.size(), dump );
fclose ( dump );
dump = fopen ( "u32bPacket.txt", "w" );
fwrite ( u32bPacket.c_str(), 1, u32bPacket.size(), dump );
fclose ( dump );
dump = fopen ( "u32lPacket.txt", "w" );
fwrite ( u32lPacket.c_str(), 1, u32lPacket.size(), dump );
fclose ( dump );
#endif
// Verify the character form. The conversion functions are tested separately.
const char * ptr;
ptr = u8Packet.c_str();
fprintf ( log, "UTF-8 : %d : %.2X %.2X \"%.10s...\"\n", u8Packet.size(), *ptr, *(ptr+1), ptr );
ptr = u16bPacket.c_str();
fprintf ( log, "UTF-16BE : %d : %.2X %.2X %.2X\n", u16bPacket.size(), *ptr, *(ptr+1), *(ptr+2) );
ptr = u16lPacket.c_str();
fprintf ( log, "UTF-16LE : %d : %.2X %.2X %.2X\n", u16lPacket.size(), *ptr, *(ptr+1), *(ptr+2) );
ptr = u32bPacket.c_str();
fprintf ( log, "UTF-32BE : %d : %.2X %.2X %.2X %.2X %.2X\n", u32bPacket.size(), *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4) );
ptr = u32lPacket.c_str();
fprintf ( log, "UTF-32LE : %d : %.2X %.2X %.2X %.2X %.2X\n", u32lPacket.size(), *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4) );
fprintf ( log, "\nBasic serialization tests done\n" );
// -------------------------------------------------
// Verify round trip reparsing of the basic packets.
std::string origDump, rtDump;
meta.DumpObject ( DumpToString, &origDump );
fprintf ( log, "Original dump\n%s\n", origDump.c_str() );
try {
meta8.ParseFromBuffer ( u8Packet.c_str(), u8Packet.size() );
meta16b.ParseFromBuffer ( u16bPacket.c_str(), u16bPacket.size() );
meta16l.ParseFromBuffer ( u16lPacket.c_str(), u16lPacket.size() );
meta32b.ParseFromBuffer ( u32bPacket.c_str(), u32bPacket.size() );
meta32l.ParseFromBuffer ( u32lPacket.c_str(), u32lPacket.size() );
} catch ( XMP_Error& excep ) {
PrintXMPErrorInfo ( excep, "## Caught reparsing exception" );
fprintf ( log, "\n" );
}
#if 0
fprintf ( log, "After UTF-8 roundtrip\n" );
meta8.DumpObject ( DumpToFile, log );
fprintf ( log, "\nAfter UTF-16 BE roundtrip\n" );
meta16b.DumpObject ( DumpToFile, log );
fprintf ( log, "\nAfter UTF-16 LE roundtrip\n" );
meta16l.DumpObject ( DumpToFile, log );
fprintf ( log, "\nAfter UTF-32 BE roundtrip\n" );
meta32b.DumpObject ( DumpToFile, log );
fprintf ( log, "\nAfter UTF-32 LE roundtrip\n" );
meta32l.DumpObject ( DumpToFile, log );
#endif
rtDump.clear();
meta8.DumpObject ( DumpToString, &rtDump );
if ( rtDump != origDump ) fprintf ( log, "#ERROR: Roundtrip failure for UTF-8\n%s\n", rtDump.c_str() );
rtDump.clear();
//.........这里部分代码省略.........