Coder Social home page Coder Social logo

cborencode's Introduction

#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. The specification 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:

{
    "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

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.

cborencode's People

Contributors

2tvenom avatar alexions avatar francislavoie avatar lrezek avatar notioncommotion avatar satori-azinoviev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.