新版wow解析库

对wow的数据分析已经有很长很长一段时间了. 其数据结构上大致能比较了解. 但是解析工具一直不如心愿. 当wow版本的升级, 很多数据变得多样化起来. 比如

  1. 一条数据中包含了一个子数据集(表现出来的形式是动态栏位).
  2. 有些数据栏位共享一个字节.

等等情况.

根据多年经验, 我对解析工作做了一个初步的改进.

Field

Field 栏位. 每个栏位我都建立了一个class. 用于表达此栏位的状态, 类型以及结构.

所有的栏位都是继承抽象类 AField.

abstract class AField {
    //unpack读取type, 比如Byte=> "b", int32=> "i"
    public $char;
    //读取长度
    public $size;
    //$name 字段名
    //$dynamic 如果位动态栏位,动态key
    //$group 所属父组
    //$primary_key 是否是主键?
    public function __construct($name = "", $dynamic=0, $group = null, $primary_key = false) {
	$this->name = $name;
	$this->dyn = $dynamic;
	$this->group = $group;
	$this->primary_key = $primary_key;
    }
    
    //重新命名栏位名称
    public function rename($name) {
	$this->name = $name;
	return $this;
    }
    
    //magic方法, 获取栏位名称
    public function __tostring(){
	return "[" . get_class($this).": ". $this->name . "]";
    }
}

AField中包含了栏位名称, 动态key, 动态组名, 主键?
接着创建一些基础栏位, 比如ByteField, UnsignedByteField, IntegerField, UnsignedIntegerField, StringField
再继承基础栏位, 延伸出一些特别栏位: IDField, UnknownField

Row

既然栏位已经写完了. 那么这个时候就要将栏目组成一条数组. 那就是Row.
为了能明确的表述该Row的性质, 我为此创建了DBRow. 其中包含了structures(Field集合), 每个栏位的数值.

DB

完成两个基础Field, Row之后. 这个时候就要组成一个抽象的DB.
这个DB是DBC(DB2), WDB的父类. 它包含了文件, 数据结构, 数据导入导出, 数据的读取地址库, 数据的header.
而它的子类就是实现父类这些方法.

结束

从上看来, 现在解析数据更加快捷方便. 同时能应对文章刚开始说的各种情况.

Leave a Comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: