php中的pb搜索所有子结构的方法

1.通过最顶层结构检索到所有子结构

1)get_lib.sh 

#!/bin/bash
grep -F '\Pp2\' proto/$1.php | grep "=> " |  awk -F' ' '{print $3}' | sed "s/'//g" | awk -F'\' '{print $3}'

2)get_all_struct.php

<?php
function get_file_name($input_path, &$global_struct_list)
{
        if($input_path != "")
        {
                $global_struct_list[] = $input_path;
        }

        ob_start();
        passthru("./get_lib.sh $input_path");
        $all_names_str = ob_get_contents();
        ob_end_clean();

        $all_names = explode("\n", $all_names_str);

        foreach($all_names as $sub_node)
        {
                if($sub_node != "")
                {
                        get_file_name($sub_node, $global_struct_list);
                }
        }
}

2.使用时,直接给顶层结构名称,

test.php 

<?php
require("comm_define.php");
require("get_all_struct.php");

$global_struct_list = array();
get_file_name("GuildDispatchList", $global_struct_list);
$global_struct_list = array_unique($global_struct_list);

foreach($global_struct_list as $sub_struct)
{
        require("proto/$sub_struct.php");
}

$p = new Pp2\GuildDispatchList();

$p->parseFromString("\x08\x00\x10\xD0\xE3\xB0\xF6\x05\x1A\x0F\x08\x01\x10\x00");

$p->dump();

?>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值