PHPackages                             spomky-labs/cbor-bundle - 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. spomky-labs/cbor-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

spomky-labs/cbor-bundle
=======================

CBOR Encoder/Decoder Bundle for Symfony.

v3.0.0(4y ago)5130.7k↓31.5%1[4 PRs](https://github.com/Spomky-Labs/cbor-bundle/pulls)MITPHPPHP &gt;=8.0CI passing

Since Nov 16Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Spomky-Labs/cbor-bundle)[ Packagist](https://packagist.org/packages/spomky-labs/cbor-bundle)[ Docs](https://github.com/spomky-labs)[ GitHub Sponsors](https://github.com/Spomky)[ Patreon](https://www.patreon.com/FlorentMorselli)[ RSS](/packages/spomky-labs-cbor-bundle/feed)WikiDiscussions 4.0.x Synced 1mo ago

READMEChangelog (4)Dependencies (16)Versions (18)Used By (0)

CBOR Bundle for Symfony
=======================

[](#cbor-bundle-for-symfony)

[![Build Status](https://github.com/spomky-labs/cbor-bundle/actions/workflows/ci.yml/badge.svg)](https://github.com/spomky-labs/cbor-bundle/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/0b4e864b41a5ed2b250b46abf2fef7890c2c08782c5fbd54d59a735eb11b8f1b/68747470733a2f2f706f7365722e707567782e6f72672f73706f6d6b792d6c6162732f63626f722d62756e646c652f762f737461626c652e737667)](https://packagist.org/packages/spomky-labs/cbor-bundle)[![Total Downloads](https://camo.githubusercontent.com/41ce9f921e561203991d13efd1041d50748444ca9cd86a0ce4bc897840f80c28/68747470733a2f2f706f7365722e707567782e6f72672f73706f6d6b792d6c6162732f63626f722d62756e646c652f646f776e6c6f6164732e737667)](https://packagist.org/packages/spomky-labs/cbor-bundle)[![License](https://camo.githubusercontent.com/ae60e20ddc787df8745db7b0cf7d181b2adb94d12906144a0395dfcc3f1ede9d/68747470733a2f2f706f7365722e707567782e6f72672f73706f6d6b792d6c6162732f63626f722d62756e646c652f6c6963656e73652e737667)](https://packagist.org/packages/spomky-labs/cbor-bundle)

[![OpenSSF Scorecard](https://camo.githubusercontent.com/b727a47a2d57e8c749448e9b91be039fd9818221d70a07e51ff9a1b69550b402/68747470733a2f2f6170692e736563757269747973636f726563617264732e6465762f70726f6a656374732f6769746875622e636f6d2f73706f6d6b792d6c6162732f63626f722d62756e646c652f6261646765)](https://securityscorecards.dev/viewer/?uri=github.com/spomky-labs/cbor-bundle)

A Symfony bundle that provides CBOR (Concise Binary Object Representation) encoding and decoding support for the Symfony Serializer component.

CBOR is a data format whose design goals include the possibility of extremely small code size, fairly small message size, and extensibility without the need for version negotiation. It is defined in [RFC 8949](https://www.rfc-editor.org/rfc/rfc8949.html).

Features
--------

[](#features)

- 🔄 **Full Symfony Serializer Integration**: Works seamlessly with Symfony's serializer component
- 📦 **Complete Type Support**: Encode/decode all PHP types (scalars, arrays, objects, enums)
- ⚙️ **Context Options**: Fine-grained control over encoding behavior
- 🎯 **Object Serialization**: Serialize any PHP object to CBOR format
- 🔢 **Enum Support**: Native support for PHP 8.1+ backed and unit enums
- 📝 **Well Documented**: Comprehensive PHPDoc and guides
- ✅ **Well Tested**: Extensive test coverage

Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- Symfony 6.4, 7.x, or 8.x

Installation
------------

[](#installation)

Install the bundle using Composer:

```
composer require spomky-labs/cbor-bundle
```

If you're using Symfony Flex, the bundle will be automatically registered. Otherwise, register it manually in `config/bundles.php`:

```
return [
    // ...
    SpomkyLabs\CborBundle\SpomkyLabsCborBundle::class => ['all' => true],
];
```

Basic Usage
-----------

[](#basic-usage)

### Encoding Data

[](#encoding-data)

```
use Symfony\Component\Serializer\SerializerInterface;

class MyController
{
    public function __construct(
        private SerializerInterface $serializer
    ) {}

    public function encodeAction(): Response
    {
        $data = [
            'name' => 'John Doe',
            'age' => 30,
            'active' => true,
            'tags' => ['developer', 'symfony']
        ];

        // Serialize to CBOR format
        $cborData = $this->serializer->serialize($data, 'cbor');

        return new Response($cborData, 200, [
            'Content-Type' => 'application/cbor'
        ]);
    }
}
```

### Decoding Data

[](#decoding-data)

```
public function decodeAction(Request $request): Response
{
    $cborData = $request->getContent();

    // Deserialize from CBOR format
    $data = $this->serializer->deserialize($cborData, 'array', 'cbor');

    return $this->json($data);
}
```

### Object Serialization

[](#object-serialization)

```
use App\Entity\Person;

class PersonController
{
    public function serializeObject(Person $person): string
    {
        // Serialize object to CBOR
        return $this->serializer->serialize($person, 'cbor');
    }

    public function deserializeObject(string $cborData): Person
    {
        // Deserialize CBOR back to object
        return $this->serializer->deserialize($cborData, Person::class, 'cbor');
    }
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Context Options

[](#context-options)

You can control encoding behavior using context options:

```
// Use single precision floats (smaller size, less precision)
$cbor = $serializer->serialize($data, 'cbor', [
    'cbor_single_precision_float' => true
]);

// Use indefinite length encoding for arrays
$cbor = $serializer->serialize([1, 2, 3], 'cbor', [
    'cbor_indefinite_list' => true
]);

// Use indefinite length encoding for maps
$cbor = $serializer->serialize(['a' => 1], 'cbor', [
    'cbor_indefinite_map' => true
]);

// Use indefinite length for text strings
$cbor = $serializer->serialize('Hello', 'cbor', [
    'cbor_indefinite_text_string' => true
]);
```

**Available context options:**

- `cbor_single_precision_float` (bool): Use 32-bit floats instead of 64-bit
- `cbor_indefinite_text_string` (bool): Use indefinite length for text strings
- `cbor_indefinite_byte_string` (bool): Use indefinite length for byte strings
- `cbor_indefinite_list` (bool): Use indefinite length for arrays
- `cbor_indefinite_map` (bool): Use indefinite length for maps

### Enum Support

[](#enum-support)

The bundle natively supports PHP 8.1+ enums:

```
// Backed enums are encoded as their backing value
enum Status: string
{
    case ACTIVE = 'active';
    case INACTIVE = 'inactive';
}

$cbor = $serializer->serialize(Status::ACTIVE, 'cbor');
// Encodes as "active"

// Unit enums are encoded as their name
enum Color
{
    case RED;
    case GREEN;
}

$cbor = $serializer->serialize(Color::RED, 'cbor');
// Encodes as "RED"
```

### Direct Service Access

[](#direct-service-access)

You can also use the encoder/decoder services directly:

```
use SpomkyLabs\CborBundle\CBOREncoder;
use SpomkyLabs\CborBundle\CBORDecoder;

class MyService
{
    public function __construct(
        private CBOREncoder $encoder,
        private CBORDecoder $decoder
    ) {}
}
```

Or use the service aliases:

```
class MyService
{
    public function __construct(
        #[Autowire(service: 'cbor.encoder')]
        private $encoder,
        #[Autowire(service: 'cbor.decoder')]
        private $decoder
    ) {}
}
```

Supported Types
---------------

[](#supported-types)

The bundle supports encoding and decoding of:

- **Scalars**: `int`, `float`, `string`, `bool`, `null`
- **Arrays**: Indexed arrays (as CBOR lists) and associative arrays (as CBOR maps)
- **Objects**: Any object that can be normalized by Symfony's normalizers
- **Enums**: PHP 8.1+ backed and unit enums
- **DateTime**: Automatically handled via Symfony's normalizers
- **Nested structures**: Arrays of objects, objects containing arrays, etc.

Extending the Bundle
--------------------

[](#extending-the-bundle)

### Custom CBOR Tags

[](#custom-cbor-tags)

You can register custom CBOR tags by implementing `TagInterface` and tagging the service:

```
services:
    App\Cbor\CustomTag:
        tags: ['cbor.tag']
```

### Custom CBOR Objects

[](#custom-cbor-objects)

You can register custom CBOR objects by implementing `OtherObjectInterface` and tagging the service:

```
services:
    App\Cbor\CustomObject:
        tags: ['cbor.other_object']
```

Upgrading
---------

[](#upgrading)

See [UPGRADE-4.0.md](UPGRADE-4.0.md) for migration instructions from version 3.x to 4.0.

Documentation
-------------

[](#documentation)

For more detailed information about CBOR:

- [RFC 8949 - CBOR Specification](https://www.rfc-editor.org/rfc/rfc8949.html)
- [CBOR Website](https://cbor.io/)

Contributing
------------

[](#contributing)

Contributions are welcome! Please read our [contributing guidelines](/.github/CONTRIBUTING.md) before submitting a pull request.

Security
--------

[](#security)

If you discover a security vulnerability, please follow our [security policy](SECURITY.md).

Support
-------

[](#support)

If you find this project useful and want to support its development:

- ⭐ Star the project on GitHub
- 💰 [Become a sponsor](https://github.com/sponsors/Spomky)
- ☕ [Support via Patreon](https://www.patreon.com/FlorentMorselli)

License
-------

[](#license)

This project is released under the [MIT License](LICENSE).

Credits
-------

[](#credits)

This bundle is maintained by [Florent Morselli](https://github.com/Spomky) and [contributors](https://github.com/spomky-labs/cbor-bundle/contributors).

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance56

Moderate activity, may be stable

Popularity37

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 71.4% 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

Every ~265 days

Recently: every ~512 days

Total

11

Last Release

85d ago

Major Versions

v1.0.1 → v2.0.02020-01-01

v1.0.x-dev → v2.0.22020-02-18

v2.0.3 → v3.0.02021-11-23

3.0.x-dev → 4.0.x-dev2026-02-22

PHP version history (5 changes)v1.0.0PHP ^7.1

v1.0.1PHP ^7.1|^8.0

v2.0.x-devPHP &gt;=7.1

v3.0.0PHP &gt;=8.0

4.0.x-devPHP &gt;=8.3

### Community

Maintainers

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

---

Top Contributors

[![Spomky](https://avatars.githubusercontent.com/u/1091072?v=4)](https://github.com/Spomky "Spomky (45 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (18 commits)")

---

Tags

symfonybundlecborConcise Binary Object RepresentationRFC7049

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/spomky-labs-cbor-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/spomky-labs-cbor-bundle/health.svg)](https://phpackages.com/packages/spomky-labs-cbor-bundle)
```

###  Alternatives

[pentatrion/vite-bundle

Vite integration for your Symfony app

2725.3M13](/packages/pentatrion-vite-bundle)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[pugx/autocompleter-bundle

Add an autocomplete type to forms

93861.6k3](/packages/pugx-autocompleter-bundle)[sineflow/clamav

ClamAV PHP Client for Symfony

10168.5k](/packages/sineflow-clamav)[bornfreee/tactician-domain-events-bundle

Bundle to integrate Tactician Domain Events library with Symfony project

10138.6k](/packages/bornfreee-tactician-domain-events-bundle)

PHPackages © 2026

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