Skip to content

weibreeze/breeze-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Breeze-PHP

License Build Status Latest Stable Version

概述

Breeze-PHP是Breeze序列化的php实现.

快速入门

添加composer依赖

在composer.json中添加依赖:

  "require" : {
    "wei-breeze/breeze": "v0.1.0"
  }

使用breeze

  1. 基础类型编解码
    // 编码
    $buf = new Buffer();
    BreezeWriter::writeString($buf, 'test string');
    //解码
    $newBuf = new Buffer($buf->buffer());
    $r = TypeString::instance()->read($newBuf);
    var_dump($r);
  1. 集合类型编解码
    $buf = new Buffer();
    $tp = new TypePackedMap(TypeInt32::instance(), TypeString::instance());
    BreezeWriter::writeMap($buf, [123 => 'erw', 45 => 'wer', 657 => 'terd'], $tp->getElemType()[0], $tp->getElemType()[1]);
    //解码
    $newBuf = new Buffer($buf->buffer());
    $r = $tp->read($newBuf);
    var_dump($r);
  1. Breeze Message编解码
    $msg = new TestMsg();
    $msg->setMyInt(1234);
    $msg->setMyString('ewjo3**#J');
    
    $subMsg = new TestSubMsg();
    $subMsg->setMyString('J(*#^H');
    $subMsg->setMyInt(-345);
    $subMsg->setMyBool(true);
    $subMsg->setMyBytes(pack('N', 2435));
    $subMsg->setMyInt64(723847289347398);
    $subMsg->setMyArray([234, 5467, -678, 0]);
    $subMsg->setMyMap1(['j(*&*(' => 'fj98A)', 'J()*#' => pack('l', -4578)]);
    $subMsg->setMyMap2([234 => [-45, 0], 3465 => [0, 345]]);
    
    $msg->setMyArray([$subMsg]);
    // 编码
    $buf = new Buffer();
    $tp = new TypeMessage(new TestMsg(false));
    BreezeWriter::writeValue($buf, $msg, $tp);
    //解码
    $newBuf = new Buffer($buf->buffer());
    $r = $tp->read($newBuf);
    var_dump($r);
    
    //直接编码
    $buf = new Buffer();
    $msg->writeTo($buf);
    
    //直接解码
    $newBuf = new Buffer($buf->buffer());
    $r = new TestMsg();
    $r->readFrom($newBuf);
    var_dump($r);
  1. 任意类型编解码(不使用BreezeType指定类型)
    //编码
    $v = 1234;
    $buf = new Buffer();
    BreezeWriter::writeValue($buf, $v);
    //解码
    $newBuf = new Buffer($buf->buffer());
    $r = BreezeReader::readValue($newBuf);
    var_dump($r);

更多demo请参考单元测试

使用Breeze Schema 生成Message类

参见breeze-generator

Breeze协议说明

参考Breeze协议说明

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages