public static CheckedRet <V> TryGet <K, V> (this Dictionary <K, V> dic, K key) { var r1 = default(V); var r2 = dic.TryGetValue(key, out r1); return(CheckedRet <V> .Gen(r2, r1)); }
private static bool OnRecieve(byte [] receved, IPEndPoint sender) { var test = Msg.Gen().Set(Msg.TO, "Debug") .Set(Msg.ACT, "log").Set("what", "get 798789789--------"); test.Pool(); if (receved.Length < 1) { return(false); } CheckedRet <Msg> obj = null; try { Serializer.SetDatatype(Serializer.SerialType.Binary); obj = Serializer.Deserialize <Msg>(ByteList.Zero.Add(receved)); if (obj.Key == false) { throw new UnDeserializableException(); } } catch (Exception e) { DebugLog.Log.Print(e.ToString()); Msg.Gen().Set(Msg.TO, "Debug"). Set(Msg.ACT, "log") .Set(Msg.MSG, "UnDeserializableException").Pool(); throw new UnDeserializableException(); } obj.Value.Set("From", "" + NetowrkUtil.GetOwnIP()).Pool(); Msg.Gen().Set(Msg.TO, "Debug").Set(Msg.ACT, "log") .Set(Msg.MSG, "receice ok:" + obj.Value.ToJson()).Pool(); DebugLog.Log.Print("test1 => " + obj.Value.ToJson()); return(true); }
public static CheckedRet <object> Deserial(ByteList bytes) { var size = bytes.DropInt32(); if (bytes.Count != size) { return(CheckedRet <object> .Fail()); } var ret = new Trfm(); for (int i = 0; i < 3; i++) { var _size = bytes.DropInt32(); var _bytes = bytes.DropRange(0, _size); var _obj = Serializer.Deserialize <Vec3>(_bytes); if (_obj.Key == false) { return(CheckedRet <object> .Fail()); } ret.mVal [i] = _obj.Value; } // 小数点に関わるため、ハッシュチェックはしない(できない) return(CheckedRet <object> .Gen(true, ret)); }
public CheckedRet <T> Pop() { if (Count < 1) { return(CheckedRet <T> .Fail()); } var r = this [0]; RemoveAt(0); return(CheckedRet <T> .Gen(true, r)); }
public static CheckedRet <T> ParseEnum <T> (this string str) where T : struct { var arr = StEnum.ToArray <T>(); foreach (var e in arr) { if (e.ToString() != str) { continue; } return(new CheckedRet <T>().Set(true, e)); } return(CheckedRet <T> .Fail()); }
public void Setup() { mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); var recv_ip = NetowrkUtil.GetOwnIP(); Debug.Log("Observe IP = " + recv_ip); Debug.Log("Observe Port = " + mReceivePort); mSocket.Bind(new IPEndPoint(IPAddress.Any, mReceivePort)); var sender = new IPEndPoint(IPAddress.Any, 0) as EndPoint; ThreadManager.Get().Work("SocketUDPReceiver Setup", null, (e) => { if (mSocket == null) { System.Threading.Thread.Sleep(10); return(ThreadState.Continue); } Msg.Gen().Set(Msg.TO, "Debug").Set(Msg.ACT, "log") .Set(Msg.MSG, "Recv").Pool(); byte [] buffer = new byte [2500]; int size = mSocket .ReceiveFrom(buffer, 0, 2499, SocketFlags.None, ref sender); if (size < 1) { return(ThreadState.Continue); } Serializer.SetDatatype(Serializer.SerialType.Binary); CheckedRet <Msg> ret = null; try { var buf = ByteList.Zero.Add(buffer); var count = buffer.Length - size; buf.RemoveRangeBase(size, count); ret = Serializer.Deserialize <Msg>(buf); } catch { Msg.Gen().Set(Msg.TO, "Debug").Set(Msg.ACT, "log") .Set(Msg.MSG, "get FAIL").Pool(); } Debug.Log("ret.Key" + ret.Key); if (ret.Key == false) { return(ThreadState.Continue); } ret.Value.Set("From", sender.AddressFamily.ToString()).Pool(); return(ThreadState.Continue); }); }
public static CheckedRet <T> Deserialize <T> (ByteList bytes) { var v = Instance.Implement.Deserial(bytes); if (v.Key == false) { return(CheckedRet <T> .Fail()); } try { var val = (T)v.Value; return(CheckedRet <T> .Gen(true, val)); } catch (Exception e) { DebugLog.Error.Print("parse fail<{0}>{1}", typeof(T).Name, e); return(CheckedRet <T> .Fail()); } }
public static LifedThread Get() { DeadTimeUpdate(); Assert.IsTrue(Instance.Enable, "Must contain the LifedThreadManager in this scene."); if (Instance.ThreadDeadTime < 1) { Instance.ThreadDeadTime = DateTime.Now.Ticks * 10; } lock (Instance.mLock) { CheckedRet <LifedThread> ret = null; lock (Instance.mLock) { ret = Instance.mUnWorking.Pop(); } if (ret.Key != false) { return(ret.Value); } Instance.PoolFill(2); lock (Instance.mLock) { ret = Instance.mUnWorking.Pop(); } return(ret.Value); } }
public static CheckedRet <object> Deserial(ByteList bytes) { var size = bytes.DropInt32(); if (bytes.Count != size) { return(CheckedRet <object> .Fail()); } var ret = new Vec3(); for (int i = 0; i < 3; i++) { ret.mVal [i] = bytes.DropFloat(); } int hash = bytes.DropInt32(); if (hash != ret.GetHashCode()) { return(CheckedRet <object> .Fail()); } return(CheckedRet <object> .Gen(true, ret)); }
public static CheckedRet <object> Deserial(ByteList bytes) { var size = bytes.DropInt32(); if (bytes.Count != size) { throw new Exception("1"); // return CheckedRet<object>.Fail(); } var ret = new Msg(); var dic_size = bytes.DropInt32(); for (int i = 0; i < dic_size; i++) { var k_l = bytes.DropInt32(); var k = Serializer.Deserialize <string>(bytes.DropRange(0, k_l)); if (k.Key == false) { throw new Exception("5"); } var v_l = bytes.DropInt32(); var v = Serializer.Deserialize <string>(bytes.DropRange(0, v_l)); if (v.Key == false) { throw new Exception("6"); } ret.Set(k.Value, v.Value); } var data_size = bytes.DropInt32(); var h_s = 0; if (data_size < 4) { h_s = bytes.DropInt32(); if (ret.GetHashCode() != h_s) { throw new Exception("2:" + ret.ToJson()); } return((ret.GetHashCode() != h_s) ? CheckedRet <object> .Fail() : CheckedRet <object> .Gen(true, ret)); } var data_bytes = bytes.DropRange(0, data_size); var obj = Serializer.Deserialize <object>(data_bytes); if (obj.Key == false) { throw new Exception("3"); //return CheckedRet<object>.Fail(); } ret.mObjectData = obj.Value; h_s = bytes.DropInt32(); if (ret.GetHashCode() != h_s) { throw new Exception("4"); } return((ret.GetHashCode() != h_s) ? CheckedRet <object> .Fail() : CheckedRet <object> .Gen(true, ret)); }