协议说明

一、概述

在不同的语境下,协议有不同的含义。
FPNN 是基于 TCP 之上的 2 进制私有协议。

根据场景的不同,FPNN 协议分为以下3个层次:
封包协议、编码协议、接口协议。

二、FPNN 封包协议

FPNN 封包协议,即一般泛指的 FPNN 协议。是对经过编码协议编码后的数据,组装成可在 TCP 协议之上传输的数据包的约定。

FPNN 封包协议细节如下

 0 1 2 3 4 5 6 7 8 9 a b c d e f 0 1 2 3 4 5 6 7 8 9 a b c d e f
 +----------------------------------------------------------------+
 |                             MAGIC                              |
 +----------------------------------------------------------------+
 |      VERSION  |       FLAG     |      Mtype    | Size o Status |
 +----------------------------------------------------------------+
 |                     PAYLOAD Size                               |
 +----------------------------------------------------------------+ 
 |                    ?SEQUENCE NUMBER                            |
 +----------------------------------------------------------------+                
 |                      ?Method Name                              |
 |                      AND                                       |
 |                      ?PAYLOAD                                  |
 +----------------------------------------------------------------+


 1, MAGIC
	1) FPNN
	2) POST
	3) GET

2, VERSION
	Max 255

3, FLAG
	first 2 bits: 10, msgpack, 01 raw json, 11 not used

4, Mtype
	1) oneway: 0
	2) twoway: 1
	3) answer: 2

5, Size OR Status
	if reqeust or oneway, this field mean method name length
	if answer message, this field mean status, 0 is ok, other is error.

6, PAYLOAD Size(little endian byte order)
	PAYLOAD length

7, SEQUENCE NUMBER(little endian byte order)
	only valid for twoway and answer, if oneway, do not have this field
	range: 0– 4294967296,some language not support unsigned
	one server have unique seq id, atomic<uint32_t>, start with 1
	!!!!should not have the same id.

8, Method name
	max length is 255, if answer, do not have this field

9, PAYLOAD  (We will not unpack data until you require the field)
	1) raw json (UTF-8)
	2) msgpack data

10, 
	This format only for FPNN, if POST or GET, then think it as HTTP protocol.

11, HTTP
	only support raw json (UTF-8),  set flags in header or cookie to identify it.

12, TCP
	support msgpack, raw json (UTF-8).

三、FPNN 编码协议

FPNN 仅支持两种编码协议:

四、FPNN 接口协议

接口协议,即对各个服务接口调用的参数与方式的约定。

FPNN 支持可选参数,且对参数顺序,没有要求。

因 FPNN 协议可与 JSON 等价互转,因此可以使用类似于 JSON 的格式进行描述。

接口描述格式说明:

标识 说明
=> 请求
<= 回复
~ oneway 请求(无回复)
? 可选参数
[] 列表
{} 字典
% 格式标识

参数格式说明:

标识 说明
b 布尔型
B Blob 类型
d, i 整形
f 浮点型
s 字符串
x b, B, d, i, f, s 某种类型
X b, B, d, i, f, s, 列表, 字典 某种类型