Language Bindings for the Compact Message Format
C++ Java C# Python C CMake QMake
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

The Compact Message Format bindings project

Bitcoin Classic introduced the Compact Message Format as a very simple but powerful format to encode and decode any type of messages.

The compact message format is a key/value-pair based format. Each key/value pair is called a token and a message is build up of a series of tokens.

Take this as a short example, a message with 3 tokens. Each having a name and a value.


In all object oriented languages there are very similar constructions available to create or parse the messages. Please refer to the API docs of your language bindings for details. I'll give a generic example here, to explain the concepts.

Message Creation

For creation of messages we use the builder pattern in the form of the MessageBuilder class.

The MessageBuilder class has a series of add() methods each of which appends a token to your message.

  byte[] bytes = new byte[100];
  MessageBuilder builder = new MessageBuilder(bytes);
  builder.add(City.Name, "Paris");
  builder.add(City.Population, 2229621);
  builder.add(City.Area, 105.6);

This allows really easy to read and understand code.

Message Parsing

The MessageParser is using more of a SOX parser approach where you call MessageParser.Next() and then you can ask the parser for the tag-is and the actual value.

  MessageParser parser = new MessageParser(inputMessage);
  while ( == MessageParser.FoundTag) {
     if (parser.tag() == City.Population) {
         int population =;

At this time there are implementations for;

  • C++ which depend on Qt
  • C++ with boost
  • C# Should work with any version, the project assumes 4.5
  • Java
  • Python
  • C