X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=blobdiff_plain;f=binary.php;h=2fd2a7627a2b289974dcb6576c61080555f6a8f1;hp=bc0a3aab61d0aa527a05121372be3e4b99b22d65;hb=HEAD;hpb=9f8ed1dba7b2bb0319ab69f843f20e0d45ff736c diff --git a/binary.php b/binary.php index bc0a3aa..2fd2a76 100644 --- a/binary.php +++ b/binary.php @@ -1,22 +1,9 @@ +# 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; +}