dasprid/cbor

This package is abandoned and no longer maintained. No replacement package was suggested.

A PHP implementation of Concise Binary Object Representation (CBOR)

1.0.0 2018-10-15 14:03 UTC

This package is auto-updated.

Last update: 2022-04-15 22:43:24 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License

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
}