PHPackages                             socialdept/atp-cbor - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. socialdept/atp-cbor

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

socialdept/atp-cbor
===================

CBOR, CAR, and CID binary encoding for AT Protocol in PHP

v0.2.1(2mo ago)04033MITPHPPHP ^8.3

Since Feb 7Pushed 2mo agoCompare

[ Source](https://github.com/socialdept/atp-cbor)[ Packagist](https://packagist.org/packages/socialdept/atp-cbor)[ Docs](https://github.com/socialdept/atp-cbor)[ RSS](/packages/socialdept-atp-cbor/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (5)Versions (7)Used By (3)

[![CBOR Header](./header.png)](https://github.com/socialdept/atp-cbor)

###  CBOR, CAR, and CID binary encoding for AT Protocol in PHP.

[](#----cbor-car-and-cid-binary-encoding-for-at-protocol-in-php)

 [![](https://camo.githubusercontent.com/1ebaf093d241b700eb5ce45e57b459077899cf9dbf94bda32e7946ab31fcfe78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6369616c646570742f6174702d63626f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/socialdept/atp-cbor "Latest Version on Packagist") [![](https://camo.githubusercontent.com/cdaafc7ba60a65a70f5638f4bcb9b7a71efffc3b8631e26d90eb68945037d74e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736f6369616c646570742f6174702d63626f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/socialdept/atp-cbor "Total Downloads") [![](https://camo.githubusercontent.com/8e71e92135bb37b92685a4bbf8db285455d5be643afc0abcacff829f4bb41f49/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736f6369616c646570742f6174702d63626f722f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/socialdept/atp-cbor/actions/workflows/tests.yml "GitHub Tests Action Status") [![](https://camo.githubusercontent.com/abe9da55b450cce6f83b502d70bce2d314d4758a845da083f62116e70b50ca41/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736f6369616c646570742f6174702d63626f723f7374796c653d666c61742d737175617265)](LICENSE "Software License")

---

What is ATP CBOR?
-----------------

[](#what-is-atp-cbor)

**ATP CBOR** is a standalone PHP library for decoding CBOR (Concise Binary Object Representation), CAR (Content Addressable aRchive), and CID (Content Identifier) binary data from the AT Protocol network. It powers the binary decoding layer used by firehose consumers and repository loaders across the Social Dept. AT Protocol packages.

No Laravel dependency required — this is a pure PHP package.

Quick Example
-------------

[](#quick-example)

```
use SocialDept\AtpCbor\Core\CBOR;
use SocialDept\AtpCbor\Core\CAR;
use SocialDept\AtpCbor\Core\CID;

// Decode CBOR data from a firehose event
$decoded = CBOR::decode($binaryData);

// Parse CAR blocks from a repository export
$blocks = CAR::blockMap($carData);

// Parse a CID string
$cid = CID::fromString('bafyreie5cvv4h45feadgeuwhbcutmh6t7ceseocckahdoe6uat64zmz454a');
echo $cid->version; // 1
```

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

[](#installation)

```
composer require socialdept/atp-cbor
```

Requires the `gmp` PHP extension for large integer handling.

Usage
-----

[](#usage)

### Decoding CBOR

[](#decoding-cbor)

The `CBOR` facade provides three methods for decoding binary CBOR data:

```
use SocialDept\AtpCbor\Core\CBOR;

// Decode a single CBOR item
$value = CBOR::decode($data);

// Decode the first item and get remaining data
[$value, $remaining] = CBOR::decodeFirst($data);

// Decode all sequential CBOR items
$items = CBOR::decodeAll($data);
```

Supports all CBOR major types including unsigned/negative integers, byte strings, text strings, arrays, maps, tagged values (including DAG-CBOR tag 42 for CID links), and special values (booleans, null, floats).

### Parsing CAR Archives

[](#parsing-car-archives)

CAR (Content Addressable aRchive) files contain blocks of CBOR data indexed by CID:

```
use SocialDept\AtpCbor\Core\CAR;
use SocialDept\AtpCbor\CAR\RecordExtractor;

// Get all blocks as a CID => data map
$blocks = CAR::blockMap($carData);

// Extract records from AT Protocol MST blocks
$extractor = new RecordExtractor($blocks, 'did:plc:xyz');
foreach ($extractor->extractRecords($rootCid) as $path => $record) {
    echo $record['uri'];       // at://did:plc:xyz/app.bsky.feed.post/3k4...
    echo $record['cid'];       // bafyrei...
    print_r($record['value']); // Decoded record data
}
```

For memory-efficient processing, use the `BlockReader` generator directly:

```
use SocialDept\AtpCbor\CAR\BlockReader;

$reader = new BlockReader($carData);
foreach ($reader->blocks() as [$cid, $blockData]) {
    // Process each block individually
}
```

### Working with CIDs

[](#working-with-cids)

Content Identifiers can be parsed from strings or binary data:

```
use SocialDept\AtpCbor\Core\CID;

// Parse from string (auto-detects v0 vs v1)
$cid = CID::fromString('bafyreie5cvv4h45feadgeuwhbcutmh6t7ceseocckahdoe6uat64zmz454a');

// Parse from binary data
$cid = CID::fromBinary($bytes);

// Access properties
$cid->version; // 0 or 1
$cid->codec;   // Codec identifier
$cid->hash;    // Raw multihash bytes

// Convert back
$cid->toString();  // Base32 (v1) or base58btc (v0)
$cid->toBinary();  // Raw binary
```

### Low-level Binary Reading

[](#low-level-binary-reading)

For custom binary parsing, use the `Reader` and `Varint` utilities:

```
use SocialDept\AtpCbor\Binary\Reader;
use SocialDept\AtpCbor\Binary\Varint;

// Stream-style binary reader
$reader = new Reader($data);
$byte = $reader->readByte();
$chunk = $reader->readBytes(32);
$varint = $reader->readVarint();

// Standalone varint decoding
$offset = 0;
$value = Varint::decode($data, $offset);
```

API Reference
-------------

[](#api-reference)

### Core Facades

[](#core-facades)

ClassMethodDescription`CBOR``decode(string $data)`Decode complete CBOR data`CBOR``decodeFirst(string $data)`Decode first item, return remaining`CBOR``decodeAll(string $data)`Decode all sequential items`CAR``blockMap(string $data, ?string $did)`Parse CAR into CID =&gt; block map### Value Objects

[](#value-objects)

ClassDescription`CID`Immutable Content Identifier (v0 and v1)### Readers

[](#readers)

ClassDescription`BlockReader`Generator-based CAR block reader`RecordExtractor`AT Protocol MST record walker`Decoder`RFC 8949 CBOR decoder with DAG-CBOR`Reader`Stream-style binary data reader`Varint`Variable-length integer decoderSupported Standards
-------------------

[](#supported-standards)

- **CBOR** - RFC 8949 (Concise Binary Object Representation)
- **DAG-CBOR** - IPLD extension with tag 42 for CID links
- **CAR** - Content Addressable aRchive (v1)
- **CID** - IPLD Content Identifiers (v0 and v1)
- **Multihash** - SHA-256 and other hash types
- **Varint** - Protocol Buffers-style variable-length integers

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

[](#requirements)

- PHP 8.2+
- ext-gmp

Resources
---------

[](#resources)

- [AT Protocol Documentation](https://atproto.com/)
- [CBOR RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
- [IPLD CID Specification](https://github.com/multiformats/cid)
- [CAR Specification](https://ipld.io/specs/transport/car/)

Support &amp; Contributing
--------------------------

[](#support--contributing)

Found a bug or have a feature request? [Open an issue](https://github.com/socialdept/atp-cbor/issues).

Want to contribute? We'd love your help! Check out the [contribution guidelines](CONTRIBUTING.md).

Credits
-------

[](#credits)

- [Miguel Batres](https://batres.co) - founder &amp; lead maintainer
- [All contributors](https://github.com/socialdept/atp-cbor/graphs/contributors)

License
-------

[](#license)

ATP CBOR is open-source software licensed under the [MIT license](LICENSE).

---

**Built for the Atmosphere** • By Social Dept.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance86

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity44

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

Every ~16 days

Total

5

Last Release

74d ago

PHP version history (2 changes)v0.1.0PHP ^8.2

v0.1.2PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/101910626?v=4)[Social Dept.](/maintainers/socialdept)[@socialdept](https://github.com/socialdept)

---

Top Contributors

[![btrsco](https://avatars.githubusercontent.com/u/1373528?v=4)](https://github.com/btrsco "btrsco (11 commits)")

---

Tags

laravelbinarycborencoderdecodercarfirehoseat protocolatpcId

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/socialdept-atp-cbor/health.svg)

```
[![Health](https://phpackages.com/badges/socialdept-atp-cbor/health.svg)](https://phpackages.com/packages/socialdept-atp-cbor)
```

###  Alternatives

[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6442.4k](/packages/sbsaga-toon)[shaarli/netscape-bookmark-parser

Generic Netscape bookmark parser

2545.7k](/packages/shaarli-netscape-bookmark-parser)[suin/json

A Simple wrapper of json\_decode() and json\_encode(). This provides object-oriented interface and exception-based error handing.

1027.6k3](/packages/suin-json)[base62/base62

base62 encoder and decoder also for big numbers with Laravel integration

1610.0k](/packages/base62-base62)

PHPackages © 2026

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