<commit_before><?php
/**
 * author: shenzhe
 * Date: 13-6-17
 * 
 */

namespace ZPHP\Common;

class MessagePacker
{
    public $data;
    private $offset;
    private $dataLen;

    public function __construct($data = '')
    {
        $this->data = $data;
        $this->offset = 0;
        $this->dataLen = strlen($data);
    }

    public function resetForUnPack($data)
    {
        $this->data = $data;
        $this->offset = 0;
        $this->dataLen = strlen($data);
    }

    public function resetForPack()
    {
        $this->data = '';
        $this->offset = 0;
    }

    public function resetOffset($len=0)
    {
        $this->offset = $len;
    }

    public function writeByte($d)
    {
        $this->data .= pack("C1", $d);
    }

    public function writeString($s, $len=null)
    {
        //$s = rtrim($s, "\0") . "\0";
        if(null === $len) {
            $len = strlen($s);
        }
        $this->writeInt($len);
        $this->data .= pack("a*", $s);
    }

    //写二进制数据
    public function writeBinary($b, $len=null)
    {
        if(null === $len) {
            $len = strlen($s);
        }
        $this->writeInt($len);
        $this->data .= $b;
        //$this->data .= pack('H*', $b);
    }

    public function writeBool($d)
    {
        $this->data .= pack("C1", $d);<commit_msg>debug message pack write binary<commit_after><?php
/**
 * author: shenzhe
 * Date: 13-6-17
 * 
 */

namespace ZPHP\Common;

class MessagePacker
{
    public $data;
    private $offset;
    private $dataLen;

    public function __construct($data = '')
    {
        $this->data = $data;
        $this->offset = 0;
        $this->dataLen = strlen($data);
    }

    public function resetForUnPack($data)
    {
        $this->data = $data;
        $this->offset = 0;
        $this->dataLen = strlen($data);
    }

    public function resetForPack()
    {
        $this->data = '';
        $this->offset = 0;
    }

    public function resetOffset($len=0)
    {
        $this->offset = $len;
    }

    public function writeByte($d)
    {
        $this->data .= pack("C1", $d);
    }

    public function writeString($s, $len=null)
    {
        //$s = rtrim($s, "\0") . "\0";
        if(null === $len) {
            $len = strlen($s);
        }
        $this->writeInt($len);
        $this->data .= pack("a*", $s);
    }

    //写二进制数据
    public function writeBinary($b, $len=null)
    {
        if(null === $len) {
            $len = strlen($b);
        }
        $this->writeInt($len);
        $this->data .= $b;
        //$this->data .= pack('H*', $b);
    }

    public function writeBool($d)
    {
        $this->data .= pack("C1", $d);
{'fraction_non_alphanumeric': 0.18721804511278195, 'fraction_numerical': 0.009774436090225564, 'mean_word_length': 1.7348406988694758, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '639626', 'n_tokens_mistral': 931, 'n_tokens_neox': 902, 'n_words': 177}