iohao / ioGame

无锁异步化、事件驱动架构设计的 java netty 网络编程框架; 轻量级,无需依赖任何第三方中间件或数据库就能支持集群、分布式; 适用于网络游戏服务器、物联网、内部系统及各种需要长连接的场景; 通过 ioGame 你可以很容易的搭建出一个集群无中心节点、集群自动化、分布式的网络服务器;FXGL、Unity、UE、Cocos Creator、Godot、Netty、Protobuf、webSocket、tcp、socket;java Netty 游戏服务器框架; Java Netty Game Server.
http://game.iohao.com
GNU Affero General Public License v3.0
920 stars 205 forks source link

[Feature] Json format data response #395

Closed duongxinh2003 closed 2 weeks ago

duongxinh2003 commented 2 weeks ago

新增功能的使用场景

When you use JsonDataCodec for codec protocol, you must convert byte array to JSON data and use it. For example: A request you send from the client has pattern (following by example github example ):

{"cmdCode":1,"cmdMerge":1245185,"data":{"name":"英雄无敌-3"}}
  1. The response data is a byte array: [123,34,110,...]
  2. The first convert byte data is:
    {
    "cmdCode": int,
    "cmdMerge": int,
    "data": byte[],
    "msgId": int,
    "protocolSwitch": int,
    "responseStatus": int
    }

    You must convert this byte[] at data field to use it. It takes 2 times to transform data in the client to use it, you can convert data to JSON and serialize it before sending to the client instead. Example:

    {
    "cmdCode": int,
    "cmdMerge": int,
    "data": {"name": String}
    "msgId": int,
    "protocolSwitch": int,
    "responseStatus": int
    }
iohao commented 2 weeks ago

By default, you can get a unified behavior, which can be well compatible when switching protocols, such as switching between json, prootbuf, or other protocols.

If the situation is special, it is recommended to rewrite MessageToMessageCodec to implement this part of the customization.

duongxinh2003 commented 2 weeks ago

I closed the issue because some languages have libraries that can convert directly like Java, C#,...