Giter Site home page Giter Site logo

cbor4php's Introduction

Cbor4Php

CBOR (Concise Binary Object Representation) is a tiny data format that can be used in place of JSON. Cbor4Php is a simple CBOR encoder/decoder for PHP.

Installation

To install the library through composer, you simply need to add the following to composer.json and run composer update or composer install:

{
    "require": {
       "lemonblast/cbor4php": "dev-master"
    }
}

Once installed, you can use the Cbor class (Lemonblast\Cbor4Php\Cbor) to encode and decode CBOR data.

Usage

Include the Cbor4Php library in your source:

use Lemonblast\Cbor4Php\Cbor;

Encoding

To encode a variable into a CBOR byte string call the encode method and pass the value as a parameter:

$foo = Cbor::encode($bar);

Encoding an object will convert it to an associative array, and encode it as such. Only public fields will be encoded.

Encoding a PHP resource is not supported and will result in a null return value.

Decoding

To decode a CBOR byte string into a PHP variable:

$bar = Cbor::decode($foo);

CBOR data tags are ignored during the decode process. Decoding a null value or empty string will result in a null return value.

Testing

To run unit tests, simply clone this repository and run composer install followed by php vendor/bin/phpunit in the project directory.

cbor4php's People

Contributors

aweebs avatar lrezek 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.