Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2tvenom/cborencode
PHP CBOR encoder/decoder
https://github.com/2tvenom/cborencode
Last synced: 3 days ago
JSON representation
PHP CBOR encoder/decoder
- Host: GitHub
- URL: https://github.com/2tvenom/cborencode
- Owner: 2tvenom
- License: other
- Created: 2014-01-23T21:32:44.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2022-03-30T10:48:07.000Z (almost 3 years ago)
- Last Synced: 2024-12-30T01:17:04.907Z (10 days ago)
- Language: PHP
- Size: 23.4 KB
- Stars: 60
- Watchers: 8
- Forks: 19
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#CBOR encoder for PHP
--------
Decoder/encoder from PHP data to CBOR binary string. This code has been developed and maintained by Ven at January 2014.CBOR is an object representation format defined by the [IETF](http://ietf.org).
The [specification](http://tools.ietf.org/html/rfc7049)
has recently been approved as an IETF Standards-Track specification
and has been published as RFC 7049.## Installation
Add `2tvenom/cborencode` as a requirement to composer.json:```JavaScript
{
"require": {
"2tvenom/cborencode": "1.0.0"
}
}
```
## Usage
```php
100000, "variable2" => "Hello, World!", "Hello!"), 0.234, 0, null, 590834290589032580);//encoded string
$encoded_data = \CBOR\CBOREncoder::encode($target);//debug info output
$byte_arr = unpack("C*", $encoded_data);echo "Byte hex map = " . implode(" ", array_map(function($byte){
return "0x" . strtoupper(dechex($byte));
}, $byte_arr)) . PHP_EOL;echo "Byte dec map = " . implode(" ", $byte_arr) . PHP_EOL;
//decode
$decoded_variable = \CBOR\CBOREncoder::decode($encoded_data);
//output
var_dump($decoded_variable);
```## Compatibility
Checked with [Ruby extension](https://github.com/cabo/cbor-ruby) in encode and decode
## Known issues
- Not support tags. 6 major type *(in future)*
- Not support 16 and 32 floats encoding *(maybe in future)*
- All floats will be serialized only as IEEE 754 Double-Precision Float (64 bits follow)
- Encode does't support indefinite-length values.