{"id":22448568,"url":"https://github.com/themainframe/php-binary","last_synced_at":"2025-08-27T11:19:31.085Z","repository":{"id":11968357,"uuid":"14540932","full_name":"themainframe/php-binary","owner":"themainframe","description":"A PHP library for parsing structured binary streams.","archived":false,"fork":false,"pushed_at":"2016-05-23T21:31:34.000Z","size":99,"stargazers_count":32,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-10T03:38:56.756Z","etag":null,"topics":["bytes","parsing","php","schema"],"latest_commit_sha":null,"homepage":"http://php-binary.damow.net","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/themainframe.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":"2013-11-19T23:17:17.000Z","updated_at":"2024-05-31T15:43:30.000Z","dependencies_parsed_at":"2022-09-01T14:42:02.280Z","dependency_job_id":null,"html_url":"https://github.com/themainframe/php-binary","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/themainframe/php-binary","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themainframe%2Fphp-binary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themainframe%2Fphp-binary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themainframe%2Fphp-binary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themainframe%2Fphp-binary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/themainframe","download_url":"https://codeload.github.com/themainframe/php-binary/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themainframe%2Fphp-binary/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272325483,"owners_count":24914642,"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","status":"online","status_checked_at":"2025-08-27T02:00:09.397Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bytes","parsing","php","schema"],"created_at":"2024-12-06T04:29:24.702Z","updated_at":"2025-08-27T11:19:31.065Z","avatar_url":"https://github.com/themainframe.png","language":"PHP","readme":"php-binary [![Build Status](https://travis-ci.org/themainframe/php-binary.svg?branch=master)](https://travis-ci.org/themainframe/php-binary)\n==========\n\nA PHP library for parsing structured binary streams.\n\n## Documentation\n\nDocumentation can be found in the `documentation` directory, as well as online at [php-binary.damow.net](http://php-binary.damow.net)\n\n## Usage\n\nHere is an example binary format:\n\n 1. **4 bytes** of text.\n 2. **1 byte** unsigned integer.\n 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**.\n\n\n### Writing a Parser Schema\n\nThis 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.\n\n```php\n$builder = new Binary\\SchemaBuilder;\n$schema = $builder-\u003ecreateFromArray(json_decode('\n\n    {\n       \"sometext\": {\n           \"_type\": \"Text\",\n           \"size\": 4\n       },\n       \"somebyte\": {\n           \"_type\": \"UnsignedInteger\",\n           \"size\": 1\n       },\n       \"somefields\": {\n           \"_type\": \"Compound\",\n           \"count\": \"@somebyte\",\n           \"_fields\": {\n               \"footext\": {\n                   \"_type\": \"Text\",\n                   \"size\": 2\n               },\n               \"foobyte\": {\n                   \"_type\": \"UnsignedInteger\",\n                   \"size\": 1\n               }\n           }\n       }\n    }\n\n', true));\n```\n\n### Parsing a Stream\n\nYou can have php-binary parse a generic stream of bytes and output fields as an associative array matching your schema definition.\n\n```php\n$stream = new Binary\\Stream\\StringStream(\"FOOO\\x03LOLLOMLON\");\n$result = $schema-\u003ereadStream($stream);\n```\n\nThe resulting associative array in `$result` (shown here as JSON for clarity) would contain:\n\n```json\n{\n    \"sometext\": \"FOOO\",\n    \"somebyte\": 3,\n    \"somefields\": [\n        {\n            \"footext\": \"LO\",\n            \"foobyte\": 76\n        },\n        {\n            \"footext\": \"LO\",\n            \"foobyte\": 77\n        },\n        {\n            \"footext\": \"LO\",\n            \"foobyte\": 78\n        }\n    ]\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthemainframe%2Fphp-binary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthemainframe%2Fphp-binary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthemainframe%2Fphp-binary/lists"}