Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cbor Php Laravel Package

spomky-labs/cbor-php

RFC 8949 CBOR encoder/decoder for PHP 8+. Supports all major types, tags (extensible), streaming decode, indefinite-length items, and normalization to native PHP values. Includes common tags and tools for custom tags.

View on GitHub
Deep Wiki
Context7

spomky-labs/cbor-php is a modern PHP 8+ library for encoding and decoding CBOR (RFC 8949). It provides a type-safe object model, a streaming decoder for efficient parsing, and robust handling of both definite and indefinite-length items.

Designed for interoperability-heavy domains (e.g., WebAuthn/COSE, IoT), it also supports an extensible tag system and normalization to native PHP types for convenient application use.

  • Full CBOR major types (0–7) support
  • Streaming decoder for lower memory usage
  • Extensible tag framework with common built-ins
  • Strong support for big integers/decimals (GMP/BCMath optional)
  • Normalize decoded data to PHP native types
Frequently asked questions about Cbor Php
How do I use this package in Laravel to replace JSON API responses with CBOR?
Install via Composer, then use middleware to negotiate CBOR responses. For example, create a middleware that checks the `Accept` header for `application/cbor` and returns CBOR-encoded data using the `Encoder` class. Laravel’s response system can be extended to support CBOR via a custom response factory.
Does this package support Laravel Eloquent for storing CBOR-encoded data in MySQL/PostgreSQL?
Yes, you can store CBOR data in a BLOB or JSONB column and decode it on retrieval using Eloquent accessors. The package provides a type-safe API, so you can normalize CBOR to PHP arrays or objects before processing in Laravel models.
What Laravel versions and PHP requirements does spomky-labs/cbor-php support?
The package requires PHP 8.0+ and is tested with Laravel 9+ (PHP 8.0+) and 10+ (PHP 8.1+). It has no Laravel-specific dependencies, making it framework-agnostic but fully compatible with modern Laravel applications.
How does the streaming decoder help with large datasets in Laravel?
The streaming decoder processes CBOR data incrementally, reducing memory usage for large payloads like logs or IoT telemetry. In Laravel, this is useful for queue workers or background jobs handling big files without memory overload.
Can I use custom tags for domain-specific validation in Laravel FormRequests?
Yes, the package supports extensible tags. You can define custom tags for validation rules in Laravel FormRequests by implementing the `TagInterface` and registering them with the decoder. This is useful for enforcing schema constraints on CBOR payloads.
What’s the performance difference between this CBOR library and JSON/XML in Laravel?
CBOR reduces payload size by 50-80% compared to JSON, improving API response times and database storage efficiency. Benchmarking shows faster parsing/encoding for complex nested data, especially with optional `ext-gmp` or `ext-bcmath` for large integers.
How do I debug CBOR payloads in Laravel logs or middleware?
Use the `Decoder` class to log raw CBOR data as normalized PHP arrays. For middleware, create a helper to convert CBOR to readable JSON for logging: `json_encode($decoder->decode($request->getContent())->normalize())`.
Are there alternatives to this package for CBOR in PHP/Laravel?
Other options include `josegonzalez/cbor.php` (older, less maintained) or `rupor-gmbh/cbor` (simpler but lacks streaming/extensible tags). This package stands out for its PHP 8+ type safety, streaming support, and Laravel-friendly features like normalization.
How do I handle indefinite-length CBOR objects in Laravel for dynamic data?
The package natively supports indefinite-length items (e.g., arrays/maps). Use `Decoder::create()->decode($stream)` with a `StringStream` for dynamic data. In Laravel, this is useful for processing unbounded logs or sensor streams without memory limits.
What’s the maintenance status of this package, and how do I stay updated?
The package follows semantic versioning and is actively maintained by Spomky-Labs. Monitor the [GitHub repo](https://github.com/Spomky-Labs/cbor-php) for updates, or subscribe to Packagist notifications. Breaking changes are rare and documented in release notes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4