PHPackages                             ljmaskey/php-cmf-bindings - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ljmaskey/php-cmf-bindings

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ljmaskey/php-cmf-bindings
=========================

A port of bitcoinclassic/cmf-bindings to PHP

v1.0.0(2y ago)02Apache-2.0PHP

Since Feb 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ljmaskey/php-cmf-bindings)[ Packagist](https://packagist.org/packages/ljmaskey/php-cmf-bindings)[ Docs](https://www.github.com/ljmaskey/php-cmf-bindings)[ RSS](/packages/ljmaskey-php-cmf-bindings/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (7)Versions (2)Used By (0)

A PHP implementation for using the Compact Message Format
=========================================================

[](#a-php-implementation-for-using-the-compact-message-format)

This is an attempt at implementing a PHP port for [The Compact Message Format bindings project](https://github.com/bitcoinclassic/cmf-bindings).

In creating this port, we referenced the Java and C# implementations the most, but the tests have been influenced by all the different implementations.

What is the Compact Message Format?
===================================

[](#what-is-the-compact-message-format)

As noted in the README of the original 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 built up by a series of tokens.

Implementation Details
======================

[](#implementation-details)

While the other implementations require a byte array to be given to the `MessageBuilder` and `MessageParser`, PHP does not have a concept of that. Instead, the classes in this package will accept either an array (specifically a list) or a stream resource.

For convenience, when using the `addByteArray` method on the `MessageBuilder`, this implementation will allow the items in the given array to either be byte values or individual ASCII characters (or a combination of these). When given an ASCII character, the package will convert that character to its corresponding byte value before adding it to the message.

Similarly, when the `MessageParser` is given an array for its data source (as opposed to a stream resource), that array can contain either byte values or individual ASCII characters. No matter the input, though, calling `getByteArray` on the parser will *always* return an array of byte values only.

Because PHP does not have support for method overloading, the `MessageBuilder` has explicitly named `add...` methods for each of the types that can be added. These should correspond with explicitly named `get...` methods defined on the `MessageParser`.

Unlike other implementations, there is no explicit `close()` method to be called.

When reading bytes from a stream, the position parameter is ignored. Instead, the package will always read the next byte (or bytes) from the stream.

Using the Package
=================

[](#using-the-package)

To demonstrate usage of the package, we will use the same short example from the original project: a message with 3 tokens, each having a name and a value.

```
   Name=Paris
   Population=2229621
   Area=105.6
```

Message Creation
----------------

[](#message-creation)

For creation of messages we use the [builder pattern](https://en.wikipedia.org/wiki/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. Each value that is added to a message requires a tag, with a tag being an integer between 0 and 65535 (inclusively).

```
$bytes = [];
$builder = new MessageBuilder($bytes, 0);
$builder->addString(CITY_NAME_TAG, 'Paris');
$builder->addInt(CITY_POPULATION_TAG, 2229621);
$builder->addDouble(CITY_AREA_TAG, 105.6);
```

Message Parsing
---------------

[](#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 and the actual value.

```
$parser = new MessageParser($inputStream, 0, $inputStreamLength);
while ($parser->next() == State.FoundTag) {
    if ($parser->tag() == CITY_POPULATION_TAG) {
        $population = $parser->getInt();
        break;
    }
}
```

Exception Handling
------------------

[](#exception-handling)

### `\InvalidArgumentException`

[](#invalidargumentexception)

When there are problems with the data being passed into a method, the package will throw this exception. This could include being passed a non-list array when one is expected, or being passed a negative number when one is not allowed. Note, though, that this does not include errors with the underlying data being processed: those will throw either a `SerializationException` or an `UnserializationException`.

*An \\InvalidArgumentException indicates an issue that should be resolved by the calling code.*

### `SerializationException`, `UnserializationException`

[](#serializationexception-unserializationexception)

These are thrown when the actual data being processed has errors. The resolution of one of these exceptions depends on the original source of the data.

### `InternalPackageException`

[](#internalpackageexception)

These are thrown when something unexpected has happened with the package's own code.

*These are exceptions that should be reported, as they need to be resolved by the package.*

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

867d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e51f98586608e7f30c2b25d7841e938cbd67480b773cc0d4065cf75f40823993?d=identicon)[ljmaskey](/maintainers/ljmaskey)

---

Top Contributors

[![ljmaskey](https://avatars.githubusercontent.com/u/1082557?v=4)](https://github.com/ljmaskey "ljmaskey (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ljmaskey-php-cmf-bindings/health.svg)

```
[![Health](https://phpackages.com/badges/ljmaskey-php-cmf-bindings/health.svg)](https://phpackages.com/packages/ljmaskey-php-cmf-bindings)
```

###  Alternatives

[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.5k78.3k91](/packages/pocketmine-pocketmine-mp)[godruoyi/php-snowflake

An ID Generator for PHP based on Snowflake Algorithm (Twitter announced).

8652.6M68](/packages/godruoyi-php-snowflake)[bitwasp/bitcoin

PHP Bitcoin library with functions for transactions, signatures, serialization, Random/Deterministic ECDSA keys, blocks, RPC bindings

1.1k539.0k43](/packages/bitwasp-bitcoin)[pocketmine/raklib

A RakNet server implementation written in PHP

101595.3k17](/packages/pocketmine-raklib)[bitwasp/buffertools

Toolbox for working with binary and hex data. Similar to NodeJS Buffer.

65779.0k42](/packages/bitwasp-buffertools)[pocketmine/math

PHP library containing math related code used in PocketMine-MP

44601.8k23](/packages/pocketmine-math)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
