{"id":16511172,"url":"https://github.com/danog/phpstruct","last_synced_at":"2025-03-21T08:31:24.534Z","repository":{"id":56962183,"uuid":"62454134","full_name":"danog/PHPStruct","owner":"danog","description":"PHP implementation of Python's struct module.","archived":false,"fork":false,"pushed_at":"2022-03-26T12:53:42.000Z","size":103,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-17T23:02:50.673Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-02T14:17:12.000Z","updated_at":"2023-09-19T07:03:29.000Z","dependencies_parsed_at":"2022-08-21T05:40:20.735Z","dependency_job_id":null,"html_url":"https://github.com/danog/PHPStruct","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2FPHPStruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2FPHPStruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2FPHPStruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2FPHPStruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danog","download_url":"https://codeload.github.com/danog/PHPStruct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244765046,"owners_count":20506750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T15:59:13.562Z","updated_at":"2025-03-21T08:31:23.707Z","avatar_url":"https://github.com/danog.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHPStruct class\n\n[![Build Status](https://travis-ci.org/danog/PHPStruct.svg?branch=master)](https://travis-ci.org/danog/PHPStruct)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7b91e30ec89a4313bdb34766ea990113)](https://www.codacy.com/app/daniil-gentili-dg/PHPStruct?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=danog/PHPStruct\u0026amp;utm_campaign=Badge_Grade)\n[![License](https://img.shields.io/packagist/l/danog/phpstruct.svg?maxAge=2592000?style=flat-square)](https://opensource.org/licenses/MIT)\n[![Packagist download count](https://img.shields.io/packagist/dm/danog/phpstruct.svg?maxAge=2592000?style=flat-square)](https://packagist.org/packages/danog/phpstruct)\n[![Packagist](https://img.shields.io/packagist/v/danog/PHPStruct.svg?maxAge=2592000?style=flat-square)](https://packagist.org/packages/danog/phpstruct)\n[![HHVM Status](http://hhvm.h4cc.de/badge/danog/phpstruct.svg?style=flat-square)](http://hhvm.h4cc.de/package/danog/phpstruct)\n[![StyleCI](https://styleci.io/repos/62454134/shield)](https://styleci.io/repos/62454134)\n\nLicensed under MIT.\n\nPHP implementation of Python's struct module.\n\nThis library was created to help me develop a [client for the mtproto protocol](https://github.com/danog/MadelineProto).  \nIt supports php 5.6, php 7 and HHVM.  \n\nThe functions and the formats are exactly the ones used in python's struct \n(https://docs.python.org/3/library/struct.html)\n\nThis library can be used to pack/unpack strings, ints, floats, chars and bools into bytes.\nIt has lots of advantages over PHP's native implementation of pack and unpack, such as:  \n* Custom byte endianness.\n* Lots of useful formats that aren't present in the native implementation.\n* The syntax of the format string of pack and unpack is the same as in python's struct module.\n* The result of unpack is normal numerically indexed array that starts from 0 like it should.\n* The result of unpack has type casted values (int for integer formats, bool for boolean formats, float for float formats and string for all of the other formats).\n* The calcsize function is implemented.\n* The q and Q formats can be used even on 32 bit systems (the downside is limited precision).\n* Padding is supported for the @ modifier.\n\nFor now custom byte size may not work properly on certain machines for the f and d formats.\n\n## Installation\n\nInstall using composer:\n```\ncomposer require danog/phpstruct\n```\n\n# Usage\nDynamic (recommended)  \n```\nrequire('vendor/autoload.php');\n$struct = new \\danog\\PHP\\StructClass();\n$pack = $struct-\u003epack(\"2cxi\", \"ab\", 44);\n$unpack = $struct-\u003eunpack(\"2cxi\", $pack);\nvar_dump($unpack);\n$count = $struct-\u003ecalcsize(\"2cxi\");\n```  \n\nDynamic (while specifying format string during istantiation)  \n```\nrequire('vendor/autoload.php');\n$struct = new \\danog\\PHP\\StructClass(\"2cxi\");\n$pack = $struct-\u003epack(\"ab\", 44);\n$unpack = $struct-\u003eunpack($pack);\nvar_dump($unpack);\n$count = $struct-\u003esize;\n$formatstring = $struct-\u003eformat;\n```\n\nStatic\n\n\n```\nrequire('vendor/autoload.php');\n$pack = \\danog\\PHP\\Struct::pack(\"2cxi\", \"ab\", 44);\n$unpack = \\danog\\PHP\\Struct::unpack(\"2cxi\", $pack);\nvar_dump($unpack);\n$count = \\danog\\PHP\\Struct::calcsize(\"2cxi\");\n```\n\n\n[Daniil Gentili](http://daniil.it)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanog%2Fphpstruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanog%2Fphpstruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanog%2Fphpstruct/lists"}