2017 © Pedro Peláez
 

library cborencode

CBOR encoder for PHP

image

2tvenom/cborencode

CBOR encoder for PHP

  • Tuesday, March 27, 2018
  • by 2tvenom
  • Repository
  • 6 Watchers
  • 26 Stars
  • 21,700 Installations
  • PHP
  • 3 Dependents
  • 1 Suggesters
  • 8 Forks
  • 0 Open issues
  • 1 Versions
  • 33 % Grown

The README.md

#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., (*1)

CBOR is an object representation format defined by the IETF. The specification has recently been approved as an IETF Standards-Track specification and has been published as RFC 7049., (*2)

Installation

Add 2tvenom/cborencode as a requirement to composer.json:, (*3)

{
    "require": {
       "2tvenom/cborencode": "1.0.0"
    }
}

Usage

<?php
include("vendor/autoload.php");

//target for encode
$target = array(true, array("variable1" => 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 in encode and decode, (*4)

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.

The Versions

27/03 2018

dev-master

9999999-dev https://github.com/2tvenom/CBOREncode

CBOR encoder for PHP

  Sources   Download

PHP

The Requires

  • php >=5.4.0

 

by Pavel Gulbin

cbor