Giter Club home page Giter Club logo

bernie's Introduction

Bernie, PHP Serialization Parser

A library to parse data serialized by PHP into Clojure data structures.

Usage

The namespace provides a single function, unserialize, which takes a string of serialized data and returns EDN.

(ns my.namespace
  (:require [bernie.core :refer [unserialize]]))

(unserialize "i:123;") ; => 123
(unserialize "a:2:{i:0;s:3:"foo";i:1;d:456.78;}") ; => ["foo" 456.78]
(unserialize "a:1:{s:3:"foo";i:123}") ; => {:foo 123}

If the data supplied is not valid then an exception will most likely be thrown.

Arrays

When serializing, PHP makes no distinction between numerically indexed and associative arrays (as it's internal implementation doesn't care). In EDN though we do care as these will end up as vectors or hashmaps respectively.

Bernie takes the approach of checking an array's keys, and if they are all numeric it'll create a vector, otherwise you'll get back a hashmap.

Custom Serialization

For custom serialization ('C') Bernie assumes the content is serialized data itself. This is because the usual way this is used is as follows:

class Test implements \Serializable
{
    public function serialize()
    {
        return serialize(array(
            // properties
        ));
    }
}

References

The reference type 'R' is currently not supported, and will return nil.

(unserialize "R:1;") ; => nil

Invalid Data

Any invalid data will throw a com.pugh.bernie.UnserializeException.

Installation

Bernie is available via Clojars.

bernie's People

Contributors

rodnaph 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.