https://github.com/firehed/cbor-php
CBOR decoder for PHP
https://github.com/firehed/cbor-php
Last synced: about 1 year ago
JSON representation
CBOR decoder for PHP
- Host: GitHub
- URL: https://github.com/firehed/cbor-php
- Owner: Firehed
- Created: 2019-05-14T05:44:05.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-09T09:55:52.000Z (over 4 years ago)
- Last Synced: 2025-03-24T09:21:12.449Z (about 1 year ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CBOR-PHP
Tools for working with the [CBOR](https://tools.ietf.org/html/rfc7049) data format in PHP
## Installation
`composer require firehed/cbor`
## Usage
Note: Only decoding is supporing at this time
### Decoding
```php
$decoder = new Firehed\CBOR\Decoder();
$binaryString = "\x18\x64"; // CBOR for int(100)
$data = $decoder->decode($binaryString);
// OR
$byteArray = [24, 100];
$data = $decoder->decodeArrayOfBytes($byteArray);
```
There is currently very limited support for [tagged types](https://tools.ietf.org/html/rfc7049#section-2.4).
When an unsupported tag is encountered, an `OutOfBoundsException` will be thrown.
## Tagged type support
- [ ] 0 DateTime as string
- [ ] 1 DateTime as epoch
- [X] 2 Positive Bignum (returns as string, requires `bcmath`)
- [X] 3 Negative Bignum (same)
- [ ] 4 Decimal fraction
- [ ] 5 Bigfloat
- [ ] 21 base64url string
- [ ] 22 base64 string
- [ ] 23 base16 string
- [ ] 24 CBOR
- [ ] 32 URI
- [ ] 33 base64url
- [ ] 34 base64
- [ ] 35 regexp
- [ ] 36 MIME message
- [ ] 55799 Self-describing CBOR