dasprid / cbor
A PHP implementation of Concise Binary Object Representation (CBOR)
Installs: 45
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/dasprid/cbor
Requires
- php: ^7.2
- brick/math: ^0.8
- dasprid/enum: ^1.0
Requires (Dev)
- ext-json: ^1.6
- phpunit/phpunit: ^7.4
- squizlabs/php_codesniffer: ^2.8
This package is auto-updated.
Last update: 2022-04-15 22:43:24 UTC
README
A PHP implementation of RFC 7049: Concise Binary Object Representation (CBOR)
Features
- Encodes and decodes all examples described in RFC 7049
- Provides a fluent interface builder for CBOR messages
- Supports semantic tags
- Supports 64bit integer values
Usage
Encoding Example
<?php $output = new \SplTempFileObject(); (new \DASPRiD\Cbor\CborEncoder($output))->encode((new \DASPRiD\Cbor\CborBuilder()) ->add('text') ->add(1234) ->addByteString("\x10") ->addArray() ->add(1) ->add('text') ->end() ->build() ); $length = $output->ftell(); $output->rewind(); $encodedBytes = $output->fread($length);
Decoding Example
<?php $dataItems = \DASPRiD\Cbor\CborDecoder::decodeString($encodedBytes); foreach ($dataItems as $dataItem) { // Process data item }