public override void ChannelRead(IChannelHandlerContext context, object message) { IByteBuffer buffer = (IByteBuffer)message; try { byte[] data = new byte[buffer.ReadableBytes]; buffer.GetBytes(buffer.ReaderIndex, data); string datajson = LZ4MessagePackSerializer.ToJson(data); var convertedMsg = _serializer.Deserialize <string, TransportMsg>(datajson); if (convertedMsg.ContentType == typeof(RemoteCallData).FullName) { convertedMsg.Content = _serializer.Deserialize <object, RemoteCallData>(convertedMsg.Content); } else if (convertedMsg.ContentType == typeof(RemoteCallBackData).FullName) { convertedMsg.Content = _serializer.Deserialize <object, RemoteCallBackData>(convertedMsg.Content); } context.FireChannelRead(convertedMsg); } finally { buffer.Release(); } }
string ToJson(byte[] bytes) { if (bytes == null || bytes.Length == 0) { return(""); } return("dump:" + LZ4MessagePackSerializer.ToJson(bytes)); }
public static void Save(string path) { var phibl = UnityEngine.Object.FindObjectOfType <PHIBL>(); var bin = LZ4MessagePackSerializer.Serialize(phibl.Snapshot(), CustomCompositeResolver.Instance); File.WriteAllBytes(path, bin); Console.WriteLine(LZ4MessagePackSerializer.ToJson(bin)); }
public static void Load(string path) { var phibl = UnityEngine.Object.FindObjectOfType <PHIBL>(); var bin = File.ReadAllBytes(path); Console.WriteLine(LZ4MessagePackSerializer.ToJson(bin)); var profile = LZ4MessagePackSerializer.Deserialize <Profile>(bin, CustomCompositeResolver.Instance); phibl.StartCoroutine(phibl.RestoreStat(profile)); }
public OperationRequest DeserializeOperationRequest(byte[] deserial) { Debug.Log(LZ4MessagePackSerializer.ToJson(deserial)); var msg = LZ4MessagePackSerializer.Deserialize <OperationRequestMsg>(deserial); //TODO Log Message var test = msg.opReq; Debug.Log(test); return(test); }
public static void AddTempItem <T>(T item) where T : Item { Dictionary <string, T> dic = Instance.GetTempDictionary <T>(); do { item.Id = GetNextTempId(item.Id); }while (dic.ContainsKey(item.Id)); Debug.Log("Try Add Temp Item: " + LZ4MessagePackSerializer.ToJson <T>(item, HeluoResolver.Instance)); dic.Add(item.Id, item); }
public void SendEvent(int conn, byte[] serializedmsg, int channel) { //TODO Log Message Debug.Log(LZ4MessagePackSerializer.ToJson(serializedmsg)); var data = new ByteMessage() { Data = serializedmsg }; NetworkServer.SendToClient(conn, (byte)RtsMessageType.Event, data); }
string ToJson(byte[] bytes) { if (bytes == null || bytes.Length == 0) { return(""); } if (bytes.Length >= 5000) { return("log is too large."); } return("dump:" + LZ4MessagePackSerializer.ToJson(bytes)); }
public void SendOpResponse(int conn, byte[] serializedmsg, int channel) { //TODO Log Message Debug.Log(LZ4MessagePackSerializer.ToJson(serializedmsg)); var data = new ByteMessage() { Data = serializedmsg }; NetworkServer.SendToClient(conn, (byte)RtsMessageType.OperationResponse, data); //TODO Log Message Debug.Log("Message Sent"); }
string ToJson(ArraySegment <byte> bytes) { if (bytes == null || bytes.Count == 0) { return(""); } if (bytes.Count >= 5000) { return("log is too large."); } return("dump:" + LZ4MessagePackSerializer.ToJson(bytes)); }
public byte[] SerializeOperationResponse(OperationResponse operationResponse, SendParameters parameterstemp) { var sessionid = parameterstemp.SessionId; //TODO Log Message Debug.Log("Serializing Message"); var msg = new OperationResponseMsg { opResp = operationResponse }; var serializedmsg = LZ4MessagePackSerializer.Serialize(msg); Debug.LogFormat("Serialized Message: {0}", LZ4MessagePackSerializer.ToJson(serializedmsg)); return(serializedmsg); }
public void LZ4MessagePackSerializer_Test1() { var array = Enumerable.Range(1, 100).Select(x => new MyClass { Age = 5, FirstName = "foo", LastName = "bar" }).ToArray(); // call LZ4MessagePackSerializer instead of MessagePackSerializer, api is completely same var lz4Bytes = LZ4MessagePackSerializer.Serialize(array); var mc2 = LZ4MessagePackSerializer.Deserialize <MyClass[]>(lz4Bytes); // you can dump lz4 message pack // [[5,"hoge","huga"],[5,"hoge","huga"],....] var json = LZ4MessagePackSerializer.ToJson(lz4Bytes); Console.WriteLine(json); // lz4Bytes is valid MessagePack, it is using ext-format( [TypeCode:99, SourceLength|CompressedBinary] ) // [99,"0gAAA+vf3ABkkwWjZm9vo2JhcgoA////yVBvo2Jhcg=="] var rawJson = MessagePackSerializer.ToJson(lz4Bytes); Console.WriteLine(rawJson); }
string JsonConvertLZ4(string json) { return(LZ4MessagePackSerializer.ToJson(LZ4MessagePackSerializer.FromJson(json))); }
/// <summary> /// 对象直接转json的byte[] /// </summary> /// <typeparam name="T"></typeparam> /// <param name="obj"></param> /// <returns></returns> public static byte[] JSONObjectToBytes <T>(T obj) { Init(); return(LZ4MessagePackSerializer.FromJson(LZ4MessagePackSerializer.ToJson <T>(obj))); }
/// <summary> /// 对象转json字符串 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="obj"></param> /// <returns></returns> public static string JSONObjectToString <T>(T obj) { Init(); return(LZ4MessagePackSerializer.ToJson <T>(obj)); }
/// <summary> /// byte[]转json字符串 /// </summary> /// <param name="json"></param> /// <returns></returns> public static string JSONBytesToString(byte[] json) { Init(); return(LZ4MessagePackSerializer.ToJson(json)); }
private void IncomingSessionHandler(NetworkMessage msg) { var peer = msg.conn.connectionId; var byteArray = msg.ReadMessage <ByteMessage>(); var recievedBytes = byteArray.Data; var deserial = _noc.DeserializeSession(recievedBytes); //TODO Log Message Debug.Log(LZ4MessagePackSerializer.ToJson(deserial)); // SendOperationResponse(new OperationRequest((byte) ServerOperationCode.AckClientUserLogin, // new AckClientUserLogin // { // SessionId = peer, // Username = userData.Username // }), // new SendParameters()); //---------------------- Session Response -------------------- var sessionID = peer; var opCode = (byte)RtsMessageType.OperationResponse; var opresponse = (byte)ResultCode.Ok; var ChannelID = PeerSettings.MmoObjectEventChannel; var debug = "Something goofed"; this.LoginData = new ClientLoginData { ClientId = 151, Username = "******", CharacterName = "instance.id" }; SendEvent( new EventData((byte)ClientEventCode.CharacterLoggedIn, new Dictionary <byte, object> { { (byte)ParameterCode.CharacterName, this.LoginData.CharacterName } }), new SendParameters { SessionId = sessionID }); //---------------------- Add Session ---- -------------------- var param = deserial.parameters; var charName = param[22]; var condition = param[59]; var Parameters = new Dictionary <byte, object> { { (byte)ParameterCode.SessionId, peer }, { (byte)ParameterCode.CharacterName, charName }, { (byte)ParameterCode.Condition, condition }, //{(byte)0, masterPeer.ClientId}, }; // _worldServerPeer.OnServerEvent( // new EventData(deserial.sessActionTemp, Parameters), // new SendParameters // { // SessionId = peer, // //ClientId = masterPeer.ClientId // }); Debug.Log("Sent"); }
string JsonConvertLZ4(string json) { return(lz4Serializer.ToJson(lz4Serializer.FromJson(json))); }