{"id":21699885,"url":"https://github.com/jonasraoni/binary-parser","last_synced_at":"2025-03-20T15:41:57.528Z","repository":{"id":124279129,"uuid":"108399559","full_name":"jonasraoni/binary-parser","owner":"jonasraoni","description":"Serializes and unserializes binary data in PHP.","archived":false,"fork":false,"pushed_at":"2017-10-26T10:58:15.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-25T14:43:12.610Z","etag":null,"topics":["binary-parser","binary-serialization","ieee-754","ieee754","php","serialization","serialize"],"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/jonasraoni.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-26T10:56:44.000Z","updated_at":"2018-03-20T15:15:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"ca66ffd5-ffbb-4ea8-98ca-81748455dba2","html_url":"https://github.com/jonasraoni/binary-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasraoni%2Fbinary-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasraoni%2Fbinary-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasraoni%2Fbinary-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasraoni%2Fbinary-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonasraoni","download_url":"https://codeload.github.com/jonasraoni/binary-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244644301,"owners_count":20486777,"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":["binary-parser","binary-serialization","ieee-754","ieee754","php","serialization","serialize"],"created_at":"2024-11-25T20:11:56.456Z","updated_at":"2025-03-20T15:41:57.505Z","avatar_url":"https://github.com/jonasraoni.png","language":"PHP","readme":"# Binary Parser\r\n\r\nSerializes and unserializes binary data in PHP.\r\n\r\n## Constants\r\n\r\n- NOT_A_NUMBER: Defines a kind of float error-flag, which isn't a number at all\r\n- POSITIVE_INFINITY: Defines a positive number higher than the maximum allowed\r\n- NEGATIVE_INFINITY: Defines a negative number lower than the minimum allowed\r\n\r\n## Classes\r\n\r\n### BinaryParser: The binary encoder/decoder\r\n\r\n#### Properties\r\n\r\n- public bigEndian: bool = false =\u003e specify which byte order the class will use the decode/encode\r\n- public constructor( bigEndian: bool = false ) =\u003e it may receive the endian kind\r\n\r\n\r\n#### Methods\r\n\r\n- public function toFloat( data: string ): float =\u003e receives string containing 4 chars/bytes and returns its respective float representation or a special value (NOT_A_NUMBER, POSITIVE_INFINITY, NEGATIVE_INFINITY)\r\n- public function fromFloat( data: float ): string =\u003e receives a floating point number and returns its binary representation in a 4 chars string, it may rise an exceptions if the number is a special value (NOT_A_NUMBER, POSITIVE_INFINITY, NEGATIVE_INFINITY) or if the number can't be represented (overflow, underflow)\r\n- public function toDouble( data: string ): float =\u003e receives string containing 8 chars/bytes and returns its respective double representation or a special value (NOT_A_NUMBER, POSITIVE_INFINITY, NEGATIVE_INFINITY)\r\n- public function fromDouble( data: float ): string =\u003e receives a floating point number and returns its binary representation in a 8 chars string, it may rise an exceptions if the number is a special value (NOT_A_NUMBER, POSITIVE_INFINITY, NEGATIVE_INFINITY) or if the number can't be represented (overflow, underflow)\r\n- public function toSmall( data: string ): int =\u003e receives string containing 1 char/byte and returns your respective numeric representation with signal\r\n- public function fromSmall( data: int ): string =\u003e receives a number and returns its binary representation in a 1 char string, it may rise an exception if the number exceeds the limit\r\n- public function toByte( data: string ): int =\u003e receives string containing 1 char/byte and returns its respective numeric representation without signal\r\n- public function fromByte( data: int ): string =\u003e receives a number and returns its binary representation in a 1 char string, it may rise an exception if the number exceeds the limit and negative numbers are converted\r\n- public function toShort( data: string ): int =\u003e receives string containing 2 chars/bytes and returns its respective numeric representation with signal\r\n- public function fromShort( data: int ): string =\u003e receives a number and returns its binary representation in a 2 chars string, it may rise an exception if the number exceeds the limit\r\n- public function toWord( data: string ): int =\u003e receives string containing 2 chars/bytes and returns its respective numeric representation without signal\r\n- public function fromWord( data: int ): string =\u003e receives a number and returns its binary representation in a 2 chars string, it may rise an exception if the number exceeds the limit and negative numbers are converted\r\n- public function toInt( data: string ): int =\u003e receives string containing 4 chars/bytes and returns its respective numeric representation with signal\r\n- public function fromInt( data: int ): string =\u003e receives a number and returns its binary representation in a 4 chars string, it may rise an exception if the number exceeds the limit\r\n- public function toDWord( data: string ): int =\u003e receives string containing 4 chars/bytes and returns its respective numeric representation without signal\r\n- public function fromDWord( data: int ): string =\u003e receives a number and returns its binary representation in a 4 chars string, it may rise an exception if the number exceeds the limit and negative numbers are converted\r\n\r\n- protected function decodeFloat( data: string, precisionBits: int, exponentBits: int ): float =\u003e internal function for decoding the standard IEEE-754, since PHP isn't able to handle float types using more than 64bits, I decided to not support the 80 and 128 bits formats.  \r\ndata: a string buffer containing the binary representation of the number (must have at least \"ceil( ( exponentBits + precisionBits + 1 ) / 8 )\" bytes)  \r\nprecisionBits: the amount of bits that specify the precision/significand  \r\nexponentBits: the amount of bits that specify the exponent that will multiply the significand to obtain the number and returns the number or the following special values: NaN, +Infinity, -Infinity\r\n\r\n- protected function decodeInt( data: string, bits: int, signed: bool ): int =\u003e internal function for decoding standard integer types, since PHP isn't able to handle integers higher than 32 bits, i decided to not support the 64 bits format.  \r\ndata: a string buffer containing the binary representation of the number (must have at least \"ceil( bits / 8 )\" bytes)\r\nbits: the amount of bits that specify the number max length and min length\r\nsigned: if the number must be decoded as signed or unsigned\r\nand returns the number\r\n\r\n- protected function encodeFloat( data: float, precisionBits: int, exponentBits: int ): string =\u003e internal function for encoding a number into the standard IEEE-754 format, since PHP isn't able to handle float types using more than 64bits, i decided to not support the 80 and 128 bits formats.  \r\ndata: the number which will be converted  \r\nprecisionBits: the amount of bits that specify the precision/significand  \r\nexponentBits: the amount of bits that specify the exponent that will multiply the significand to obtain the number and returns a binary string representation of the number containing \"ceil( ( exponentBits + precisionBits + 1 ) / 8 )\" bytes\r\n\r\n- protected function encodeInt( data: string, bits: int, signed: bool ): int =\u003e internal function for decoding standard integer types, since PHP isn't able to handle integers higher than 32 bits, i decided to not support the 64 bits format.  \r\ndata: the number which will be converted  \r\nbits: the amount of bits that specify the number max length and min length  \r\nsigned: if the number must be decoded as signed or unsigned and returns a binary string representation of the number containing \"ceil( bits / 8 )\" bytes\r\n\r\n\r\n### BinaryBuffer\r\n\r\nSimple class to hold some bytes while decoding the data into a numerical format\r\n\r\n#### Properties\r\n\r\n- public  length: int = 0 =\u003e the amount of bytes stored in the class\r\n- private bigEndian: bool = false =\u003e keeps safe the internal endian-format that was chosed\r\n- private buffer: array = [] =\u003e buffer storage, hold the bytes\r\n\r\n\r\n#### Methods\r\n\r\n- public constructor( bigEndian: bool = false, buffer: string = '' ): void =\u003e it may receive the ordering type and a starting string buffer\r\n- public function setBuffer( data: string ): void =\u003e set new content into the buffer array\r\n- public function getBuffer(): array =\u003e returns the buffer array\r\n- public function hasNeededBits( neededBits: int ): bool =\u003e returns if the buffer has \"neededBits\" bits avaiable for reading\r\n- public function checkBuffer( $neededBits ): void =\u003e the same as BinaryBuffer::hasNeededBits, but it rises an exception when there isn't enough data available\r\n- public function byte( $i ): int =\u003e returns the byte value in the buffer at the specified \"i\" offset\r\n- public function setEndian( $bigEndian ): void =\u003e sets up the endian\r\n- public function readBits( $start, $length ): int =\u003e read the bits interval and returns the corresponding integer value\r\n- private private function shl( a: Int, b: Int ): int =\u003e rotates \"a\" bits \"b\" times to the left\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonasraoni%2Fbinary-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonasraoni%2Fbinary-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonasraoni%2Fbinary-parser/lists"}