Configuration Files Containing Binary Data

A general discussion forum.
Posts: 20
Joined: 02 Nov 2010, 18:17

Configuration Files Containing Binary Data

Postby elemings » 18 Jul 2011, 23:46


Since standard strings can contain raw, binary data in addition to textual data, I've extended the AbstractConfiguration interface to support strings containing binary data.

Code: Select all

namespace MyPocoExtensions {

typedef unsigned char Byte;
typedef std::basic_string<Byte> Data;

class AbstractConfiguration
    Data getData (const std::string&);
    void setData (const std::string&, const Data&);
    void setData (const std::string&, const Byte*, size_t);

} // namespace MyPocoExtensions

There's really no difference implementation-wise; the difference is mostly semantic.

My question though is, can the configuration file classes (e.g. PropertyFileConfiguration, XMLConfiguration, etc.) also be extended to support binary data? If so, which format would be most dependable, flexible? XMLConfiguration?


Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Configuration Files Containing Binary Data

Postby guenter » 28 Jul 2011, 14:41

Since all configuration file formats are text based, the easiest way to implement binary data support would be to extend the AbstractConfiguration class with methods that perform Base64 encoding/decoding for binary data.


Code: Select all

std::string getBase64Binary(const std::string& key);
std::string getBase64Binary(const std::string& key, const std::string& deflt);
void setBase64Binary(const std::string& key, const std::string& value);
void setBase64Binary(const std::string& key, const void* value, std::size_t length);

Extending the entire configuration framework so that each implementation of AbstractConfiguration (e.g., PropertyFileConfiguration, XMLConfiguration, etc.) would also support this (and allow some control how the binary data is encoded) would be more work, which I'd like to avoid for now.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests