537 lines
24 KiB
XML
537 lines
24 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<xsl:stylesheet version="1.0"
|
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
xmlns:msxsl="urn:schemas-microsoft-com:xslt "
|
|
xmlns:user="whatever ">
|
|
|
|
<!-- 对type的处理 -->
|
|
<xsl:template match="type" name="type">
|
|
<xsl:param name="section_id"/>
|
|
<xsl:if test="count(.) > 0">
|
|
<div class="type">
|
|
<h3>类型:
|
|
<xsl:value-of select="@name"/> (<xsl:value-of select="@desc"/>)
|
|
<xsl:if test="$section_id > 0">
|
|
<a class="backToIndex" target="_self">
|
|
<xsl:attribute name="href">#<xsl:value-of select="$section_id"/>
|
|
</xsl:attribute>回分类头部
|
|
</a>
|
|
</xsl:if>
|
|
<a class="backToIndex" href="#index" target="_self">回目录</a>
|
|
</h3>
|
|
<table cellspacing="0">
|
|
<tr>
|
|
<th width="80px">类型</th>
|
|
<th width="80px">注解</th>
|
|
<th width="80px">名称</th>
|
|
<th>描述</th>
|
|
</tr>
|
|
<xsl:for-each select="*">
|
|
<tr>
|
|
<td>
|
|
<xsl:if test="substring(@t,0,3) = 'p_'">
|
|
<a>
|
|
<xsl:attribute name="href">#<xsl:value-of select="@t"/>
|
|
</xsl:attribute>
|
|
<xsl:value-of select="@t"/>
|
|
</a>
|
|
</xsl:if>
|
|
<xsl:if test="substring(@t,0,3) != 'p_'">
|
|
<xsl:value-of select="@t"/>
|
|
</xsl:if>
|
|
</td>
|
|
<xsl:if test="name(.) = 'r'">
|
|
<td>必填</td>
|
|
</xsl:if>
|
|
<xsl:if test="name(.) = 'o'">
|
|
<td>可选</td>
|
|
</xsl:if>
|
|
<xsl:if test="name(.) = 'loop'">
|
|
<td>循环</td>
|
|
</xsl:if>
|
|
<td>
|
|
<xsl:value-of select="@name"/>
|
|
</td>
|
|
<td>
|
|
<xsl:value-of select="@desc"/>
|
|
</td>
|
|
</tr>
|
|
</xsl:for-each>
|
|
</table>
|
|
</div>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
|
|
<!-- 对msg.c2s的处理 -->
|
|
<xsl:template match="c2s" name="msg_c2s">
|
|
<xsl:param name="sectionName"/>
|
|
<xsl:param name="subsectionName"/>
|
|
<div class="msg_c2s">
|
|
<h1>C->S:(<xsl:value-of select="$sectionName"/>_<xsl:value-of select="$subsectionName"/>_c2s)
|
|
</h1>
|
|
<table cellspacing="0">
|
|
<tr>
|
|
<th width="80px">类型</th>
|
|
<th width="80px">注解</th>
|
|
<th width="80px">名称</th>
|
|
<th>描述</th>
|
|
</tr>
|
|
<!-- 判断是否包含字段 -->
|
|
<xsl:choose>
|
|
<xsl:when test="count(./*) = 0">
|
|
<tr>
|
|
<td colspan="4">无字段</td>
|
|
</tr>
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<xsl:for-each select="*">
|
|
<tr>
|
|
<td>
|
|
<xsl:if test="substring(@t,0,3) = 'p_'">
|
|
<a>
|
|
<xsl:attribute name="href">#<xsl:value-of select="@t"/>
|
|
</xsl:attribute>
|
|
<xsl:value-of select="@t"/>
|
|
</a>
|
|
</xsl:if>
|
|
<xsl:if test="substring(@t,0,3) != 'p_'">
|
|
<xsl:value-of select="@t"/>
|
|
</xsl:if>
|
|
</td>
|
|
<xsl:if test="name(.) = 'r'">
|
|
<td>必填</td>
|
|
</xsl:if>
|
|
<xsl:if test="name(.) = 'o'">
|
|
<td>可选</td>
|
|
</xsl:if>
|
|
<xsl:if test="name(.) = 'loop'">
|
|
<td>循环</td>
|
|
</xsl:if>
|
|
<td>
|
|
<xsl:value-of select="@name"/>
|
|
</td>
|
|
<td>
|
|
<xsl:value-of select="@desc"/>
|
|
</td>
|
|
</tr>
|
|
</xsl:for-each>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</table>
|
|
<br/>
|
|
</div>
|
|
</xsl:template>
|
|
|
|
<!-- 对msg.s2c的处理 -->
|
|
<xsl:template match="s2c" name="msg_s2c">
|
|
<xsl:param name="sectionName"/>
|
|
<xsl:param name="subsectionName"/>
|
|
<div class="msg_s2c">
|
|
<h1>S->C:(<xsl:value-of select="$sectionName"/>_<xsl:value-of select="$subsectionName"/>_s2c)
|
|
</h1>
|
|
<br/>
|
|
<table cellspacing="0">
|
|
<tr>
|
|
<th width="80px">类型</th>
|
|
<th width="80px">注解</th>
|
|
<th width="80px">名称</th>
|
|
<th>描述</th>
|
|
</tr>
|
|
<!-- 判断是否包含字段 -->
|
|
<xsl:choose>
|
|
<xsl:when test="count(./*) = 0">
|
|
<tr>
|
|
<td colspan="4">无字段</td>
|
|
</tr>
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<xsl:for-each select="*">
|
|
<tr>
|
|
<td>
|
|
<xsl:if test="substring(@t,0,3) = 'p_'">
|
|
<a>
|
|
<xsl:attribute name="href">#<xsl:value-of select="@t"/>
|
|
</xsl:attribute>
|
|
<xsl:value-of select="@t"/>
|
|
</a>
|
|
</xsl:if>
|
|
<xsl:if test="substring(@t,0,3) != 'p_'">
|
|
<xsl:value-of select="@t"/>
|
|
</xsl:if>
|
|
</td>
|
|
<xsl:if test="name(.) = 'r'">
|
|
<td>必填</td>
|
|
</xsl:if>
|
|
<xsl:if test="name(.) = 'o'">
|
|
<td>可选</td>
|
|
</xsl:if>
|
|
<xsl:if test="name(.) = 'loop'">
|
|
<td>循环</td>
|
|
</xsl:if>
|
|
<td>
|
|
<xsl:value-of select="@name"/>
|
|
</td>
|
|
<td>
|
|
<xsl:value-of select="@desc"/>
|
|
</td>
|
|
</tr>
|
|
</xsl:for-each>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</table>
|
|
</div>
|
|
</xsl:template>
|
|
|
|
<!-- 匹配整个xml -->
|
|
<xsl:template match="/">
|
|
<html>
|
|
<style type="text/css">
|
|
|
|
.type {
|
|
margin:10px;
|
|
}
|
|
.type table{
|
|
border:1px solid #99ccff;
|
|
}
|
|
.type td{
|
|
padding:3px;
|
|
border-bottom:1px solid #99ccff;
|
|
border-right:1px solid #99ccff;
|
|
border-left:1px solid #99ccff;
|
|
}
|
|
.type th{
|
|
padding:4px;
|
|
background-color:#99ccff;
|
|
}
|
|
|
|
.msg {
|
|
margin:20px 5px 10px;
|
|
}
|
|
.msg .id{
|
|
color:#208822;
|
|
font-weight:bold;
|
|
margin-right:8px;
|
|
}
|
|
.msg .desc{
|
|
font-weight:bold;
|
|
margin-right:8px;
|
|
}
|
|
|
|
.msg_c2s {
|
|
margin-top:3px;
|
|
margin-left:10px;
|
|
}
|
|
.msg_c2s h1{
|
|
font-size:15px;
|
|
font-weight:bold;
|
|
color:#339900;
|
|
}
|
|
.msg_c2s table{
|
|
border:1px solid #66cc00;
|
|
}
|
|
.msg_c2s td{
|
|
padding:3px;
|
|
border-bottom:1px solid #66cc00;
|
|
border-right:1px solid #66cc00;
|
|
border-left:1px solid #66cc00;
|
|
}
|
|
.msg_c2s th{
|
|
padding:4px;
|
|
background-color:#66cc00;
|
|
}
|
|
|
|
.msg_s2c {
|
|
margin-top:3px;
|
|
margin-left:10px;
|
|
}
|
|
.msg_s2c h1{
|
|
font-size:15px;
|
|
font-weight:bold;
|
|
color:#ff6600;
|
|
margin:0;
|
|
padding:0;
|
|
}
|
|
.msg_s2c table{
|
|
border:1px solid #ff9900;
|
|
}
|
|
.msg_s2c td{
|
|
padding:3px;
|
|
border-bottom:1px solid #ff9900;
|
|
border-right:1px solid #ff9900;
|
|
border-left:1px solid #ff9900;
|
|
}
|
|
.msg_s2c th{
|
|
padding:4px;
|
|
background-color:#ff9900;
|
|
}
|
|
|
|
.loopTd td{
|
|
padding:2px;
|
|
padding-left:20px;
|
|
color:#990033;
|
|
}
|
|
.backToIndex{
|
|
margin-left:30px;
|
|
text-decoration:none;
|
|
color:#208822;font-weight:bold;margin-right:8px; border:1px solid #666633;
|
|
}
|
|
.index_title{
|
|
text-decoration:none;
|
|
padding:0px;
|
|
margin:1px; margin-top:3px;
|
|
font-size:16px;font-weight:bold;
|
|
color:#700023;font-weight:bold;margin-right:8px;
|
|
}
|
|
.index_item{
|
|
padding:0px; padding-left:20px;
|
|
margin:1px;
|
|
}
|
|
.index_item a{
|
|
text-decoration:none;
|
|
font-size:12px;
|
|
color:#3a54a3;font-weight:normal;margin-right:8px;
|
|
}
|
|
.index_item span{
|
|
color:#503e53;font-weight:normal;margin-left:5px;
|
|
}
|
|
</style>
|
|
<body>
|
|
<h1>协议文档</h1>
|
|
<h2>协议说明</h2>
|
|
<div>
|
|
<p>
|
|
[c2s]=>
|
|
[2字节包长]+[2字节Uiq(自增序列)65535之后,变为100 ]+[1字节SectionId]+[1字节MethodId]+[body数据]
|
|
<br/>
|
|
[s2c]=>
|
|
[2字节包长]+[1字节SectionId]+[1字节MethodId]+[1字节Zip,1表示进行了压缩,0表示没有压缩]+[body数据]
|
|
<br/>
|
|
所有数据采用big-endian(网络字节序号)
|
|
</p>
|
|
<p>
|
|
可以使用的基本类型
|
|
<br/>
|
|
int32:
|
|
<br/>
|
|
uint32:
|
|
<br/>
|
|
int64:
|
|
<br/>
|
|
uint64:
|
|
<br/>
|
|
double:
|
|
<br/>
|
|
string:
|
|
<br/>
|
|
bool:
|
|
<br/>
|
|
bytes:
|
|
<br/>
|
|
loop节点表示里面内容进行循环(protobuff 中的repeated类型)
|
|
<br/>
|
|
</p>
|
|
<p>
|
|
对于请求(c2s)的应答(s2c),直接将请求中的序列号返回。对于服务器主动
|
|
推送的数据的,序列号为0
|
|
</p>
|
|
<p>
|
|
section 表明消息分类,type属性为此类消息的标识
|
|
<br/>
|
|
msg 为具体的一个消息,包含c2s(请求)和s2c(应答),有些消息包含一个请求一个 应答,有的消息没有请求只有应答(服务器推送)。
|
|
<br/>
|
|
c2s为请求,id为消息id,<f>为对应的字段。
|
|
<br/>
|
|
s2c为应答,id为消息id,<f>定义同c2s。
|
|
</p>
|
|
<p>
|
|
<b>定义协议时推荐字段顺序(从上到下):</b>
|
|
<ol>
|
|
<li>基本类型(int, string)</li>
|
|
<li>自定义类型</li>
|
|
<li>loop</li>
|
|
</ol>
|
|
这样效率会比较高!
|
|
</p>
|
|
<p>
|
|
<b>属性id映射表</b>
|
|
<ul>
|
|
<li>1 - 体质</li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
<a name="index"/>
|
|
<!--目录处理 -->
|
|
<div style="background-color:#eeeeee; width:600px; padding:10px; padding-left:20px;">
|
|
<h2>目录</h2>
|
|
<!--自定义结构-->
|
|
<a class="index_title" target="_self">
|
|
自定义结构
|
|
</a>
|
|
|
|
<xsl:for-each select="protocol/custom_type/type">
|
|
<xsl:variable name="struct_name" select="@name">
|
|
</xsl:variable>
|
|
<p class="index_item">
|
|
<a>
|
|
<xsl:attribute name="href">#<xsl:value-of select="$struct_name"/>
|
|
</xsl:attribute>
|
|
自定义结构:[
|
|
<xsl:value-of select="@desc"/>]
|
|
<span>
|
|
----------------[<xsl:value-of select="$struct_name"/>]
|
|
</span>
|
|
</a>
|
|
</p>
|
|
</xsl:for-each>
|
|
|
|
<xsl:for-each select="protocol/section">
|
|
<a class="index_title" target="_self">
|
|
<xsl:attribute name="href">#<xsl:value-of select="@id"/>
|
|
</xsl:attribute>
|
|
<xsl:value-of select="@desc"/>
|
|
分类Id:<xsl:value-of select="@id"/>
|
|
</a>
|
|
<xsl:variable name="section_id" select="@id">
|
|
</xsl:variable>
|
|
<!-- 显示自定义结构 -->
|
|
<xsl:for-each select="type">
|
|
<xsl:variable name="struct_name" select="@name">
|
|
</xsl:variable>
|
|
<p class="index_item">
|
|
<a>
|
|
<xsl:attribute name="href">#<xsl:value-of select="$struct_name"/>
|
|
</xsl:attribute>
|
|
自定义结构:[
|
|
<xsl:value-of select="@desc"/>]
|
|
<span>
|
|
----------------[<xsl:value-of select="$struct_name"/>]
|
|
</span>
|
|
</a>
|
|
</p>
|
|
</xsl:for-each>
|
|
<!-- 显示消息 -->
|
|
<xsl:for-each select="msg">
|
|
<xsl:variable name="sub_id" select="@id">
|
|
</xsl:variable>
|
|
<p class="index_item">
|
|
<a>
|
|
<xsl:attribute name="href">#<xsl:value-of select="$section_id * 1000 + $sub_id"/>
|
|
</xsl:attribute>
|
|
(<xsl:value-of select="$section_id"/>-<xsl:value-of select="@id"/>)
|
|
<xsl:value-of select="@desc"/>
|
|
<span>
|
|
----------------[<xsl:value-of select="$section_id * 1000 + $sub_id"/>]
|
|
</span>
|
|
</a>
|
|
</p>
|
|
</xsl:for-each>
|
|
</xsl:for-each>
|
|
</div>
|
|
|
|
<!--关于自定义协议 -->
|
|
<xsl:for-each select="protocol/custom_type/type">
|
|
<xsl:variable name="struct_name" select="@name"></xsl:variable>
|
|
<a>
|
|
<xsl:attribute name="name">
|
|
<xsl:value-of select="$struct_name"/>
|
|
</xsl:attribute>
|
|
<xsl:attribute name="id">
|
|
<xsl:value-of select="$struct_name"/>
|
|
</xsl:attribute>
|
|
</a>
|
|
<xsl:call-template name="type">
|
|
<xsl:with-param name="section_id">0</xsl:with-param>
|
|
</xsl:call-template>
|
|
</xsl:for-each>
|
|
|
|
<!--关于各个协议部分 -->
|
|
<xsl:for-each select="protocol/section">
|
|
<a>
|
|
<xsl:attribute name="name">
|
|
<xsl:value-of select="@id"/>
|
|
</xsl:attribute>
|
|
<xsl:attribute name="id">
|
|
<xsl:value-of select="@id"/>
|
|
</xsl:attribute>
|
|
</a>
|
|
<h2>
|
|
<xsl:value-of select="@desc"/>
|
|
分类Id:<xsl:value-of select="@id"/>(<xsl:value-of select="@name"/>)
|
|
</h2>
|
|
<xsl:variable name="section_id" select="@id"></xsl:variable>
|
|
<xsl:variable name="sectionName" select="@name"></xsl:variable>
|
|
<xsl:for-each select="*">
|
|
<xsl:choose>
|
|
<!-- 自定义协议 -->
|
|
<xsl:when test="name(.) = 'type'">
|
|
<xsl:variable name="struct_name" select="@name"></xsl:variable>
|
|
<a>
|
|
<xsl:attribute name="name">
|
|
<xsl:value-of select="$struct_name"/>
|
|
</xsl:attribute>
|
|
<xsl:attribute name="id">
|
|
<xsl:value-of select="$struct_name"/>
|
|
</xsl:attribute>
|
|
</a>
|
|
<xsl:call-template name="type">
|
|
<xsl:with-param name="section_id"><xsl:value-of select="$section_id"/></xsl:with-param>
|
|
</xsl:call-template>
|
|
</xsl:when>
|
|
<!-- 消息定义 -->
|
|
<xsl:when test="name(.) = 'msg'">
|
|
<xsl:variable name="sub_id" select="@id"></xsl:variable>
|
|
<xsl:variable name="subsectionName" select="@name"></xsl:variable>
|
|
<a>
|
|
<xsl:attribute name="name">
|
|
<xsl:value-of select="$section_id * 1000 + $sub_id"/>
|
|
</xsl:attribute>
|
|
<xsl:attribute name="id">
|
|
<xsl:value-of select="$section_id * 1000 + $sub_id"/>
|
|
</xsl:attribute>
|
|
</a>
|
|
<div class="msg">ID:
|
|
<span class="id">(<xsl:value-of select="$section_id"/>-<xsl:value-of select="@id"/>)
|
|
</span>
|
|
<span class="id">(<xsl:value-of select="@name"/>)
|
|
</span>
|
|
<span class="desc">
|
|
<xsl:value-of select="@desc"/>
|
|
</span>
|
|
<a class="backToIndex" target="_self">
|
|
<xsl:attribute name="href">#<xsl:value-of select="$section_id"/>
|
|
</xsl:attribute>
|
|
回分类头部
|
|
</a>
|
|
<a class="backToIndex" href="#index" target="_self">回目录</a>
|
|
|
|
<xsl:for-each select="*">
|
|
<xsl:choose>
|
|
<!-- 处理c2s -->
|
|
<xsl:when test="name(.) ='c2s'">
|
|
<xsl:call-template name="msg_c2s">
|
|
<xsl:with-param name="sectionName" select="$sectionName"/>
|
|
<xsl:with-param name="subsectionName" select="$subsectionName"/>
|
|
</xsl:call-template>
|
|
</xsl:when>
|
|
|
|
<!-- 处理s2c -->
|
|
<xsl:when test="name(.) ='s2c'">
|
|
<xsl:call-template name="msg_s2c">
|
|
<xsl:with-param name="sectionName" select="$sectionName"/>
|
|
<xsl:with-param name="subsectionName" select="$subsectionName"/>
|
|
</xsl:call-template>
|
|
</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:for-each>
|
|
</div>
|
|
</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:for-each>
|
|
</xsl:for-each>
|
|
</body>
|
|
</html>
|
|
</xsl:template>
|
|
|
|
</xsl:stylesheet>
|