fudge-cpp /

Filename Size Date modified Message
2.1 KB


by Jens Alfke -- (c)2011

Fudge-Cpp is a C++ library for reading and writing Fudge, "a binary messaging system designed to scale from ad-hoc messages to long-term persistance." Fudge is somewhat similar in semantics to JSON, but uses a binary encoding that's more compact and faster to parse.

Fudge-Cpp's advantages over the existing Fudge-C library are:

  • Simpler, idiomatic C++ API using classes.
  • Integrates with STL and iostreams.
  • Uses less memory -- in fact, it allocates no heap space at all unless you use STL string accessors. When you access the fields in a message, the objects returned to you are really pointers directly into the existing binary message data. When you write a message, the library writes directly to the output stream without needing any heap space for bookkeeping.

Fudge-Cpp is intended to be cross-platform, but the current version still has some OS X dependencies, primarily for byte-swapping. Fixes for these are welcome :)


Writing a simple message with a few fields into an in-memory string object:

std::stringstream out;
Writer writer(out);
std::string fudgeData = out.str();   // binary 'string', not human-readable

Writing a JSON-style dictionary directly to a file:

std::ofstream out("/tmp/fudgetest.dat");
Writer writer(out);
Message nested = writer.beginMessage();

Parsing the Fudge message generated by the first example:

const Envelope* envelope = Envelope::FromBytes(fudgeData);
Message msg = envelope->message();
Message::iterator i = msg.begin();
int value = i->asInt32();

Writing the above Fudge message as JSON:

WriteJSON(envelope, std::cout);

The test cases in the "test" subdirectory show many examples of using the complete API.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.