Git Product home page Git Product logo

structphp's Introduction

structphp

Python Struct Port to PHP for pack and unpack functions

Install

composer require desean1625/structphp

The module defines the following functions:

unpack(fmt, a, p) Return an array containing values unpacked from the octet array a, beginning at position p, according to the supplied format string. If there are more octets in a than required by the format string, the excess is ignored. If there are fewer octets than required, Unpack() will return undefined. If no value is supplied for the p argument, zero is assumed.

pack(fmt, values) Return an octet array containing the packed values array. If there are more values supplied than are specified in the format string, the excess is ignored. If there are fewer values supplied, Pack() will return false. If any value is of an inappropriate type, the results are undefined. calcsize(fmt) Return the number of octets required to store the given format string. calcLength(fmt) same as calcsize

    Format | C Type         |  Size (octets) | s
    -------------------------------------------------------------------
       A   | char[]         |     Length     
       x   | pad byte       |        1      
       c   | char           |        1       
       b   | signed char    |        1       
       B   | unsigned char  |        1       
       h   | signed short   |        2      
       H   | unsigned short |        2       
       i   | signed long    |        4      
       I   | unsigned long  |        4       
       l   | signed long    |        4      
       L   | unsigned long  |        4      
       s   | char[]         |     Length     
       f   | float          |        4      
       d   | double         |        8       
require "./vendor/audoload.php";
$struct = new Desean1625\Struct();

 print_r($struct->unpack("<2h", pack("v2", 10, 10)));//v	unsigned short (always 16 bit, little endian byte order)
 print_r($struct->unpack(">2h", pack("n2", 10, 10)));//n	unsigned short (always 16 bit, big endian byte order)
 print_r($struct->unpack(">2L", pack("N2", 10, 10)));//N	unsigned long (always 32 bit, big endian byte order)
 print_r($struct->unpack("<2L", pack("V2", 10, 10)));//V	unsigned long (always 32 bit, little endian byte order)

structphp's People

Contributors

desean1625 avatar

Watchers

James Cloos 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.