X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=binary.php;h=51f44f83c060d257136ea74ed2f2819b480a86e8;hb=09617312a7eff11be39355b053237565c7ad614d;hp=bc0a3aab61d0aa527a05121372be3e4b99b22d65;hpb=9f8ed1dba7b2bb0319ab69f843f20e0d45ff736c;p=wfpl.git diff --git a/binary.php b/binary.php index bc0a3aa..51f44f8 100644 --- a/binary.php +++ b/binary.php @@ -44,4 +44,25 @@ function pop_int(&$string) { return $int; } +# convert an array (not hash) to a string of bytes +function array_to_raw($data) { + $ret = to_raw_int(count($data)); + foreach($data as $dat) { + $ret .= to_raw_int(strlen($dat)); + $ret .= $dat; + } + return $ret; +} + +function raw_to_array($data) { + $header_count = pop_int($data); + $ret = array(); + while($header_count--) { + $size = pop_int($data); + $ret[] = substr($data, 0, $size); + $data = substr($data, $size); + } + return $ret; +} + ?>