All Projects → themainframe → php-binary

themainframe / php-binary

Licence: MIT license
A PHP library for parsing structured binary streams.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-binary

CalPack
Packets in Python Simplified
Stars: ✭ 19 (-36.67%)
Mutual labels:  parsing, bytes
octet
A library that makes working with bytebuffers painless.
Stars: ✭ 79 (+163.33%)
Mutual labels:  parsing, bytes
fefe
Validate, sanitize and transform values with proper TypeScript types and zero dependencies.
Stars: ✭ 34 (+13.33%)
Mutual labels:  schema, parsing
Pollinate
Template your base files and generate new projects from Git(Hub).
Stars: ✭ 213 (+610%)
Mutual labels:  schema, parsing
gdelt2HeaderRows
A file that contains the schema for GDELT 2.0 Header rows for the Events Database.
Stars: ✭ 28 (-6.67%)
Mutual labels:  schema
hcl-lang
Schema and decoder to be used as building blocks for an HCL2-based language server.
Stars: ✭ 44 (+46.67%)
Mutual labels:  schema
bracer
Java library for parsing and evaluating math expressions
Stars: ✭ 18 (-40%)
Mutual labels:  parsing
ballade
For unidirectional data flow.
Stars: ✭ 44 (+46.67%)
Mutual labels:  schema
siemstress
Very basic CLI SIEM (Security Information and Event Management system).
Stars: ✭ 24 (-20%)
Mutual labels:  parsing
attach-juxtapose-parser
Code for the paper "Strongly Incremental Constituency Parsing with Graph Neural Networks"
Stars: ✭ 25 (-16.67%)
Mutual labels:  parsing
BitByteData
Read and write bits and bytes in Swift.
Stars: ✭ 21 (-30%)
Mutual labels:  bytes
shex.js
shex.js javascript package
Stars: ✭ 45 (+50%)
Mutual labels:  schema
avro ex
An Avro Library that emphasizes testability and ease of use.
Stars: ✭ 47 (+56.67%)
Mutual labels:  schema
PSStringScanner
Provides lexical scanning operations on a String
Stars: ✭ 45 (+50%)
Mutual labels:  parsing
xsdata
Naive XML & JSON Bindings for python
Stars: ✭ 144 (+380%)
Mutual labels:  schema
storage
Mongoose-like schema validation, collections and documents on browser (client-side)
Stars: ✭ 17 (-43.33%)
Mutual labels:  schema
tangle-rs
a collection of tools to do tangle in rust
Stars: ✭ 23 (-23.33%)
Mutual labels:  parsing
hodur-lacinia-schema
Hodur is a domain modeling approach and collection of libraries to Clojure. By using Hodur you can define your domain model as data, parse and validate it, and then either consume your model via an API or use one of the many plugins to help you achieve mechanical results faster and in a purely functional manner.
Stars: ✭ 20 (-33.33%)
Mutual labels:  schema
JuCC
JuCC - Jadavpur University Compiler Compiler
Stars: ✭ 34 (+13.33%)
Mutual labels:  parsing
Ohm-S
A Squeak/Smalltalk implementation of the metaprogramming framework Ohm.
Stars: ✭ 18 (-40%)
Mutual labels:  parsing

php-binary Build Status

A PHP library for parsing structured binary streams.

Documentation

Documentation can be found in the documentation directory, as well as online at php-binary.damow.net

Usage

Here is an example binary format:

  1. 4 bytes of text.
  2. 1 byte unsigned integer.
  3. A field of 2 bytes of text followed by a 1 byte unsigned integer; repeated n times, where n is a backreference to the byte described in point 2.

Writing a Parser Schema

This format can be parsed as follows. In this example, the schema is described using JSON for clarity, though in practise any array may be used.

$builder = new Binary\SchemaBuilder;
$schema = $builder->createFromArray(json_decode('

    {
       "sometext": {
           "_type": "Text",
           "size": 4
       },
       "somebyte": {
           "_type": "UnsignedInteger",
           "size": 1
       },
       "somefields": {
           "_type": "Compound",
           "count": "@somebyte",
           "_fields": {
               "footext": {
                   "_type": "Text",
                   "size": 2
               },
               "foobyte": {
                   "_type": "UnsignedInteger",
                   "size": 1
               }
           }
       }
    }

', true));

Parsing a Stream

You can have php-binary parse a generic stream of bytes and output fields as an associative array matching your schema definition.

$stream = new Binary\Stream\StringStream("FOOO\x03LOLLOMLON");
$result = $schema->readStream($stream);

The resulting associative array in $result (shown here as JSON for clarity) would contain:

{
    "sometext": "FOOO",
    "somebyte": 3,
    "somefields": [
        {
            "footext": "LO",
            "foobyte": 76
        },
        {
            "footext": "LO",
            "foobyte": 77
        },
        {
            "footext": "LO",
            "foobyte": 78
        }
    ]
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].