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, indefinite-length items, and streaming decode for low memory. Type-safe API with normalization to native PHP types; extensible custom tags.

View on GitHub
Deep Wiki
Context7

CBOR Encoder/Decoder for PHP

Frequently asked questions about Cbor Php
How do I use this package in a Laravel API to replace JSON with CBOR for smaller payloads?
Install the package via Composer, then use the `Encoder` and `Decoder` classes to serialize/deserialize data. For APIs, add middleware to handle `Accept: application/cbor` headers and encode responses with `Response::make($cborData, 200, ['Content-Type' => 'application/cbor'])`.
Does this package support Laravel’s Eloquent for storing CBOR in database columns?
Yes. Store CBOR as binary blobs (e.g., `mediumBlob` in MySQL) and use accessors/mutators to decode/encode. Example: Add a `cbor_preferences` column, then decode it in a model getter using `Decoder::create()->decode($this->cbor_preferences)`.
What Laravel versions and PHP versions are officially supported?
This package requires **PHP 8.0+** and is framework-agnostic, but works seamlessly with Laravel 8+. No Laravel-specific dependencies exist; it integrates via native PHP types (arrays/objects). Tested with Laravel’s latest LTS releases.
How does the streaming decoder help with large CBOR payloads in Laravel queues?
The streaming decoder processes CBOR incrementally, avoiding memory overload for large payloads (e.g., IoT telemetry). In Laravel queues, decode payloads with `Decoder::create()->decode(new StringStream($payload))` instead of loading entire blobs into memory.
Can I customize CBOR tags for domain-specific semantics (e.g., COSE or CWT) in Laravel?
Absolutely. The package supports custom tags via `TagRegistry`. Register your tags in a service provider (e.g., `TagRegistry::getInstance()->register(new MyCustomTag())`) and use them in encoding/decoding logic for protocols like COSE or CWT.
Will this package conflict with existing JSON serialization in Laravel (e.g., `json_encode`)?
No. Use it alongside Laravel’s JSON tools. For hybrid APIs, check `Accept` headers: return JSON for `application/json` and CBOR for `application/cbor`. The package normalizes CBOR to PHP arrays/objects, compatible with Laravel’s serialization.
Do I need `ext-gmp` or `ext-bcmath` for basic CBOR usage in Laravel?
No, they’re optional but improve performance for large integers/decimals. The package uses `brick/math` as a fallback. For most Laravel use cases (e.g., IoT data, WebAuthn), the default setup suffices unless dealing with extreme numeric precision.
How do I validate CBOR payloads in Laravel requests (e.g., incoming WebAuthn tokens)?
Use the `Decoder` to parse payloads and validate structure with Laravel’s validation rules. Example: `Validator::make(['cbor' => $request->cbor], ['cbor' => 'required|array'])` after decoding. For strict schemas, combine with `spomky-labs/assert` for custom assertions.
Are there performance benchmarks comparing CBOR vs. JSON in Laravel?
CBOR is typically **30–50% smaller** than JSON for similar data. Benchmark with your payloads: encode/decode 10K iterations and compare memory/CPU usage. Use `microtime(true)` for timing. For APIs, CBOR reduces bandwidth and improves latency for binary-heavy data.
What are the alternatives to `spomky-labs/cbor-php` for Laravel, and why choose this one?
Alternatives include `ruflin/elastica` (limited CBOR support) or JavaScript libraries via FFmpeg. This package is the **only PHP 8+ native, RFC 8949-compliant** solution with streaming, extensible tags, and Laravel-friendly normalization. It’s actively maintained and integrates cleanly with Laravel’s ecosystem.
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope