/* * See the file LICENSE for redistribution information. * * Copyright (c) 2004,2009 Oracle. All rights reserved. * * ******* * * Compression API * * A very simple Berkeley DB XML program that demonstrates * compression API usage. * * This program demonstrates: * Registration of a custom compression class in XmlManager * Compression configuration for XmlContainer * Turn off default compression * Using default compression * Custom compression class implementation * * MyCompression is an subclass of XmlCompression. It is a very simple * implementation and not intended to be particularly efficient. As an example, * it uses buffer inverse permutation to simulate the compression process. * * Compression only works with whole document containers. User compression must * always be registered with the manager in order to open/create the container. * */ #include "dbxml/DbXml.hpp" #include using namespace DbXml; using namespace std; /* * MyCompression implements the XmlCompression interface: required * member functions are compress() and decompress(). The two member functions * are required to return tree for success and false for error. * This class must be thread-safe in multi-thread environment. * */ class MyCompression : public XmlCompression { bool compress(XmlTransaction &txn, const XmlData &source, XmlData &dest); bool decompress(XmlTransaction &txn, const XmlData &source, XmlData &dest); }; bool MyCompression::compress(XmlTransaction &txn, const XmlData &source, XmlData &dest) { try { // Get the data to compress char *pSrc = (char *)source.get_data(); size_t size = source.get_size(); // Use inverse permutation to simulate the compression process dest.reserve(size); char *buf = (char *)dest.get_data(); for(size_t i=0; i