void Start() { LoginReq model1 = new LoginReq() { username = "******", password = "******" }; // 序列化 byte[] req = Util.Serialize(model1); Debug.Log(System.BitConverter.ToString(req)); // 模拟打包 byte[] data = MessageParse.Parse(1, Consts_CommandId.C2S_Login, req); // -------------------- // 网络传输...... // -------------------- // 模拟解包 MessageData res = MessageParse.Unparse(data); // 反序列化 LoginReq model2 = Util.Deserialize <LoginReq>(res.body.msg); // 查看结果 Debug.Log("commandId : " + res.body.commandId); Debug.Log("username : "******"password : " + model2.password); }
public void SendMsg <T>(int commandId, T data) { // -----------Protobuf----------- byte[] msg = Util.Serialize <T>(data); byte[] sendBytes = MessageParse.Parse(SERVERVERSION, commandId, msg); NetManager.Send(sendBytes); }
// 发送数据 参数 数据 + 命令号 public void SendMsg <T>(T data, int iCommand) where T : Data_Base { string sJson = LitJson.JsonMapper.ToJson(data); Debug.LogWarning(string.Format("::OnSend:{0} ,{1}", iCommand, sJson)); byte[] sendBytes = MessageParse.Parse(SERVERVERSION, iCommand, sJson); Globals.It.NetManager.Send(sendBytes); // 转交给 网络管理类 处理 }
/// <summary> /// 初始化 /// </summary> /// <param name="connectionGuid">服务器链接标识</param> /// <param name="eventName">事件名</param> /// <param name="privateMsgArgs">私聊消息事件参数</param> internal PrivateMessageEventArgs(Guid connectionGuid, string eventName, ApiPrivateMsgEventArgs privateMsgArgs) : base(connectionGuid, eventName, privateMsgArgs.SelfID, privateMsgArgs.Time) { //将api消息段转换为CQ码 this.Message = new Message(connectionGuid, privateMsgArgs.MessageId, privateMsgArgs.RawMessage, MessageParse.Parse(privateMsgArgs.MessageList), privateMsgArgs.Time, privateMsgArgs.Font, null); this.Sender = new User(connectionGuid, privateMsgArgs.UserId); this.SenderInfo = privateMsgArgs.SenderInfo; }
/// <summary> /// 初始化 /// </summary> /// <param name="connectionGuid">服务器链接标识</param> /// <param name="eventName">事件名</param> /// <param name="groupMsgArgs">群消息事件参数</param> internal GroupMessageEventArgs(Guid connectionGuid, string eventName, ApiGroupMsgEventArgs groupMsgArgs ) : base(connectionGuid, eventName, groupMsgArgs.SelfID, groupMsgArgs.Time) { this.IsAnonymousMessage = groupMsgArgs.Anonymous != null; //将api消息段转换为CQ码 this.Message = new Message(connectionGuid, groupMsgArgs.MessageId, groupMsgArgs.RawMessage, MessageParse.Parse(groupMsgArgs.MessageList), groupMsgArgs.Time, groupMsgArgs.Font, groupMsgArgs.MessageSequence); this.Sender = new User(connectionGuid, groupMsgArgs.UserId); this.SourceGroup = new Group(connectionGuid, groupMsgArgs.GroupId); this.SenderInfo = groupMsgArgs.SenderInfo; this.Anonymous = IsAnonymousMessage ? groupMsgArgs.Anonymous : null; }
/// <summary> /// 处理消息节点的消息为CQCode /// </summary> public void ParseNode() { this.NodeMsgList.ForEach(node => node.CQCodeMsgList = MessageParse.Parse(node.MessageList)); }
// 发送消息 public void SendMsg(int commandId) { // -----------只有命令,没有消息----------- byte[] sendBytes = MessageParse.Parse(SERVERVERSION, commandId); NetManager.Send(sendBytes); }