Contenu connexe Similaire à ソシャゲにおけるサーバとクライアントの決めごと (20) ソシャゲにおけるサーバとクライアントの決めごと9. データ形式
XML : 肥大化して遅くなりがち
JSON : 可読性よい。割りと小さい
MessagePack : バイナリ。小さく速い
RPC : どうしても使いたかったら
独自シリアライズ : 大変
MessagePackおすすめです
10. データ形式
<?xml version="1.0" encoding="UTF-8" ?>
<user_id>123456</user_id>
<name>hogehoge</name>
<age>20</age>
{"user_id":123456,
"name":"hogehoge",
"age":20}
83 a7 75 73 65 72 5f 69 64 ce 00 01 e2 40
a4 6e 61 6d 65 a8 68 6f 67 65 68 6f 67 65 a3
61 67 65 14 0a
XML
102 byte
JSON
51 byte
50%削減
MessagePack
34 byte
67%削減
24. プロトコルのコンバート
プロトコルの管理方法
{
“request”: {
“user_id”: {“type”: “int”, “comment”: “ユーザーID"}
},
"response": {
"result": {"type": "int", "comment": "結果"}
}
}
public class UserReq {
public int userId;
}
public class UserRes {
public int result;
}
public class MessageUserRequest {
public int UserId { get; set; }
}
public class MessageUserResponse {
public override int Result { get; set; }
}
25. 定数のコンバート
プロトコルの管理方法
STATE_SEND_REQUEST,0,,フレンド未登録,
STATE_RECV_REQUEST,1,,申請中,
STATE_ACCEPTED,2,,フレンド登録済,
public final class ConstFriend {
public static final int STATE_SEND_REQUEST = 0;
public static final int STATE_RECV_REQUEST = 1;
public static final int STATE_ACCEPTED = 2;
}
public static class ConstFriend {
public const int STATE_SEND_REQUEST = 0;
public const int STATE_RECV_REQUEST = 1;
public const int STATE_ACCEPTED = 2;
}
26. マスタのコンバート
プロトコルの管理方法
id name rarity type
1 ゴブリン 1 1
2 ドラゴン 2 2
INSERT INTO `data_monsters` (`id`, `name`,
`rarity`, `type`) VALUES
(1, ‘ゴブリン’, 1, 1),
(2, ‘ドラゴン’, 2, 2);
1,ゴブリン,1,1
2,ドラゴン,2,2
DB
配信用
アセット