FlyRPC,用最少的流量满足最多的需求。
go get gopkg.in/flyrpc.v1
Name | Length | Flag | Transfer Flag | Sequence | CMD Len | CMD | Buffer | CRC16 |
---|---|---|---|---|---|---|---|---|
Bytes | 2 | 1 | 1 | 2 | 1 | * | * | 2 |
消息长度 | 标志位 | 传输控制位 | 序列ID | 命令长度 | 命令ID | 消息体 | 校验 |
子协议 | 控制位 |
---|---|
2 bit | 6 bit |
子协议 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---|---|---|---|---|---|---|---|---|
RPC | 1 | 1 | ? | CRC16 | Buffer | Error | Resp | Req |
Ping | 1 | 0 | ? | CRC16 | ? | ? | Pong | Ping |
Helo | 0 | 1 | ? | CRC16 | ? | ? | ? | ? |
MQ | 0 | 0 | ? | CRC16 | ? | ? | ? | ? |
CRC16 允许加盐
Transfer Flag 0x00 should be plain
json
.
Not complete.
Design A
Accept Encoding | Encoding | Accept Serializer | Serializer |
---|---|---|---|
2 bits | 2 bits | 2 bits | 2 bits |
Up to 4 encoding and 4 serializer.
Design B
Encoding | Serializer |
---|---|
2 bits | 2 bits |
If HELO, it means Accept-Encoding and Accept-Serializer
Up to 16 encoding and 16 serializer. (Who need 16 encoding and 16 serializer)
如果Error
为1
,Buffer
为 string
Client count | Client Id 1 | ... | Client Id n | Buffer Length | Buffer |
---|---|---|---|---|---|
1 byte | 2 byte | ... | 2 byte | 2byte | n byte |
- [OK]Send/Recv
- [OK]Req/Res
- Pub/Sub
- [OK]TCP
- UDP
- Websocket
- P2P
- 数据压缩
- [OK]自定义
- [OK]json
- [OK]protobuf (proto3)
- [OK]msgpack
- Gateway Node
- Backend Node
MessageHandler 可以有以下几种形式的参数的组合或无参数
- *Context
- *Packet
- []byte
- *UserCustomMessage
返回可以是:
- UserCustomMessage
- UserCustomMessage, error
- non return
- error
// 有返回值,用于处理Call
func(*Context, in MyMessage) (out Message, err error)
func(*Packet, in MyMessage) out Message
// 无返回值,用于处理SendMessage
func(bytes []byte) err error
func()
type ClientStub struct {
foo func(a) b `flyid:1`
}
rpc := &ClientStub{}
client.InjectService(rpc)
b := rpc.foo(a)
TCP/UDP/WS Packet json/protobuf/msgpack
| + + + |
| | | | |
-->Protocol ------ | | Serializer <--
+ ------- | +
| | ----Route --------
| | | *+
| | | |
| | | Router
| | | + +
------- | | ---- |
1*| | + | |
--->Context |
|transport+* |
| ------ |
| | |
-->Client Server<-- MultiplexedServer<--
| | |
| | |
TCP/UDP/WS TCP/UDP/WS TCP/UDP/WS
- * 多实例
- --> 继承或实现
- + 被引用