/// <summary> /// 登録された手続を使ってオブジェクトを直列化する /// 基本的に [型番号] [[情報長]情報]です。 /// </summary> public ByteList ToSerial(object obj) { var ms = new MemoryStream(); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(ms, obj); var arr = ByteList.Gen().Add(ms.ToArray()); return(arr); }
public ByteList GetTypeList(List <string> list) { var count = list.Count; var bytes = ByteList.Gen().Add(count); foreach (var t in list) { bytes.Add(ToSerial(t)); } return(bytes); }
public static ByteList Serial(object obj) { var bytes = ByteList.Gen(); var arr = (Array)obj; bytes.Add(arr.Length); foreach (var e in arr) { bytes.Add(Serializer.Serialize(e)); } return(bytes); }
public static ByteList Serial(object obj) { var bytes = ByteList.Gen(); var arr = (Dictionary <object, object>)obj; bytes.Add(arr.Count); foreach (var e in arr) { bytes.Add(Serializer.Serialize(e.Key)); bytes.Add(Serializer.Serialize(e.Value)); } return(bytes); }
public string String_Test_Int1() { int num = 1; int target = 1; Serializer.SetDatatype(Serializer.SerialType.String); var bytes = Serializer.Serialize(num); var arr = bytes.ToArray(); var arr2 = ByteList.Gen() .Add(System.BitConverter.GetBytes(Serializer.GetTypeId(0.GetType().Name).Value)) .Add(System.BitConverter.GetBytes(target)).ToArray(); if (arr.Length != arr2.Length) { return(Fail("Failed convert ({0},{1})", arr.Length, arr2.Length)); } for (int i = 0; i < arr.Length; i++) { if (arr [i] != arr2 [i]) { return(Fail("Failed bytes in {0}", i)); } } var s2 = Serializer.Deserialize <int>(bytes); if (s2.Key == false) { return(Fail("Faild deserialize" + s2.ToJson())); } if (s2.Value != target) { return(Fail("Faild deserialize" + s2.ToJson())); } return(Pass()); }
public static ByteList Serial(object obj) { return(ByteList.Gen().Add(BitConverter.GetBytes((Int32)obj))); }
public static ByteList Serial(object obj) { var data = BitConverter.GetBytes((Single)obj); return(ByteList.Gen().Add(data.Length).Add(data)); }