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)); }
private ByteList ParseToDic(ByteList data) { var length = data.DropInt32(); for (int i = 0; i < length; i++) { var size = data.DropInt32(); var str = data.DropString(0, size); Serializer.GetTypeId(str); } return(data); }
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()); } }
/// <summary> /// [総情報長] /// </summary> /// <param name="filename"></param> /// <returns></returns> private ByteList ReadFromFile(string filename) { string path = DataPath(filename); FileStream fs_r = new FileStream(path, FileMode.Open, FileAccess.Read); if (mDataStack.Count == 0 || fs_r.CanRead == false) { return(null); } fs_r.Read(buf, 0, sizeof(int)); ByteList data = new ByteList(); var data_size = System.BitConverter.ToInt32(buf, 0); byte[] b = new byte[data_size]; fs_r.Read(b, sizeof(int), data_size); data.AddRange(b); return(data); }
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)); }
public ByteList Add(ByteList obj) { AddRange(obj); return(this); }
public static CheckedRet <object> Deserialize(ByteList bytes) { return(Instance.Implement.Deserial(bytes)); }
public static ByteList ToUTF8Lst(this string str) { return(ByteList.Gen().Add(Encoding.UTF8.GetBytes(str))); }
public static string ToUTF8String(this ByteList bytes) { return(Encoding.UTF8.GetString(bytes.ToArray())); }
private bool CheckHash(ByteList data) { throw new System.NotImplementedException(); }